linbox-team / linbox

LinBox - C++ library for exact, high-performance linear algebra
https://linbox-team.github.io/linbox
GNU Lesser General Public License v2.1
83 stars 28 forks source link

issue calculating rank of blackbox sparse matrix over GF2 #311

Open singerng opened 5 months ago

singerng commented 5 months ago

When I try to calculate the rank of a large blackbox sparse matrix over GF2, the code is always outputting zero. Here is an MWE:

#include <iostream>
#include <linbox/linbox-config.h>
#include <sstream>
#include <linbox/ring/modular.h>
#include <linbox/field/gf2.h>
#include <linbox/matrix/sparse-matrix.h>
#include <linbox/solutions/rank.h>
#include "linbox/solutions/solve.h"

#include "square.h"

using namespace LinBox;

int main (int argc, char **argv)
{
    typedef Givaro::Modular<double> Field;
    Field F2(2);

    SparseMatrix<Field> M(F2, 10000, 100000);

    for (int i = 0; i < 1000; i++) {
        M.setEntry(i, i, 1);
    }

    size_t rankResult;
    rank(rankResult, M, Method::Blackbox());

    std::cout << "Rank of M: " << rankResult << std::endl;

    return 0;
}

Is this known behavior because the blackbox solvers are randomized and fail if the field size is small? Or is something else going on? I thought maybe I am supposed to use the GF2 field class directly but can't seem to manage to make that work either.

If the matrix is smaller or if I use SparseElimination instead, everything works fine.

jgdumas commented 5 months ago

Hello, thank you for the report. Indeed our "blackbox" method modulo 2 will not work at all, but still I can reproduce this strange "silent" fail. I'll investigate ...

In the meantime, if you want that kind of rank via Wiedemann's iteration, one way is to ask for a certification as follows: Method::Blackbox meth; meth.certifyInconsistency=true; rank(rankResult, M, meth); This will setup an extension field and produce the rank with much higher probability.