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_BandMatrixArithFunc_H
24 #define TMV_BandMatrixArithFunc_H
25 
26 #include "tmv/TMV_BaseBandMatrix.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 GenBandMatrix<Ta>& A,
37         const GenVector<Tx>& x, VectorView<T> y);
38 
39     // A *= alpha
40     template <typename T>
41     void MultXM(const T alpha, BandMatrixView<T> A);
42 
43     // B += alpha * A
44     template <typename T, typename Ta>
45     void AddMM(
46         const T alpha, const GenBandMatrix<Ta>& A, BandMatrixView<T> B);
47     template <typename T, typename Ta>
AddMM(const T alpha,const GenBandMatrix<Ta> & A,MatrixView<T> B)48     inline void AddMM(
49         const T alpha, const GenBandMatrix<Ta>& A, MatrixView<T> B)
50     { AddMM(alpha,A,BandMatrixView<T>(B,A.nlo(),A.nhi())); }
51     // C = alpha * A + beta * B
52     template <typename T, typename Ta, typename Tb>
53     void AddMM(
54         const T alpha, const GenBandMatrix<Ta>& A,
55         const T beta, const GenBandMatrix<Tb>& B, BandMatrixView<T> C);
56     template <typename T, typename Ta, typename Tb>
57     void AddMM(
58         const T alpha, const GenBandMatrix<Ta>& A,
59         const T beta, const GenMatrix<Tb>& B, MatrixView<T> C);
60     template <typename T, typename Ta, typename Tb>
AddMM(const T alpha,const GenMatrix<Ta> & A,const T beta,const GenBandMatrix<Tb> & B,MatrixView<T> C)61     inline void AddMM(
62         const T alpha, const GenMatrix<Ta>& A,
63         const T beta, const GenBandMatrix<Tb>& B, MatrixView<T> C)
64     { AddMM(beta,B,alpha,A,C); }
65 
66     // C (+)= alpha * A * B
67     template <bool add, typename T, typename Ta, typename Tb>
68     void MultMM(
69         const T alpha, const GenBandMatrix<Ta>& A,
70         const GenMatrix<Tb>& B, MatrixView<T> C);
71     template <bool add, typename T, typename Ta, typename Tb>
72     void MultMM(
73         const T alpha, const GenBandMatrix<Ta>& A,
74         const GenBandMatrix<Tb>& B, BandMatrixView<T> C);
75     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const T alpha,const GenMatrix<Ta> & A,const GenBandMatrix<Tb> & B,MatrixView<T> C)76     inline void MultMM(
77         const T alpha, const GenMatrix<Ta>& A,
78         const GenBandMatrix<Tb>& B, MatrixView<T> C)
79     { MultMM<add>(alpha,B.transpose(),A.transpose(),C.transpose()); }
80 
81     template <bool add, typename T, typename Ta, typename Tb>
82     void ElemMultMM(
83         const T alpha, const GenBandMatrix<Ta>& A,
84         const GenBandMatrix<Tb>& B, BandMatrixView<T> C);
85 
86     template <typename T>
87     class BandMatrixComposite : public GenBandMatrix<T>
88     {
89     public:
90 
BandMatrixComposite()91         inline BandMatrixComposite() : itsm(0) {}
BandMatrixComposite(const BandMatrixComposite<T> &)92         inline BandMatrixComposite(const BandMatrixComposite<T>&) : itsm(0) {}
~BandMatrixComposite()93         virtual inline ~BandMatrixComposite() {}
94 
95         // Definitions are in TMV_MultBV.cpp
96         const T* cptr() const;
97         ptrdiff_t stepi() const;
98         ptrdiff_t stepj() const;
99         ptrdiff_t diagstep() const;
100 
ct()101         inline ConjType ct() const { return NonConj; }
isconj()102         inline bool isconj() const { return false; }
103         ptrdiff_t ls() const;
104 
105         ConstVectorView<T> constLinearView() const;
canLinearize()106         inline bool canLinearize() const { return true; }
107 
108     private:
109 
110         mutable AlignedArray<T> itsm1;
111         mutable T* itsm;
112 
113         BandMatrixComposite<T>& operator=(const BandMatrixComposite<T>&);
114     };
115 
116     // Specialize allowed complex combinations:
117     template <bool add, typename T, typename Ta, typename Tx>
MultMV(const T alpha,const GenBandMatrix<Ta> & A,const GenVector<Tx> & x,VectorView<CT> y)118     inline void MultMV(
119         const T alpha, const GenBandMatrix<Ta>& A, const GenVector<Tx>& x,
120         VectorView<CT> y)
121     { MultMV<add>(CT(alpha),A,x,y); }
122 
123     template <typename T>
MultXM(const T x,BandMatrixView<CT> m)124     inline void MultXM(
125         const T x, BandMatrixView<CT> m)
126     { MultXM(CT(x),m); }
127 
128     template <typename T, typename Ta>
AddMM(const T alpha,const GenBandMatrix<Ta> & A,BandMatrixView<CT> B)129     inline void AddMM(
130         const T alpha, const GenBandMatrix<Ta>& A, BandMatrixView<CT> B)
131     { AddMM(CT(alpha),A,B); }
132     template <typename T, typename Ta>
AddMM(const T alpha,const GenBandMatrix<Ta> & A,MatrixView<CT> B)133     inline void AddMM(
134         const T alpha, const GenBandMatrix<Ta>& A, MatrixView<CT> B)
135     { AddMM(CT(alpha),A,B); }
136 
137     template <typename T, typename Ta, typename Tb>
AddMM(const T alpha,const GenBandMatrix<Ta> & A,const T beta,const GenBandMatrix<Tb> & B,BandMatrixView<CT> C)138     inline void AddMM(
139         const T alpha, const GenBandMatrix<Ta>& A, const T beta,
140         const GenBandMatrix<Tb>& B, BandMatrixView<CT> C)
141     { AddMM(CT(alpha),A,CT(beta),B,C); }
142     template <typename T, typename Ta, typename Tb>
AddMM(const T alpha,const GenBandMatrix<Ta> & A,const T beta,const GenMatrix<Tb> & B,MatrixView<CT> C)143     inline void AddMM(
144         const T alpha, const GenBandMatrix<Ta>& A, const T beta,
145         const GenMatrix<Tb>& B, MatrixView<CT> C)
146     { AddMM(CT(alpha),A,CT(beta),B,C); }
147     template <typename T, typename Ta, typename Tb>
AddMM(const T alpha,const GenMatrix<Ta> & A,const T beta,const GenBandMatrix<Tb> & B,MatrixView<CT> C)148     inline void AddMM(
149         const T alpha, const GenMatrix<Ta>& A, const T beta,
150         const GenBandMatrix<Tb>& B, MatrixView<CT> C)
151     { AddMM(CT(alpha),A,CT(beta),B,C); }
152     template <typename T>
AddMM(const CT alpha,const GenBandMatrix<CT> & A,const CT beta,const GenBandMatrix<T> & B,BandMatrixView<CT> C)153     inline void AddMM(
154         const CT alpha, const GenBandMatrix<CT>& A, const CT beta,
155         const GenBandMatrix<T>& B, BandMatrixView<CT> C)
156     { AddMM(beta,B,alpha,A,C); }
157 
158     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const T alpha,const GenBandMatrix<Ta> & A,const GenMatrix<Tb> & B,MatrixView<CT> C)159     inline void MultMM(
160         const T alpha, const GenBandMatrix<Ta>& A, const GenMatrix<Tb>& B,
161         MatrixView<CT> C)
162     { MultMM<add>(CT(alpha),A,B,C); }
163     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const T alpha,const GenBandMatrix<Ta> & A,const GenBandMatrix<Tb> & B,BandMatrixView<CT> C)164     inline void MultMM(
165         const T alpha, const GenBandMatrix<Ta>& A, const GenBandMatrix<Tb>& B,
166         BandMatrixView<CT> C)
167     { MultMM<add>(CT(alpha),A,B,C); }
168     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const T alpha,const GenMatrix<Ta> & A,const GenBandMatrix<Tb> & B,MatrixView<CT> C)169     inline void MultMM(
170         const T alpha, const GenMatrix<Ta>& A, const GenBandMatrix<Tb>& B,
171         MatrixView<CT> C)
172     { MultMM<add>(CT(alpha),A,B,C); }
173 
174     template <bool add, typename T, typename Ta, typename Tb>
ElemMultMM(const T alpha,const GenBandMatrix<Ta> & A,const GenBandMatrix<Tb> & B,BandMatrixView<CT> C)175     inline void ElemMultMM(
176         const T alpha, const GenBandMatrix<Ta>& A, const GenBandMatrix<Tb>& B,
177         BandMatrixView<CT> C)
178     { ElemMultMM<add>(CT(alpha),A,B,C); }
179 
180     // Specialize disallowed complex combinations:
181     template <bool add, typename T, typename Ta, typename Tb>
MultMV(const CT,const GenBandMatrix<Ta> &,const GenVector<Tb> &,VectorView<T>)182     inline void MultMV(
183         const CT , const GenBandMatrix<Ta>& ,
184         const GenVector<Tb>& , VectorView<T> )
185     { TMVAssert(TMV_FALSE); }
186 
187     template <typename T>
MultXM(const CT,BandMatrixView<T>)188     inline void MultXM(const CT , BandMatrixView<T> )
189     { TMVAssert(TMV_FALSE); }
190 
191     template <typename T, typename Ta>
AddMM(const CT,const GenBandMatrix<Ta> &,BandMatrixView<T>)192     inline void AddMM(
193         const CT , const GenBandMatrix<Ta>& , BandMatrixView<T> )
194     { TMVAssert(TMV_FALSE); }
195     template <typename T, typename Ta>
AddMM(const CT,const GenBandMatrix<Ta> &,MatrixView<T>)196     inline void AddMM(
197         const CT , const GenBandMatrix<Ta>& , MatrixView<T> )
198     { TMVAssert(TMV_FALSE); }
199     template <typename T, typename Ta, typename Tb>
AddMM(const CT,const GenBandMatrix<Ta> &,const CT,const GenBandMatrix<Tb> &,BandMatrixView<T>)200     inline void AddMM(
201         const CT , const GenBandMatrix<Ta>& ,
202         const CT , const GenBandMatrix<Tb>& , BandMatrixView<T> )
203     { TMVAssert(TMV_FALSE); }
204     template <typename T, typename Ta, typename Tb>
AddMM(const CT,const GenBandMatrix<Ta> &,const CT,const GenMatrix<Tb> &,MatrixView<T>)205     inline void AddMM(
206         const CT , const GenBandMatrix<Ta>& ,
207         const CT , const GenMatrix<Tb>& , MatrixView<T> )
208     { TMVAssert(TMV_FALSE); }
209     template <typename T, typename Ta, typename Tb>
AddMM(const CT,const GenMatrix<Ta> &,const CT,const GenBandMatrix<Tb> &,MatrixView<T>)210     inline void AddMM(
211         const CT , const GenMatrix<Ta>& ,
212         const CT , const GenBandMatrix<Tb>& , MatrixView<T> )
213     { TMVAssert(TMV_FALSE); }
214 
215     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const CT,const GenBandMatrix<Ta> &,const GenMatrix<Tb> &,MatrixView<T>)216     inline void MultMM(
217         const CT , const GenBandMatrix<Ta>& ,
218         const GenMatrix<Tb>& , MatrixView<T> )
219     { TMVAssert(TMV_FALSE); }
220     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const CT,const GenBandMatrix<Ta> &,const GenBandMatrix<Tb> &,BandMatrixView<T>)221     inline void MultMM(
222         const CT , const GenBandMatrix<Ta>& ,
223         const GenBandMatrix<Tb>& , BandMatrixView<T> )
224     { TMVAssert(TMV_FALSE); }
225     template <bool add, typename T, typename Ta, typename Tb>
MultMM(const CT,const GenMatrix<Ta> &,const GenBandMatrix<Tb> &,MatrixView<T>)226     inline void MultMM(
227         const CT , const GenMatrix<Ta>& ,
228         const GenBandMatrix<Tb>& , MatrixView<T> )
229     { TMVAssert(TMV_FALSE); }
230 
231     template <bool add, typename T, typename Ta, typename Tb>
ElemMultMM(const CT,const GenBandMatrix<Ta> &,const GenBandMatrix<Tb> &,BandMatrixView<T>)232     inline void ElemMultMM(
233         const CT , const GenBandMatrix<Ta>& ,
234         const GenBandMatrix<Tb>& , BandMatrixView<T> )
235     { TMVAssert(TMV_FALSE); }
236 
237 }
238 
239 #undef CT
240 
241 #endif
242