Is it possible to get the stride value from a (Sub)Matrix/(Sub)Vector?

Issue #187 resolved
Mikhail Katliar created an issue

Is it possible to get the value of stride (pointer distance between subsequent rows (for row-major matrices) or columns (for column-major matrices)) for dense matrices and submatrices, accounted for padding? Similarly, is it possible to get the pointer difference between adjacent elements for subvectors? I need to know the strides to interface Blaze objects to a C-code which takes raw pointers.

Comments (4)

  1. Klaus Iglberger

    Hi Mikhail!

    For matrices you are looking for the spacing() function:

    blaze::DynamicMatrix<int,blaze::rowMajor> A( 13UL, 17UL );  // Create a 13x17 row-major dense matrix
    const size_t S1 = A.spacing();  // Returns the total number of elements in a row, including padding
    
    blaze::DynamicMatrix<int,blaze::columnMajor> B( 15UL, 11UL );  // Create a 15x11 column-major dense matrix
    const size_t S2 = B.spacing();  // Returns the total number of elements in a column, including padding
    
    auto C = submatrix( A, 2UL, 3UL, 5UL, 6UL );  // Creating a 5x6 row-major submatrix
    const size_t S3 = C.spacing();  // Returns the total number of elements in a submatrix row, including padding
    

    Unfortunately this function is missing in the documentation. We will update the tutorial and wiki accordingly. Please excuse this oversight.

    In case of subvectors you can safely assume a stride of 1. The only case where this is not true is when you use a subvector on an element selection or a band.

    Best regards,

    Klaus!

  2. Klaus Iglberger

    The spacing() function has been documented in the tutorial and the wiki. The updated tutorial is immediately available via cloning the Blaze repository, the updated wiki will be available with the officially release of Blaze 3.4.

  3. Log in to comment