FEDRA emulsion software from the OPERA Collaboration
Dsfact.hh
Go to the documentation of this file.
1#ifndef __DSFACT_HH
2#define __DSFACT_HH
3// ********************************************************************
4//
5// source:
6//
7// type: source code
8//
9// created: 22. Mar 2001
10//
11// author: Thorsten Glebe
12// HERA-B Collaboration
13// Max-Planck-Institut fuer Kernphysik
14// Saupfercheckweg 1
15// 69117 Heidelberg
16// Germany
17// E-mail: T.Glebe@mpi-hd.mpg.de
18//
19// Description: Determinant of a symmetric, positive definite matrix.
20// Code was taken from CERNLIB::kernlib dsfact function, translated
21// from FORTRAN to C++ and optimized.
22//
23// changes:
24// 22 Mar 2001 (TG) creation
25// 18 Apr 2001 (TG) removed internal copying of array.
26//
27// ********************************************************************
28
35template <class Matrix, unsigned int n, unsigned int idim>
36bool Dsfact(Matrix& rhs, typename Matrix::value_type& det) {
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
94
95#endif
bool Dsfact(Matrix &rhs, typename Matrix::value_type &det)
Definition: Dsfact.hh:36
void a()
Definition: check_aligned.C:59