11 #ifndef EIGEN_BROWSE_MATRICES_H 12 #define EIGEN_BROWSE_MATRICES_H 41 template <
typename Scalar>
49 MatrixMarketIterator(
const std::string folder):m_sym(0),m_isvalid(
false),m_matIsLoaded(
false),m_hasRhs(
false),m_hasrefX(
false),m_folder(folder)
51 m_folder_id = opendir(folder.c_str());
54 std::cerr <<
"The provided Matrix folder could not be opened \n\n";
62 if (m_folder_id) closedir(m_folder_id);
67 m_matIsLoaded =
false;
73 inline operator bool()
const {
return m_isvalid;}
79 if (m_matIsLoaded)
return m_mat;
81 std::string matrix_file = m_folder +
"/" + m_matname +
".mtx";
82 if ( !loadMarket(m_mat, matrix_file))
84 m_matIsLoaded =
false;
89 if (m_sym != NonSymmetric)
93 m_mat = B.template selfadjointView<Lower>();
104 if (m_hasRhs)
return m_rhs;
106 std::string rhs_file;
107 rhs_file = m_folder +
"/" + m_matname +
"_b.mtx";
108 m_hasRhs = Fileexists(rhs_file);
112 m_hasRhs = loadMarketVector(m_rhs, rhs_file);
117 if (!m_matIsLoaded) this->
matrix();
120 m_rhs = m_mat * m_refX;
136 if (m_hasrefX)
return m_refX;
138 std::string lhs_file;
139 lhs_file = m_folder +
"/" + m_matname +
"_x.mtx";
140 m_hasrefX = Fileexists(lhs_file);
144 m_hasrefX = loadMarketVector(m_refX, lhs_file);
149 inline std::string& matname() {
return m_matname; }
151 inline int sym() {
return m_sym; }
153 inline bool hasRhs() {
return m_hasRhs; }
154 inline bool hasrefX() {
return m_hasrefX; }
158 inline bool Fileexists(std::string file)
160 std::ifstream file_id(file.c_str());
161 if (!file_id.good() )
172 void Getnextvalidmatrix( )
176 while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
179 curfile = m_folder +
"/" + m_curs_id->d_name;
181 if (m_curs_id->d_type == DT_DIR)
continue;
187 bool isvector,iscomplex=
false;
188 if(!getMarketHeader(curfile,m_sym,iscomplex,isvector))
continue;
189 if(isvector)
continue;
203 std::string filename = m_curs_id->d_name;
204 m_matname = filename.substr(0, filename.length()-4);
207 size_t found = m_matname.find(
"SPD");
208 if( (found!=std::string::npos) && (m_sym != NonSymmetric) )
219 std::string m_matname;
224 std::string m_folder;
226 struct dirent *m_curs_id;
MatrixType & matrix()
Return the sparse matrix corresponding to the current file.
Definition: MatrixMarketIterator.h:76
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Index cols() const
Definition: SparseMatrix.h:121
VectorType & rhs()
Return the right hand side corresponding to the current matrix.
Definition: MatrixMarketIterator.h:101
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:235
Iterator to browse matrices from a specified folder.
Definition: MatrixMarketIterator.h:42
VectorType & refX()
Return a reference solution If it is not provided and if the right hand side is not available then re...
Definition: MatrixMarketIterator.h:133
Derived & setRandom(Index size)
Resizes to the given newSize, and sets all coefficients in this expression to random values...
Definition: Random.h:126