Loading src/implementation/matrices/tnlMatrixReader_impl.h +47 −12 Original line number Diff line number Diff line Loading @@ -27,7 +27,8 @@ using namespace std; template< typename Matrix > bool tnlMatrixReader::readMtxFile( std::istream& file, Matrix& matrix, bool verbose ) bool verbose, bool verify ) { typedef typename Matrix::IndexType IndexType; typedef typename Matrix::RealType RealType; Loading @@ -39,6 +40,7 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, IndexType size( 0 ); bool symmetric( false ); tnlVector< IndexType, tnlHost, IndexType > rowLengths; rowLengths.setName( "tnlMatrixReader::rowLengths"); if( verbose ) cout << "Counting the non-zero elements in rows..." << endl; while( line.getLine( file ) ) Loading Loading @@ -104,9 +106,9 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, numberOfElements ++; if( verbose ) cout << "Parsed thousands of elements: " << setw( 9 ) << right << numberOfElements / 1000 << "\r" << flush; rowLengths[ row ]++; rowLengths[ row - 1 ]++; if( symmetric && row != column ) rowLengths[ column ]++; rowLengths[ column - 1 ]++; } if( ! matrix.setRowLengths( rowLengths ) ) { Loading @@ -119,19 +121,45 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, */ if( verbose ) cout << endl; formatOk = false; dimensionsLine = false; file.seekg( 0 ); file.clear(); file.seekg( 0, ios::beg ); IndexType parsedElements( 0 ); if( verbose ) cout << "Reading the matrix elements ..." << endl; while( line.getLine( file ) ) { if( ! formatOk ) if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) { formatOk = checkMtxHeader( line, symmetric ); dimensionsLine = true; continue; } parsedLine.EraseAll(); line.parse( parsedLine ); const IndexType row = atoi( parsedLine[ 0 ].getString() ); const IndexType column = atoi( parsedLine[ 1 ].getString() ); const RealType value = ( RealType ) atof( parsedLine[ 2 ].getString() ); matrix.setElement( row - 1, column - 1, value ); if( symmetric && row != column ) matrix.setElement( column - 1, row - 1, value ); parsedElements++; if( verbose ) cout << parsedElements << " / " << numberOfElements << " \r " << flush; } if( verbose ) cout << endl; if( verify ) { if( verbose ) cout << "Verifying the matrix elements ... " << endl; dimensionsLine = false; file.clear(); file.seekg( 0, ios::beg ); IndexType parsedElements( 0 ); while( line.getLine( file ) ) { if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) { dimensionsLine = true; Loading @@ -142,13 +170,20 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, const IndexType row = atoi( parsedLine[ 0 ].getString() ); const IndexType column = atoi( parsedLine[ 1 ].getString() ); const RealType value = ( RealType ) atof( parsedLine[ 2 ].getString() ); matrix.setElement( row, column, value ); if( symmetric && row != column ) matrix.setElement( column, row, value ); parsedElements++; if( value != matrix.getElement( row-1, column-1 ) || ( symmetric && value != matrix.getElement( column-1, row-1 ) ) ) { cerr << "The elements differ at " << row-1 << " row " << column-1 << " column." << endl << "The matrix value is " << matrix.getElement( row-1, column-1 ) << " while the file value is " << value << "." << endl; return false; } if( verbose ) cout << parsedElements << " / " << numberOfElements << " \r " << flush; } if( verbose ) cout << endl; } return true; } Loading src/matrices/tnlMatrixReader.h +2 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ class tnlMatrixReader template< typename Matrix > static bool readMtxFile( std::istream& file, Matrix& matrix, bool verbose = false ); bool verbose = false, bool verify = false ); protected: inline static bool checkMtxHeader( const tnlString& header, Loading tests/long-time-unit-tests/matrix-formats-test.h +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ bool testMatrix( const tnlParameterContainer& parameters ) cerr << "Cannot open the file " << fileName << endl; return false; } if( ! tnlMatrixReader::readMtxFile( file, matrix, verbose ) ) if( ! tnlMatrixReader::readMtxFile( file, matrix, verbose, true ) ) { file.close(); return false; Loading tests/long-time-unit-tests/tnl-run-matrix-formats-test +6 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ VERBOSE="yes" PWD=`pwd` TNL_MATRIX_TEST="tnl-test-matrix-formats" TNL_MATRIX_TEST="tnl-test-matrix-formats-dbg" IWD="$PWD" #source ../tnl-env-variables Loading @@ -30,7 +31,9 @@ do else #if test -e $unzipped_matrix.double.bin.bz2; #then test_matrix $unzipped_matrix gunzip -c $matrix > $unzipped_matrix time test_matrix $unzipped_matrix rm $unzipped_matrix #else # echo "Matrix $unzipped_matrix.double.bin.bz2 is missing - run the script convert-matrices first." #fi Loading @@ -56,7 +59,7 @@ do do #if test -e $file.double.bin.bz2; #then test_matrix $file time test_matrix $file #else # echo "Matrix $file.double.bin.bz2 is missing - run the script convert-matrices first." #fi Loading Loading
src/implementation/matrices/tnlMatrixReader_impl.h +47 −12 Original line number Diff line number Diff line Loading @@ -27,7 +27,8 @@ using namespace std; template< typename Matrix > bool tnlMatrixReader::readMtxFile( std::istream& file, Matrix& matrix, bool verbose ) bool verbose, bool verify ) { typedef typename Matrix::IndexType IndexType; typedef typename Matrix::RealType RealType; Loading @@ -39,6 +40,7 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, IndexType size( 0 ); bool symmetric( false ); tnlVector< IndexType, tnlHost, IndexType > rowLengths; rowLengths.setName( "tnlMatrixReader::rowLengths"); if( verbose ) cout << "Counting the non-zero elements in rows..." << endl; while( line.getLine( file ) ) Loading Loading @@ -104,9 +106,9 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, numberOfElements ++; if( verbose ) cout << "Parsed thousands of elements: " << setw( 9 ) << right << numberOfElements / 1000 << "\r" << flush; rowLengths[ row ]++; rowLengths[ row - 1 ]++; if( symmetric && row != column ) rowLengths[ column ]++; rowLengths[ column - 1 ]++; } if( ! matrix.setRowLengths( rowLengths ) ) { Loading @@ -119,19 +121,45 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, */ if( verbose ) cout << endl; formatOk = false; dimensionsLine = false; file.seekg( 0 ); file.clear(); file.seekg( 0, ios::beg ); IndexType parsedElements( 0 ); if( verbose ) cout << "Reading the matrix elements ..." << endl; while( line.getLine( file ) ) { if( ! formatOk ) if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) { formatOk = checkMtxHeader( line, symmetric ); dimensionsLine = true; continue; } parsedLine.EraseAll(); line.parse( parsedLine ); const IndexType row = atoi( parsedLine[ 0 ].getString() ); const IndexType column = atoi( parsedLine[ 1 ].getString() ); const RealType value = ( RealType ) atof( parsedLine[ 2 ].getString() ); matrix.setElement( row - 1, column - 1, value ); if( symmetric && row != column ) matrix.setElement( column - 1, row - 1, value ); parsedElements++; if( verbose ) cout << parsedElements << " / " << numberOfElements << " \r " << flush; } if( verbose ) cout << endl; if( verify ) { if( verbose ) cout << "Verifying the matrix elements ... " << endl; dimensionsLine = false; file.clear(); file.seekg( 0, ios::beg ); IndexType parsedElements( 0 ); while( line.getLine( file ) ) { if( line[ 0 ] == '%' ) continue; if( ! dimensionsLine ) { dimensionsLine = true; Loading @@ -142,13 +170,20 @@ bool tnlMatrixReader::readMtxFile( std::istream& file, const IndexType row = atoi( parsedLine[ 0 ].getString() ); const IndexType column = atoi( parsedLine[ 1 ].getString() ); const RealType value = ( RealType ) atof( parsedLine[ 2 ].getString() ); matrix.setElement( row, column, value ); if( symmetric && row != column ) matrix.setElement( column, row, value ); parsedElements++; if( value != matrix.getElement( row-1, column-1 ) || ( symmetric && value != matrix.getElement( column-1, row-1 ) ) ) { cerr << "The elements differ at " << row-1 << " row " << column-1 << " column." << endl << "The matrix value is " << matrix.getElement( row-1, column-1 ) << " while the file value is " << value << "." << endl; return false; } if( verbose ) cout << parsedElements << " / " << numberOfElements << " \r " << flush; } if( verbose ) cout << endl; } return true; } Loading
src/matrices/tnlMatrixReader.h +2 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ class tnlMatrixReader template< typename Matrix > static bool readMtxFile( std::istream& file, Matrix& matrix, bool verbose = false ); bool verbose = false, bool verify = false ); protected: inline static bool checkMtxHeader( const tnlString& header, Loading
tests/long-time-unit-tests/matrix-formats-test.h +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ bool testMatrix( const tnlParameterContainer& parameters ) cerr << "Cannot open the file " << fileName << endl; return false; } if( ! tnlMatrixReader::readMtxFile( file, matrix, verbose ) ) if( ! tnlMatrixReader::readMtxFile( file, matrix, verbose, true ) ) { file.close(); return false; Loading
tests/long-time-unit-tests/tnl-run-matrix-formats-test +6 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ VERBOSE="yes" PWD=`pwd` TNL_MATRIX_TEST="tnl-test-matrix-formats" TNL_MATRIX_TEST="tnl-test-matrix-formats-dbg" IWD="$PWD" #source ../tnl-env-variables Loading @@ -30,7 +31,9 @@ do else #if test -e $unzipped_matrix.double.bin.bz2; #then test_matrix $unzipped_matrix gunzip -c $matrix > $unzipped_matrix time test_matrix $unzipped_matrix rm $unzipped_matrix #else # echo "Matrix $unzipped_matrix.double.bin.bz2 is missing - run the script convert-matrices first." #fi Loading @@ -56,7 +59,7 @@ do do #if test -e $file.double.bin.bz2; #then test_matrix $file time test_matrix $file #else # echo "Matrix $file.double.bin.bz2 is missing - run the script convert-matrices first." #fi Loading