#include <iostream>
#include "givaro/modular.h"
#include "linbox/solutions/solve.h"
#include "linbox/util/matrix-stream.h"
#include "linbox/solutions/methods.h"
using namespace std;
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc < 2 || argc > 4) {
cerr << "Usage: solve <matrix-file-in-supported-format> [<dense-vector-file>]" << endl;
return 0;
}
std::ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file " << argv[1] << endl; return -1; }
std::ifstream invect;
bool createB = false;
if (argc == 2) {
createB = true;
}
if (argc == 3) {
invect.open (argv[2], std::ifstream::in);
if (!invect) {
createB = true;
}
else {
createB = false;
}
}
{
typedef Givaro::QField<Givaro::Rational> Rats;
Rats QQ;
typedef DenseVector<Rats> RVector;
MatrixStream<Rats> ms( QQ, input );
DenseMatrix<Rats> A ( ms );
std::cout << "A is " << A.rowdim() << " by " << A.coldim() << std::endl;
RVector X(QQ, A.coldim()),B(QQ, A.rowdim());
if (createB) {
cerr << "Creating a random {-1,1} vector " << endl;
for(auto it=B.begin(); it != B.end(); ++it)
if (drand48() <0.5)
*it = -1;
else
*it = 1;
} else {
for(auto&& it:B) invect >> it;
invect.close();
}
std::cout << "B is [";
for(auto it:B) QQ.write(cout, it) << ' ';
std::cout << ']' << std::endl;
Timer chrono;
std::cout << "DenseElimination" << std::endl;
chrono.start();
solve (X, A, B, Method::DenseElimination());
chrono.stop();
std::cout << "(DenseElimination) Solution is [";
for(auto it:X) QQ.write(cout, it) << " ";
std::cout << ']' << std::endl;
std::cout << "CPU time (seconds): " << chrono.usertime() << std::endl;
}
return 0;
}
Namespace in which all linbox code resides.
Definition: alt-blackbox-block-container.h:4
ResultVector & solve(ResultVector &x, const Matrix &A, const Vector &b, const CategoryTag &tag, const Method::Auto &m)
Solve specialisation for Auto.
Definition: solve-auto.h:38
A SparseMatrix<_Field, _Storage> ....