Matrix trace
Issue #61
resolved
Hi again,
Another common linalg operation I cannot find is the trace of a matrix. It would be great to have that function as well.
Cheers, Jonas Glesaaen
Comments (4)
-
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Summary
The feature has been implemented, tested, optimized and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.1.
Computing the trace of a matrix
The
trace()
function sums the diagonal elements of a square dense or sparse matrix:blaze::StaticMatrix<int,3UL,3UL> A{ { -1, 2, -3 } , { -4, -5, 6 } , { 7, -8, -9 } }; trace( A ); // Returns the sum of the diagonal elements, i.e. -15
In case the given matrix is not a square matrix, a
std::invalid_argument
exception is thrown. - Log in to comment
Hi Jonas!
Unfortunately, Blaze currently does not provide the feature to compute the trace of a matrix. However, without giving any promise, we might be able to add this feature to the upcoming 3.1 release. Thanks for the great suggestion,
Best regards,
Klaus!