1 #ifndef TOON_INCLUDE_DETERMINANT_H
2 #define TOON_INCLUDE_DETERMINANT_H
6 #ifdef TOON_DETERMINANT_LAPACK
30 static const int Size = R;
39 static const int Size = R;
47 static const int Size = C;
65 template<
int R,
int C,
typename Precision,
typename Base>
73 int size=A.num_rows();
81 for (
int i=0; i<size; ++i) {
85 Precision maxval =
abs(A[i][i]);
87 for (
int ii=i+1; ii<size; ++ii) {
88 double v =
abs(A[ii][i]);
94 Precision pivot = A[argmax][i];
102 for (
int j=i; j<size; ++j)
103 swap(A[i][j], A[argmax][j]);
106 determinant *= A[i][i];
111 for (
int u=i+1; u<size; ++u) {
114 double factor = A[u][i]/pivot;
116 for (
int j=i+1; j<size; ++j)
117 A[u][j] = A[u][j] - factor * A[i][j];
124 #ifdef TOON_DETERMINANT_LAPACK
130 template<
int R,
int C,
class P,
class B>
131 P determinant_LU(
const Matrix<R, C, P, B>& A)
134 LU<Internal::Square<R,C>::Size, P> lu(A);
135 return lu.determinant();
148 template<
int R,
int C,
class P,
class B>
152 if(A.num_rows() == 2)
153 return A[0][0]*A[1][1] - A[1][0]*A[0][1];
154 #if defined TOON_DETERMINANT_LAPACK && TOON_DETERMINANT_LAPACK != -1
155 else if(A.num_rows() >= TOON_DETERMINANT_LAPACK)
156 return determinant_LU(A);
P determinant(const Matrix< R, C, P, B > &A)
Everything lives inside this namespace.
Precision determinant_gaussian_elimination(const Matrix< R, C, Precision, Base > &A_)
static const int Dynamic
Template size value used to indicate dynamically sized vectors and matrices.
static void test(int s1, int s2)