Slicing and removing matrix columns/rows support?

Issue #352 resolved
Nafis Sadat created an issue

Hello! I couldn’t find this in the docs anywhere so I was wondering if you guys have plans for implementing functions for dropping specific columns from a matrix (or slicing a matrix to a vector)?

Comments (3)

  1. Klaus Iglberger

    Hi Nafis!

    Thanks a lot for taking the time to create this issue. The feature(s) you’re looking for are views, in particular rows and columns. These can for instance be used to implement custom operations for dropping rows and/or columns:

    template< typename MT, bool SO >
    void dropRow( blaze::DenseMatrix<MT,SO>& m, size_t index )
    {
       BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE( MT );
    
       if( index >= rows(m) ) {
          throw std::invalid_argument( "Invalid row index" );
       }
    
       for( size_t i=index+1UL; i<rows(m); ++i ) {
          row( m, i-1UL ) = row( m, i );
       }
    
       resize( m, rows(m)-1UL, columns(m) );
    }
    
    template< typename MT, bool SO >
    void dropColumn( blaze::DenseMatrix<MT,SO>& m, size_t index )
    {
       BLAZE_CONSTRAINT_MUST_BE_RESIZABLE_TYPE( MT );
    
       if( index >= columns(m) ) {
          throw std::invalid_argument( "Invalid column index" );
       }
    
       for( size_t i=index+1UL; i<columns(m); ++i ) {
          column( m, i-1UL ) = column( m, i );
       }
    
       resize( m, rows(m), columns(m)-1UL );
    }
    

    For more information on adding types and operations to Blaze, please see the Customization page in the wiki (in particular the page about Vector and Matrix customization). I hope this helps,

    Best regards,

    Klaus!

  2. Nafis Sadat reporter

    Thank you so much Klaus! I’m super new to using Blaze so I’ll give all those pages a read!

  3. Log in to comment