+ // Now come the minor expansion schemes. We always develop such that the
+ // smallest minors (i.e, the trivial 1x1 ones) are on the rightmost column.
+ // For this to be efficient it turns out that the emptiest columns (i.e.
+ // the ones with most zeros) should be the ones on the right hand side.
+ // Therefore we presort the columns of the matrix:
+ typedef pair<unsigned,unsigned> uintpair; // # of zeros, column
+ vector<uintpair> c_zeros; // number of zeros in column
+ for (unsigned c=0; c<col; ++c) {
+ unsigned acc = 0;
+ for (unsigned r=0; r<row; ++r)
+ if (m[r*col+c].is_zero())
+ ++acc;
+ c_zeros.push_back(uintpair(acc,c));
+ }
+ sort(c_zeros.begin(),c_zeros.end());
+ vector<unsigned> pre_sort; // unfortunately vector<uintpair> can't be used
+ // for permutation_sign.
+ for (vector<uintpair>::iterator i=c_zeros.begin(); i!=c_zeros.end(); ++i)
+ pre_sort.push_back(i->second);
+ int sign = permutation_sign(pre_sort);
+ exvector result(row*col); // represents sorted matrix
+ unsigned c = 0;
+ for (vector<unsigned>::iterator i=pre_sort.begin();
+ i!=pre_sort.end();
+ ++i,++c) {
+ for (unsigned r=0; r<row; ++r)
+ result[r*col+c] = m[r*col+(*i)];
+ }
+
+ if (0*sparse_count>row*col) { // MAGIC, maybe 10 some day?
+ if (normal_flag)
+ return sign*matrix(row,col,result).determinant_minor_sparse().normal();
+ return sign*matrix(row,col,result).determinant_minor_sparse();
+ }
+ if (normal_flag)
+ return sign*matrix(row,col,result).determinant_minor_dense().normal();
+ return sign*matrix(row,col,result).determinant_minor_dense();