How to get a strictly lower matrix L from a given general matrix A, which is not a strictly lower matrix
I am trying to get a strictly lower matrix L from a given general matrix A. Since A is not a strictly lower matrix and triangular property is always enforced, I cannot directly construct L from A or assign A to L.
One possible solution is to use blaze::band function. But band function can only use one specific band each time. If I want to use the band from 1L to (m1)L, where m is the dimension of matrix A. How can I get the strictly lower matrix L from the matrix A without using a for loop?
Comments (9)


reporter HI Klaus,
Thank you so much for your reply. It really helps.
Best regards
Nanmiao


 changed status to duplicate
Duplicate of #29.

reporter Hi Klaus,
I tried to run the code. But it did not work. First of all, I did not find a matrix type named “DenseMatrix“, so I change all DenseMatrix to DynamicMatrix.
Then it is shown:

Hi!
I implicitly use an
using namespace blaze;
before the code. Please replace allDenseMatrix
byblaze::DenseMatrix
:template< typename MT1, bool SO1, typename MT2, bool SO2 > void copyStrictlyLowerPart( const blaze::DenseMatrix<MT1,SO1>& src, blaze::DenseMatrix<MT2,SO2>& dst ) { decltype(auto) target( derestrict( ~dst ) ); for( size_t i=1UL; i<(~src).rows(); ++i ) { for( size_t j=0UL; j<i; ++j ) { (~target)(i,j) = (~src)(i,j); } } }
Best regards,
Klaus!

reporter Hi Klaus,
Thanks for the reply. But blaze::DenseMatrix is not the issue.
Since matrix A in my code is in the form of:
template< typename MatrixType>
void function_name( ..., const MatrixType& A, ... ),
I change the code you showed me to make them match, as:
template< typename MatrixType>
void copyStrictlyLowerPart( const MatrixType& src, MatrixType& dst )
{
the same
}
But it does not work, shown as:
Do you have any idea about the error information and what I can do?
Thanks!

Hi!
From the given information I can only take a wild guess. Do the two matrices have the same dimensions? In the function it is assumed that both matrices have the same size and that
dst
is already initialized. Else you would have to resize and initialize the target matrix manually:template< typename MT1, bool SO1, typename MT2, bool SO2 > void copyStrictlyLowerPart( const blaze::DenseMatrix<MT1,SO1>& src, blaze::DenseMatrix<MT2,SO2>& dst ) { decltype(auto) target( derestrict( ~dst ) ); resize( target, (~src).rows(), (~src).columns() ); reset( target ); for( size_t i=1UL; i<(~src).rows(); ++i ) { for( size_t j=0UL; j<i; ++j ) { (~target)(i,j) = (~src)(i,j); } } }
That’s unfortunately the only idea I have. I hope this help,
Best regards,
Klaus!

reporter Hi Klaus,
You are right. I forget to declare the size of
dst
matrix before passing it to thecopyStrictlyLowerPart
function. It works correct now! Thank you so much!
Best regards,
Nanmiao
 Log in to comment
Hi!
From your description I understand that the general matrix
A
is not strictly lower and that you want to extract the (strictly) lower part ofA
. This feature unfortunately hasn’t been implemented yet, but is planned (see issue#26). For now you will have to copy explicitly by means of for loops.The following code example gives an impression how to do this copy operation without any performance penalties due to runtime checks in the strictly lower target matrix:
I hope this helps. Thanks for creating this issue,
Best regards,
Klaus!