#include <iostream>
#include <givaro/modular.h>
#include <linbox/solutions/smith-form.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, size_t StPr) {
typedef Ring_type Ring;
typedef LinBox::SparseMatrix<Ring,
SmithList<Ring> local;
Ring R;
SparseMat A (ms);
input.close();
LinBox::GF2 F2;
Permutation<GF2> Q(F2,A.coldim());
cout << "A is " << A.rowdim() << " by " << A.coldim() << endl;
if (A.rowdim() <= 20 && A.coldim() <= 20) A.write(cout,Tag::FileFormat::Maple) << endl;
Givaro::Timer tim;
tim.clear(); tim.start();
if (StPr)
PGD(local, A, Q, exponent, StPr);
else
PGD(local, A, Q, exponent);
tim.stop();
R.write(std::cout << "Local Smith Form ") << " : " << std::endl << '(';
int num = A.rowdim();
for (auto p = local.begin(); p != local.end(); ++p) {
std::cout << '[' << p->first << ',' << p->second << "] ";
num -= p->second;
}
if (num > 0) std::cout << '[' << F2.zero << ',' << num << "] ";
std::cout << ')' << std::endl;
if (A.rowdim() <= 20 && A.coldim() <= 20) {
A.write(cerr,Tag::FileFormat::Maple) << endl;
Q.write(cerr,Tag::FileFormat::Maple) << 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 > 5)
{ cerr << "Usage: rank <matrix-file-in-supported-format> <power of two exponent> [<method>] [<flag>]" << endl; return -1; }
ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file: " << argv[1] << endl; return -1; }
int method( argc>3? atoi(argv[3]): 0 );
Givaro::Timer tim;
int exponent = atoi(argv[2]);
size_t StPr( argc>4? atoi(argv[4]): 0);
if ((method == 2) || ((method == 0) && (exponent >= (1<<11))) ) {
runpoweroftworank<Givaro::Integer>(input, exponent, StPr);
} else {
if ((method == 1) || ((method == 0) && (exponent < 64)) ) {
runpoweroftworank<uint64_t>(input, exponent, StPr);
} else {
switch (method) {
case 6: runpoweroftworank<RecInt::ruint<6>>(input, exponent, StPr); break;
case 7: runpoweroftworank<RecInt::ruint<7>>(input, exponent, StPr); break;
case 8: runpoweroftworank<RecInt::ruint<8>>(input, exponent, StPr); break;
case 9: runpoweroftworank<RecInt::ruint<9>>(input, exponent, StPr); break;
case 10: runpoweroftworank<RecInt::ruint<10>>(input, exponent, StPr); break;
case 11: runpoweroftworank<RecInt::ruint<11>>(input, exponent, StPr); break;
default: std::cerr << "Choose between ruint<6> ... ruint<11>" << std::endl;
break;
}
}
}
std::cerr << tim << std::endl;
return 0;
}