Loading src/TNL/Matrices/DenseMatrix.h +3 −0 Original line number Diff line number Diff line Loading @@ -346,6 +346,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * \par Output * \include DenseMatrixExample_setElement.out */ __cuda_callable__ void setElement( const IndexType row, const IndexType column, const RealType& value ); Loading @@ -365,6 +366,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * \param thisElementMultiplicator is multiplicator the original matrix element * value is multiplied by before addition of given e value. */ __cuda_callable__ void addElement( const IndexType row, const IndexType column, const RealType& value, Loading @@ -384,6 +386,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * * \return value of given matrix element. */ __cuda_callable__ Real getElement( const IndexType row, const IndexType column ) const; Loading src/TNL/Matrices/DenseMatrix.hpp +4 −3 Original line number Diff line number Diff line Loading @@ -233,6 +233,7 @@ DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: reset() { Matrix< Real, Device, Index >::reset(); this->segments.reset(); } template< typename Real, Loading Loading @@ -300,7 +301,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > void __cuda_callable__ void DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: setElement( const IndexType row, const IndexType column, Loading @@ -314,7 +315,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > void __cuda_callable__ void DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: addElement( const IndexType row, const IndexType column, Loading @@ -329,7 +330,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > Real __cuda_callable__ Real DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: getElement( const IndexType row, const IndexType column ) const Loading src/TNL/Matrices/DenseMatrixView.h +3 −2 Original line number Diff line number Diff line Loading @@ -91,8 +91,6 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > IndexType getNonzeroElementsCount() const; void reset(); __cuda_callable__ const RowView getRow( const IndexType& rowIdx ) const; Loading @@ -110,15 +108,18 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > const Real& operator()( const IndexType row, const IndexType column ) const; __cuda_callable__ void setElement( const IndexType row, const IndexType column, const RealType& value ); __cuda_callable__ void addElement( const IndexType row, const IndexType column, const RealType& value, const RealType& thisElementMultiplicator = 1.0 ); __cuda_callable__ Real getElement( const IndexType row, const IndexType column ) const; Loading src/TNL/Matrices/DenseMatrixView.hpp +3 −14 Original line number Diff line number Diff line Loading @@ -168,17 +168,6 @@ getNonzeroElementsCount() const return Algorithms::Reduction< DeviceType >::reduce( this->values.getSize(), std::plus<>{}, fetch, 0 ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder > void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: reset() { Matrix< Real, Device, Index >::reset(); } template< typename Real, typename Device, typename Index, Loading Loading @@ -250,7 +239,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > void __cuda_callable__ void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: setElement( const IndexType row, const IndexType column, Loading @@ -263,7 +252,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > void __cuda_callable__ void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: addElement( const IndexType row, const IndexType column, Loading @@ -283,7 +272,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > Real __cuda_callable__ Real DenseMatrixView< Real, Device, Index, RowMajorOrder >:: getElement( const IndexType row, const IndexType column ) const Loading src/UnitTests/Matrices/DenseMatrixTest.h +177 −161 Original line number Diff line number Diff line Loading @@ -8,15 +8,17 @@ /* See Copyright Notice in tnl/Copyright */ #include <iostream> #include <functional> #include <TNL/Devices/Host.h> #include <TNL/Matrices/Matrix.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Containers/Array.h> #include <TNL/Containers/Vector.h> #include <TNL/Containers/VectorView.h> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Algorithms/Reduction.h> #include <TNL/Math.h> #include <iostream> using Dense_host_float = TNL::Matrices::DenseMatrix< float, TNL::Devices::Host, int >; using Dense_host_int = TNL::Matrices::DenseMatrix< int, TNL::Devices::Host, int >; Loading Loading @@ -380,6 +382,7 @@ void test_SetElement() using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; /* * Sets up the following 5x5 dense matrix: * Loading @@ -392,9 +395,7 @@ void test_SetElement() const IndexType rows = 5; const IndexType cols = 5; Matrix m; m.reset(); m.setDimensions( rows, cols ); Matrix m( rows, cols ); RealType value = 1; for( IndexType i = 0; i < rows; i++ ) Loading Loading @@ -430,6 +431,22 @@ void test_SetElement() EXPECT_EQ( m.getElement( 4, 2 ), 23 ); EXPECT_EQ( m.getElement( 4, 3 ), 24 ); EXPECT_EQ( m.getElement( 4, 4 ), 25 ); TNL::Containers::Vector< RealType, DeviceType, IndexType > v( m.getRows(), 0 ); auto v_view = v.getView(); auto m_view = m.getView(); auto f1 = [=] __cuda_callable__ ( IndexType i ) mutable { v_view[ i ] = m_view.getElement( i, i ); }; TNL::Algorithms::ParallelFor< DeviceType >::exec( ( IndexType ) 0, m.getRows(), f1 ); for( IndexType i = 0; i < m.getRows(); i++ ) EXPECT_EQ( v.getElement( i ), m.getElement( i, i ) ); auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( v_view[ i ] == m_view.getElement( i, i ) ); }; EXPECT_TRUE( TNL::Algorithms::Reduction< DeviceType >::reduce( m.getRows(), std::logical_and<>{}, fetch, true ) ); } template< typename Matrix > Loading @@ -438,6 +455,7 @@ void test_AddElement() using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; /* * Sets up the following 6x5 dense matrix: * Loading @@ -451,9 +469,7 @@ void test_AddElement() const IndexType rows = 6; const IndexType cols = 5; Matrix m; m.reset(); m.setDimensions( rows, cols ); Matrix m( rows, cols ); RealType value = 1; for( IndexType i = 0; i < rows; i++ ) Loading Loading
src/TNL/Matrices/DenseMatrix.h +3 −0 Original line number Diff line number Diff line Loading @@ -346,6 +346,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * \par Output * \include DenseMatrixExample_setElement.out */ __cuda_callable__ void setElement( const IndexType row, const IndexType column, const RealType& value ); Loading @@ -365,6 +366,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * \param thisElementMultiplicator is multiplicator the original matrix element * value is multiplied by before addition of given e value. */ __cuda_callable__ void addElement( const IndexType row, const IndexType column, const RealType& value, Loading @@ -384,6 +386,7 @@ class DenseMatrix : public Matrix< Real, Device, Index > * * \return value of given matrix element. */ __cuda_callable__ Real getElement( const IndexType row, const IndexType column ) const; Loading
src/TNL/Matrices/DenseMatrix.hpp +4 −3 Original line number Diff line number Diff line Loading @@ -233,6 +233,7 @@ DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: reset() { Matrix< Real, Device, Index >::reset(); this->segments.reset(); } template< typename Real, Loading Loading @@ -300,7 +301,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > void __cuda_callable__ void DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: setElement( const IndexType row, const IndexType column, Loading @@ -314,7 +315,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > void __cuda_callable__ void DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: addElement( const IndexType row, const IndexType column, Loading @@ -329,7 +330,7 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > Real __cuda_callable__ Real DenseMatrix< Real, Device, Index, RowMajorOrder, RealAllocator >:: getElement( const IndexType row, const IndexType column ) const Loading
src/TNL/Matrices/DenseMatrixView.h +3 −2 Original line number Diff line number Diff line Loading @@ -91,8 +91,6 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > IndexType getNonzeroElementsCount() const; void reset(); __cuda_callable__ const RowView getRow( const IndexType& rowIdx ) const; Loading @@ -110,15 +108,18 @@ class DenseMatrixView : public MatrixView< Real, Device, Index > const Real& operator()( const IndexType row, const IndexType column ) const; __cuda_callable__ void setElement( const IndexType row, const IndexType column, const RealType& value ); __cuda_callable__ void addElement( const IndexType row, const IndexType column, const RealType& value, const RealType& thisElementMultiplicator = 1.0 ); __cuda_callable__ Real getElement( const IndexType row, const IndexType column ) const; Loading
src/TNL/Matrices/DenseMatrixView.hpp +3 −14 Original line number Diff line number Diff line Loading @@ -168,17 +168,6 @@ getNonzeroElementsCount() const return Algorithms::Reduction< DeviceType >::reduce( this->values.getSize(), std::plus<>{}, fetch, 0 ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder > void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: reset() { Matrix< Real, Device, Index >::reset(); } template< typename Real, typename Device, typename Index, Loading Loading @@ -250,7 +239,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > void __cuda_callable__ void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: setElement( const IndexType row, const IndexType column, Loading @@ -263,7 +252,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > void __cuda_callable__ void DenseMatrixView< Real, Device, Index, RowMajorOrder >:: addElement( const IndexType row, const IndexType column, Loading @@ -283,7 +272,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > Real __cuda_callable__ Real DenseMatrixView< Real, Device, Index, RowMajorOrder >:: getElement( const IndexType row, const IndexType column ) const Loading
src/UnitTests/Matrices/DenseMatrixTest.h +177 −161 Original line number Diff line number Diff line Loading @@ -8,15 +8,17 @@ /* See Copyright Notice in tnl/Copyright */ #include <iostream> #include <functional> #include <TNL/Devices/Host.h> #include <TNL/Matrices/Matrix.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Containers/Array.h> #include <TNL/Containers/Vector.h> #include <TNL/Containers/VectorView.h> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Algorithms/Reduction.h> #include <TNL/Math.h> #include <iostream> using Dense_host_float = TNL::Matrices::DenseMatrix< float, TNL::Devices::Host, int >; using Dense_host_int = TNL::Matrices::DenseMatrix< int, TNL::Devices::Host, int >; Loading Loading @@ -380,6 +382,7 @@ void test_SetElement() using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; /* * Sets up the following 5x5 dense matrix: * Loading @@ -392,9 +395,7 @@ void test_SetElement() const IndexType rows = 5; const IndexType cols = 5; Matrix m; m.reset(); m.setDimensions( rows, cols ); Matrix m( rows, cols ); RealType value = 1; for( IndexType i = 0; i < rows; i++ ) Loading Loading @@ -430,6 +431,22 @@ void test_SetElement() EXPECT_EQ( m.getElement( 4, 2 ), 23 ); EXPECT_EQ( m.getElement( 4, 3 ), 24 ); EXPECT_EQ( m.getElement( 4, 4 ), 25 ); TNL::Containers::Vector< RealType, DeviceType, IndexType > v( m.getRows(), 0 ); auto v_view = v.getView(); auto m_view = m.getView(); auto f1 = [=] __cuda_callable__ ( IndexType i ) mutable { v_view[ i ] = m_view.getElement( i, i ); }; TNL::Algorithms::ParallelFor< DeviceType >::exec( ( IndexType ) 0, m.getRows(), f1 ); for( IndexType i = 0; i < m.getRows(); i++ ) EXPECT_EQ( v.getElement( i ), m.getElement( i, i ) ); auto fetch = [=] __cuda_callable__ ( IndexType i ) -> bool { return ( v_view[ i ] == m_view.getElement( i, i ) ); }; EXPECT_TRUE( TNL::Algorithms::Reduction< DeviceType >::reduce( m.getRows(), std::logical_and<>{}, fetch, true ) ); } template< typename Matrix > Loading @@ -438,6 +455,7 @@ void test_AddElement() using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; /* * Sets up the following 6x5 dense matrix: * Loading @@ -451,9 +469,7 @@ void test_AddElement() const IndexType rows = 6; const IndexType cols = 5; Matrix m; m.reset(); m.setDimensions( rows, cols ); Matrix m( rows, cols ); RealType value = 1; for( IndexType i = 0; i < rows; i++ ) Loading