#include <iostream>
#include <givaro/modular.h>
#include <linbox/algorithms/smith-form-sparseelim-poweroftwo.h>
template<class Int_type, class Ring_type = Givaro::ZRing<Int_type> >
void runpoweroftworank(ifstream& input, const size_t exponent) {
typedef std::vector<std::pair<size_t,Int_type> > Smith_t;
typedef Ring_type Ring;
Smith_t local;
Ring R;
LinBox::SparseMatrix<Ring, LinBox::SparseMatrixFormat::SparseSeq > A (ms);
input.close();
cout << "B is " << A.rowdim() << " by " << A.coldim() << endl;
Givaro::Timer tim;
tim.clear(); tim.start();
PGD(local, A, exponent);
tim.stop();
R.write(std::cout << "Local Smith Form ") << " : " << std::endl << '(';
for (auto p = local.begin(); p != local.end(); ++p)
std::cout << '[' << p->second << ',' << p->first << "] ";
cout << ')' << endl;
std::cerr << tim << std::endl;
}
int main (int argc, char **argv) {
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc < 3 || argc > 4)
{ cerr << "Usage: rank <matrix-file-in-supported-format> <power of two exponent> [<method>]" << endl; return -1; }
ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file: " << argv[1] << endl; return -1; }
size_t method( argc>3? atoi(argv[3]): 0 );
Givaro::Timer tim;
size_t exponent = atoi(argv[2]);
if ((method == 2) || ((method == 0) && (exponent >= (1<<10))) ) {
runpoweroftworank<Givaro::Integer>(input, exponent);
} else {
if ((method == 1) || ((method == 0) && (exponent < 64)) ) {
runpoweroftworank<uint64_t, Givaro::ZRing<int64_t> >(input, exponent);
} else {
switch (method) {
case 6: runpoweroftworank<RecInt::ruint<6>>(input, exponent); break;
case 7: runpoweroftworank<RecInt::ruint<7>>(input, exponent); break;
case 8: runpoweroftworank<RecInt::ruint<8>>(input, exponent); break;
case 9: runpoweroftworank<RecInt::ruint<9>>(input, exponent); break;
case 10: runpoweroftworank<RecInt::ruint<10>>(input, exponent); break;
case 11: runpoweroftworank<RecInt::ruint<11>>(input, exponent); break;
}
}
}
std::cerr << tim << std::endl;
return 0;
}