Loading src/core/mfuncs.h +6 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,12 @@ inline double tnlAbs( const double& d ) return fabs( d ); }; template< typename Real > bool isSmall( const Real& v, const Real& tolerance = 1.0e-5 ) { return ( -tolerance <= v && v <= tolerance ); } /*template< typename T > void swap( T& a, T& b) { Loading src/implementation/matrices/tnlMultidiagonalMatrix_impl.h +36 −25 Original line number Diff line number Diff line Loading @@ -62,22 +62,32 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDimensions( const Index << " columns = " << columns << endl ); this->rows = rows; this->columns = columns; if( this->diagonalsOffsets.getSize() != 0 ) return values.setSize( Min( this->rows, this->columns ) * this->diagonalsOffsets.getSize() ); if( this->diagonalsShift.getSize() != 0 ) { if( ! this->values.setSize( Min( this->rows, this->columns ) * this->diagonalsShift.getSize() ) ) return false; this->values.setValue( 0.0 ); } return true; } template< typename Real, typename Device, typename Index > bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDiagonals( const tnlVector< Index, Device, Index >& diagonals ) { tnlAssert( diagonals.getSize() > 0, cerr << "New number of diagonals = " << diagonals.getSize() << endl ); this->diagonalsOffsets.setLike( diagonals ); this->diagonalsOffsets = diagonals; bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDiagonals( const IndexType diagonalsNumber, const IndexType* diagonalsShift ) { tnlAssert( diagonalsNumber > 0, cerr << "New number of diagonals = " << diagonalsNumber << endl ); this->diagonalsShift.setSize( diagonalsNumber ); for( IndexType i = 0; i < diagonalsNumber; i++ ) this->diagonalsShift.setElement( i, diagonalsShift[ i ] ); if( this->rows != 0 && this->columns != 0 ) return values.setSize( Min( this->rows, this->columns ) * this->diagonalsOffsets.getSize() ); { if( ! this->values.setSize( Min( this->rows, this->columns ) * this->diagonalsShift.getSize() ) ) return false;\ this->values.setValue( 0.0 ); } return true; } Loading @@ -86,7 +96,7 @@ template< typename Real, typename Index > const tnlVector< Index, Device, Index >& tnlMultidiagonalMatrix< Real, Device, Index > :: getDiagonals() const { return this->diagonalsOffsets; return this->diagonalsShift; } template< typename Real, Loading @@ -98,7 +108,8 @@ template< typename Real, bool tnlMultidiagonalMatrix< Real, Device, Index > :: setLike( const tnlMultidiagonalMatrix< Real2, Device2, Index2 >& matrix ) { setDimensions( matrix.getRows(), matrix.getColumns() ); if( ! setDiagonals( matrix.getDiagonals() ) ) if( ! setDiagonals( matrix.getDiagonals().getSize(), matrix.getDiagonals().getData() ) ) return false; } Loading Loading @@ -212,7 +223,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: addToElement( const IndexT Index index; if( ! this->getElementIndex( row, column, index ) ) return false; this->values[ index ] = thisElementMultiplicator * this->values[ index ] * value; this->values[ index ] = thisElementMultiplicator * this->values[ index ] + value; return true; } Loading @@ -229,12 +240,12 @@ void tnlMultidiagonalMatrix< Real, Device, Index >::vectorProduct( const Vector& { Real result = 0.0; for( Index i = 0; i < this->diagonalsOffsets.getSize(); i < this->diagonalsShift.getSize(); i ++ ) { const Index column = row + this->diagonalsOffsets.getElement( i ); const Index column = row + this->diagonalsShift.getElement( i ); if( column >= 0 && column < this->getColumns() ) result += this->values.getElement( row * this->diagonalsOffsets.getSize() + i ) * result += this->values.getElement( row * this->diagonalsShift.getSize() + i ) * inVector.getElement( column ); } outVector.setElement( row, result ); Loading Loading @@ -281,15 +292,15 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: performSORIteration( const RealType diagonalValue( 0.0 ); RealType sum( 0.0 ); for( IndexType i = 0; i < this->getDiagonalsOffsets.getSize(); i++ ) for( IndexType i = 0; i < this->getDiagonalsShift.getSize(); i++ ) { const IndexType column = i + this -> diagonalsOffsets. getElement( i ); const IndexType column = i + this -> diagonalsShift. getElement( i ); if( column >= 0 && column < this->getColumns() ) { if( column == row ) diagonalValue = this->values.getElement( row * this->diagonalsOffsets.getSize() + i ); diagonalValue = this->values.getElement( row * this->diagonalsShift.getSize() + i ); else sum += this->values.getElement( row * this->diagonalsOffsets.getSize() + i ) * x. getElement( column ); sum += this->values.getElement( row * this->diagonalsShift.getSize() + i ) * x. getElement( column ); } } if( diagonalValue == ( Real ) 0.0 ) Loading @@ -310,7 +321,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::save( tnlFile& file ) const if( ! file.write( &this->rows ) ) return false; if( ! file.write( &this->columns ) ) return false; if( ! this->values.save( file ) ) return false; if( ! this->diagonalsOffsets.save( file ) ) return false; if( ! this->diagonalsShift.save( file ) ) return false; return true; } Loading @@ -322,7 +333,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::load( tnlFile& file ) if( ! file.read( &this->rows ) ) return false; if( ! file.read( &this->columns ) ) return false; if( ! this->values.load( file ) ) return false; if( ! this->diagonalsOffsets.load( file ) ) return false; if( ! this->diagonalsShift.load( file ) ) return false; return true; } Loading Loading @@ -350,9 +361,9 @@ void tnlMultidiagonalMatrix< Real, Device, Index >::print( ostream& str ) const for( IndexType row = 0; row < this->getRows(); row++ ) { str <<"Row: " << row << " -> "; for( IndexType i = 0; i < this->diagonalsOffsets.getSize(); i++ ) for( IndexType i = 0; i < this->diagonalsShift.getSize(); i++ ) { const IndexType column = row + diagonalsOffsets[ i ]; const IndexType column = row + diagonalsShift[ i ]; if( column >=0 && columns < this-columns ) str << " Col:" << column << "->" << this->operator()( row, column ) << "\t"; } Loading @@ -377,11 +388,11 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::getElementIndex( const Index << " this->getName() = " << this->getName() << endl ); IndexType i( 0 ); while( i < this->diagonalsOffsets.getSize() ) while( i < this->diagonalsShift.getSize() ) { if( diagonalsOffsets[ i ] == column - row ) if( diagonalsShift[ i ] == column - row ) { index = row*this->diagonalsOffsets.getSize() + i; index = row*this->diagonalsShift.getSize() + i; return true; } i++; Loading src/matrices/tnlMultidiagonalMatrix.h +3 −2 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ class tnlMultidiagonalMatrix : public tnlObject bool setDimensions( const IndexType rows, const IndexType columns ); bool setDiagonals( const tnlVector< Index, Device, Index >& diagonals ); bool setDiagonals( const IndexType diagonalsNumber, const IndexType* diagonalsShift ); const tnlVector< Index, Device, Index >& getDiagonals() const; Loading Loading @@ -113,7 +114,7 @@ class tnlMultidiagonalMatrix : public tnlObject tnlVector< Real, Device, Index > values; tnlVector< Index, Device, Index > diagonalsOffsets; tnlVector< Index, Device, Index > diagonalsShift; }; Loading tests/unit-tests/CMakeLists.txt +3 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ ADD_TEST( core/arrays/tnlArrayTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH} ADD_TEST( core/vectors/tnlVectorOperationsTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlVectorOperationsTest${mpiExt}${debugExt} ) ADD_TEST( core/vectors/tnlVectorTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlVectorTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlDenseMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlDenseVectorTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlDenseMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlDenseMatrixTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlTridiagonalMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlTridiagonalMatrixTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlMultidiagonalMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlMultidiagonalMatrixTest${mpiExt}${debugExt} ) if( BUILD_CUDA ) ADD_TEST( core/cuda/tnlCudaTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlCudaTest${mpiExt}${debugExt} ) Loading tests/unit-tests/core/vectors/tnlVectorTester.h +28 −70 Original line number Diff line number Diff line Loading @@ -26,11 +26,17 @@ #include <cppunit/Message.h> #include <core/vectors/tnlVector.h> #include <core/tnlFile.h> #include <core/mfuncs.h> template< typename RealType, typename Device, typename IndexType > class tnlVectorTester : public CppUnit :: TestCase { public: typedef tnlVector< RealType, Device, IndexType > VectorType; typedef tnlVectorTester< RealType, Device, IndexType > TesterType; typedef typename CppUnit::TestCaller< TesterType > TestCallerType; tnlVectorTester(){}; virtual Loading @@ -41,70 +47,22 @@ class tnlVectorTester : public CppUnit :: TestCase CppUnit :: TestSuite* suiteOfTests = new CppUnit :: TestSuite( "tnlVectorTester" ); CppUnit :: TestResult result; suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testMax", & tnlVectorTester< RealType, Device, IndexType > :: testMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testMin", & tnlVectorTester< RealType, Device, IndexType > :: testMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testAbsMax", & tnlVectorTester< RealType, Device, IndexType > :: testAbsMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testAbsMin", & tnlVectorTester< RealType, Device, IndexType > :: testAbsMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testLpNorm", & tnlVectorTester< RealType, Device, IndexType > :: testLpNorm ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testSum", & tnlVectorTester< RealType, Device, IndexType > :: testSum ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceMax", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceMin", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceAbsMax", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceAbsMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceAbsMin", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceAbsMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceLpNorm", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceLpNorm ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceSum", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceSum ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testScalarMultiplication", & tnlVectorTester< RealType, Device, IndexType > :: testScalarMultiplication ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testScalarProduct", & tnlVectorTester< RealType, Device, IndexType > :: testScalarProduct ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testalphaXPlusY", & tnlVectorTester< RealType, Device, IndexType > :: testalphaXPlusY ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testalphaXPlusY", & tnlVectorTester< RealType, Device, IndexType > :: testalphaXPlusY ) ); suiteOfTests -> addTest( new TestCallerType( "testMax", &TesterType::testMax ) ); suiteOfTests -> addTest( new TestCallerType( "testMin", &TesterType::testMin ) ); suiteOfTests -> addTest( new TestCallerType( "testAbsMax", &TesterType::testAbsMax ) ); suiteOfTests -> addTest( new TestCallerType( "testAbsMin", &TesterType::testAbsMin ) ); suiteOfTests -> addTest( new TestCallerType( "testLpNorm", &TesterType::testLpNorm ) ); suiteOfTests -> addTest( new TestCallerType( "testSum", &TesterType::testSum ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceMax", &TesterType::testDifferenceMax ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceMin", &TesterType::testDifferenceMin ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceAbsMax", &TesterType::testDifferenceAbsMax ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceAbsMin", &TesterType::testDifferenceAbsMin ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceLpNorm", &TesterType::testDifferenceLpNorm ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceSum", &TesterType::testDifferenceSum ) ); suiteOfTests -> addTest( new TestCallerType( "testScalarMultiplication", &TesterType::testScalarMultiplication ) ); suiteOfTests -> addTest( new TestCallerType( "testScalarProduct", &TesterType::testScalarProduct ) ); suiteOfTests -> addTest( new TestCallerType( "testalphaXPlusY", &TesterType::testalphaXPlusY ) ); suiteOfTests -> addTest( new TestCallerType( "testalphaXPlusY", &TesterType::testalphaXPlusY ) ); return suiteOfTests; } Loading Loading @@ -150,9 +108,9 @@ class tnlVectorTester : public CppUnit :: TestCase v. setSize( 10 ); for( int i = 0; i < 10; i ++ ) v[ i ] = -2; CPPUNIT_ASSERT( v. lpNorm( 1 ) == 20.0 ); CPPUNIT_ASSERT( v. lpNorm( 2 ) == sqrt( 40.0 ) ); CPPUNIT_ASSERT( v. lpNorm( 3 ) == pow( 80.0, 1.0/3.0 ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 1 ) - 20.0 ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 2 ) - sqrt( 40.0 ) ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 3 ) - pow( 80.0, 1.0/3.0 ) ) ); }; void testSum() Loading Loading @@ -230,9 +188,9 @@ class tnlVectorTester : public CppUnit :: TestCase v1[ i ] = -1; v2[ i ] = 1; } CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 1.0 ) == 20.0 ); CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 2.0 ) == sqrt( 40.0 ) ); CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 3.0 ) == pow( 80.0, 1.0/3.0 ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 1.0 ) - 20.0 ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 2.0 ) - sqrt( 40.0 ) ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 3.0 ) - pow( 80.0, 1.0/3.0 ) ) ); }; void testDifferenceSum() Loading Loading
src/core/mfuncs.h +6 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,12 @@ inline double tnlAbs( const double& d ) return fabs( d ); }; template< typename Real > bool isSmall( const Real& v, const Real& tolerance = 1.0e-5 ) { return ( -tolerance <= v && v <= tolerance ); } /*template< typename T > void swap( T& a, T& b) { Loading
src/implementation/matrices/tnlMultidiagonalMatrix_impl.h +36 −25 Original line number Diff line number Diff line Loading @@ -62,22 +62,32 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDimensions( const Index << " columns = " << columns << endl ); this->rows = rows; this->columns = columns; if( this->diagonalsOffsets.getSize() != 0 ) return values.setSize( Min( this->rows, this->columns ) * this->diagonalsOffsets.getSize() ); if( this->diagonalsShift.getSize() != 0 ) { if( ! this->values.setSize( Min( this->rows, this->columns ) * this->diagonalsShift.getSize() ) ) return false; this->values.setValue( 0.0 ); } return true; } template< typename Real, typename Device, typename Index > bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDiagonals( const tnlVector< Index, Device, Index >& diagonals ) { tnlAssert( diagonals.getSize() > 0, cerr << "New number of diagonals = " << diagonals.getSize() << endl ); this->diagonalsOffsets.setLike( diagonals ); this->diagonalsOffsets = diagonals; bool tnlMultidiagonalMatrix< Real, Device, Index > :: setDiagonals( const IndexType diagonalsNumber, const IndexType* diagonalsShift ) { tnlAssert( diagonalsNumber > 0, cerr << "New number of diagonals = " << diagonalsNumber << endl ); this->diagonalsShift.setSize( diagonalsNumber ); for( IndexType i = 0; i < diagonalsNumber; i++ ) this->diagonalsShift.setElement( i, diagonalsShift[ i ] ); if( this->rows != 0 && this->columns != 0 ) return values.setSize( Min( this->rows, this->columns ) * this->diagonalsOffsets.getSize() ); { if( ! this->values.setSize( Min( this->rows, this->columns ) * this->diagonalsShift.getSize() ) ) return false;\ this->values.setValue( 0.0 ); } return true; } Loading @@ -86,7 +96,7 @@ template< typename Real, typename Index > const tnlVector< Index, Device, Index >& tnlMultidiagonalMatrix< Real, Device, Index > :: getDiagonals() const { return this->diagonalsOffsets; return this->diagonalsShift; } template< typename Real, Loading @@ -98,7 +108,8 @@ template< typename Real, bool tnlMultidiagonalMatrix< Real, Device, Index > :: setLike( const tnlMultidiagonalMatrix< Real2, Device2, Index2 >& matrix ) { setDimensions( matrix.getRows(), matrix.getColumns() ); if( ! setDiagonals( matrix.getDiagonals() ) ) if( ! setDiagonals( matrix.getDiagonals().getSize(), matrix.getDiagonals().getData() ) ) return false; } Loading Loading @@ -212,7 +223,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: addToElement( const IndexT Index index; if( ! this->getElementIndex( row, column, index ) ) return false; this->values[ index ] = thisElementMultiplicator * this->values[ index ] * value; this->values[ index ] = thisElementMultiplicator * this->values[ index ] + value; return true; } Loading @@ -229,12 +240,12 @@ void tnlMultidiagonalMatrix< Real, Device, Index >::vectorProduct( const Vector& { Real result = 0.0; for( Index i = 0; i < this->diagonalsOffsets.getSize(); i < this->diagonalsShift.getSize(); i ++ ) { const Index column = row + this->diagonalsOffsets.getElement( i ); const Index column = row + this->diagonalsShift.getElement( i ); if( column >= 0 && column < this->getColumns() ) result += this->values.getElement( row * this->diagonalsOffsets.getSize() + i ) * result += this->values.getElement( row * this->diagonalsShift.getSize() + i ) * inVector.getElement( column ); } outVector.setElement( row, result ); Loading Loading @@ -281,15 +292,15 @@ bool tnlMultidiagonalMatrix< Real, Device, Index > :: performSORIteration( const RealType diagonalValue( 0.0 ); RealType sum( 0.0 ); for( IndexType i = 0; i < this->getDiagonalsOffsets.getSize(); i++ ) for( IndexType i = 0; i < this->getDiagonalsShift.getSize(); i++ ) { const IndexType column = i + this -> diagonalsOffsets. getElement( i ); const IndexType column = i + this -> diagonalsShift. getElement( i ); if( column >= 0 && column < this->getColumns() ) { if( column == row ) diagonalValue = this->values.getElement( row * this->diagonalsOffsets.getSize() + i ); diagonalValue = this->values.getElement( row * this->diagonalsShift.getSize() + i ); else sum += this->values.getElement( row * this->diagonalsOffsets.getSize() + i ) * x. getElement( column ); sum += this->values.getElement( row * this->diagonalsShift.getSize() + i ) * x. getElement( column ); } } if( diagonalValue == ( Real ) 0.0 ) Loading @@ -310,7 +321,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::save( tnlFile& file ) const if( ! file.write( &this->rows ) ) return false; if( ! file.write( &this->columns ) ) return false; if( ! this->values.save( file ) ) return false; if( ! this->diagonalsOffsets.save( file ) ) return false; if( ! this->diagonalsShift.save( file ) ) return false; return true; } Loading @@ -322,7 +333,7 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::load( tnlFile& file ) if( ! file.read( &this->rows ) ) return false; if( ! file.read( &this->columns ) ) return false; if( ! this->values.load( file ) ) return false; if( ! this->diagonalsOffsets.load( file ) ) return false; if( ! this->diagonalsShift.load( file ) ) return false; return true; } Loading Loading @@ -350,9 +361,9 @@ void tnlMultidiagonalMatrix< Real, Device, Index >::print( ostream& str ) const for( IndexType row = 0; row < this->getRows(); row++ ) { str <<"Row: " << row << " -> "; for( IndexType i = 0; i < this->diagonalsOffsets.getSize(); i++ ) for( IndexType i = 0; i < this->diagonalsShift.getSize(); i++ ) { const IndexType column = row + diagonalsOffsets[ i ]; const IndexType column = row + diagonalsShift[ i ]; if( column >=0 && columns < this-columns ) str << " Col:" << column << "->" << this->operator()( row, column ) << "\t"; } Loading @@ -377,11 +388,11 @@ bool tnlMultidiagonalMatrix< Real, Device, Index >::getElementIndex( const Index << " this->getName() = " << this->getName() << endl ); IndexType i( 0 ); while( i < this->diagonalsOffsets.getSize() ) while( i < this->diagonalsShift.getSize() ) { if( diagonalsOffsets[ i ] == column - row ) if( diagonalsShift[ i ] == column - row ) { index = row*this->diagonalsOffsets.getSize() + i; index = row*this->diagonalsShift.getSize() + i; return true; } i++; Loading
src/matrices/tnlMultidiagonalMatrix.h +3 −2 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ class tnlMultidiagonalMatrix : public tnlObject bool setDimensions( const IndexType rows, const IndexType columns ); bool setDiagonals( const tnlVector< Index, Device, Index >& diagonals ); bool setDiagonals( const IndexType diagonalsNumber, const IndexType* diagonalsShift ); const tnlVector< Index, Device, Index >& getDiagonals() const; Loading Loading @@ -113,7 +114,7 @@ class tnlMultidiagonalMatrix : public tnlObject tnlVector< Real, Device, Index > values; tnlVector< Index, Device, Index > diagonalsOffsets; tnlVector< Index, Device, Index > diagonalsShift; }; Loading
tests/unit-tests/CMakeLists.txt +3 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ ADD_TEST( core/arrays/tnlArrayTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH} ADD_TEST( core/vectors/tnlVectorOperationsTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlVectorOperationsTest${mpiExt}${debugExt} ) ADD_TEST( core/vectors/tnlVectorTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlVectorTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlDenseMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlDenseVectorTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlDenseMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlDenseMatrixTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlTridiagonalMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlTridiagonalMatrixTest${mpiExt}${debugExt} ) ADD_TEST( matrices/tnlMultidiagonalMatrixTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlMultidiagonalMatrixTest${mpiExt}${debugExt} ) if( BUILD_CUDA ) ADD_TEST( core/cuda/tnlCudaTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/tnlCudaTest${mpiExt}${debugExt} ) Loading
tests/unit-tests/core/vectors/tnlVectorTester.h +28 −70 Original line number Diff line number Diff line Loading @@ -26,11 +26,17 @@ #include <cppunit/Message.h> #include <core/vectors/tnlVector.h> #include <core/tnlFile.h> #include <core/mfuncs.h> template< typename RealType, typename Device, typename IndexType > class tnlVectorTester : public CppUnit :: TestCase { public: typedef tnlVector< RealType, Device, IndexType > VectorType; typedef tnlVectorTester< RealType, Device, IndexType > TesterType; typedef typename CppUnit::TestCaller< TesterType > TestCallerType; tnlVectorTester(){}; virtual Loading @@ -41,70 +47,22 @@ class tnlVectorTester : public CppUnit :: TestCase CppUnit :: TestSuite* suiteOfTests = new CppUnit :: TestSuite( "tnlVectorTester" ); CppUnit :: TestResult result; suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testMax", & tnlVectorTester< RealType, Device, IndexType > :: testMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testMin", & tnlVectorTester< RealType, Device, IndexType > :: testMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testAbsMax", & tnlVectorTester< RealType, Device, IndexType > :: testAbsMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testAbsMin", & tnlVectorTester< RealType, Device, IndexType > :: testAbsMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testLpNorm", & tnlVectorTester< RealType, Device, IndexType > :: testLpNorm ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testSum", & tnlVectorTester< RealType, Device, IndexType > :: testSum ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceMax", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceMin", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceAbsMax", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceAbsMax ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceAbsMin", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceAbsMin ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceLpNorm", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceLpNorm ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testDifferenceSum", & tnlVectorTester< RealType, Device, IndexType > :: testDifferenceSum ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testScalarMultiplication", & tnlVectorTester< RealType, Device, IndexType > :: testScalarMultiplication ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testScalarProduct", & tnlVectorTester< RealType, Device, IndexType > :: testScalarProduct ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testalphaXPlusY", & tnlVectorTester< RealType, Device, IndexType > :: testalphaXPlusY ) ); suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlVectorTester< RealType, Device, IndexType > >( "testalphaXPlusY", & tnlVectorTester< RealType, Device, IndexType > :: testalphaXPlusY ) ); suiteOfTests -> addTest( new TestCallerType( "testMax", &TesterType::testMax ) ); suiteOfTests -> addTest( new TestCallerType( "testMin", &TesterType::testMin ) ); suiteOfTests -> addTest( new TestCallerType( "testAbsMax", &TesterType::testAbsMax ) ); suiteOfTests -> addTest( new TestCallerType( "testAbsMin", &TesterType::testAbsMin ) ); suiteOfTests -> addTest( new TestCallerType( "testLpNorm", &TesterType::testLpNorm ) ); suiteOfTests -> addTest( new TestCallerType( "testSum", &TesterType::testSum ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceMax", &TesterType::testDifferenceMax ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceMin", &TesterType::testDifferenceMin ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceAbsMax", &TesterType::testDifferenceAbsMax ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceAbsMin", &TesterType::testDifferenceAbsMin ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceLpNorm", &TesterType::testDifferenceLpNorm ) ); suiteOfTests -> addTest( new TestCallerType( "testDifferenceSum", &TesterType::testDifferenceSum ) ); suiteOfTests -> addTest( new TestCallerType( "testScalarMultiplication", &TesterType::testScalarMultiplication ) ); suiteOfTests -> addTest( new TestCallerType( "testScalarProduct", &TesterType::testScalarProduct ) ); suiteOfTests -> addTest( new TestCallerType( "testalphaXPlusY", &TesterType::testalphaXPlusY ) ); suiteOfTests -> addTest( new TestCallerType( "testalphaXPlusY", &TesterType::testalphaXPlusY ) ); return suiteOfTests; } Loading Loading @@ -150,9 +108,9 @@ class tnlVectorTester : public CppUnit :: TestCase v. setSize( 10 ); for( int i = 0; i < 10; i ++ ) v[ i ] = -2; CPPUNIT_ASSERT( v. lpNorm( 1 ) == 20.0 ); CPPUNIT_ASSERT( v. lpNorm( 2 ) == sqrt( 40.0 ) ); CPPUNIT_ASSERT( v. lpNorm( 3 ) == pow( 80.0, 1.0/3.0 ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 1 ) - 20.0 ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 2 ) - sqrt( 40.0 ) ) ); CPPUNIT_ASSERT( isSmall( v.lpNorm( 3 ) - pow( 80.0, 1.0/3.0 ) ) ); }; void testSum() Loading Loading @@ -230,9 +188,9 @@ class tnlVectorTester : public CppUnit :: TestCase v1[ i ] = -1; v2[ i ] = 1; } CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 1.0 ) == 20.0 ); CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 2.0 ) == sqrt( 40.0 ) ); CPPUNIT_ASSERT( v1. differenceLpNorm( v2, 3.0 ) == pow( 80.0, 1.0/3.0 ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 1.0 ) - 20.0 ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 2.0 ) - sqrt( 40.0 ) ) ); CPPUNIT_ASSERT( isSmall( v1.differenceLpNorm( v2, 3.0 ) - pow( 80.0, 1.0/3.0 ) ) ); }; void testDifferenceSum() Loading