Determinant of sparse matrix over Z or Zp.
Determinant of sparse matrix over Z or Zp.
#include <iostream>
int main (
int argc,
char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc <= 1 || argc > 3) {
cerr << "Usage: det <matrix-file-in-supported-format> [<p>]" << endl;
return -1;
}
if (argc == 2 ) {
typedef Givaro::ZRing<Integer> Integers;
Integers ZZ;
ifstream input (argv[1]);
if (!input)
{ cerr << "Error opening matrix file " << argv[1] << endl;
return -1;
}
cout <<
"Matrix is " << A.
rowdim() <<
" by " << A.
coldim() << endl;
Integers::Element det_A;
det (det_A, A);
cout << "Determinant is ";
ZZ.write(cout, det_A) << endl;
}
if (argc == 3) {
typedef Givaro::Modular<double> Field;
double q = atof(argv[2]);
Field F(q);
ifstream input (argv[1]);
if (!input)
{ cerr << "Error opening matrix file " << argv[1] << endl;
return -1;
}
SparseMatrix<Field> B (F); B.read(input);
cout << "Matrix is " << B.rowdim() << " by " << B.coldim() << endl;
Field::Element det_B;
det (det_B, B);
cout << "Determinant is ";
F.write(cout, det_B) << " mod " << q << endl;
}
return 0;
}
size_t rowdim() const
Get the number of rows in the matrix.
Definition: blas-matrix.inl:502
size_t coldim() const
Get the number of columns in the matrix.
Definition: blas-matrix.inl:508
std::istream & read(std::istream &file)
Read the matrix from an input stream.
Definition: blas-matrix.inl:423
int main()
no command line args
Definition: ex-fields-archetype.C:70
linbox base configuration file
A Givaro::Modular ring is a representations of Z/mZ.
Namespace in which all linbox code resides.
Definition: alt-blackbox-block-container.h:4
A SparseMatrix<_Field, _Storage> ....