FEDRA emulsion software from the OPERA Collaboration
Dsfact.hh File Reference

Go to the source code of this file.

Functions

template<class Matrix , unsigned int n, unsigned int idim>
bool Dsfact (Matrix &rhs, typename Matrix::value_type &det)
 

Function Documentation

◆ Dsfact()

template<class Matrix , unsigned int n, unsigned int idim>
bool Dsfact ( Matrix &  rhs,
typename Matrix::value_type &  det 
)

Dsfact. Compute determinant of a symmetric, positive definite matrix of dimension $idim$ and order $n$.

Author
T. Glebe
36 {
37
38#ifdef XXX
39 /* Function Body */
40 if (idim < n || n <= 0) {
41 return false;
42 }
43#endif
44
45 typename Matrix::value_type* a = rhs.Array();
46
47#ifdef XXX
48 const typename Matrix::value_type* A = rhs.Array();
49 typename Matrix::value_type array[Matrix::size];
50 typename Matrix::value_type* a = array;
51
52 // copy contents of matrix to working place
53 for(unsigned int i=0; i<Matrix::size; ++i) {
54 array[i] = A[i];
55 }
56#endif
57
58 /* Local variables */
59 static unsigned int i, j, l;
60
61 /* Parameter adjustments */
62 a -= idim + 1;
63
64 /* sfactd.inc */
65 det = 1.;
66 for (j = 1; j <= n; ++j) {
67 const unsigned int ji = j * idim;
68 const unsigned int jj = j + ji;
69
70 if (a[jj] <= 0.) {
71 det = 0.;
72 return false;
73 }
74
75 const unsigned int jp1 = j + 1;
76 const unsigned int jpi = jp1 * idim;
77
78 det *= a[jj];
79 a[jj] = 1. / a[jj];
80
81 for (l = jp1; l <= n; ++l) {
82 a[j + l * idim] = a[jj] * a[l + ji];
83
84 const unsigned int lj = l + jpi;
85
86 for (i = 1; i <= j; ++i) {
87 a[lj] -= a[l + i * idim] * a[i + jpi];
88 } // for i
89 } // for l
90 } // for j
91
92 return true;
93} // end of Dsfact
void a()
Definition: check_aligned.C:59