File indexing completed on 2025-04-19 09:09:49
0001 #ifndef ATOOLS_Math_Matrix_H
0002 #define ATOOLS_Math_Matrix_H
0003
0004
0005
0006
0007 #include "ATOOLS/Math/Vector.H"
0008 #include "ATOOLS/Math/MyComplex.H"
0009
0010 namespace ATOOLS {
0011
0012 template<int _rank>
0013 class Matrix {
0014 protected:
0015 double ** p_m;
0016 void NumRecipesNotation();
0017 void AmegicNotation();
0018 void Jacobi(double d[], Matrix<_rank>&, int *) const;
0019 public:
0020 Matrix();
0021 Matrix(const double ma[_rank][_rank]);
0022 Matrix(const Matrix<_rank>&);
0023 ~Matrix();
0024 Matrix<_rank>& operator=(const Matrix<_rank>&);
0025 Matrix<_rank> operator*(const double);
0026 Matrix<_rank> operator*(const Matrix<_rank>&);
0027 double * operator[](int i);
0028 const double * operator[](int i) const;
0029 void MatrixOut() const;
0030 int Rank() const {return _rank;}
0031 void Diagonalize(double *,Matrix<_rank>&) const;
0032 void DiagonalizeSort(double *,Matrix<_rank>&) const;
0033 Matrix<_rank> Dagger();
0034
0035 };
0036
0037 class CMatrix {
0038 protected:
0039 Complex ** p_m;
0040 int m_rank;
0041 public:
0042 CMatrix() { m_rank = 0; p_m = NULL; }
0043 CMatrix(int);
0044 CMatrix(Complex**,int);
0045 CMatrix(const CMatrix&);
0046 ~CMatrix();
0047 CMatrix Conjugate();
0048 int Rank() const { return m_rank; }
0049 Complex * operator[](int i) { return p_m[i]; }
0050 const Complex * operator[](int i) const { return p_m[i]; }
0051 Vec4C operator* (const Vec4C& cvec);
0052 Complex ** GetMatrix() const { return p_m; }
0053 };
0054
0055
0056
0057
0058 template<int _rank>
0059 inline Matrix<_rank> operator*(const double scal, const Matrix<_rank>& in) {
0060 Matrix<_rank> out;
0061 for(short int i=0; i<_rank; i++) {
0062 for(short int j=0; j<_rank; j++) {
0063 out[i][j]=scal*in[i][j];
0064 }
0065 }
0066 return out;
0067 }
0068
0069 template<int _rank>
0070 Matrix<_rank> operator*(const Matrix<_rank>& a,const Matrix<_rank>& b) {
0071 Matrix<_rank> out;
0072
0073 for(short int i=0; i<_rank; i++) {
0074 for(short int j=0; j<_rank; j++) {
0075 out[i][j] = 0.;
0076 for(short int k=0; k<_rank; k++) out[i][j] += a[i][k]*b[k][j];
0077 }
0078 }
0079 return out;
0080 }
0081
0082 inline Vec4D operator*(const Matrix<4>& a,const Vec4D& b) {
0083 Vec4D out;
0084
0085 for(short int i=0; i<4; i++) {
0086 out[i] = 0.;
0087 for(short int k=0; k<4; k++) out[i] += a[i][k]*b[k];
0088 }
0089 return out;
0090 }
0091
0092 inline Vec4D operator*(const Vec4D& a,const Matrix<4>& b) {
0093 Vec4D out;
0094
0095 for(short int i=0; i<4; i++) {
0096 out[i] = 0.;
0097 for(short int k=0; k<4; k++) out[i] += a[k]*b[k][i];
0098 }
0099 return out;
0100 }
0101
0102 CMatrix operator*(const Complex scal, const CMatrix& in);
0103 CMatrix operator*(const CMatrix& a,const CMatrix& b);
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 }
0227
0228 #endif
0229
0230