Rank of sparse matrix over Z or Zp.
#include <iostream>
#include <sstream>
#include <givaro/givrational.h>
#include <linbox/field/gf2.h>
#include <linbox/blackbox/zero-one.h>
#include <linbox/solutions/rank.h>
#include <linbox/util/matrix-stream.h>
#define SP_STOR SparseMatrixFormat::SparseSeq
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc < 2 || argc > 3) {
std::cerr << "Usage: rank <matrix-file-in-supported-format> [<p>]" << std::endl;
return -1;
}
std::ifstream input (argv[1]);
if (!input) {
std::cerr << "Error opening matrix file: " << argv[1] << std::endl;
return -1;
}
size_t r;
Givaro::QField<Givaro::Rational> QQ;
LinBox::Timer tim ; tim.clear() ; tim.start();
SparseMatrix<Givaro::QField<Givaro::Rational>, SP_STOR> A ( ms );
tim.stop();
std::cout << "matrix is " << A.rowdim() << " by " << A.coldim() << " (" << tim << ")" << std::endl;
tim.clear() ; tim.start();
if (argc == 2) {
}
if (argc == 3) {
uint32_t q = atoi(argv[2]);
if (q == 0) {
std::cerr << "second argument should be a non-zero integer or missing\n";
return -1;
}
typedef Givaro::Modular<double> Field;
Field F(q);
if (q > F.maxCardinality()) {
std::cerr << "your number is too big for this field" << std::endl;
return -1 ;
}
SparseMatrix<Field, SP_STOR > B (F, A.rowdim(), A.coldim());
MatrixHom::map(B, A);
tim.stop();
std::cout << "matrix is " << B.rowdim() << " by " << B.coldim() <<" (time for map: "<< tim << ")" << std::endl;
tim.clear();tim.start();
}
tim.stop();
std::cout << "Rank is " << r << " (" << tim << " )" << std::endl;
return 0;
}