26 #ifndef EIGEN_BROWSE_MATRICES_H
27 #define EIGEN_BROWSE_MATRICES_H
56 template <
typename Scalar>
60 typedef Matrix<Scalar,Dynamic,1> VectorType;
61 typedef SparseMatrix<Scalar,ColMajor> MatrixType;
64 MatrixMarketIterator(
const std::string folder):m_sym(0),m_isvalid(
false),m_matIsLoaded(
false),m_hasRhs(
false),m_hasrefX(
false),m_folder(folder)
66 m_folder_id = opendir(folder.c_str());
69 std::cerr <<
"The provided Matrix folder could not be opened \n\n";
77 if (m_folder_id) closedir(m_folder_id);
82 m_matIsLoaded =
false;
88 inline operator bool() {
return m_isvalid;}
94 if (m_matIsLoaded)
return m_mat;
96 std::string matrix_file = m_folder +
"/" + m_matname +
".mtx";
97 if ( !loadMarket(m_mat, matrix_file))
99 m_matIsLoaded =
false;
102 m_matIsLoaded =
true;
104 if (m_sym != NonSymmetric)
108 m_mat = B.template selfadjointView<Lower>();
119 if (m_hasRhs)
return m_rhs;
121 std::string rhs_file;
122 rhs_file = m_folder +
"/" + m_matname +
"_b.mtx";
123 m_hasRhs = Fileexists(rhs_file);
126 m_rhs.resize(m_mat.cols());
127 m_hasRhs = loadMarketVector(m_rhs, rhs_file);
132 if (!m_matIsLoaded) this->
matrix();
133 m_refX.resize(m_mat.cols());
135 m_rhs = m_mat * m_refX;
151 if (m_hasrefX)
return m_refX;
153 std::string lhs_file;
154 lhs_file = m_folder +
"/" + m_matname +
"_x.mtx";
155 m_hasrefX = Fileexists(lhs_file);
158 m_refX.resize(m_mat.cols());
159 m_hasrefX = loadMarketVector(m_refX, lhs_file);
164 inline std::string& matname() {
return m_matname; }
166 inline int sym() {
return m_sym; }
168 inline bool hasRhs() {
return m_hasRhs; }
169 inline bool hasrefX() {
return m_hasrefX; }
173 inline bool Fileexists(std::string file)
175 std::ifstream file_id(file.c_str());
176 if (!file_id.good() )
187 void Getnextvalidmatrix( )
190 while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
193 curfile = m_folder +
"/" + m_curs_id->d_name;
195 if (m_curs_id->d_type == DT_DIR)
continue;
201 bool isvector,iscomplex;
202 if(!getMarketHeader(curfile,m_sym,iscomplex,isvector))
continue;
203 if(isvector)
continue;
206 std::string filename = m_curs_id->d_name;
207 m_matname = filename.substr(0, filename.length()-4);
210 size_t found = m_matname.find(
"SPD");
211 if( (found!=std::string::npos) && (m_sym != NonSymmetric) )
222 std::string m_matname;
227 std::string m_folder;
229 struct dirent *m_curs_id;