AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
AbstractLinAlgPack_LinAlgOpPack.hpp
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef ABSTRACT_LIN_ALG_OP_PACK_H
00043 #define ABSTRACT_LIN_ALG_OP_PACK_H
00044 
00045 #include "AbstractLinAlgPack_Types.hpp"
00046 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
00047 #include "AbstractLinAlgPack_VectorMutable.hpp"
00048 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00049 #include "AbstractLinAlgPack_AssertOp.hpp"
00050 
00051 namespace LinAlgOpPack {
00052 
00054 typedef AbstractLinAlgPack::size_type  size_type;
00056 typedef AbstractLinAlgPack::value_type value_type;
00057 
00059 using AbstractLinAlgPack::VectorSpace;
00061 using AbstractLinAlgPack::Vector;
00063 using AbstractLinAlgPack::VectorMutable;
00065 using AbstractLinAlgPack::MatrixOp;
00067 using AbstractLinAlgPack::MatrixNonsing;
00069 using AbstractLinAlgPack::MatrixOpNonsing;
00070 
00071 // Inject names of base linear algebra functions for DenseLinAlgPack.
00072 // Note that this is neccesary in MS VC++ 5.0 because
00073 // it does not perform name lookups properly but it
00074 // is not adverse to the standard so it is a portable
00075 // fix.
00077 using AbstractLinAlgPack::sum;
00079 using AbstractLinAlgPack::dot;
00081 using AbstractLinAlgPack::Vp_S;
00083 using AbstractLinAlgPack::Vt_S;
00085 using AbstractLinAlgPack::Vp_StV;
00087 using AbstractLinAlgPack::Vp_StMtV;
00089 using AbstractLinAlgPack::Mt_S;
00091 using AbstractLinAlgPack::Mp_StM;
00093 using AbstractLinAlgPack::Mp_StMtM;
00095 using AbstractLinAlgPack::syrk;
00097 using AbstractLinAlgPack::V_InvMtV;
00099 using AbstractLinAlgPack::M_StInvMtM;
00100 
00117 
00129 
00134 template <class V>
00135 void Vp_V(VectorMutable* v_lhs, const V& V_rhs);
00136 
00141 template <class V>
00142 void assign(VectorMutable* v_lhs, const V& V_rhs);
00143 
00148 template <class V>
00149 void V_StV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs);
00150 
00155 template <class V>
00156 void V_mV(VectorMutable* v_lhs, const V& V_rhs);
00157 
00159 
00163 template <class V1, class V2>
00164 void V_VpV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2);
00165 
00170 template <class V1, class V2>
00171 void V_VmV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2);
00172 
00177 template <class V>
00178 void V_StVpV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs1
00179   , const Vector& vs_rhs2);
00180 
00181 //    end Level 1 BLAS for Vectors
00183 
00184 // //////////////////////////////////////////////////////////////////////////////
00185 // ///////////////////////////////////////////////////////////////////////////////
00197 
00202 void Mp_M(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs);
00203 
00204 //    end += operations
00206 
00211 void assign(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs);
00212 
00217 void M_StM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs
00218   , BLAS_Cpp::Transp trans_rhs);
00219 
00224 void M_mM(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) ;
00225 
00227 
00231 void M_MpM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00232   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2);
00233 
00238 void M_MmM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00239   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2);
00240 
00245 void M_StMpM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00246   , const MatrixOp& gms_rhs2, BLAS_Cpp::Transp trans_rhs2);
00247 
00248 //    end Level 1 BLAS for Matrices
00250 
00251 // //////////////////////////////////////////////////////////////////////////////
00252 // /////////////////////////////////////////////////////////////////////// 
00260 
00265 template <class V>
00266 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00267   , const V& V_rhs2);
00268 
00273 template <class V>
00274 void V_StMtV(VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00275   , BLAS_Cpp::Transp trans_rhs1, const V& V_rhs2);
00276 
00281 template <class V>
00282 void V_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00283   , const V& V_rhs2);
00284 
00285 //    end Level 2 BLAS
00287 
00288 // //////////////////////////////////////////////////////////////////////////////
00289 // //////////////////////////////////////////////////////////////////////////////
00297 
00302 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00303   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2);
00304 
00309 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00310   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta);
00311 
00316 void M_StMtM(MatrixOp* M_lhs, value_type alpha, const MatrixOp& M_rhs1
00317   , BLAS_Cpp::Transp trans_rhs1, const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2);
00318 
00323 void M_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1
00324   , BLAS_Cpp::Transp trans_rhs1, const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2);
00325 
00326 //    end Level 3 BLAS
00328 
00329 //    end Default Linear Algebra Implementations
00331 
00332 // ///////////////////////////////////////////////////////////////////////////
00333 // ///////////////////////////////////////////////////////////////////////////
00334 // Inline definitions
00335 
00336 // ///////////////////////////////////////////////////////////////////////////////
00337 // Level 1 BLAS for Vectors
00338 
00339 // v_lhs += V_rhs.
00340 template <class V>
00341 inline
00342 void Vp_V(VectorMutable* v_lhs, const V& V_rhs) {
00343   Vp_StV(v_lhs,1.0,V_rhs);
00344 }
00345 
00346 // v_lhs = - V_rhs.
00347 template <class V>
00348 inline
00349 void V_mV(VectorMutable* v_lhs, const V& V_rhs) {
00350   V_StV(v_lhs,-1.0,V_rhs);
00351 }
00352 
00353 // ///////////////////////////////////////////////////////////////////////////////
00354 // Level 1 BLAS for Matrices
00355 
00356 // M_lhs += op(M_rhs).
00357 inline
00358 void Mp_M(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) {
00359   Mp_StM(M_lhs,1.0,M_rhs,trans_rhs);
00360 }
00361 
00362 // M_lhs = - op(M_rhs).
00363 inline
00364 void M_mM(MatrixOp* M_lhs, const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs) {
00365   M_StM(M_lhs,-1.0,M_rhs,trans_rhs);
00366 }
00367 
00368 // /////////////////////////////////////////////////////////////////////// 
00369 // Level 2 BLAS
00370 
00371 // v_lhs += op(M_rhs1) * V_rhs2.
00372 template <class V>
00373 inline
00374 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00375   , const V& V_rhs2)
00376 {
00377   Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2);
00378 }
00379 
00380 // v_lhs = op(M_rhs1) * V_rhs2 + beta * v_lhs.
00381 template <class V>
00382 inline
00383 void Vp_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00384   , const V& V_rhs2, value_type beta)
00385 {
00386   Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2,beta);
00387 }
00388 
00389 // //////////////////////////////////////////////////////////////////////////////
00390 // Level 3 BLAS
00391 
00392 // M_lhs += op(M_rhs1) * op(M_rhs2).
00393 inline
00394 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00395   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2)
00396 {
00397   Mp_StMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2);
00398 }
00399 
00400 // M_lhs = op(M_rhs1) * op(M_rhs2) + beta * gms_rhs.
00401 inline
00402 void Mp_MtM(MatrixOp* M_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00403   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta)
00404 {
00405   Mp_StMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2,beta);
00406 }
00407 
00408 // M_lhs = inv(op(M_rhs1)) * op(M_rhs2)
00409 inline
00410 void M_InvMtM(MatrixOp* M_lhs, const MatrixNonsing& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00411   , const MatrixOp& M_rhs2, BLAS_Cpp::Transp trans_rhs2 )
00412 {
00413   M_StInvMtM(M_lhs,1.0,M_rhs1,trans_rhs1,M_rhs2,trans_rhs2);
00414 }
00415 
00416 } // end namespace LinAlgOpPack
00417 
00418 //
00419 // Definitions
00420 //
00421 
00422 namespace LinAlgOpPack {
00423 
00424 using BLAS_Cpp::rows;
00425 using BLAS_Cpp::cols;
00426 
00427 // Inject assert functions
00428 using AbstractLinAlgPack::Vp_V_assert_compatibility;
00429 using AbstractLinAlgPack::VopV_assert_compatibility;
00430 using AbstractLinAlgPack::Mp_M_assert_compatibility;
00431 using AbstractLinAlgPack::MopM_assert_compatibility;
00432 using AbstractLinAlgPack::Vp_MtV_assert_compatibility;
00433 using AbstractLinAlgPack::MtV_assert_compatibility;
00434 using AbstractLinAlgPack::MtM_assert_compatibility;
00435 using AbstractLinAlgPack::Mp_MtM_assert_compatibility;
00436 
00437 // ///////////////////////////////////////////////////////////////////////////////
00438 // Level 1 BLAS for Vectors
00439 
00440 // v_lhs = V_rhs.
00441 template <class V>
00442 void assign(VectorMutable* v_lhs, const V& V_rhs) {
00443   Vp_V_assert_compatibility(v_lhs,V_rhs);
00444   (*v_lhs) = 0.0;
00445   Vp_V(v_lhs,V_rhs);
00446 }
00447 
00448 // v_lhs = alpha * V_rhs.
00449 template <class V>
00450 void V_StV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs) {
00451   Vp_V_assert_compatibility(v_lhs,V_rhs);
00452   (*v_lhs) = 0.0;
00453   Vp_StV(v_lhs,alpha,V_rhs);
00454 }
00455 
00456 // v_lhs = V1_rhs1 + V2_rhs2.
00457 template <class V1, class V2>
00458 void V_VpV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2) {
00459   VopV_assert_compatibility(V1_rhs1,V2_rhs2);
00460   Vp_V_assert_compatibility(v_lhs,V1_rhs1);
00461   (*v_lhs) = 0.0;
00462   Vp_V(v_lhs,V1_rhs1);
00463   Vp_V(v_lhs,V2_rhs2);
00464 }
00465 
00466 // v_lhs = V_rhs1 - V_rhs2.
00467 template <class V1, class V2>
00468 void V_VmV(VectorMutable* v_lhs, const V1& V1_rhs1, const V2& V2_rhs2) {
00469   VopV_assert_compatibility(V1_rhs1,V2_rhs2);
00470   Vp_V_assert_compatibility(v_lhs,V1_rhs1);
00471   (*v_lhs) = 0.0;
00472   Vp_V(v_lhs,V1_rhs1);
00473   Vp_StV(v_lhs,-1.0,V2_rhs2);
00474 }
00475 
00476 // v_lhs = alpha * V_rhs1 + v_rhs2.
00477 template <class V>
00478 void V_StVpV(VectorMutable* v_lhs, value_type alpha, const V& V_rhs1
00479   , const Vector& v_rhs2)
00480 {
00481   VopV_assert_compatibility(V_rhs1,v_rhs2);
00482   (*v_lhs) = v_rhs2;
00483   Vp_StV(v_lhs,alpha,V_rhs1);
00484 }
00485 
00486 // ////////////////////////////////////////////////////////////////
00487 // Level 2 BLAS
00488 
00489 // v_lhs = alpha * op(M_rhs1) * V_rhs2.
00490 template <class V>
00491 void V_StMtV(VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00492   , BLAS_Cpp::Transp trans_rhs1, const V& V_rhs2)
00493 {
00494   Vp_MtV_assert_compatibility(v_lhs,M_rhs1,trans_rhs1,V_rhs2);
00495   Vp_StMtV(v_lhs,alpha,M_rhs1,trans_rhs1,V_rhs2,0.0);
00496 }
00497 
00498 // v_lhs = op(M_rhs1) * V_rhs2.
00499 template <class V>
00500 void V_MtV(VectorMutable* v_lhs, const MatrixOp& M_rhs1, BLAS_Cpp::Transp trans_rhs1
00501   , const V& V_rhs2)
00502 {
00503   Vp_MtV_assert_compatibility(v_lhs,M_rhs1,trans_rhs1,V_rhs2);
00504   Vp_StMtV(v_lhs,1.0,M_rhs1,trans_rhs1,V_rhs2,0.0);
00505 }
00506 
00507 } // end namespace LinAlgOpPack
00508 
00509 #endif // ABSTRACT_LIN_ALG_OP_PACK_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends