vendredi 8 mai 2015

Permute rows of a eigen matrix with specific indexes

Following the indications published in this previous question, I'm trying to permute the rows of a Eigen matrix using specific indexes.

Basically I have a function that performs the next steps:

    PermutationMatrix<Dynamic, Dynamic, size_t> perm(indices.size());
    copy(indices.begin(), indices.end(), perm.indices().data());
    return perm * mat; // permute rows

But writing some unit tests I realized that in most of the cases the permutation is done incorrectly. This unit tests can corroborate what I just stated (fmatrix_t is a type defined by myself which basically wrap a eigen dynamic mat with float values):

    fmatrix_t m;
    m.resize(8,1);
    m << 0, 1, 2, 3, 4, 5, 6, 7;

    indices_t indices {2,1,4,0,3,7,6,5};
    fmatrix_t m2 = apply_permutation(m, indices);
    BOOST_CHECK_NE(m, m2);
    for (size_t i = 0; i < indices.size(); ++i)
    {
            BOOST_CHECK_EQUAL(m2(i,0), indices[i]);
    }

However when indices is {0,1,2,3,4,5,6,7} or {7,6,5,4,3,2,1,0} the permutation is done correctly. Am I doing something wrong or it could be a Eigen bug?

Aucun commentaire:

Enregistrer un commentaire