diff --git a/src/TNL/Matrices/Matrix_impl.h b/src/TNL/Matrices/Matrix_impl.h index 33c4d2e654cb32f9ba56516a1678b73d17ee3b96..0e73e6a9a8e9e0e53a722d27fdea47baa7bd019b 100644 --- a/src/TNL/Matrices/Matrix_impl.h +++ b/src/TNL/Matrices/Matrix_impl.h @@ -70,6 +70,20 @@ void Matrix< Real, Device, Index >::setLike( const Matrix< Real2, Device2, Index setDimensions( matrix.getRows(), matrix.getColumns() ); } +template< typename Real, + typename Device, + typename Index > +Index Matrix< Real, Device, Index >::getNumberOfNonzeroMatrixElements() const +{ + IndexType elements( 0 ); + for( IndexType row = 0; row < this->getRows(); row++ ) + for( IndexType column = 0; column < this->getColumns(); column++ ) + if( this->getElement( row, column ) != 0 ) + elements++; + + return elements; +} + template< typename Real, typename Device, typename Index >