mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-14 17:11:50 +08:00
Matrix-Market: fix perf issue and infinite loop
This commit is contained in:
parent
c858fb353f
commit
3fd2beebc8
@ -157,6 +157,9 @@ bool loadMarket(SparseMatrixType& mat, const std::string& filename)
|
|||||||
|
|
||||||
bool readsizes = false;
|
bool readsizes = false;
|
||||||
|
|
||||||
|
typedef Triplet<Scalar,int> T;
|
||||||
|
std::vector<T> elements;
|
||||||
|
|
||||||
int M(-1), N(-1), NNZ(-1);
|
int M(-1), N(-1), NNZ(-1);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while(input.getline(buffer, maxBuffersize))
|
while(input.getline(buffer, maxBuffersize))
|
||||||
@ -186,13 +189,13 @@ bool loadMarket(SparseMatrixType& mat, const std::string& filename)
|
|||||||
if( internal::GetMarketLine(line, M, N, i, j, value) )
|
if( internal::GetMarketLine(line, M, N, i, j, value) )
|
||||||
{
|
{
|
||||||
++ count;
|
++ count;
|
||||||
mat.insert(i,j) = value;
|
elements.push_back(T(i,j,value));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << "Invalid read: " << i << "," << j << "\n";
|
std::cerr << "Invalid read: " << i << "," << j << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mat.makeCompressed();
|
mat.setFromTriplets(elements.begin(), elements.end());
|
||||||
if(count!=NNZ)
|
if(count!=NNZ)
|
||||||
std::cerr << count << "!=" << NNZ << "\n";
|
std::cerr << count << "!=" << NNZ << "\n";
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class MatrixMarketIterator
|
|||||||
Getnextvalidmatrix();
|
Getnextvalidmatrix();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline operator bool() { return m_isvalid;}
|
inline operator bool() const { return m_isvalid;}
|
||||||
|
|
||||||
/** Return the sparse matrix corresponding to the current file */
|
/** Return the sparse matrix corresponding to the current file */
|
||||||
inline MatrixType& matrix()
|
inline MatrixType& matrix()
|
||||||
@ -186,6 +186,7 @@ class MatrixMarketIterator
|
|||||||
|
|
||||||
void Getnextvalidmatrix( )
|
void Getnextvalidmatrix( )
|
||||||
{
|
{
|
||||||
|
m_isvalid = false;
|
||||||
// Here, we return with the next valid matrix in the folder
|
// Here, we return with the next valid matrix in the folder
|
||||||
while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
|
while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
|
||||||
m_isvalid = false;
|
m_isvalid = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user