File indexing completed on 2025-01-18 10:10:15
0001
0002
0003
0004 #ifndef ROOT_Math_Dfactir
0005 #define ROOT_Math_Dfactir
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 #include <cmath>
0032
0033 namespace ROOT {
0034
0035 namespace Math {
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 template <class Matrix, unsigned int n, unsigned int idim>
0046 bool Dfactir(Matrix& rhs, typename Matrix::value_type& det, unsigned int* ir)
0047
0048 {
0049
0050 #ifdef XXX
0051 if (idim < n || n <= 0) {
0052 return false;
0053 }
0054 #endif
0055
0056
0057
0058 typename Matrix::value_type* a = rhs.Array();
0059
0060
0061 unsigned int nxch, i, j, k, l;
0062 typename Matrix::value_type p, q, tf;
0063
0064
0065 a -= idim + 1;
0066 --ir;
0067
0068
0069
0070
0071 nxch = 0;
0072 det = 1.;
0073 for (j = 1; j <= n; ++j) {
0074 const unsigned int ji = j * idim;
0075 const unsigned int jj = j + ji;
0076
0077 k = j;
0078 p = std::abs(a[jj]);
0079
0080 if (j != n) {
0081 for (i = j + 1; i <= n; ++i) {
0082 q = std::abs(a[i + ji]);
0083 if (q > p) {
0084 k = i;
0085 p = q;
0086 }
0087 }
0088
0089 if (k != j) {
0090 for (l = 1; l <= n; ++l) {
0091 const unsigned int li = l*idim;
0092 const unsigned int jli = j + li;
0093 const unsigned int kli = k + li;
0094 tf = a[jli];
0095 a[jli] = a[kli];
0096 a[kli] = tf;
0097 }
0098 ++nxch;
0099 ir[nxch] = (j << 12) + k;
0100 }
0101 }
0102
0103 if (p <= 0.) {
0104 det = 0;
0105 return false;
0106 }
0107
0108 det *= a[jj];
0109 #ifdef XXX
0110 t = std::abs(det);
0111 if (t < 1e-19 || t > 1e19) {
0112 det = 0;
0113 return false;
0114 }
0115 #endif
0116
0117 a[jj] = 1. / a[jj];
0118 if (j == n) {
0119 continue;
0120 }
0121
0122 const unsigned int jm1 = j - 1;
0123 const unsigned int jpi = (j + 1) * idim;
0124 const unsigned int jjpi = j + jpi;
0125
0126 for (k = j + 1; k <= n; ++k) {
0127 const unsigned int ki = k * idim;
0128 const unsigned int jki = j + ki;
0129 const unsigned int kji = k + jpi;
0130 if (j != 1) {
0131 for (i = 1; i <= jm1; ++i) {
0132 const unsigned int ii = i * idim;
0133 a[jki] -= a[i + ki] * a[j + ii];
0134 a[kji] -= a[i + jpi] * a[k + ii];
0135 }
0136 }
0137 a[jki] *= a[jj];
0138 a[kji] -= a[jjpi] * a[k + ji];
0139 }
0140 }
0141
0142 if (nxch % 2 != 0) {
0143 det = -(det);
0144 }
0145 ir[n] = nxch;
0146 return true;
0147 }
0148
0149
0150 }
0151
0152 }
0153
0154
0155
0156 #endif