LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
MyMatrix.h
Go to the documentation of this file.
1 #ifndef MeasAlgoShapeletMyMatrix_H
2 #define MeasAlgoShapeletMyMatrix_H
3 
4 #ifdef USE_TMV
5 
6 #include "TMV.h"
7 #include "TMV_Sym.h"
8 #include "TMV_Small.h"
9 
10 namespace lsst {
11 namespace meas {
12 namespace algorithms {
13 namespace shapelet {
14 
15  typedef tmv::Vector<double> DVector;
16  typedef tmv::VectorView<double> DVectorView;
17  typedef tmv::ConstVectorView<double> DConstVectorView;
18  typedef tmv::Matrix<double> DMatrix;
19  typedef tmv::MatrixView<double> DMatrixView;
20  typedef tmv::ConstMatrixView<double> DConstMatrixView;
21  typedef tmv::SmallMatrix<double,2,2> DSmallMatrix22;
22  typedef tmv::Matrix<double> DRowVector;
23  typedef tmv::BandMatrix<double> DBandMatrix;
24 
25  typedef tmv::Vector<std::complex<double> > CDVector;
26  typedef tmv::VectorView<std::complex<double> > CDVectorView;
27  typedef tmv::ConstVectorView<std::complex<double> > CDConstVectorView;
28  typedef tmv::Matrix<std::complex<double> > CDMatrix;
29  typedef tmv::MatrixView<std::complex<double> > CDMatrixView;
30  typedef tmv::ConstMatrixView<std::complex<double> > CDConstMatrixView;
31 
32  typedef tmv::Vector<float> FVector;
33  typedef tmv::VectorView<float> FVectorView;
34  typedef tmv::ConstVectorView<float> FConstVectorView;
35  typedef tmv::Matrix<float> FMatrix;
36  typedef tmv::MatrixView<float> FMatrixView;
37  typedef tmv::ConstMatrixView<float> FConstMatrixView;
38  typedef tmv::SmallMatrix<float,2,2> FSmallMatrix22;
39 
40  typedef tmv::Vector<std::complex<float> > CFVector;
41  typedef tmv::VectorView<std::complex<float> > CFVectorView;
42  typedef tmv::ConstVectorView<std::complex<float> > CFConstVectorView;
43  typedef tmv::Matrix<std::complex<float> > CFMatrix;
44  typedef tmv::MatrixView<std::complex<float> > CFMatrixView;
45  typedef tmv::ConstMatrixView<std::complex<float> > CFConstMatrixView;
46 
47  typedef tmv::DiagMatrix<double> DDiagMatrix;
48  typedef tmv::SymMatrix<double> DSymMatrix;
49 
50 }}}}
51 
52 #define TVector(T) tmv::Vector<T>
53 #define TVectorView(T) tmv::VectorView<T>
54 #define TConstVectorView(T) tmv::ConstVectorView<T>
55 #define TMatrix(T) tmv::Matrix<T>
56 #define TMatrixView(T) tmv::MatrixView<T>
57 #define TConstMatrixView(T) tmv::ConstMatrixView<T>
58 
59 // Macros that go after a . or ->
60 #define TMV_rowsize() rowsize()
61 #define TMV_colsize() colsize()
62 #define TMV_cref(i,j) cref(i,j)
63 #define TMV_ref(i,j) ref(i,j)
64 #define TMV_diag() diag()
65 #define EIGEN_diag()
66 #define EIGEN_asDiag()
67 #define TMV_setToIdentity() setToIdentity()
68 #define TMV_subVector(i1,i2) subVector(i1,i2)
69 #define TMV_subMatrix(i1,i2,j1,j2) subMatrix(i1,i2,j1,j2)
70 #define TMV_realPart() realPart()
71 #define TMV_imagPart() imagPart()
72 #define TMV_normSq() normSq()
73 #define TMV_normInf() normInf()
74 #define TMV_maxAbsElement() maxAbsElement()
75 #define TMV_addToAll(x) addToAll(x)
76 #define TMV_setAllTo(x) setAllTo(x)
77 #define TMV_colpart(j,i1,i2) col(j,i1,i2)
78 #define TMV_rowpart(i,j1,j2) row(i,j1,j2)
79 #define TMV_diagpart(i,j1,j2) diag(i,j1,j2)
80 #define TMV_det() det()
81 #define TMV_transposeSelf() transposeSelf()
82 #define TMV_sumElements() sumElements()
83 
84 // Macros that require the matrix or vector as an argument:
85 #define TMV_view(m) (m).view()
86 #define TMV_vview(v) (v).view()
87 #define TMV_colRange(m,j1,j2) (m).colRange(j1,j2)
88 #define TMV_rowRange(m,i1,i2) (m).rowRange(i1,i2)
89 #define TMV_ptr(m) (m).ptr()
90 #define TMV_cptr(m) (m).cptr()
91 #define TMV_stepi(m) (m).stepi()
92 #define TMV_stepj(m) (m).stepj()
93 #define TMV_DiagMatrixViewOf(v) DiagMatrixViewOf(v)
94 #define TMV_conjugateSelf(m) (m).conjugateSelf();
95 #define EIGEN_Transpose(m) m
96 #define EIGEN_ToScalar(m) m
97 #define TMV_NormInf(m) NormInf(m)
98 #define TMV_Norm(m) Norm(m)
99 
100 // Standalone macros:
101 #define TMV_const const
102 #define EIGEN_mutable
103 #define EIGEN_twice(x) x
104 
105 // QR solver:
106 #define TMV_QR(m) (m).divideUsing(tmv::QR); (m).saveDiv()
107 #define TMV_QR1(m) (m).divideUsing(tmv::QR); (m).saveDiv()
108 #define TMV_QR2(m) (m).resetDiv()
109 #define TMV_QRisSingular(m) (m).isSingular()
110 #define TMV_throwSingular throw tmv::Singular()
111 #define TMV_QR_Solve(m,x,b) x = b/m
112 #define TMV_QR_InverseATA(m,cov) (m).makeInverseATA(cov)
113 
114 #else
115 
116 #include "Eigen/Core"
117 #include "Eigen/QR"
118 #include "Eigen/SVD"
119 #include "Eigen/LU"
120 #include "Eigen/Cholesky"
121 
122 
123 namespace lsst {
124 namespace meas {
125 namespace algorithms {
126 namespace shapelet {
127 
128 
129  typedef Eigen::VectorXd DVector;
130  typedef Eigen::Block<DVector,Eigen::Dynamic,1> DVectorView;
132  typedef Eigen::MatrixXd DMatrix;
133  typedef Eigen::Block<DMatrix> DMatrixView;
135  typedef Eigen::Matrix<double,2,2> DSmallMatrix22;
136  typedef Eigen::RowVectorXd DRowVector;
137  typedef Eigen::MatrixXd DBandMatrix;
138 
139  typedef Eigen::VectorXcd CDVector;
140  typedef Eigen::Block<CDVector,Eigen::Dynamic,1> CDVectorView;
142  typedef Eigen::MatrixXcd CDMatrix;
143  typedef Eigen::Block<CDMatrix> CDMatrixView;
145 
146  typedef Eigen::VectorXf FVector;
147  typedef Eigen::Block<FVector,Eigen::Dynamic,1> FVectorView;
149  typedef Eigen::MatrixXf FMatrix;
150  typedef Eigen::Block<FMatrix> FMatrixView;
152  typedef Eigen::Matrix<float,2,2> FSmallMatrix22;
153 
154  typedef Eigen::VectorXcf CFVector;
155  typedef Eigen::Block<CFVector,Eigen::Dynamic,1> CFVectorView;
157  typedef Eigen::MatrixXcf CFMatrix;
158  typedef Eigen::Block<CFMatrix> CFMatrixView;
160 
163 
164 }}}}
165 
166 #define TVector(T) Eigen::Matrix<T,Eigen::Dynamic,1>
167 #define TVectorView(T) Eigen::Block<TVector(T) >
168 #define TConstVectorView(T) const Eigen::Block<TVector(T) >
169 #define TMatrix(T) Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>
170 #define TMatrixView(T) Eigen::Block<TMatrix(T) >
171 #define TConstMatrixView(T) const Eigen::Block<TMatrix(T) >
172 
173 // Macros that go after a . or ->
174 #define TMV_rowsize() cols()
175 #define TMV_colsize() rows()
176 #define TMV_cref(i,j) coeff(i,j)
177 #define TMV_ref(i,j) coeffRef(i,j)
178 #define TMV_diag() diagonal()
179 #define EIGEN_diag() diagonal().array()
180 #define EIGEN_asDiag() .asDiagonal()
181 #define TMV_setToIdentity() setIdentity()
182 #define TMV_subVector(i1,i2) segment(i1,((i2)-(i1)))
183 #define TMV_subMatrix(i1,i2,j1,j2) block(i1,j1,((i2)-(i1)),((j2)-(j1)))
184 #define TMV_realPart() real()
185 #define TMV_imagPart() imag()
186 #define TMV_normSq() squaredNorm()
187 #define TMV_normInf() lpNorm<Eigen::Infinity>()
188 #define TMV_maxAbsElement() array().abs().maxCoeff()
189 #define TMV_addToAll(x) array() += (x)
190 #define TMV_setAllTo(x) setConstant(x)
191 #define TMV_colpart(j,i1,i2) col(j).segment(i1,i2)
192 #define TMV_rowpart(i,j1,j2) row(i).segment(j1,j2)
193 // This is only right if i == 0. I don't think Eigen has the
194 // more general functionality, but that's not usually what I use.
195 #define TMV_diagpart(i,j1,j2) diagonal().segment(j1,j2)
196 #define TMV_det() determinant()
197 #define TMV_transposeSelf() transposeInPlace()
198 #define TMV_sumElements() sum()
199 
200 // Macros that require the matrix or vector as an argument:
201 #define TMV_view(m) (m).block(0,0,(m).rows(),(m).cols())
202 #define TMV_vview(v) (v).segment(0,(v).size())
203 #define TMV_colRange(m,j1,j2) (m).block(0,j1,(m).rows(),((j2)-(j1)))
204 #define TMV_rowRange(m,i1,i2) (m).block(i1,0,((i2)-(i1)),(m).cols())
205 #define TMV_ptr(m) &((m).coeffRef(0,0))
206 #define TMV_cptr(m) &((m).coeff(0,0))
207 #define TMV_stepi(m) ((m).rowStride())
208 #define TMV_stepj(m) ((m).colStride())
209 #define TMV_DiagMatrixViewOf(v) (v).asDiagonal()
210 #define TMV_conjugateSelf(m) (m) = (m).conjugate()
211 #define EIGEN_Transpose(m) (m).transpose()
212 #define EIGEN_ToScalar(m) (m)(0,0)
213 #define TMV_NormInf(m) (m).lpNorm<Eigen::Infinity>()
214 #define TMV_Norm(m) (m).norm()
215 
216 // Standalone macros:
217 #define TMV_const
218 #define EIGEN_mutable mutable
219 #define EIGEN_twice(x) x,x
220 
221 // QR solver:
222 #define TMV_QR(m) Eigen::ColPivHouseholderQR<DMatrix> QR_Solver_ ## m = (m).colPivHouseholderQr();
223 #define TMV_QR1(m)
224 #define TMV_QR2(m) Eigen::ColPivHouseholderQR<DMatrix> QR_Solver_ ## m = (m).colPivHouseholderQr();
225 // Eigen changed how the QR module works sometime between 2.0.0 and 2.0.10
226 #define TMV_QRisSingular(m) QR_Solver_ ## m .isInjective()
227 #define TMV_QR_Solve(m,x,b) (x) = QR_Solver_ ## m .solve(b);
228 #define TMV_throwSingular throw std::runtime_error("Singular")
229 #define TMV_QR_InverseATA(m,cov) \
230  do { \
231  (cov).setIdentity(); \
232  QR_Solver_ ## m .matrixQR().triangularView<Eigen::Upper>().transpose().solveInPlace(cov); \
233  QR_Solver_ ## m .matrixQR().triangularView<Eigen::Upper>().solveInPlace(cov); \
234  } while (false)
235 
236 #endif
237 
238 #endif
Eigen::Block< DVector, Eigen::Dynamic, 1 > DVectorView
Definition: MyMatrix.h:130
Eigen::Block< CFVector, Eigen::Dynamic, 1 > CFVectorView
Definition: MyMatrix.h:155
const CFMatrixView CFConstMatrixView
Definition: MyMatrix.h:159
Eigen::Matrix< float, 2, 2 > FSmallMatrix22
Definition: MyMatrix.h:152
const DVectorView DConstVectorView
Definition: MyMatrix.h:131
Eigen::Block< CDVector, Eigen::Dynamic, 1 > CDVectorView
Definition: MyMatrix.h:140
Eigen::Block< FMatrix > FMatrixView
Definition: MyMatrix.h:150
const FMatrixView FConstMatrixView
Definition: MyMatrix.h:151
Eigen::Block< FVector, Eigen::Dynamic, 1 > FVectorView
Definition: MyMatrix.h:147
const CFVectorView CFConstVectorView
Definition: MyMatrix.h:156
Eigen::Block< DMatrix > DMatrixView
Definition: MyMatrix.h:133
const CDVectorView CDConstVectorView
Definition: MyMatrix.h:141
const FVectorView FConstVectorView
Definition: MyMatrix.h:148
Eigen::RowVectorXd DRowVector
Definition: MyMatrix.h:136
const DMatrixView DConstMatrixView
Definition: MyMatrix.h:134
const CDMatrixView CDConstMatrixView
Definition: MyMatrix.h:144
Eigen::Matrix< double, 2, 2 > DSmallMatrix22
Definition: MyMatrix.h:135
Eigen::Block< CDMatrix > CDMatrixView
Definition: MyMatrix.h:143
Eigen::Block< CFMatrix > CFMatrixView
Definition: MyMatrix.h:158