From aa62701262719ff850f0936c5b03689988aef254 Mon Sep 17 00:00:00 2001 From: Lukas Cejka <lukas.ostatek@gmail.com> Date: Tue, 5 Mar 2019 16:54:24 +0100 Subject: [PATCH] Improved implementation of getNumberOfNonzeroMatrixElements(). --- src/TNL/Matrices/Matrix_impl.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/TNL/Matrices/Matrix_impl.h b/src/TNL/Matrices/Matrix_impl.h index 0e73e6a9a8..3371ee4ec4 100644 --- a/src/TNL/Matrices/Matrix_impl.h +++ b/src/TNL/Matrices/Matrix_impl.h @@ -75,13 +75,12 @@ template< typename Real, 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++; + IndexType nonZeroElements( 0 ); + for( IndexType i = 0; this->values.getSize(); i++ ) + if( this->values.getElement( i ) != 0.0 ) + nonZeroElements++; - return elements; + return nonZeroElements; } template< typename Real, -- GitLab