core/vnl/algo/vnl_determinant.cxx
Go to the documentation of this file.
00001 #include "vnl_determinant.h"
00002 #include <vcl_cassert.h>
00003 
00004 int vnl_determinant(vnl_matrix<int> const &M, bool balance )
00005 {
00006   unsigned n = M.rows();
00007   assert(M.cols() == n);
00008 
00009   switch (n)
00010   {
00011    case 1: return M[0][0];
00012    case 2: return vnl_determinant(M[0], M[1]);
00013    case 3: return vnl_determinant(M[0], M[1], M[2]);
00014    case 4: return vnl_determinant(M[0], M[1], M[2], M[3]);
00015    default:
00016     vnl_matrix<double> m(n,n);
00017     for (unsigned int i=0; i<n; ++i)
00018       for (unsigned int j=0; j<n; ++j)
00019         m(i,j)=double(M(i,j));
00020     return int(0.5+vnl_determinant(m, balance)); // round to nearest integer
00021   }
00022 }