Skip to content
Snippets Groups Projects
Commit 8bf2a0ae authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixed matrix reader to work with empty lines in MTX files.

parent 09af2ea2
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <TNL/Matrices/MatrixReader.h> #include <TNL/Matrices/MatrixReader.h>
namespace TNL { namespace TNL {
namespace Matrices { namespace Matrices {
template< typename Matrix > template< typename Matrix >
bool MatrixReader< Matrix >::readMtxFile( const String& fileName, bool MatrixReader< Matrix >::readMtxFile( const String& fileName,
...@@ -68,7 +68,7 @@ bool MatrixReader< Matrix >::readMtxFileHostMatrix( std::istream& file, ...@@ -68,7 +68,7 @@ bool MatrixReader< Matrix >::readMtxFileHostMatrix( std::istream& file,
if( ! computeCompressedRowLengthsFromMtxFile( file, rowLengths, columns, rows, symmetricMatrix, verbose ) ) if( ! computeCompressedRowLengthsFromMtxFile( file, rowLengths, columns, rows, symmetricMatrix, verbose ) )
return false; return false;
matrix.setCompressedRowLengths( rowLengths ); matrix.setCompressedRowLengths( rowLengths );
if( ! readMatrixElementsFromMtxFile( file, matrix, symmetricMatrix, verbose, symReader ) ) if( ! readMatrixElementsFromMtxFile( file, matrix, symmetricMatrix, verbose, symReader ) )
...@@ -271,7 +271,7 @@ bool MatrixReader< Matrix >::computeCompressedRowLengthsFromMtxFile( std::istrea ...@@ -271,7 +271,7 @@ bool MatrixReader< Matrix >::computeCompressedRowLengthsFromMtxFile( std::istrea
timer.start(); timer.start();
while( std::getline( file, line ) ) while( std::getline( file, line ) )
{ {
if( line[ 0 ] == '%' ) continue; if( ! line.getSize() || line[ 0 ] == '%' ) continue;
if( ! dimensionsLine ) if( ! dimensionsLine )
{ {
dimensionsLine = true; dimensionsLine = true;
...@@ -340,10 +340,10 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file, ...@@ -340,10 +340,10 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
IndexType processedElements( 0 ); IndexType processedElements( 0 );
Timer timer; Timer timer;
timer.start(); timer.start();
while( std::getline( file, line ) ) while( std::getline( file, line ) )
{ {
if( line[ 0 ] == '%' ) continue; if( ! line.getSize() || line[ 0 ] == '%' ) continue;
if( ! dimensionsLine ) if( ! dimensionsLine )
{ {
dimensionsLine = true; dimensionsLine = true;
...@@ -371,7 +371,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file, ...@@ -371,7 +371,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
processedElements++; processedElements++;
} }
} }
file.clear(); file.clear();
long int fileSize = file.tellg(); long int fileSize = file.tellg();
timer.stop(); timer.stop();
...@@ -379,7 +379,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file, ...@@ -379,7 +379,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
std::cout << " Reading the matrix elements ... " << processedElements << " / " << matrix.getNumberOfMatrixElements() std::cout << " Reading the matrix elements ... " << processedElements << " / " << matrix.getNumberOfMatrixElements()
<< " -> " << timer.getRealTime() << " -> " << timer.getRealTime()
<< " sec. i.e. " << fileSize / ( timer.getRealTime() * ( 1 << 20 )) << "MB/s." << std::endl; << " sec. i.e. " << fileSize / ( timer.getRealTime() * ( 1 << 20 )) << "MB/s." << std::endl;
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment