1 /////////////////////////////////////////////////////////////////////////////// 2 // // 3 // The Template Matrix/Vector Library for C++ was created by Mike Jarvis // 4 // Copyright (C) 1998 - 2016 // 5 // All rights reserved // 6 // // 7 // The project is hosted at https://code.google.com/p/tmv-cpp/ // 8 // where you can find the current version and current documention. // 9 // // 10 // For concerns or problems with the software, Mike may be contacted at // 11 // mike_jarvis17 [at] gmail. // 12 // // 13 // This software is licensed under a FreeBSD license. The file // 14 // TMV_LICENSE should have bee included with this distribution. // 15 // It not, you can get a copy from https://code.google.com/p/tmv-cpp/. // 16 // // 17 // Essentially, you can use this software however you want provided that // 18 // you include the TMV_LICENSE file in any distribution that uses it. // 19 // // 20 /////////////////////////////////////////////////////////////////////////////// 21 22 23 #ifndef TMV_MatrixArithFunc_H 24 #define TMV_MatrixArithFunc_H 25 26 #include "tmv/TMV_BaseMatrix.h" 27 #include "tmv/TMV_Array.h" 28 29 #define CT std::complex<T> 30 31 namespace tmv { 32 33 // y (+)= alpha * A * x 34 template <bool add, typename T, typename Ta, typename Tx> 35 void MultMV( 36 const T alpha, const GenMatrix<Ta>& A, const GenVector<Tx>& x, 37 VectorView<T> y); 38 39 // A *= alpha 40 template <typename T> 41 void MultXM(const T alpha, MatrixView<T> A); 42 43 // B += alpha * A 44 template <typename T, typename Ta> 45 void AddMM(const T alpha, const GenMatrix<Ta>& A, MatrixView<T> B); 46 47 // C = alpha * A + beta * B 48 template <typename T, typename Ta, typename Tb> 49 void AddMM( 50 const T alpha, const GenMatrix<Ta>& A, 51 const T beta, const GenMatrix<Tb>& B, MatrixView<T> C); 52 53 // C (+)= alpha * A * B 54 template <bool add, typename T, typename Ta, typename Tb> 55 void MultMM( 56 const T alpha, const GenMatrix<Ta>& A, const GenMatrix<Tb>& B, 57 MatrixView<T> C); 58 59 // A (+)= alpha * x * yT 60 template <bool add, typename T, typename Tx, typename Ty> 61 void Rank1Update( 62 const T alpha, const GenVector<Tx>& x, const GenVector<Ty>& y, 63 MatrixView<T> A); 64 65 template <bool add, typename T, typename Ta, typename Tb> 66 void ElemMultMM( 67 const T alpha, const GenMatrix<Ta>& A, 68 const GenMatrix<Tb>& B, MatrixView<T> C); 69 70 template <typename T> 71 class MatrixComposite : public GenMatrix<T> 72 { 73 public: 74 MatrixComposite()75 inline MatrixComposite() {} MatrixComposite(const MatrixComposite<T> &)76 inline MatrixComposite(const MatrixComposite<T>&) {} ~MatrixComposite()77 virtual inline ~MatrixComposite() {} 78 const T* cptr() const; 79 ptrdiff_t stepi() const; 80 ptrdiff_t stepj() const; ct()81 inline ConjType ct() const { return NonConj; } canLinearize()82 inline bool canLinearize() const { return true; } 83 ptrdiff_t ls() const; 84 85 private: 86 mutable AlignedArray<T> itsm; 87 }; 88 89 // Specialize allowed complex combinations: 90 template <bool add, typename T, typename Ta, typename Tx> MultMV(const T alpha,const GenMatrix<Ta> & A,const GenVector<Tx> & x,VectorView<CT> y)91 inline void MultMV( 92 const T alpha, const GenMatrix<Ta>& A, 93 const GenVector<Tx>& x, VectorView<CT> y) 94 { MultMV<add>(CT(alpha),A,x,y); } 95 96 template <typename T> MultXM(const T alpha,MatrixView<CT> A)97 inline void MultXM(const T alpha, MatrixView<CT> A) 98 { MultXM(CT(alpha),A); } 99 100 template <typename T, typename Ta> AddMM(const T alpha,const GenMatrix<Ta> & A,MatrixView<CT> B)101 inline void AddMM( 102 const T alpha, const GenMatrix<Ta>& A, MatrixView<CT> B) 103 { AddMM(CT(alpha),A,B); } 104 105 template <typename T, typename Ta, typename Tb> AddMM(const T alpha,const GenMatrix<Ta> & A,const T beta,const GenMatrix<Tb> & B,MatrixView<CT> C)106 inline void AddMM( 107 const T alpha, const GenMatrix<Ta>& A, 108 const T beta, const GenMatrix<Tb>& B, MatrixView<CT> C) 109 { AddMM(CT(alpha),A,CT(beta),B,C); } 110 template <typename T> AddMM(const CT alpha,const GenMatrix<CT> & A,const CT beta,const GenMatrix<T> & B,MatrixView<CT> C)111 inline void AddMM( 112 const CT alpha, const GenMatrix<CT>& A, 113 const CT beta, const GenMatrix<T>& B, MatrixView<CT> C) 114 { AddMM(beta,B,alpha,A,C); } 115 116 template <bool add, typename T, typename Ta, typename Tb> MultMM(const T alpha,const GenMatrix<Ta> & A,const GenMatrix<Tb> & B,MatrixView<CT> C)117 inline void MultMM( 118 const T alpha, const GenMatrix<Ta>& A, 119 const GenMatrix<Tb>& B, MatrixView<CT> C) 120 { MultMM<add>(CT(alpha),A,B,C); } 121 122 template <bool add, typename T, typename Tx, typename Ty> Rank1Update(const T alpha,const GenVector<Tx> & x,const GenVector<Ty> & y,MatrixView<CT> A)123 inline void Rank1Update( 124 const T alpha, const GenVector<Tx>& x, 125 const GenVector<Ty>& y, MatrixView<CT> A) 126 { Rank1Update<add>(CT(alpha),x,y,A); } 127 128 template <bool add, typename T, typename Ta, typename Tb> ElemMultMM(const T alpha,const GenMatrix<Ta> & A,const GenMatrix<Tb> & B,MatrixView<CT> C)129 inline void ElemMultMM( 130 const T alpha, const GenMatrix<Ta>& A, 131 const GenMatrix<Tb>& B, MatrixView<CT> C) 132 { ElemMultMM<add>(CT(alpha),A,B,C); } 133 134 // Specialize disallowed complex combinations: 135 template <bool add, typename T, typename Ta, typename Tb> MultMV(const CT,const GenMatrix<Ta> &,const GenVector<Tb> &,VectorView<T>)136 inline void MultMV( 137 const CT , const GenMatrix<Ta>& , 138 const GenVector<Tb>& , VectorView<T> ) 139 { TMVAssert(TMV_FALSE); } 140 141 template <typename T> MultXM(const CT,MatrixView<T>)142 inline void MultXM(const CT , MatrixView<T> ) 143 { TMVAssert(TMV_FALSE); } 144 145 template <typename T, typename Ta> AddMM(const CT,const GenMatrix<Ta> &,MatrixView<T>)146 inline void AddMM(const CT , const GenMatrix<Ta>& , MatrixView<T> ) 147 { TMVAssert(TMV_FALSE); } 148 149 template <typename T, typename Ta, typename Tb> AddMM(const CT,const GenMatrix<Ta> &,const CT,const GenMatrix<Tb> &,MatrixView<T>)150 inline void AddMM( 151 const CT , const GenMatrix<Ta>& , 152 const CT , const GenMatrix<Tb>& , MatrixView<T> ) 153 { TMVAssert(TMV_FALSE); } 154 155 template <bool add, typename T, typename Ta, typename Tb> MultMM(const CT,const GenMatrix<Ta> &,const GenMatrix<Tb> &,MatrixView<T>)156 inline void MultMM( 157 const CT , const GenMatrix<Ta>& , const GenMatrix<Tb>& , 158 MatrixView<T> ) 159 { TMVAssert(TMV_FALSE); } 160 161 template <bool add, typename T, typename Ta, typename Tb> ElemMultMM(const CT,const GenMatrix<Ta> &,const GenMatrix<Tb> &,MatrixView<T>)162 inline void ElemMultMM( 163 const CT , const GenMatrix<Ta>& , const GenMatrix<Tb>& , 164 MatrixView<T> ) 165 { TMVAssert(TMV_FALSE); } 166 167 template <bool add, typename T, typename Ta, typename Tb> Rank1Update(const CT,const GenVector<Ta> &,const GenVector<Tb> &,MatrixView<T>)168 inline void Rank1Update( 169 const CT , const GenVector<Ta>& , 170 const GenVector<Tb>& , MatrixView<T> ) 171 { TMVAssert(TMV_FALSE); } 172 173 } // namespace tmv 174 175 #undef CT 176 177 #endif 178