Commit 64e9cb07 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixing the matrix formats test.

parent 5a6e0718
Loading
Loading
Loading
Loading
+47 −12
Original line number Diff line number Diff line
@@ -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;
@@ -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 ) )
@@ -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 ) )
   {
@@ -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;
@@ -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;
}

+2 −1
Original line number Diff line number Diff line
@@ -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,
+1 −1
Original line number Diff line number Diff line
@@ -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;
+6 −3
Original line number Diff line number Diff line
@@ -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
@@ -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           
@@ -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