Skip to content
Snippets Groups Projects
Commit 40db8e95 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Implementing SparseMatrix::getNumberOfNonzeroMatrixElements.

parent 2ee53835
No related branches found
No related tags found
1 merge request!48Segments
...@@ -17,7 +17,7 @@ namespace TNL { ...@@ -17,7 +17,7 @@ namespace TNL {
namespace Matrices { namespace Matrices {
template< typename Real, template< typename Real,
template< typename, typename > class Segments, template< typename Device_, typename Index_ > class Segments,
typename Device = Devices::Host, typename Device = Devices::Host,
typename Index = int, typename Index = int,
typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >, typename RealAllocator = typename Allocators::Default< Device >::template Allocator< Real >,
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#pragma once #pragma once
#include <functional>
#include <TNL/Matrices/SparseMatrix.h> #include <TNL/Matrices/SparseMatrix.h>
#include <TNL/Algorithms/Reduction.h>
namespace TNL { namespace TNL {
namespace Matrices { namespace Matrices {
...@@ -192,6 +194,12 @@ Index ...@@ -192,6 +194,12 @@ Index
SparseMatrix< Real, Segments, Device, Index, RealAllocator, IndexAllocator >:: SparseMatrix< Real, Segments, Device, Index, RealAllocator, IndexAllocator >::
getNumberOfNonzeroMatrixElements() const getNumberOfNonzeroMatrixElements() const
{ {
const auto columns_view = this->columnIndexes.getConstView();
const IndexType paddingIndex = this->getPaddingIndex();
auto fetch = [=] __cuda_callable__ ( const IndexType i ) -> IndexType {
return ( columns_view[ i ] != paddingIndex );
};
return Algorithms::Reduction< DeviceType >::reduce( this->columnIndexes.getSize(), std::plus<>{}, fetch, 0 );
} }
template< typename Real, template< typename Real,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment