Solving of sparse matrix over Z or Zp.
#include <iostream>
#include <linbox/solutions/solve.h>
#include <linbox/util/matrix-stream.h>
#include <linbox/solutions/methods.h>
int main (int argc, char **argv)
{
if (argc < 2 || argc > 4) {
std::cerr << "Usage: checksolve <matrix-file-in-supported-format> <dense-vector-file> <p>" << std::endl;
return 0;
}
std::ifstream input (argv[1]);
if (!input) { std::cerr << "Error opening matrix file " << argv[1] << std::endl; return -1; }
std::ifstream invect(argv[2]);
if (!input) { std::cerr << "Error opening vector file " << argv[2] << std::endl; return -1; }
typedef Givaro::Modular<double> Field;
double q = atof(argv[3]);
Field F(q);
std::cout <<
"A is " << A.
rowdim() <<
" by " << A.
coldim() << std::endl;
for(DenseVector<Field>::iterator it=B.begin();
it != B.end(); ++it)
invect >> *it;
std::cout << "B is [ "<<B<< "]" << std::endl;
solve (X, A, B, Method::DenseElimination());
std::cout << "(DenseElimination) Solution is [ "<<X<< "]" << std::endl;
DenseVector<Field> r(F, A.
rowdim());
VectorDomain<Field> VD(F);
if (VD.areEqual (r,B))
std::cout<<"CHECK"<<std::endl;
else{
std::cout<<"FAIL"<<std::endl;
std::cout<<"r = "<<r<<std::endl;
std::cout<<"B = "<<B<<std::endl;
}
return 0;
}