Loading src/TNL/Matrices/DenseMatrix.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ setDimensions( const IndexType rows, { Matrix< Real, Device, Index, RealAllocator >::setDimensions( rows, columns ); this->segments.setSegmentsSizes( rows, columns ); this->values.setSize( rows * columns ); this->values.setSize( this->segments.getStorageSize() ); this->values = 0.0; this->view = this->getView(); } Loading src/UnitTests/Matrices/DenseMatrixTest.h +49 −0 Original line number Diff line number Diff line Loading @@ -996,6 +996,48 @@ void test_VectorProduct() EXPECT_EQ( outVector.getElement( 4 ), 148 ); } template< typename Matrix > void test_LargeVectorProduct() { using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; if( std::is_same< IndexType, short >::value ) return; const IndexType rows = 5000; const IndexType cols = 5000; Matrix m( rows, cols ); m.forAllElements( [] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value ) { value = columnIdx + 1.0; } ); using VectorType = TNL::Containers::Vector< RealType, DeviceType, IndexType >; VectorType inVector( cols ); inVector.forAllElements( [] __cuda_callable__ ( IndexType i, RealType& value ) { value = 1.0; } ); VectorType outVector( rows, 0.0 ); m.vectorProduct( inVector, outVector); for( IndexType i = 0; i < rows; i++ ) { //RealType diag = ( i % 2 == 1 ? cols - 1 : -cols + 1 ); //RealType non_diag = ( cols % 2 == 0 ? 0.0 : 1.0 ); RealType rcols = cols; EXPECT_EQ( outVector.getElement( i ), ( 0.5 * rcols ) * ( rcols + 1.0 ) ); } } template< typename Matrix > void test_AddMatrix() { Loading Loading @@ -1622,6 +1664,13 @@ TYPED_TEST( MatrixTest, vectorProductTest ) test_VectorProduct< MatrixType >(); } TYPED_TEST( MatrixTest, largeVectorProductTest ) { using MatrixType = typename TestFixture::MatrixType; test_LargeVectorProduct< MatrixType >(); } TYPED_TEST( MatrixTest, addMatrixTest ) { using MatrixType = typename TestFixture::MatrixType; Loading Loading
src/TNL/Matrices/DenseMatrix.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ setDimensions( const IndexType rows, { Matrix< Real, Device, Index, RealAllocator >::setDimensions( rows, columns ); this->segments.setSegmentsSizes( rows, columns ); this->values.setSize( rows * columns ); this->values.setSize( this->segments.getStorageSize() ); this->values = 0.0; this->view = this->getView(); } Loading
src/UnitTests/Matrices/DenseMatrixTest.h +49 −0 Original line number Diff line number Diff line Loading @@ -996,6 +996,48 @@ void test_VectorProduct() EXPECT_EQ( outVector.getElement( 4 ), 148 ); } template< typename Matrix > void test_LargeVectorProduct() { using RealType = typename Matrix::RealType; using DeviceType = typename Matrix::DeviceType; using IndexType = typename Matrix::IndexType; if( std::is_same< IndexType, short >::value ) return; const IndexType rows = 5000; const IndexType cols = 5000; Matrix m( rows, cols ); m.forAllElements( [] __cuda_callable__ ( IndexType rowIdx, IndexType columnIdx, IndexType columnIdx_, RealType& value ) { value = columnIdx + 1.0; } ); using VectorType = TNL::Containers::Vector< RealType, DeviceType, IndexType >; VectorType inVector( cols ); inVector.forAllElements( [] __cuda_callable__ ( IndexType i, RealType& value ) { value = 1.0; } ); VectorType outVector( rows, 0.0 ); m.vectorProduct( inVector, outVector); for( IndexType i = 0; i < rows; i++ ) { //RealType diag = ( i % 2 == 1 ? cols - 1 : -cols + 1 ); //RealType non_diag = ( cols % 2 == 0 ? 0.0 : 1.0 ); RealType rcols = cols; EXPECT_EQ( outVector.getElement( i ), ( 0.5 * rcols ) * ( rcols + 1.0 ) ); } } template< typename Matrix > void test_AddMatrix() { Loading Loading @@ -1622,6 +1664,13 @@ TYPED_TEST( MatrixTest, vectorProductTest ) test_VectorProduct< MatrixType >(); } TYPED_TEST( MatrixTest, largeVectorProductTest ) { using MatrixType = typename TestFixture::MatrixType; test_LargeVectorProduct< MatrixType >(); } TYPED_TEST( MatrixTest, addMatrixTest ) { using MatrixType = typename TestFixture::MatrixType; Loading