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_VectorArithFunc_H 24 #define TMV_VectorArithFunc_H 25 26 #include "tmv/TMV_BaseVector.h" 27 #include "tmv/TMV_Array.h" 28 29 #define CT std::complex<T> 30 31 namespace tmv { 32 33 // v *= x 34 template <typename T> 35 void MultXV(const T x, VectorView<T> v2); 36 // v2 = x * v1 37 template <typename T, typename T1> 38 void MultXV(const T x, const GenVector<T1>& v1, VectorView<T> v2); 39 40 // v2 += x * v1 41 template <typename T, typename T1> 42 void AddVV(const T x, const GenVector<T1>& v1, VectorView<T> v2); 43 // v3 = x1 * v1 + x2 * v2 44 template <typename T, typename T1, typename T2> 45 void AddVV( 46 const T x1, const GenVector<T1>& v1, 47 const T x2, const GenVector<T2>& v2, VectorView<T> v3); 48 49 // v1 * v2 (dot product) 50 // Note: the return type is the type of the first vector 51 // This is important for mixing complex and real vectors 52 template <typename T, typename T2> 53 T MultVV(const GenVector<T>& v1, const GenVector<T2>& v2); 54 55 template <bool add, typename T, typename Tx, typename Ty> 56 void ElemMultVV( 57 const T alpha, const GenVector<Tx>& x, 58 const GenVector<Ty>& y, VectorView<T> z); 59 60 template <typename T> 61 class VectorComposite : public GenVector<T> 62 { 63 public: 64 VectorComposite()65 inline VectorComposite() {} VectorComposite(const VectorComposite<T> &)66 inline VectorComposite(const VectorComposite<T>&) {} ~VectorComposite()67 virtual inline ~VectorComposite() {} 68 69 const T* cptr() const; step()70 inline ptrdiff_t step() const { return 1; } ct()71 inline ConjType ct() const { return NonConj; } isconj()72 inline bool isconj() const { return false; } 73 74 private: 75 mutable AlignedArray<T> _v; 76 }; 77 78 // Specialize allowed complex combinations: 79 template <typename T> MultXV(const T x,VectorView<CT> v2)80 inline void MultXV(const T x, VectorView<CT> v2) 81 { MultXV(CT(x),v2); } 82 template <typename T, typename T1> MultXV(const T x,const GenVector<T1> & v1,VectorView<CT> v2)83 inline void MultXV( 84 const T x, const GenVector<T1>& v1, VectorView<CT> v2) 85 { MultXV(CT(x),v1,v2); } 86 87 template <typename T, typename T1> AddVV(const T x,const GenVector<T1> & v1,VectorView<CT> v2)88 inline void AddVV( 89 const T x, const GenVector<T1>& v1, VectorView<CT> v2) 90 { AddVV(CT(x),v1,v2); } 91 template <typename T, typename T1, typename T2> AddVV(const T x1,const GenVector<T1> & v1,const T x2,const GenVector<T2> & v2,VectorView<CT> v3)92 inline void AddVV( 93 const T x1, const GenVector<T1>& v1, 94 const T x2, const GenVector<T2>& v2, VectorView<CT> v3) 95 { AddVV(CT(x1),v1,CT(x2),v2,v3); } 96 template <typename T> AddVV(const CT x1,const GenVector<CT> & v1,const CT x2,const GenVector<T> & v2,VectorView<CT> v3)97 inline void AddVV( 98 const CT x1, const GenVector<CT>& v1, 99 const CT x2, const GenVector<T>& v2, VectorView<CT> v3) 100 { AddVV(x2,v2,x1,v1,v3); } 101 102 template <typename T> MultVV(const GenVector<T> & v1,const GenVector<CT> & v2)103 inline CT MultVV(const GenVector<T>& v1, const GenVector<CT>& v2) 104 { return MultVV(v2,v1); } 105 106 template <bool add, typename T, typename Tx, typename Ty> ElemMultVV(const T alpha,const GenVector<Tx> & x,const GenVector<Ty> & y,VectorView<CT> z)107 inline void ElemMultVV( 108 const T alpha, const GenVector<Tx>& x, 109 const GenVector<Ty>& y, VectorView<CT> z) 110 { ElemMultVV<add>(CT(alpha),x,y,z); } 111 112 // Specialize disallowed complex combinations: 113 template <typename T> MultXV(const CT,VectorView<T>)114 inline void MultXV(const CT , VectorView<T> ) 115 { TMVAssert(TMV_FALSE); } 116 template <typename T, typename Ta> MultXV(const CT,const GenVector<Ta> &,VectorView<T>)117 inline void MultXV( 118 const CT , const GenVector<Ta>& , VectorView<T> ) 119 { TMVAssert(TMV_FALSE); } 120 121 template <typename T, typename T1> AddVV(const CT,const GenVector<T1> &,VectorView<T>)122 inline void AddVV( 123 const CT , const GenVector<T1>& , VectorView<T> ) 124 { TMVAssert(TMV_FALSE); } 125 template <typename T, typename Ta, typename Tb> AddVV(const CT,const GenVector<Ta> &,const CT,const GenVector<Tb> &,VectorView<T>)126 inline void AddVV( 127 const CT , const GenVector<Ta>& , 128 const CT , const GenVector<Tb>& , VectorView<T> ) 129 { TMVAssert(TMV_FALSE); } 130 131 template <bool add, typename T, typename Ta, typename Tb> ElemMultVV(const CT,const GenVector<Ta> &,const GenVector<Tb> &,VectorView<T>)132 inline void ElemMultVV( 133 const CT , const GenVector<Ta>& , const GenVector<Tb>& , 134 VectorView<T> ) 135 { TMVAssert(TMV_FALSE); } 136 137 } // namespace tmv 138 139 #undef CT 140 141 #endif 142