From efef3872b64d8c995febaaf87ed3f7039d747196 Mon Sep 17 00:00:00 2001
From: Lukas Cejka <lukas.ostatek@gmail.com>
Date: Mon, 4 Mar 2019 23:32:28 +0100
Subject: [PATCH] Implemented getNumberofNonzeroMatrixElements().

---
 src/TNL/Matrices/Matrix_impl.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/TNL/Matrices/Matrix_impl.h b/src/TNL/Matrices/Matrix_impl.h
index 33c4d2e654..0e73e6a9a8 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 >
-- 
GitLab