Static assertion fails for row selection with lambdas on submatrices

Issue #247 resolved
Tim Zimmermann created an issue

Consider the following code snippet:

#include "blaze/math/DynamicMatrix.h"
#include "blaze/math/Submatrix.h"
#include "blaze/math/Rows.h"

int main() {
    const size_t N = 10;
    blaze::DynamicMatrix<double> M(N, N, 0);
    auto submat = blaze::submatrix(M, 0, N / 2, N / 2, N / 2);

    // This line compiles just fine.
    //auto odd_rows = blaze::rows(submat, {1, 3}); 

    //This won't: static_assert(!::blaze::IsSubmatrix_v<T>, "Submatrix type detected")
    auto odd_rows = blaze::rows(submat, [](int i) { return 2 * i + 1; }, N / 2);
    return 0;
}

It seems like I can only get row selections of submatrices, if I specify all rows explicitly. Using a lambda, however, fails for submatrices but works for proper matrices (i.e. replace submat with M and everything works fine).

Is this the expected behavior? If so, can you document it in the wiki? Maybe I didn't look carefully enough but I couldn't find any information on this at first sight.

Thanks for the support, Tim

Comments (6)

  1. Klaus Iglberger

    Hi Tim!

    Thanks a lot for taking the time to report this error. Also thank for the minimum example, which helped to quickly reproduce the issue. You are correct, this is a bug on our side. Of course it should also be possible to create a callable-based row selection on a submatrix. We will fix the issue as quickly as possible and apologize for the inconvenience.

    We have noted two possible improvements for your code: First, please prefer size_t to int in order to evade mixing signed and unsigned integrals. Second, there will only be two odd rows in the resulting row selection (i.e. row 1 and 3).

    auto odd_rows = blaze::rows(submat, [](size_t i) { return 2 * i + 1; }, 2);
                                             ^                              ^
                                             |                              |
    //                     prefer 'size_t' to 'int'        There will only be two odd rows in the submatrix (i.e. '1' and '3')
    

    Thanks again, we really appreciate the help,

    Best regards,

    Klaus!

  2. Klaus Iglberger

    Commit 2551cd9 provides the missing overloads for the rows() and columns() functions, which enable a callable-based selection on a submatrix. The fix is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.6.

  3. Log in to comment