File indexing completed on 2025-01-18 10:10:16
0001
0002
0003
0004 #ifndef ROOT_Math_Dsfact
0005 #define ROOT_Math_Dsfact
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #include "Math/MatrixRepresentationsStatic.h"
0033
0034 namespace ROOT {
0035
0036 namespace Math {
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 template <unsigned int n, unsigned int idim =n>
0049 class SDeterminant {
0050
0051 public:
0052 template <class T>
0053 static bool Dsfact(MatRepStd<T,n,idim>& rhs, T& det) {
0054
0055 #ifdef XXX
0056
0057 if (idim < n || n <= 0) {
0058 return false;
0059 }
0060 #endif
0061
0062 #ifdef OLD_IMPL
0063 typename MatrixRep::value_type* a = rhs.Array();
0064 #endif
0065
0066 #ifdef XXX
0067 const typename MatrixRep::value_type* A = rhs.Array();
0068 typename MatrixRep::value_type array[MatrixRep::kSize];
0069 typename MatrixRep::value_type* a = array;
0070
0071
0072 for(unsigned int i=0; i<MatrixRep::kSize; ++i) {
0073 array[i] = A[i];
0074 }
0075 #endif
0076
0077
0078 unsigned int i, j, l;
0079
0080
0081
0082 const int arrayOffset = -(idim+1);
0083
0084 det = 1.;
0085 for (j = 1; j <= n; ++j) {
0086 const unsigned int ji = j * idim;
0087 const unsigned int jj = j + ji;
0088
0089 if (rhs[jj + arrayOffset] <= 0.) {
0090 det = 0.;
0091 return false;
0092 }
0093
0094 const unsigned int jp1 = j + 1;
0095 const unsigned int jpi = jp1 * idim;
0096
0097 det *= rhs[jj + arrayOffset];
0098 rhs[jj + arrayOffset] = 1. / rhs[jj + arrayOffset];
0099
0100 for (l = jp1; l <= n; ++l) {
0101 rhs[j + l * idim + arrayOffset] = rhs[jj + arrayOffset] * rhs[l + ji + arrayOffset];
0102
0103 const unsigned int lj = l + jpi;
0104
0105 for (i = 1; i <= j; ++i) {
0106 rhs[lj + arrayOffset] -= rhs[l + i * idim + arrayOffset] * rhs[i + jpi + arrayOffset];
0107 }
0108 }
0109 }
0110
0111 return true;
0112 }
0113
0114
0115
0116
0117 template <class T>
0118 static bool Dsfact(MatRepSym<T,n> & rhs, T & det) {
0119
0120
0121 MatRepStd<T,n> tmp;
0122 for (unsigned int i = 0; i< n*n; ++i)
0123 tmp[i] = rhs[i];
0124 if (! SDeterminant<n>::Dsfact(tmp,det) ) return false;
0125
0126
0127
0128
0129 return true;
0130 }
0131
0132
0133 };
0134
0135 }
0136
0137 }
0138
0139 #endif
0140