00001
00002
00003
00004 #ifndef ROOT_Math_Dsfact
00005 #define ROOT_Math_Dsfact
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 namespace ROOT {
00034
00035 namespace Math {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 template <unsigned int n, unsigned int idim =n>
00048 class SDeterminant {
00049
00050 public:
00051 template <class T>
00052 static bool Dsfact(MatRepStd<T,n,idim>& rhs, T& det) {
00053
00054 #ifdef XXX
00055
00056 if (idim < n || n <= 0) {
00057 return false;
00058 }
00059 #endif
00060
00061 #ifdef OLD_IMPL
00062 typename MatrixRep::value_type* a = rhs.Array();
00063 #endif
00064
00065 #ifdef XXX
00066 const typename MatrixRep::value_type* A = rhs.Array();
00067 typename MatrixRep::value_type array[MatrixRep::kSize];
00068 typename MatrixRep::value_type* a = array;
00069
00070
00071 for(unsigned int i=0; i<MatrixRep::kSize; ++i) {
00072 array[i] = A[i];
00073 }
00074 #endif
00075
00076
00077 static unsigned int i, j, l;
00078
00079
00080
00081 static int arrayOffset = -(idim+1);
00082
00083 det = 1.;
00084 for (j = 1; j <= n; ++j) {
00085 const unsigned int ji = j * idim;
00086 const unsigned int jj = j + ji;
00087
00088 if (rhs[jj + arrayOffset] <= 0.) {
00089 det = 0.;
00090 return false;
00091 }
00092
00093 const unsigned int jp1 = j + 1;
00094 const unsigned int jpi = jp1 * idim;
00095
00096 det *= rhs[jj + arrayOffset];
00097 rhs[jj + arrayOffset] = 1. / rhs[jj + arrayOffset];
00098
00099 for (l = jp1; l <= n; ++l) {
00100 rhs[j + l * idim + arrayOffset] = rhs[jj + arrayOffset] * rhs[l + ji + arrayOffset];
00101
00102 const unsigned int lj = l + jpi;
00103
00104 for (i = 1; i <= j; ++i) {
00105 rhs[lj + arrayOffset] -= rhs[l + i * idim + arrayOffset] * rhs[i + jpi + arrayOffset];
00106 }
00107 }
00108 }
00109
00110 return true;
00111 }
00112
00113
00114
00115
00116 template <class T>
00117 static bool Dsfact(MatRepSym<T,n> & rhs, T & det) {
00118
00119
00120 MatRepStd<T,n> tmp;
00121 for (unsigned int i = 0; i< n*n; ++i)
00122 tmp[i] = rhs[i];
00123 if (! SDeterminant<n>::Dsfact(tmp,det) ) return false;
00124
00125
00126
00127
00128 return true;
00129 }
00130
00131
00132 };
00133
00134 }
00135
00136 }
00137
00138 #endif
00139