From e1926c3be18c3c43a1cc3c425fe5b5750bfbdab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Sun, 31 Jan 2021 11:22:27 +0100 Subject: [PATCH] Refuciktoring matrix reader and writer. --- src/TNL/Matrices/MatrixReader.h | 81 ++++-- .../{MatrixReader_impl.h => MatrixReader.hpp} | 111 ++++---- src/TNL/Matrices/MatrixWriter.h | 71 ++++- src/TNL/Matrices/MatrixWriter.hpp | 243 ++++++++++++++++++ src/TNL/Matrices/MatrixWriter_impl.h | 101 -------- 5 files changed, 420 insertions(+), 187 deletions(-) rename src/TNL/Matrices/{MatrixReader_impl.h => MatrixReader.hpp} (85%) create mode 100644 src/TNL/Matrices/MatrixWriter.hpp delete mode 100644 src/TNL/Matrices/MatrixWriter_impl.h diff --git a/src/TNL/Matrices/MatrixReader.h b/src/TNL/Matrices/MatrixReader.h index 6c0a388478..15dee4b8f3 100644 --- a/src/TNL/Matrices/MatrixReader.h +++ b/src/TNL/Matrices/MatrixReader.h @@ -17,13 +17,6 @@ namespace TNL { namespace Matrices { -/// This is to prevent from appearing in Doxygen documentation. -/// \cond HIDDEN_CLASS -template< typename Device > -class MatrixReaderDeviceDependentCode -{}; -/// \endcond - /** * \brief Helper class for reading of matrices from files. * @@ -32,8 +25,62 @@ class MatrixReaderDeviceDependentCode * * \tparam Matrix is a type of matrix into which we want to import the MTX file. */ -template< typename Matrix > +template< typename Matrix, + typename Device = typename Matrix::DeviceType > class MatrixReader +{ + public: + + /** + * \brief Type of matrix elements values. + */ + using RealType = typename Matrix::RealType; + + /** + * \brief Device where the matrix is allocated. + */ + using DeviceType = typename Matrix::RealType; + + /** + * \brief Type used for indexing of matrix elements. + */ + using IndexType = typename Matrix::IndexType; + using HostMatrix = typename Matrix::Self< RealType, TNL::Devices::Host >; + + /** + * \brief Method for importing matrix from file with given filename. + * + * \param fileName is the name of the source file. + * \param matrix is the target matrix. + * \param verbose controls verbosity of the matrix import. + * + * \par Example + * \include Matrices/MatrixWriterReaderExample.cpp + * \par Output + * \include Matrices/MatrixWriterReaderExample.out + * + */ + static void readMtxFile( const String& fileName, + Matrix& matrix, + bool verbose = false ); + + /** + * \brief Method for importing matrix from STL input stream. + * + * \param file is the input stream. + * \param matrix is the target matrix. + * \param verbose controls verbosity of the matrix import. + */ + static void readMtxFile( std::istream& file, + Matrix& matrix, + bool verbose = false ); +}; + +/// This is to prevent from appearing in Doxygen documentation. +/// \cond HIDDEN_CLASS + +template< typename Matrix > +class MatrixReader< Matrix, TNL::Devices::Host > { public: @@ -58,6 +105,12 @@ class MatrixReader * \param fileName is the name of the source file. * \param matrix is the target matrix. * \param verbose controls verbosity of the matrix import. + * + * \par Example + * \include Matrices/MatrixWriterReaderExample.cpp + * \par Output + * \include Matrices/MatrixWriterReaderExample.out + * */ static void readMtxFile( const String& fileName, Matrix& matrix, @@ -75,11 +128,6 @@ class MatrixReader bool verbose = false ); protected: - static void readMtxFileHostMatrix( std::istream& file, - Matrix& matrix, - typename Matrix::RowsCapacitiesType& rowLengths, - bool verbose ); - static void verifyMtxFile( std::istream& file, const Matrix& matrix, @@ -118,12 +166,11 @@ class MatrixReader IndexType& row, IndexType& column, RealType& value ); - - template< typename Device > - friend class MatrixReaderDeviceDependentCode; }; +/// \endcond + } // namespace Matrices } // namespace TNL -#include <TNL/Matrices/MatrixReader_impl.h> +#include <TNL/Matrices/MatrixReader.hpp> diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader.hpp similarity index 85% rename from src/TNL/Matrices/MatrixReader_impl.h rename to src/TNL/Matrices/MatrixReader.hpp index 92ab4102dc..30d8ee6d96 100644 --- a/src/TNL/Matrices/MatrixReader_impl.h +++ b/src/TNL/Matrices/MatrixReader.hpp @@ -20,11 +20,42 @@ namespace TNL { namespace Matrices { + +template< typename Matrix, typename Device > +void +MatrixReader< Matrix, Device >:: +readMtxFile( const TNL::String& fileName, + Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + MatrixReader< HostMatrix >::readMtxFile( fileName, hostMatrix, verbose ); + matrix = hostMatrix; +} + +template< typename Matrix, typename Device > +void +MatrixReader< Matrix, Device >:: +readMtxFile( std::istream& str, + Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + MatrixReader< HostMatrix >::readMtxFile( str, hostMatrix, verbose ); + matrix = hostMatrix; +} + + +/** + * MatrixReader specialization for TNL::Devices::Host. + */ + template< typename Matrix > void -MatrixReader< Matrix >::readMtxFile( const String& fileName, - Matrix& matrix, - bool verbose ) +MatrixReader< Matrix, TNL::Devices::Host >:: +readMtxFile( const String& fileName, + Matrix& matrix, + bool verbose ) { std::fstream file; file.open( fileName.getString(), std::ios::in ); @@ -35,21 +66,12 @@ MatrixReader< Matrix >::readMtxFile( const String& fileName, template< typename Matrix > void -MatrixReader< Matrix >::readMtxFile( std::istream& file, - Matrix& matrix, - bool verbose ) -{ - MatrixReaderDeviceDependentCode< typename Matrix::DeviceType >::readMtxFile( file, matrix, verbose ); -} - -template< typename Matrix > -void -MatrixReader< Matrix >:: -readMtxFileHostMatrix( std::istream& file, - Matrix& matrix, - typename Matrix::RowsCapacitiesType& rowLengths, - bool verbose ) +MatrixReader< Matrix, TNL::Devices::Host >:: +readMtxFile( std::istream& file, + Matrix& matrix, + bool verbose ) { + matrix.setDimensions( 5, 5 ); IndexType rows, columns; bool symmetricSourceMatrix( false ); @@ -58,8 +80,10 @@ readMtxFileHostMatrix( std::istream& file, if( Matrix::isSymmetric() && !symmetricSourceMatrix ) throw std::runtime_error( "Matrix is not symmetric, but flag for symmetric matrix is given. Aborting." ); + if( verbose ) + std::cout << "Matrix dimensions are " << rows << " x " << columns << std::endl; matrix.setDimensions( rows, columns ); - rowLengths.setSize( rows ); + typename Matrix::RowsCapacitiesType rowLengths( rows ); computeCompressedRowLengthsFromMtxFile( file, rowLengths, columns, rows, symmetricSourceMatrix, Matrix::isSymmetric(), verbose ); @@ -70,7 +94,7 @@ readMtxFileHostMatrix( std::istream& file, template< typename Matrix > void -MatrixReader< Matrix >:: +MatrixReader< Matrix, TNL::Devices::Host >:: verifyMtxFile( std::istream& file, const Matrix& matrix, bool verbose ) { bool symmetricSourceMatrix( false ); @@ -121,7 +145,7 @@ verifyMtxFile( std::istream& file, const Matrix& matrix, bool verbose ) template< typename Matrix > bool -MatrixReader< Matrix >:: +MatrixReader< Matrix, TNL::Devices::Host >:: findLineByElement( std::istream& file, const IndexType& row, const IndexType& column, @@ -154,7 +178,7 @@ findLineByElement( std::istream& file, template< typename Matrix > void -MatrixReader< Matrix >::checkMtxHeader( const String& header, bool& symmetric ) +MatrixReader< Matrix, TNL::Devices::Host >::checkMtxHeader( const String& header, bool& symmetric ) { std::vector< String > parsedLine = header.split( ' ', String::SplitSkip::SkipEmpty ); if( (int) parsedLine.size() < 5 || parsedLine[ 0 ] != "%%MatrixMarket" ) @@ -177,7 +201,7 @@ MatrixReader< Matrix >::checkMtxHeader( const String& header, bool& symmetric ) template< typename Matrix > void -MatrixReader< Matrix >::readMtxHeader( std::istream& file, +MatrixReader< Matrix, TNL::Devices::Host >::readMtxHeader( std::istream& file, IndexType& rows, IndexType& columns, bool& symmetric, @@ -218,7 +242,7 @@ MatrixReader< Matrix >::readMtxHeader( std::istream& file, template< typename Matrix > void -MatrixReader< Matrix >:: +MatrixReader< Matrix, TNL::Devices::Host >:: computeCompressedRowLengthsFromMtxFile( std::istream& file, Containers::Vector< int, DeviceType, int >& rowLengths, const int columns, @@ -293,7 +317,7 @@ computeCompressedRowLengthsFromMtxFile( std::istream& file, template< typename Matrix > void -MatrixReader< Matrix >:: +MatrixReader< Matrix, TNL::Devices::Host >:: readMatrixElementsFromMtxFile( std::istream& file, Matrix& matrix, bool symmetricSourceMatrix, @@ -345,7 +369,7 @@ readMatrixElementsFromMtxFile( std::istream& file, template< typename Matrix > void -MatrixReader< Matrix >:: +MatrixReader< Matrix, TNL::Devices::Host >:: parseMtxLineWithElement( const String& line, IndexType& row, IndexType& column, @@ -363,42 +387,5 @@ parseMtxLineWithElement( const String& line, value = ( RealType ) atof( parsedLine[ 2 ].getString() ); } -/// This is to prevent from appearing in Doxygen documentation. -/// \cond HIDDEN_CLASS -template<> -class MatrixReaderDeviceDependentCode< Devices::Host > -{ - public: - - template< typename Matrix > - static void readMtxFile( std::istream& file, - Matrix& matrix, - bool verbose ) - { - typename Matrix::RowsCapacitiesType rowLengths; - MatrixReader< Matrix >::readMtxFileHostMatrix( file, matrix, rowLengths, verbose ); - } -}; - -template<> -class MatrixReaderDeviceDependentCode< Devices::Cuda > -{ - public: - - template< typename Matrix > - static void readMtxFile( std::istream& file, - Matrix& matrix, - bool verbose ) - { - using HostMatrixType = typename Matrix::template Self< typename Matrix::RealType, Devices::Sequential >; - using RowsCapacitiesType = typename HostMatrixType::RowsCapacitiesType; - - HostMatrixType hostMatrix; - RowsCapacitiesType rowLengths; - MatrixReader< Matrix >::readMtxFileHostMatrix( file, matrix, rowLengths, verbose ); - } -}; -/// \endcond - } // namespace Matrices } // namespace TNL diff --git a/src/TNL/Matrices/MatrixWriter.h b/src/TNL/Matrices/MatrixWriter.h index 634a3437b9..0359eb5bc8 100644 --- a/src/TNL/Matrices/MatrixWriter.h +++ b/src/TNL/Matrices/MatrixWriter.h @@ -12,39 +12,96 @@ #include <ostream> #include <iostream> +#include <TNL/String.h> namespace TNL { -namespace Matrices { +namespace Matrices { -template< typename Matrix > +template< typename Matrix, typename Device = typename Matrix::DeviceType > class MatrixWriter +{ + public: + + using RealType = typename Matrix::RealType; + using DeviceType = typename Matrix::RealType; + using IndexType = typename Matrix::IndexType; + using HostMatrix = typename Matrix::Self< RealType, TNL::Devices::Host >; + + + static void writeToGnuplot( const TNL::String& fileName, + const Matrix& matrix, + bool verbose = false ); + + + static void writeToGnuplot( std::ostream& str, + const Matrix& matrix, + bool verbose = false ); + + static void writeToEps( const TNL::String& fileName, + const Matrix& matrix, + bool verbose = false ); + + static void writeToEps( std::ostream& str, + const Matrix& matrix, + bool verbose = false ); + + static void writeToMtx( const TNL::String& fileName, + const Matrix& matrix, + bool verbose = false ); + + static void writeToMtx( std::ostream& str, + const Matrix& matrix, + bool verbose = false ); +}; + +template< typename Matrix > +class MatrixWriter< Matrix, TNL::Devices::Host > { public: typedef typename Matrix::IndexType IndexType; typedef typename Matrix::RealType RealType; - static bool writeToGnuplot( std::ostream& str, + static void writeToGnuplot( const TNL::String& fileName, const Matrix& matrix, bool verbose = false ); - static bool writeToEps( std::ostream& str, + + static void writeToGnuplot( std::ostream& str, + const Matrix& matrix, + bool verbose = false ); + + static void writeToEps( const TNL::String& fileName, + const Matrix& matrix, + bool verbose = false ); + + static void writeToEps( std::ostream& str, + const Matrix& matrix, + bool verbose = false ); + + static void writeToMtx( const TNL::String& fileName, + const Matrix& matrix, + bool verbose = false ); + + static void writeToMtx( std::ostream& str, const Matrix& matrix, bool verbose = false ); protected: - static bool writeEpsHeader( std::ostream& str, + static void writeEpsHeader( std::ostream& str, const Matrix& matrix, const int elementSize ); - static bool writeEpsBody( std::ostream& str, + static void writeEpsBody( std::ostream& str, const Matrix& matrix, const int elementSize, bool verbose ); }; + + } // namespace Matrices } // namespace TNL -#include <TNL/Matrices/MatrixWriter_impl.h> +#include <TNL/Matrices/MatrixWriter.hpp> diff --git a/src/TNL/Matrices/MatrixWriter.hpp b/src/TNL/Matrices/MatrixWriter.hpp new file mode 100644 index 0000000000..016f6ff3a0 --- /dev/null +++ b/src/TNL/Matrices/MatrixWriter.hpp @@ -0,0 +1,243 @@ +/*************************************************************************** + MatrixWriter_impl.h - description + ------------------- + begin : Dec 18, 2013 + copyright : (C) 2013 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <iomanip> +#include <TNL/Matrices/MatrixWriter.h> + +namespace TNL { +namespace Matrices { + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToGnuplot( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToGnuplot( fileName, hostMatrix, verbose ); +} + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToGnuplot( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToGnuplot( str, hostMatrix, verbose ); +} + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToMtx( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToMtx( fileName, hostMatrix, verbose ); +} + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToMtx( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToMtx( str, hostMatrix, verbose ); +} + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToEps( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToEps( fileName, hostMatrix, verbose ); +} + +template< typename Matrix, typename Device > +void +MatrixWriter< Matrix, Device >:: +writeToEps( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + HostMatrix hostMatrix; + hostMatrix = matrix; + MatrixWriter< HostMatrix >::writeToEps( str, hostMatrix, verbose ); +} + +/** + * MatrixWriter specialization for TNL::Devices::Host. + */ + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToGnuplot( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + std::fstream str; + str.open( fileName.getString(), std::ios::out ); + MatrixWriter< Matrix >::writeToGnuplot( str, matrix, verbose ); +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToGnuplot( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + str << "# This file was generated by TNL (www.tnl-project.org)" << std::endl; + for( IndexType row = 0; row < matrix.getRows(); row ++ ) + { + for( IndexType column = 0; column < matrix.getColumns(); column ++ ) + { + RealType elementValue = matrix.getElement( row, column ); + if( elementValue != ( RealType ) 0.0 ) + str << column << " " << row << " " << elementValue << "\n"; + } + if( verbose ) + std::cout << "Drawing the row " << row << " \r" << std::flush; + } + if( verbose ) + std::cout << std::endl; +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToMtx( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + std::fstream str; + str.open( fileName.getString(), std::ios::out ); + MatrixWriter< Matrix >::writeToMtx( str, matrix, verbose ); +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToMtx( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + str << "%%MatrixMarket matrix coordinate real general" << std::endl; + str << "%%" << std::endl; + str << "%% This file was generated by TNL (www.tnl-project.org)" << std::endl; + str << "%%" << std::setw( 9 ) << " ROWS " << std::setw( 9 ) << " COLUMNS " << std::setw( 12 ) << " ELEMENTS " << std::endl; + str << std::setw( 9 ) << matrix.getRows() << " " << std::setw( 9 ) << matrix.getColumns() << " " << std::setw( 12 ) << matrix.getNonzeroElementsCount() << std::endl; + std::ostream* str_ptr = &str; + auto cout_ptr = &std::cout; + auto f = [=] __cuda_callable__ ( IndexType rowIdx, IndexType localIdx, IndexType columnIdx, RealType value, bool& compute ) mutable { + if( value != 0 ) + { + *str_ptr << std::setw( 9 ) << rowIdx + 1 << std::setw( 9 ) << columnIdx + 1 << std::setw( 12 ) << value << std::endl; + if( verbose ) + *cout_ptr << "Drawing the row " << rowIdx << " \r" << std::flush; + } + }; + matrix.forAllRows( f ); +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToEps( const TNL::String& fileName, + const Matrix& matrix, + bool verbose ) +{ + std::fstream str; + str.open( fileName.getString(), std::ios::out ); + MatrixWriter< Matrix >::writeToEps( str, matrix, verbose ); +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeToEps( std::ostream& str, + const Matrix& matrix, + bool verbose ) +{ + const int elementSize = 10; + writeEpsHeader( str, matrix, elementSize ); + writeEpsBody( str, matrix, elementSize, verbose ); + + str << "showpage" << std::endl; + str << "%%EOF" << std::endl; + + if( verbose ) + std::cout << std::endl; +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeEpsHeader( std::ostream& str, + const Matrix& matrix, + const int elementSize ) +{ + const double scale = elementSize * max( matrix.getRows(), matrix.getColumns() ); + str << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl; + str << "%%BoundingBox: 0 0 " << scale << " " << scale << std::endl; + str << "%%Creator: TNL" << std::endl; + str << "%%LanguageLevel: 2" << std::endl; + str << "%%EndComments" << std::endl << std::endl; + str << "0 " << scale << " translate" << std::endl; +} + +template< typename Matrix > +void +MatrixWriter< Matrix, TNL::Devices::Host >:: +writeEpsBody( std::ostream& str, + const Matrix& matrix, + const int elementSize, + bool verbose ) +{ + IndexType lastRow( 0 ), lastColumn( 0 ); + for( IndexType row = 0; row < matrix.getRows(); row ++ ) + { + for( IndexType column = 0; column < matrix.getColumns(); column ++ ) + { + RealType elementValue = matrix.getElement( row, column ); + if( elementValue != ( RealType ) 0.0 ) + { + str << ( column - lastColumn ) * elementSize + << " " << -( row - lastRow ) * elementSize + << " translate newpath 0 0 " << elementSize << " " << elementSize << " rectstroke\n"; + lastColumn = column; + lastRow = row; + } + } + if( verbose ) + std::cout << "Drawing the row " << row << " \r" << std::flush; + } +} + + +} // namespace Matrices +} // namespace TNL diff --git a/src/TNL/Matrices/MatrixWriter_impl.h b/src/TNL/Matrices/MatrixWriter_impl.h deleted file mode 100644 index 40368d0dd9..0000000000 --- a/src/TNL/Matrices/MatrixWriter_impl.h +++ /dev/null @@ -1,101 +0,0 @@ -/*************************************************************************** - MatrixWriter_impl.h - description - ------------------- - begin : Dec 18, 2013 - copyright : (C) 2013 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/* See Copyright Notice in tnl/Copyright */ - -#pragma once - -#include <TNL/Matrices/MatrixWriter.h> - -namespace TNL { -namespace Matrices { - -template< typename Matrix > -bool MatrixWriter< Matrix >::writeToGnuplot( std::ostream& str, - const Matrix& matrix, - bool verbose ) -{ - for( IndexType row = 0; row < matrix.getRows(); row ++ ) - { - for( IndexType column = 0; column < matrix.getColumns(); column ++ ) - { - RealType elementValue = matrix.getElement( row, column ); - if( elementValue != ( RealType ) 0.0 ) - str << column << " " << row << " " << elementValue << "\n"; - } - if( verbose ) - std::cout << "Drawing the row " << row << " \r" << std::flush; - } - if( verbose ) - std::cout << std::endl; - return true; -} - -template< typename Matrix > -bool MatrixWriter< Matrix >::writeToEps( std::ostream& str, - const Matrix& matrix, - bool verbose ) -{ - const int elementSize = 10; - if( ! writeEpsHeader( str, matrix, elementSize ) ) - return false; - if( !writeEpsBody( str, matrix, elementSize, verbose ) ) - return false; - - str << "showpage" << std::endl; - str << "%%EOF" << std::endl; - - if( verbose ) - std::cout << std::endl; - return true; -} - -template< typename Matrix > -bool MatrixWriter< Matrix >::writeEpsHeader( std::ostream& str, - const Matrix& matrix, - const int elementSize ) -{ - const double scale = elementSize * max( matrix.getRows(), matrix.getColumns() ); - str << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl; - str << "%%BoundingBox: 0 0 " << scale << " " << scale << std::endl; - str << "%%Creator: TNL" << std::endl; - str << "%%LanguageLevel: 2" << std::endl; - str << "%%EndComments" << std::endl << std::endl; - str << "0 " << scale << " translate" << std::endl; - return true; -} - -template< typename Matrix > -bool MatrixWriter< Matrix >::writeEpsBody( std::ostream& str, - const Matrix& matrix, - const int elementSize, - bool verbose ) -{ - IndexType lastRow( 0 ), lastColumn( 0 ); - for( IndexType row = 0; row < matrix.getRows(); row ++ ) - { - for( IndexType column = 0; column < matrix.getColumns(); column ++ ) - { - RealType elementValue = getElement( row, column ); - if( elementValue != ( RealType ) 0.0 ) - { - str << ( column - lastColumn ) * elementSize - << " " << -( row - lastRow ) * elementSize - << " translate newpath 0 0 " << elementSize << " " << elementSize << " rectstroke\n"; - lastColumn = column; - lastRow = row; - } - } - if( verbose ) - std::cout << "Drawing the row " << row << " \r" << std::flush; - } - return true; -} - -} // namespace Matrices -} // namespace TNL -- GitLab