From 3b631afcbb877516e42a9650b59470c368ea8365 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Thu, 6 Feb 2020 12:30:19 +0100 Subject: [PATCH] Fixed --- src/TNL/Matrices/SparseMatrix.hpp | 6 ++++-- .../Matrices/BinarySparseMatrixCopyTest.h | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/TNL/Matrices/SparseMatrix.hpp b/src/TNL/Matrices/SparseMatrix.hpp index 60f4695f05..9924434346 100644 --- a/src/TNL/Matrices/SparseMatrix.hpp +++ b/src/TNL/Matrices/SparseMatrix.hpp @@ -590,7 +590,8 @@ operator=( const Dense< Real_, Device_, Index_, RowMajorOrder, RealAllocator_ >& { IndexType thisGlobalIdx = segments_view.getGlobalIndex( rowIdx, rowLocalIndexes_view[ rowIdx ]++ ); columns_view[ thisGlobalIdx ] = columnIdx; - values_view[ thisGlobalIdx ] = value; + if( ! isBinary() ) + values_view[ thisGlobalIdx ] = value; } }; matrix.forAllRows( f ); @@ -700,7 +701,8 @@ operator=( const RHSMatrix& matrix ) { IndexType thisGlobalIdx = segments_view.getGlobalIndex( rowIdx, localIdx++ ); columns_view[ thisGlobalIdx ] = columnIndex; - values_view[ thisGlobalIdx ] = value; + if( ! isBinary() ) + values_view[ thisGlobalIdx ] = value; rowLocalIndexes_view[ rowIdx ] = localIdx; } }; diff --git a/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h b/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h index d8fefeed79..b901acbbd9 100644 --- a/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h +++ b/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h @@ -440,7 +440,7 @@ void tridiagonalMatrixAssignment() TridiagonalHost hostMatrix( rows, columns ); for( IndexType i = 0; i < rows; i++ ) for( IndexType j = TNL::max( 0, i - 1 ); j < TNL::min( columns, i + 2 ); j++ ) - hostMatrix.setElement( i, j, 1 ); + hostMatrix.setElement( i, j, TNL::min( i + j, 1 ) ); Matrix matrix; matrix = hostMatrix; @@ -456,7 +456,7 @@ void tridiagonalMatrixAssignment() if( abs( i - j ) > 1 ) EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); else - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); } #ifdef HAVE_CUDA @@ -471,7 +471,7 @@ void tridiagonalMatrixAssignment() if( abs( i - j ) > 1 ) EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); else - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); } #endif } @@ -493,7 +493,7 @@ void multidiagonalMatrixAssignment() for( IndexType i = 0; i < rows; i++ ) for( IndexType j = 0; j < columns; j++ ) if( diagonals.containsValue( j - i ) ) - hostMatrix.setElement( i, j, 1 ); + hostMatrix.setElement( i, j, TNL::min( i + j, 1 ) ); Matrix matrix; matrix = hostMatrix; @@ -510,7 +510,7 @@ void multidiagonalMatrixAssignment() for( IndexType j = 0; j < columns; j++ ) { if( diagonals.containsValue( j - i ) ) - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); else EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); } @@ -525,7 +525,7 @@ void multidiagonalMatrixAssignment() for( IndexType j = 0; j < columns; j++ ) { if( diagonals.containsValue( j - i ) ) - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); else EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); } @@ -546,7 +546,7 @@ void denseMatrixAssignment() DenseHost hostMatrix( rows, columns ); for( IndexType i = 0; i < columns; i++ ) for( IndexType j = 0; j <= i; j++ ) - hostMatrix( i, j ) = i + j; + hostMatrix( i, j ) = TNL::min( i + j, 1 ); Matrix matrix; matrix = hostMatrix; @@ -561,7 +561,7 @@ void denseMatrixAssignment() if( j > i ) EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); else - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); } #ifdef HAVE_CUDA @@ -576,7 +576,7 @@ void denseMatrixAssignment() if( j > i ) EXPECT_EQ( matrix.getElement( i, j ), 0.0 ); else - EXPECT_EQ( matrix.getElement( i, j ), 1.0 ); + EXPECT_EQ( matrix.getElement( i, j ), TNL::min( i + j, 1 ) ); } #endif } -- GitLab