From 3fd2beebc8a3d118f508fe43efd4217c1bfa9c97 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 15 Jun 2012 09:07:13 +0200 Subject: [PATCH] Matrix-Market: fix perf issue and infinite loop --- unsupported/Eigen/src/SparseExtra/MarketIO.h | 7 +++++-- unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/unsupported/Eigen/src/SparseExtra/MarketIO.h b/unsupported/Eigen/src/SparseExtra/MarketIO.h index ddca225d7..9cfe1d9f5 100644 --- a/unsupported/Eigen/src/SparseExtra/MarketIO.h +++ b/unsupported/Eigen/src/SparseExtra/MarketIO.h @@ -156,6 +156,9 @@ bool loadMarket(SparseMatrixType& mat, const std::string& filename) char buffer[maxBuffersize]; bool readsizes = false; + + typedef Triplet T; + std::vector elements; int M(-1), N(-1), NNZ(-1); int count = 0; @@ -186,13 +189,13 @@ bool loadMarket(SparseMatrixType& mat, const std::string& filename) if( internal::GetMarketLine(line, M, N, i, j, value) ) { ++ count; - mat.insert(i,j) = value; + elements.push_back(T(i,j,value)); } else std::cerr << "Invalid read: " << i << "," << j << "\n"; } } - mat.makeCompressed(); + mat.setFromTriplets(elements.begin(), elements.end()); if(count!=NNZ) std::cerr << count << "!=" << NNZ << "\n"; diff --git a/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h b/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h index e04481c01..3c34effca 100644 --- a/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h +++ b/unsupported/Eigen/src/SparseExtra/MatrixMarketIterator.h @@ -85,7 +85,7 @@ class MatrixMarketIterator Getnextvalidmatrix(); return *this; } - inline operator bool() { return m_isvalid;} + inline operator bool() const { return m_isvalid;} /** Return the sparse matrix corresponding to the current file */ inline MatrixType& matrix() @@ -186,6 +186,7 @@ class MatrixMarketIterator void Getnextvalidmatrix( ) { + m_isvalid = false; // Here, we return with the next valid matrix in the folder while ( (m_curs_id = readdir(m_folder_id)) != NULL) { m_isvalid = false;