vnl_determinant.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include "vnl_determinant.h"
3 
4 int vnl_determinant(vnl_matrix<int> const &M, bool balance )
5 {
6  unsigned n = M.rows();
7  assert(M.cols() == n);
8 
9  switch (n)
10  {
11  case 1: return M[0][0];
12  case 2: return vnl_determinant(M[0], M[1]);
13  case 3: return vnl_determinant(M[0], M[1], M[2]);
14  case 4: return vnl_determinant(M[0], M[1], M[2], M[3]);
15  default:
16  vnl_matrix<double> m(n,n);
17  for (unsigned int i=0; i<n; ++i)
18  for (unsigned int j=0; j<n; ++j)
19  m(i,j)=double(M(i,j));
20  return int(0.5+vnl_determinant(m, balance)); // round to nearest integer
21  }
22 }
unsigned int cols() const
Return the number of columns.
Definition: vnl_matrix.h:183
#define m
Definition: vnl_vector.h:43
calculates the determinant of a matrix
T vnl_determinant(vnl_matrix< T > const &M, bool balance=false)
evaluation using direct methods for sizes of 2x2, 3x3, and 4x4 or qr decomposition for other matrices...
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179