|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef ABSTRACT_LIN_ALG_OP_PACK_H 00030 #define ABSTRACT_LIN_ALG_OP_PACK_H 00031 00032 #include "AbstractLinAlgPack_Types.hpp" 00033 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp" 00034 #include "AbstractLinAlgPack_VectorMutable.hpp" 00035 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00036 #include "AbstractLinAlgPack_AssertOp.hpp" 00037 00038 namespace LinAlgOpPack { 00039 00041 typedef AbstractLinAlgPack::size_type size_type; 00043 typedef AbstractLinAlgPack::value_type value_type; 00044 00046 using AbstractLinAlgPack::VectorSpace; 00048 using AbstractLinAlgPack::Vector; 00050 using AbstractLinAlgPack::VectorMutable; 00052 using AbstractLinAlgPack::MatrixOp; 00054 using AbstractLinAlgPack::MatrixNonsing; 00056 using AbstractLinAlgPack::MatrixOpNonsing; 00057 00058 // Inject names of base linear algebra functions for DenseLinAlgPack. 00059 // Note that this is neccesary in MS VC++ 5.0 because 00060 // it does not perform name lookups properly but it 00061 // is not adverse to the standard so it is a portable 00062 // fix. 00064 using AbstractLinAlgPack::sum; 00066 using AbstractLinAlgPack::dot; 00068 using AbstractLinAlgPack::Vp_S; 00070 using AbstractLinAlgPack::Vt_S; 00072 using AbstractLinAlgPack::Vp_StV; 00074 using AbstractLinAlgPack::Vp_StMtV; 00076 using AbstractLinAlgPack::Mt_S; 00078 using AbstractLinAlgPack::Mp_StM; 00080 using AbstractLinAlgPack::Mp_StMtM; 00082 using AbstractLinAlgPack::syrk; 00084 using AbstractLinAlgPack::V_InvMtV; 00086 using AbstractLinAlgPack::M_StInvMtM; 00087 00104 00116 00121 template <class V> 00122 void Vp_V(VectorMutable* v_lhs, const V& V_rhs); 00123 00128 template <class V> 00129 void assign(VectorMutable* v_lhs, const V& V_rhs); 00130 00135 template <class V> 00136 void V_StV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs); 00137 00142 template <class V> 00143 void V_mV(VectorMutable* v_lhs, const V& V_rhs); 00144 00146 00150 template <class V1, class V2> 00151 void V_VpV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2); 00152 00157 template <class V1, class V2> 00158 void V_VmV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2); 00159 00164 template <class V> 00165 void V_StVpV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs1 00166 , const Vector& vs_rhs2); 00167 00168 // end Level 1 BLAS for Vectors 00170 00171 // ////////////////////////////////////////////////////////////////////////////// 00172 // /////////////////////////////////////////////////////////////////////////////// 00184 00189 void Mp_M(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs); 00190 00191 // end += operations 00193 00198 void assign(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs); 00199 00204 void M_StM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs 00205 , BLAS_Cpp::Transp trans_rhs); 00206 00211 void M_mM(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) ; 00212 00214 00218 void M_MpM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00219 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2); 00220 00225 void M_MmM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00226 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2); 00227 00232 void M_StMpM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00233 , const MatrixOp& gms_rhs2, BLAS_Cpp::Transp trans_rhs2); 00234 00235 // end Level 1 BLAS for Matrices 00237 00238 // ////////////////////////////////////////////////////////////////////////////// 00239 // /////////////////////////////////////////////////////////////////////// 00247 00252 template <class V> 00253 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00254 , const V& V_rhs2); 00255 00260 template <class V> 00261 void V_StMtV(VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00262 , BLAS_Cpp::Transp trans_rhs1, const V& V_rhs2); 00263 00268 template <class V> 00269 void V_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00270 , const V& V_rhs2); 00271 00272 // end Level 2 BLAS 00274 00275 // ////////////////////////////////////////////////////////////////////////////// 00276 // ////////////////////////////////////////////////////////////////////////////// 00284 00289 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00290 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2); 00291 00296 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00297 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta); 00298 00303 void M_StMtM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs1 00304 , BLAS_Cpp::Transp trans_rhs1, const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2); 00305 00310 void M_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1 00311 , BLAS_Cpp::Transp trans_rhs1, const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2); 00312 00313 // end Level 3 BLAS 00315 00316 // end Default Linear Algebra Implementations 00318 00319 // /////////////////////////////////////////////////////////////////////////// 00320 // /////////////////////////////////////////////////////////////////////////// 00321 // Inline definitions 00322 00323 // /////////////////////////////////////////////////////////////////////////////// 00324 // Level 1 BLAS for Vectors 00325 00326 // v_lhs += V_rhs. 00327 template <class V> 00328 inline 00329 void Vp_V(VectorMutable* v_lhs, const V& V_rhs) { 00330 Vp_StV(v_lhs,1.0,V_rhs); 00331 } 00332 00333 // v_lhs = - V_rhs. 00334 template <class V> 00335 inline 00336 void V_mV(VectorMutable* v_lhs, const V& V_rhs) { 00337 V_StV(v_lhs,-1.0,V_rhs); 00338 } 00339 00340 // /////////////////////////////////////////////////////////////////////////////// 00341 // Level 1 BLAS for Matrices 00342 00343 // M_lhs += op(M_rhs). 00344 inline 00345 void Mp_M(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) { 00346 Mp_StM(M_lhs,1.0,M_rhs,trans_rhs); 00347 } 00348 00349 // M_lhs = - op(M_rhs). 00350 inline 00351 void M_mM(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) { 00352 M_StM(M_lhs,-1.0,M_rhs,trans_rhs); 00353 } 00354 00355 // /////////////////////////////////////////////////////////////////////// 00356 // Level 2 BLAS 00357 00358 // v_lhs += op(M_rhs1) * V_rhs2. 00359 template <class V> 00360 inline 00361 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00362 , const V& V_rhs2) 00363 { 00364 Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2); 00365 } 00366 00367 // v_lhs = op(M_rhs1) * V_rhs2 + beta * v_lhs. 00368 template <class V> 00369 inline 00370 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00371 , const V& V_rhs2, value_type beta) 00372 { 00373 Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2,beta); 00374 } 00375 00376 // ////////////////////////////////////////////////////////////////////////////// 00377 // Level 3 BLAS 00378 00379 // M_lhs += op(M_rhs1) * op(M_rhs2). 00380 inline 00381 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00382 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2) 00383 { 00384 Mp_StMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2); 00385 } 00386 00387 // M_lhs = op(M_rhs1) * op(M_rhs2) + beta * gms_rhs. 00388 inline 00389 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00390 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta) 00391 { 00392 Mp_StMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2,beta); 00393 } 00394 00395 // M_lhs = inv(op(M_rhs1)) * op(M_rhs2) 00396 inline 00397 void M_InvMtM(MatrixOp* M_lhs, const MatrixNonsing& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00398 , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2 ) 00399 { 00400 M_StInvMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2); 00401 } 00402 00403 } // end namespace LinAlgOpPack 00404 00405 // 00406 // Definitions 00407 // 00408 00409 namespace LinAlgOpPack { 00410 00411 using BLAS_Cpp::rows; 00412 using BLAS_Cpp::cols; 00413 00414 // Inject assert functions 00415 using AbstractLinAlgPack::Vp_V_assert_compatibility; 00416 using AbstractLinAlgPack::VopV_assert_compatibility; 00417 using AbstractLinAlgPack::Mp_M_assert_compatibility; 00418 using AbstractLinAlgPack::MopM_assert_compatibility; 00419 using AbstractLinAlgPack::Vp_MtV_assert_compatibility; 00420 using AbstractLinAlgPack::MtV_assert_compatibility; 00421 using AbstractLinAlgPack::MtM_assert_compatibility; 00422 using AbstractLinAlgPack::Mp_MtM_assert_compatibility; 00423 00424 // /////////////////////////////////////////////////////////////////////////////// 00425 // Level 1 BLAS for Vectors 00426 00427 // v_lhs = V_rhs. 00428 template <class V> 00429 void assign(VectorMutable* v_lhs, const V& V_rhs) { 00430 Vp_V_assert_compatibility(v_lhs,V_rhs); 00431 (*v_lhs) = 0.0; 00432 Vp_V(v_lhs,V_rhs); 00433 } 00434 00435 // v_lhs = alpha * V_rhs. 00436 template <class V> 00437 void V_StV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs) { 00438 Vp_V_assert_compatibility(v_lhs,V_rhs); 00439 (*v_lhs) = 0.0; 00440 Vp_StV(v_lhs,alpha,V_rhs); 00441 } 00442 00443 // v_lhs = V1_rhs1 + V2_rhs2. 00444 template <class V1, class V2> 00445 void V_VpV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2) { 00446 VopV_assert_compatibility(V1_rhs1,V2_rhs2); 00447 Vp_V_assert_compatibility(v_lhs,V1_rhs1); 00448 (*v_lhs) = 0.0; 00449 Vp_V(v_lhs,V1_rhs1); 00450 Vp_V(v_lhs,V2_rhs2); 00451 } 00452 00453 // v_lhs = V_rhs1 - V_rhs2. 00454 template <class V1, class V2> 00455 void V_VmV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2) { 00456 VopV_assert_compatibility(V1_rhs1,V2_rhs2); 00457 Vp_V_assert_compatibility(v_lhs,V1_rhs1); 00458 (*v_lhs) = 0.0; 00459 Vp_V(v_lhs,V1_rhs1); 00460 Vp_StV(v_lhs,-1.0,V2_rhs2); 00461 } 00462 00463 // v_lhs = alpha * V_rhs1 + v_rhs2. 00464 template <class V> 00465 void V_StVpV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs1 00466 , const Vector& v_rhs2) 00467 { 00468 VopV_assert_compatibility(V_rhs1,v_rhs2); 00469 (*v_lhs) = v_rhs2; 00470 Vp_StV(v_lhs,alpha,V_rhs1); 00471 } 00472 00473 // //////////////////////////////////////////////////////////////// 00474 // Level 2 BLAS 00475 00476 // v_lhs = alpha * op(M_rhs1) * V_rhs2. 00477 template <class V> 00478 void V_StMtV(VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00479 , BLAS_Cpp::Transp trans_rhs1, const V& V_rhs2) 00480 { 00481 Vp_MtV_assert_compatibility(v_lhs,M_rhs1,trans_rhs1,V_rhs2); 00482 Vp_StMtV(v_lhs,alpha,M_rhs1,trans_rhs1,V_rhs2,0.0); 00483 } 00484 00485 // v_lhs = op(M_rhs1) * V_rhs2. 00486 template <class V> 00487 void V_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1 00488 , const V& V_rhs2) 00489 { 00490 Vp_MtV_assert_compatibility(v_lhs,M_rhs1,trans_rhs1,V_rhs2); 00491 Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2,0.0); 00492 } 00493 00494 } // end namespace LinAlgOpPack 00495 00496 #endif // ABSTRACT_LIN_ALG_OP_PACK_H
1.7.4