11 #ifndef EIGEN_BROWSE_MATRICES_H 12 #define EIGEN_BROWSE_MATRICES_H 41 template <
typename Scalar>
51 : m_sym(0), m_isvalid(
false), m_matIsLoaded(
false), m_hasRhs(
false), m_hasrefX(
false), m_folder(folder)
53 m_folder_id = opendir(folder.c_str());
60 if (m_folder_id) closedir(m_folder_id);
65 m_matIsLoaded =
false;
71 inline operator bool()
const {
return m_isvalid;}
77 if (m_matIsLoaded)
return m_mat;
79 std::string matrix_file = m_folder +
"/" + m_matname +
".mtx";
80 if ( !loadMarket(m_mat, matrix_file))
82 std::cerr <<
"Warning loadMarket failed when loading \"" << matrix_file <<
"\"" << std::endl;
83 m_matIsLoaded =
false;
88 if (m_sym != NonSymmetric)
91 RealScalar diag_norm = m_mat.
diagonal().norm();
92 RealScalar lower_norm = m_mat.template triangularView<Lower>().norm();
93 RealScalar upper_norm = m_mat.template triangularView<Upper>().norm();
94 if(lower_norm>diag_norm && upper_norm==diag_norm)
97 MatrixType tmp(m_mat);
98 m_mat = tmp.template selfadjointView<Lower>();
100 else if(upper_norm>diag_norm && lower_norm==diag_norm)
103 MatrixType tmp(m_mat);
104 m_mat = tmp.template selfadjointView<Upper>();
116 if (m_hasRhs)
return m_rhs;
118 std::string rhs_file;
119 rhs_file = m_folder +
"/" + m_matname +
"_b.mtx";
120 m_hasRhs = Fileexists(rhs_file);
124 m_hasRhs = loadMarketVector(m_rhs, rhs_file);
129 if (!m_matIsLoaded) this->
matrix();
132 m_rhs = m_mat * m_refX;
148 if (m_hasrefX)
return m_refX;
150 std::string lhs_file;
151 lhs_file = m_folder +
"/" + m_matname +
"_x.mtx";
152 m_hasrefX = Fileexists(lhs_file);
156 m_hasrefX = loadMarketVector(m_refX, lhs_file);
163 inline std::string& matname() {
return m_matname; }
165 inline int sym() {
return m_sym; }
167 bool hasRhs() {
return m_hasRhs; }
168 bool hasrefX() {
return m_hasrefX; }
169 bool isFolderValid() {
return bool(m_folder_id); }
173 inline bool Fileexists(std::string file)
175 std::ifstream file_id(file.c_str());
176 if (!file_id.good() )
187 void Getnextvalidmatrix( )
191 while ( (m_curs_id = readdir(m_folder_id)) != NULL) {
194 curfile = m_folder +
"/" + m_curs_id->d_name;
196 if (m_curs_id->d_type == DT_DIR)
continue;
202 bool isvector,iscomplex=
false;
203 if(!getMarketHeader(curfile,m_sym,iscomplex,isvector))
continue;
204 if(isvector)
continue;
218 std::string filename = m_curs_id->d_name;
219 m_matname = filename.substr(0, filename.length()-4);
222 size_t found = m_matname.find(
"SPD");
223 if( (found!=std::string::npos) && (m_sym != NonSymmetric) )
234 std::string m_matname;
239 std::string m_folder;
241 struct dirent *m_curs_id;
MatrixType & matrix()
Return the sparse matrix corresponding to the current file.
Definition: MatrixMarketIterator.h:74
const ConstDiagonalReturnType diagonal() const
Definition: SparseMatrix.h:646
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Index cols() const
Definition: SparseMatrix.h:134
VectorType & rhs()
Return the right hand side corresponding to the current matrix.
Definition: MatrixMarketIterator.h:113
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:273
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:145
Derived & setRandom(Index size)
Resizes to the given newSize, and sets all coefficients in this expression to random values...
Definition: Random.h:151