Skip to content
Snippets Groups Projects
Commit 369ae3ce authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Fixing MatrixReader.

parent 0b14ec64
No related branches found
No related tags found
1 merge request!48Segments
...@@ -58,7 +58,7 @@ class MatrixReader ...@@ -58,7 +58,7 @@ class MatrixReader
IndexType& lineNumber ); IndexType& lineNumber );
protected: protected:
static void checkMtxHeader( const String& header, static bool checkMtxHeader( const String& header,
bool& symmetric ); bool& symmetric );
static void readMtxHeader( std::istream& file, static void readMtxHeader( std::istream& file,
......
...@@ -156,12 +156,12 @@ bool MatrixReader< Matrix >::findLineByElement( std::istream& file, ...@@ -156,12 +156,12 @@ bool MatrixReader< Matrix >::findLineByElement( std::istream& file,
} }
template< typename Matrix > template< typename Matrix >
void MatrixReader< Matrix >::checkMtxHeader( const String& header, bool MatrixReader< Matrix >::checkMtxHeader( const String& header,
bool& symmetric ) bool& symmetric )
{ {
std::vector< String > parsedLine = header.split( ' ', String::SplitSkip::SkipEmpty ); std::vector< String > parsedLine = header.split( ' ', String::SplitSkip::SkipEmpty );
if( (int) parsedLine.size() < 5 || parsedLine[ 0 ] != "%%MatrixMarket" ) if( (int) parsedLine.size() < 5 || parsedLine[ 0 ] != "%%MatrixMarket" )
throw std::runtime_error( "Wrong MTX file header. We expect line like this: %%MatrixMarket matrix coordinate real general" ); return false;
if( parsedLine[ 1 ] != "matrix" ) if( parsedLine[ 1 ] != "matrix" )
throw std::runtime_error( std::string( "Keyword 'matrix' is expected in the header line: " ) + header.getString() ); throw std::runtime_error( std::string( "Keyword 'matrix' is expected in the header line: " ) + header.getString() );
if( parsedLine[ 2 ] != "coordinates" && if( parsedLine[ 2 ] != "coordinates" &&
...@@ -176,6 +176,7 @@ void MatrixReader< Matrix >::checkMtxHeader( const String& header, ...@@ -176,6 +176,7 @@ void MatrixReader< Matrix >::checkMtxHeader( const String& header,
else else
throw std::runtime_error( std::string( "Only 'general' matrices are supported, not " ) + parsedLine[ 4 ].getString() ); throw std::runtime_error( std::string( "Only 'general' matrices are supported, not " ) + parsedLine[ 4 ].getString() );
} }
return true;
} }
template< typename Matrix > template< typename Matrix >
...@@ -195,7 +196,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file, ...@@ -195,7 +196,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file,
std::getline( file, line ); std::getline( file, line );
if( ! headerParsed ) if( ! headerParsed )
{ {
checkMtxHeader( line, symmetric ); headerParsed = checkMtxHeader( line, symmetric );
if( verbose && symmetric ) if( verbose && symmetric )
std::cout << "The matrix is SYMMETRIC ... "; std::cout << "The matrix is SYMMETRIC ... ";
continue; continue;
...@@ -215,6 +216,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file, ...@@ -215,6 +216,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file,
if( rows <= 0 || columns <= 0 ) if( rows <= 0 || columns <= 0 )
throw std::runtime_error( "Row or column index is negative." ); throw std::runtime_error( "Row or column index is negative." );
break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment