11 #ifndef EIGEN_BROWSE_MATRICES_H
12 #define EIGEN_BROWSE_MATRICES_H
14 #include "./InternalHeaderCheck.h"
43 template <
typename Scalar>
53 : m_sym(0), m_isvalid(
false), m_matIsLoaded(
false), m_hasRhs(
false), m_hasrefX(
false), m_folder(folder)
55 m_folder_id = opendir(folder.c_str());
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";
84 std::cerr <<
"Warning loadMarket failed when loading \"" << matrix_file <<
"\"" << std::endl;
85 m_matIsLoaded =
false;
90 if (m_sym != NonSymmetric)
93 RealScalar diag_norm = m_mat.
diagonal().norm();
94 RealScalar lower_norm = m_mat.template triangularView<Lower>().norm();
95 RealScalar upper_norm = m_mat.template triangularView<Upper>().norm();
96 if(lower_norm>diag_norm && upper_norm==diag_norm)
100 m_mat = tmp.template selfadjointView<Lower>();
102 else if(upper_norm>diag_norm && lower_norm==diag_norm)
106 m_mat = tmp.template selfadjointView<Upper>();
118 if (m_hasRhs)
return m_rhs;
120 std::string rhs_file;
121 rhs_file = m_folder +
"/" + m_matname +
"_b.mtx";
122 m_hasRhs = Fileexists(rhs_file);
131 if (!m_matIsLoaded) this->
matrix();
134 m_rhs = m_mat * m_refX;
150 if (m_hasrefX)
return m_refX;
152 std::string lhs_file;
153 lhs_file = m_folder +
"/" + m_matname +
"_x.mtx";
154 m_hasrefX = Fileexists(lhs_file);
165 inline std::string& matname() {
return m_matname; }
167 inline int sym() {
return m_sym; }
169 bool hasRhs() {
return m_hasRhs; }
170 bool hasrefX() {
return m_hasrefX; }
171 bool isFolderValid() {
return bool(m_folder_id); }
175 inline bool Fileexists(std::string file)
177 std::ifstream file_id(file.c_str());
178 if (!file_id.good() )
189 void Getnextvalidmatrix( )
193 while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
196 curfile = m_folder +
"/" + m_curs_id->d_name;
198 if (m_curs_id->d_type == DT_DIR)
continue;
204 bool isvector,iscomplex=
false;
206 if(isvector)
continue;
209 if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value)
214 if(internal::is_same<Scalar, float>::value || internal::is_same<Scalar, double>::value)
220 std::string filename = m_curs_id->d_name;
221 m_matname = filename.substr(0, filename.length()-4);
224 size_t found = m_matname.find(
"SPD");
225 if( (found!=std::string::npos) && (m_sym != NonSymmetric) )
236 std::string m_matname;
241 std::string m_folder;
243 struct dirent *m_curs_id;
Iterator to browse matrices from a specified folder.
Definition: MatrixMarketIterator.h:45
VectorType & refX()
Definition: MatrixMarketIterator.h:147
VectorType & rhs()
Definition: MatrixMarketIterator.h:115
MatrixType & matrix()
Definition: MatrixMarketIterator.h:76
Derived & setRandom(Index size)
void resize(Index rows, Index cols)
DiagonalReturnType diagonal()
Namespace containing all symbols from the Eigen library.