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_TriBandArithFunc_H
24 #define TMV_TriBandArithFunc_H
25 
26 #include "tmv/TMV_BaseTriMatrix.h"
27 #include "tmv/TMV_BaseBandMatrix.h"
28 #include "tmv/TMV_BandMatrixArithFunc.h"
29 
30 #define CT std::complex<T>
31 
32 namespace tmv {
33 
34     template <typename T, typename T2>
AddMM(const T x2,const GenUpperTriMatrix<T2> & m2,BandMatrixView<T> m1)35     inline void AddMM(
36         const T x2, const GenUpperTriMatrix<T2>& m2,
37         BandMatrixView<T> m1)
38     {
39         if (m2.isunit()) {
40             if (m2.size() > 1)
41                 AddMM(x2,BandMatrixViewOf(m2.offDiag()),
42                       m1.diagRange(1,m2.size()));
43             m1.diag().addToAll(x2);
44         } else {
45             AddMM(x2,BandMatrixViewOf(m2),m1);
46         }
47     }
48 
49     template <typename T, typename T2>
AddMM(const T x2,const GenLowerTriMatrix<T2> & m2,BandMatrixView<T> m1)50     inline void AddMM(
51         const T x2, const GenLowerTriMatrix<T2>& m2,
52         BandMatrixView<T> m1)
53     {
54         if (m2.isunit()) {
55             if (m2.size() > 1)
56                 AddMM(x2,BandMatrixViewOf(m2.offDiag()),
57                       m1.diagRange(-m2.size()+1,0));
58             m1.diag().addToAll(x2);
59         } else {
60             AddMM(x2,BandMatrixViewOf(m2),m1);
61         }
62     }
63 
64     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenUpperTriMatrix<T1> & m1,const GenBandMatrix<T2> & m2,BandMatrixView<T> m0)65     inline void MultMM(
66         const T x, const GenUpperTriMatrix<T1>& m1,
67         const GenBandMatrix<T2>& m2, BandMatrixView<T> m0)
68     {
69         if (m1.isunit()) {
70             UpperTriMatrix<T1,NonUnitDiag|RowMajor> m1x = m1;
71             MultMM<add>(x,BandMatrixViewOf(m1x),m2,m0);
72         } else {
73             MultMM<add>(x,BandMatrixViewOf(m1),m2,m0);
74         }
75     }
76     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenBandMatrix<T1> & m1,const GenUpperTriMatrix<T2> & m2,BandMatrixView<T> m0)77     inline void MultMM(
78         const T x, const GenBandMatrix<T1>& m1,
79         const GenUpperTriMatrix<T2>& m2, BandMatrixView<T> m0)
80     {
81         if (m2.isunit()) {
82             UpperTriMatrix<T2,NonUnitDiag|RowMajor> m2x = m2;
83             MultMM<add>(x,m1,BandMatrixViewOf(m2x),m0);
84         } else {
85             MultMM<add>(x,m1,BandMatrixViewOf(m2),m0);
86         }
87     }
88     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenLowerTriMatrix<T1> & m1,const GenBandMatrix<T2> & m2,BandMatrixView<T> m0)89     inline void MultMM(
90         const T x, const GenLowerTriMatrix<T1>& m1,
91         const GenBandMatrix<T2>& m2, BandMatrixView<T> m0)
92     {
93         if (m1.isunit()) {
94             LowerTriMatrix<T1,NonUnitDiag|RowMajor> m1x = m1;
95             MultMM<add>(x,BandMatrixViewOf(m1x),m2,m0);
96         } else {
97             MultMM<add>(x,BandMatrixViewOf(m1),m2,m0);
98         }
99     }
100     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenBandMatrix<T1> & m1,const GenLowerTriMatrix<T2> & m2,BandMatrixView<T> m0)101     inline void MultMM(
102         const T x, const GenBandMatrix<T1>& m1,
103         const GenLowerTriMatrix<T2>& m2, BandMatrixView<T> m0)
104     {
105         if (m2.isunit()) {
106             LowerTriMatrix<T2,NonUnitDiag|RowMajor> m2x = m2;
107             MultMM<add>(x,m1,BandMatrixViewOf(m2x),m0);
108         } else {
109             MultMM<add>(x,m1,BandMatrixViewOf(m2),m0);
110         }
111     }
112 
113     template <typename T, typename T2>
AddMM(const T x2,const GenUpperTriMatrix<T2> & m2,BandMatrixView<CT> m1)114     inline void AddMM(
115         const T x2, const GenUpperTriMatrix<T2>& m2,
116         BandMatrixView<CT> m1)
117     { AddMM(CT(x2),m2,m1); }
118     template <typename T, typename T2>
AddMM(const T x2,const GenLowerTriMatrix<T2> & m2,BandMatrixView<CT> m1)119     inline void AddMM(
120         const T x2, const GenLowerTriMatrix<T2>& m2,
121         BandMatrixView<CT> m1)
122     { AddMM(CT(x2),m2,m1); }
123 
124     template <typename T, typename T2>
AddMM(const CT,const GenUpperTriMatrix<T2> &,BandMatrixView<T>)125     inline void AddMM(
126         const CT , const GenUpperTriMatrix<T2>& , BandMatrixView<T> )
127     { TMVAssert(TMV_FALSE); }
128     template <typename T, typename T2>
AddMM(const CT,const GenLowerTriMatrix<T2> &,BandMatrixView<T>)129     inline void AddMM(
130         const CT , const GenLowerTriMatrix<T2>& , BandMatrixView<T> )
131     { TMVAssert(TMV_FALSE); }
132 
133     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenUpperTriMatrix<T1> & m1,const GenBandMatrix<T2> & m2,BandMatrixView<CT> m0)134     inline void MultMM(
135         const T x, const GenUpperTriMatrix<T1>& m1,
136         const GenBandMatrix<T2>& m2, BandMatrixView<CT> m0)
137     { MultMM<add>(CT(x),m1,m2,m0); }
138     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenBandMatrix<T1> & m1,const GenUpperTriMatrix<T2> & m2,BandMatrixView<CT> m0)139     inline void MultMM(
140         const T x, const GenBandMatrix<T1>& m1,
141         const GenUpperTriMatrix<T2>& m2, BandMatrixView<CT> m0)
142     { MultMM<add>(CT(x),m1,m2,m0); }
143     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenLowerTriMatrix<T1> & m1,const GenBandMatrix<T2> & m2,BandMatrixView<CT> m0)144     inline void MultMM(
145         const T x, const GenLowerTriMatrix<T1>& m1,
146         const GenBandMatrix<T2>& m2, BandMatrixView<CT> m0)
147     { MultMM<add>(CT(x),m1,m2,m0); }
148     template <bool add, typename T, typename T1, typename T2>
MultMM(const T x,const GenBandMatrix<T1> & m1,const GenLowerTriMatrix<T2> & m2,BandMatrixView<CT> m0)149     inline void MultMM(
150         const T x, const GenBandMatrix<T1>& m1,
151         const GenLowerTriMatrix<T2>& m2, BandMatrixView<CT> m0)
152     { MultMM<add>(CT(x),m1,m2,m0); }
153 
154     template <bool add, typename T, typename T1, typename T2>
MultMM(const CT,const GenUpperTriMatrix<T1> &,const GenBandMatrix<T2> &,BandMatrixView<T>)155     inline void MultMM(
156         const CT , const GenUpperTriMatrix<T1>& ,
157         const GenBandMatrix<T2>& , BandMatrixView<T> )
158     { TMVAssert(TMV_FALSE); }
159     template <bool add, typename T, typename T1, typename T2>
MultMM(const CT,const GenBandMatrix<T1> &,const GenUpperTriMatrix<T2> &,BandMatrixView<T>)160     inline void MultMM(
161         const CT , const GenBandMatrix<T1>& ,
162         const GenUpperTriMatrix<T2>& , BandMatrixView<T> )
163     { TMVAssert(TMV_FALSE); }
164     template <bool add, typename T, typename T1, typename T2>
MultMM(const CT,const GenLowerTriMatrix<T1> &,const GenBandMatrix<T2> &,BandMatrixView<T>)165     inline void MultMM(
166         const CT , const GenLowerTriMatrix<T1>& ,
167         const GenBandMatrix<T2>& , BandMatrixView<T> )
168     { TMVAssert(TMV_FALSE); }
169     template <bool add, typename T, typename T1, typename T2>
MultMM(const CT,const GenBandMatrix<T1> &,const GenLowerTriMatrix<T2> &,BandMatrixView<T>)170     inline void MultMM(
171         const CT , const GenBandMatrix<T1>& ,
172         const GenLowerTriMatrix<T2>& , BandMatrixView<T> )
173     { TMVAssert(TMV_FALSE); }
174 
175 }
176 
177 #undef CT
178 
179 #endif
180