linbox-team / linbox

LinBox - C++ library for exact, high-performance linear algebra

Home Page:https://linbox-team.github.io/linbox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dense solve with Method::Lanczos is segfaulting

Breush opened this issue · comments

#include <linbox/solutions/solve.h>

using namespace LinBox;

int main(void)
{
    using Field = Givaro::Modular<double>;
    using Matrix = DenseMatrix<Field>;
    using Vector = DenseVector<Field>;

    Field F(101);

    Matrix A(F, 1, 2);
    Vector x(F, A.coldim());
    Vector b(F, A.rowdim());

    A.setEntry(0, 0, 13);
    A.setEntry(0, 1, 27);
    F.assign(b[0], 52);

    // Calling Lanczos
    Method::Lanczos method;
    solve(x, A, b, method);

    std::cout << "[ " << A.getEntry(0, 0) << " " << A.getEntry(0, 1) << " ] x = [ " << b[0] << " ]";
    std::cout << " => x = [ " << x[0] << " " << x[1] << " ]" << std::endl;

    Field::Element Ax0, Ax1, Ax;
    F.mul(Ax0, A.getEntry(0, 0), x[0]);
    F.mul(Ax1, A.getEntry(0, 1), x[1]);
    F.add(Ax, Ax0, Ax1);
    if (!F.areEqual(Ax, b[0])) {
        std::cerr << "PROBLEM! Ax != b" << std::endl;
    }

    return 0;
}

Sparse Lanczos seems ok.