Gaussian elimination Rank of sparse matrix over Z or Zp.
#include <iostream>
#include <vector>
#include <utility>
#include <givaro/zring.h>
#include <givaro/givrational.h>
#include <givaro/modular.h>
#include <linbox/field/gf2.h>
#include <linbox/blackbox/zero-one.h>
#include <linbox/solutions/rank.h>
#include <linbox/util/matrix-stream.h>
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
commentator().
setBriefReportStream (std::cout);
if (argc < 2 || argc > 3)
{ cerr << "Usage: rank <matrix-file-in-supported-format> [<p>]" << endl; return -1; }
ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file: " << argv[1] << endl; return -1; }
size_t r;
if (argc == 2) {
Givaro::QField<Givaro::Rational> QQ;
if (A.rowdim() <= 20 && A.coldim() <= 20) A.write(std::cerr << "A:=",Tag::FileFormat::Maple) << ';' << std::endl;
cout << "A is " << A.rowdim() << " by " << A.coldim() << endl;
cout << "Z Rank is " << r << endl;
}
if (argc == 3) {
double q = atof(argv[2]);
typedef Givaro::Modular<double> Field;
Field F(q);
SparseMatrix<Field, SparseMatrixFormat::SparseSeq > B (ms);
cout << "B is " << B.rowdim() << " by " << B.coldim() << endl;
if (B.rowdim() <= 20 && B.coldim() <= 20) B.write(cout) << endl;
Method::SparseElimination SE;
SE.pivotStrategy = PivotStrategy::Linear;
Givaro::Timer chrono; chrono.start();
LinBox::rankInPlace (r, B, SE);
chrono.stop();
if (B.rowdim() <= 20 && B.coldim() <= 20) B.write(cout) << endl;
F.write(cout << "Rank is " << r << " over ") << endl;
std::cerr << chrono << std::endl;
}
return 0;
}