File indexing completed on 2024-04-06 12:04:43
0001 #ifdef NEWSMATRIX
0002
0003 #define SMATRIX_USE_CONSTEXPR
0004 #include "Math/SMatrix.h"
0005
0006 typedef unsigned int IndexType;
0007
0008
0009
0010 namespace ROOT {
0011
0012 namespace Math {
0013
0014 constexpr int fOff15x15[] =
0015 { 0,1,3,6,10,15,21,28,36,45,55,66,78,91,105,1,2,4,7,11,16,22,29,37,46,56,67,79,92,106,3,4,5,8,12,17,23,30,38,47,57,68,80,93,107,6,7,8,9,13,18,24,31,39,48,58,69,81,94,108,10,11,12,13,14,19,25,32,40,49,59,70,82,95,109,15,16,17,18,19,20,26,33,41,50,60,71,83,96,110,21,22,23,24,25,26,27,34,42,51,61,72,84,97,111,28,29,30,31,32,33,34,35,43,52,62,73,85,98,112,36,37,38,39,40,41,42,43,44,53,63,74,86,99,113,45,46,47,48,49,50,51,52,53,54,64,75,87,100,114,55,56,57,58,59,60,61,62,63,64,65,76,88,101,115,66,67,68,69,70,71,72,73,74,75,76,77,89,102,116,78,79,80,81,82,83,84,85,86,87,88,89,90,103,117,91,92,93,94,95,96,97,98,99,100,101,102,103,104,118,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119 };
0016
0017 constexpr int const * pfOff15x15[]= {fOff15x15+0,fOff15x15+15,fOff15x15+2*15,fOff15x15+3*15,fOff15x15+4*15,fOff15x15+5*15,fOff15x15+6*15,fOff15x15+7*15,fOff15x15+8*15,fOff15x15+9*15,fOff15x15+10*15,fOff15x15+11*15,fOff15x15+12*15,fOff15x15+13*15,fOff15x15+14*15};
0018 template<>
0019 struct RowOffsets<15> {
0020 RowOffsets() {}
0021 int operator()(unsigned int i, unsigned int j) const { return pfOff15x15[i][j]; }
0022 int apply(unsigned int i) const { return fOff15x15[i]; }
0023 };
0024
0025
0026
0027
0028
0029
0030
0031
0032 struct AssignAsSym
0033 {
0034
0035 template <class T,
0036 IndexType D,
0037 class A,
0038 class R>
0039 static void Evaluate(SMatrix<T,D,D,MatRepStd<T,D> >& lhs, const Expr<A,T,D,D,R>& rhs)
0040 {
0041
0042 for( IndexType i=0; i<D; ++i)
0043
0044 for( IndexType j=0; j<=i; ++j) {
0045 lhs(i,j) = rhs(i,j);
0046 }
0047 }
0048
0049 template <class T,
0050 IndexType D,
0051 class R>
0052 static void Evaluate(SMatrix<T,D,D,MatRepStd<T,D> >& lhs, const SMatrix<T,D,D,R>& rhs)
0053 {
0054
0055 for( IndexType i=0; i<D; ++i)
0056
0057 for( IndexType j=0; j<=i; ++j) {
0058 lhs(i,j) = rhs(i,j);
0059 }
0060 }
0061 };
0062
0063
0064 template <class T, IndexType D1, IndexType D2, class R>
0065 inline SMatrix<T,D1,D1,MatRepSym<T,D1> > Similarity(const SMatrix<T,D1,D2,R>& lhs, const SMatrix<T,D2,D2,MatRepStd<T,D2> >& rhs) {
0066 SMatrix<T,D1,D2, MatRepStd<T,D1,D2> > tmp = lhs * rhs;
0067 typedef SMatrix<T,D1,D1,MatRepSym<T,D1> > SMatrixSym;
0068 SMatrixSym mret;
0069 AssignSym::Evaluate(mret, tmp * Transpose(lhs) );
0070 return mret;
0071 }
0072
0073 }
0074 }
0075
0076 template<typename T, IndexType N>
0077 inline void
0078 mult(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > & a,
0079 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & rh,
0080 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & lh) {
0081
0082 for (IndexType i=0; i!=N; ++i) {
0083 IndexType off_i = a.fRep.offset(i,0);
0084 for (IndexType k=0; k!=N; ++k) {
0085 IndexType off_k = a.fRep.offset(k,0);
0086 if (k<i) {
0087 for (IndexType j=0; j!=(k+1); ++j)
0088 a.Array()[off_i+j] += rh(i,k)*lh.Array()[off_k+j];
0089 for (IndexType j=k+1; j!=(i+1); ++j)
0090 a.Array()[off_i+j] += rh(i,k)*lh(k,j);
0091 }
0092 else
0093 for (IndexType j=0; j!=(i+1); ++j)
0094 a.Array()[off_i+j] += rh(i,k)*lh.Array()[off_k+j];
0095 }
0096 }
0097 }
0098
0099
0100 template<typename T, IndexType N>
0101 inline void
0102 mult(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > & a,
0103 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & rh,
0104 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & lh) {
0105
0106 for (IndexType i=0; i!=N; ++i) {
0107 for (IndexType j=0; j<=i; ++j) {
0108
0109
0110 for (IndexType k=0; k!=N; ++k)
0111 a(i,j) += rh(i,k)*lh(j,k);
0112 }
0113
0114 }
0115
0116 for (IndexType i=0; i!=N-1; ++i)
0117 for (IndexType j=i+1; j!=N; ++j)
0118 a(i,j)=a(j,i);
0119
0120 }
0121
0122
0123 template<typename T, IndexType N>
0124 inline void
0125 similarity(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > & b,
0126 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & u,
0127 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & a) {
0128 for (IndexType i=0; i!=N; ++i)
0129 for (IndexType j=0; j<=i; ++j)
0130 for (IndexType k=0; k!=N; ++k)
0131 for (IndexType l=0; l!=N; ++l)
0132 b(i,j) += u(i,k)*a(k,l)*u(j,l);
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 for (IndexType i=0; i!=N-1; ++i)
0148 for (IndexType j=i+1; j!=N; ++j)
0149 b(i,j)=b(j,i);
0150
0151 }
0152
0153
0154 template<typename T, IndexType N>
0155 inline void
0156 similarityT(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > & b,
0157 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & u,
0158 ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepStd<T,N> > const & a) {
0159 for (IndexType i=0; i!=N; ++i)
0160 for (IndexType j=0; j<=i; ++j)
0161 for (IndexType k=0; k!=N; ++k)
0162 for (IndexType l=0; l!=N; ++l)
0163 b(i,j) += u(k,i)*a(k,l)*u(l,j);
0164
0165 for (IndexType i=0; i!=N-1; ++i)
0166 for (IndexType j=i+1; j!=N; ++j)
0167 b(i,j)=b(j,i);
0168
0169 }
0170
0171 template<typename M1, typename M2>
0172 double eps(M1 const & m1, M2 const & m2) {
0173 IndexType N = M1::kRows;
0174 double ret=0.;
0175 for (IndexType i=0; i!=N; ++i)
0176 for (IndexType j=0; j!=N; ++j)
0177 ret = std::max(ret,std::abs(m1(i,j)-m2(i,j)));
0178 return ret;
0179 }
0180
0181 template<typename M>
0182 bool isSym(M const & m) {
0183 IndexType N = M::kRows;
0184 for (IndexType i=0; i!=N; ++i)
0185 for (IndexType j=0; j<=i; ++j)
0186 if (m(i,j)!=m(j,i)) return false;
0187 return true;
0188 }
0189
0190 #include