|
bool | Eigen::getMarketHeader (const std::string &filename, int &sym, bool &iscomplex, bool &isdense) |
| Reads the header of a matrixmarket file and determines the properties of a matrix. More...
|
|
template<typename SparseMatrixType > |
bool | Eigen::loadMarket (SparseMatrixType &mat, const std::string &filename) |
| Loads a sparse matrix from a matrixmarket format file. More...
|
|
template<typename DenseType > |
bool | Eigen::loadMarketDense (DenseType &mat, const std::string &filename) |
| Loads a dense Matrix or Vector from a matrixmarket file. If a statically sized matrix has to be parsed and the file contains the wrong dimensions it is undefined behaviour. More...
|
|
template<typename VectorType > |
bool | Eigen::loadMarketVector (VectorType &vec, const std::string &filename) |
| Same functionality as loadMarketDense, deprecated. More...
|
|
template<typename SparseMatrixType > |
bool | Eigen::saveMarket (const SparseMatrixType &mat, const std::string &filename, int sym=0) |
| writes a sparse Matrix to a marketmarket format file More...
|
|
template<typename DenseType > |
bool | Eigen::saveMarketDense (const DenseType &mat, const std::string &filename) |
| writes a dense Matrix or vector to a marketmarket format file More...
|
|
template<typename VectorType > |
bool | Eigen::saveMarketVector (const VectorType &vec, const std::string &filename) |
| Same functionality as saveMarketDense, deprecated. More...
|
|
This module contains some experimental features extending the sparse module:
- A RandomSetter which is a wrapper object allowing to set/update a sparse matrix with random access.
- A SparseInverse which calculates a sparse subset of the inverse of a sparse matrix corresponding to nonzeros of the input
- MatrixMarket format(https://math.nist.gov/MatrixMarket/formats.html) readers and writers for sparse and dense matrices.
◆ getMarketHeader()
bool Eigen::getMarketHeader |
( |
const std::string & |
filename, |
|
|
int & |
sym, |
|
|
bool & |
iscomplex, |
|
|
bool & |
isdense |
|
) |
| |
|
inline |
Reads the header of a matrixmarket file and determines the properties of a matrix.
- Parameters
-
filename | of the file |
sym | if the matrix is hermitian,symmetric or none of the latter (sym=0) |
iscomplex | if the matrix has complex or real coefficients |
isdense | if the matrix is dense or sparse |
- Returns
- true if the file was found
Definition at line 122 of file MarketIO.h.
127 std::ifstream in(filename.c_str(),std::ios::in);
135 std::stringstream fmtline(line);
136 std::string substr[5];
137 fmtline>> substr[0] >> substr[1] >> substr[2] >> substr[3] >> substr[4];
138 if(substr[2].compare(
"array") == 0) isdense =
true;
139 if(substr[3].compare(
"complex") == 0) iscomplex =
true;
140 if(substr[4].compare(
"symmetric") == 0) sym =
Symmetric;
141 else if (substr[4].compare(
"Hermitian") == 0) sym =
SelfAdjoint;
◆ loadMarket()
template<typename SparseMatrixType >
bool Eigen::loadMarket |
( |
SparseMatrixType & |
mat, |
|
|
const std::string & |
filename |
|
) |
| |
Loads a sparse matrix from a matrixmarket format file.
- Template Parameters
-
SparseMatrixType | to read into, symmetries are not supported |
- Parameters
-
mat | SparseMatrix to read into, current values are overwritten |
filename | to parse matrix from |
- Returns
- returns true if file exists. Returns false if the parsing did not succeed.
Definition at line 155 of file MarketIO.h.
157 typedef typename SparseMatrixType::Scalar Scalar;
158 typedef typename SparseMatrixType::StorageIndex StorageIndex;
159 std::ifstream input(filename.c_str(),std::ios::in);
164 input.rdbuf()->pubsetbuf(rdbuffer, 4096);
166 const int maxBuffersize = 2048;
167 char buffer[maxBuffersize];
169 bool readsizes =
false;
171 typedef Triplet<Scalar,StorageIndex>
T;
172 std::vector<T> elements;
174 Index M(-1), N(-1), NNZ(-1);
176 while(input.getline(buffer, maxBuffersize))
185 std::stringstream line(buffer);
186 line >>
M >> N >> NNZ;
192 elements.reserve(NNZ);
197 StorageIndex
i(-1),
j(-1);
203 if(i>=0 && j>=0 && i<M && j<N)
206 elements.push_back(
T(i,j,value));
210 std::cerr <<
"Invalid read: " <<
i <<
"," <<
j <<
"\n";
216 mat.setFromTriplets(elements.begin(), elements.end());
218 std::cerr << count <<
"!=" << NNZ <<
"\n";
void GetMarketLine(const char *line, StorageIndex &i, StorageIndex &j, std::complex< Scalar > &value)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
◆ loadMarketDense()
template<typename DenseType >
bool Eigen::loadMarketDense |
( |
DenseType & |
mat, |
|
|
const std::string & |
filename |
|
) |
| |
Loads a dense Matrix or Vector from a matrixmarket file. If a statically sized matrix has to be parsed and the file contains the wrong dimensions it is undefined behaviour.
- Template Parameters
-
DenseMatrixType | to read into |
- Parameters
-
mat | DenseMatrix to read into, current values are overwritten, symmetries are not supported |
filename | to parse matrix from |
- Returns
- true if parsing was successful. Returns false if the parsing did not succeed.
Definition at line 236 of file MarketIO.h.
238 typedef typename DenseType::Scalar Scalar;
239 std::ifstream in(filename.c_str(), std::ios::in);
248 }
while (line[0] ==
'%');
249 std::istringstream newline(line);
252 bool sizes_not_positive=(
rows<1 ||
cols<1);
253 bool wrong_input_rows = (DenseType::MaxRowsAtCompileTime !=
Dynamic &&
rows > DenseType::MaxRowsAtCompileTime) ||
254 (DenseType::RowsAtCompileTime!=Dynamic && rows!=DenseType::RowsAtCompileTime);
255 bool wrong_input_cols = (DenseType::MaxColsAtCompileTime !=
Dynamic &&
cols > DenseType::MaxColsAtCompileTime) ||
256 (DenseType::ColsAtCompileTime!=Dynamic && cols!=DenseType::ColsAtCompileTime);
258 if(sizes_not_positive || wrong_input_rows || wrong_input_cols){
259 if(sizes_not_positive){
260 std::cerr<<
"non-positive row or column size in file" << filename <<
"\n";
262 std::cerr<<
"Input matrix can not be resized to"<<
rows<<
" x "<<
cols<<
"as given in " << filename <<
"\n";
268 mat.resize(rows,cols);
273 while ( std::getline(in, line) && (
row <
rows) && (col < cols)){
276 mat(row,col) = value;
286 std::cerr<<
"Unable to read all elements from file " << filename <<
"\n";
RowXpr row(Index i) const
ColXpr col(Index i) const
void GetDenseElt(const std::string &line, std::complex< RealScalar > &val)
◆ loadMarketVector()
template<typename VectorType >
bool Eigen::loadMarketVector |
( |
VectorType & |
vec, |
|
|
const std::string & |
filename |
|
) |
| |
Same functionality as loadMarketDense, deprecated.
Definition at line 296 of file MarketIO.h.
◆ saveMarket()
template<typename SparseMatrixType >
bool Eigen::saveMarket |
( |
const SparseMatrixType & |
mat, |
|
|
const std::string & |
filename, |
|
|
int |
sym = 0 |
|
) |
| |
writes a sparse Matrix to a marketmarket format file
- Template Parameters
-
SparseMatrixType | to write to file |
- Parameters
-
mat | matrix to write to file |
filename | filename to write to |
sym | at the moment no symmetry operations are supported |
- Returns
- true if writing succeeded
Definition at line 312 of file MarketIO.h.
314 typedef typename SparseMatrixType::Scalar Scalar;
315 typedef typename SparseMatrixType::RealScalar RealScalar;
316 std::ofstream out(filename.c_str(),std::ios::out);
320 out.flags(std::ios_base::scientific);
321 out.precision(std::numeric_limits<RealScalar>::digits10 + 2);
323 internal::putMarketHeader<Scalar>(header, sym);
324 out << header << std::endl;
325 out <<
mat.rows() <<
" " <<
mat.cols() <<
" " <<
mat.nonZeros() <<
"\n";
327 for(
int j=0;
j<
mat.outerSize(); ++
j)
328 for(
typename SparseMatrixType::InnerIterator it(mat,j); it; ++it)
void PutMatrixElt(std::complex< Scalar > value, StorageIndex row, StorageIndex col, std::ofstream &out)
◆ saveMarketDense()
template<typename DenseType >
bool Eigen::saveMarketDense |
( |
const DenseType & |
mat, |
|
|
const std::string & |
filename |
|
) |
| |
writes a dense Matrix or vector to a marketmarket format file
- Template Parameters
-
DenseMatrixType | to write to file |
- Parameters
-
mat | matrix to write to file |
filename | filename to write to |
- Returns
- true if writing succeeded
Definition at line 349 of file MarketIO.h.
351 typedef typename DenseType::Scalar Scalar;
352 typedef typename DenseType::RealScalar RealScalar;
353 std::ofstream out(filename.c_str(),std::ios::out);
357 out.flags(std::ios_base::scientific);
358 out.precision(std::numeric_limits<RealScalar>::digits10 + 2);
359 if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value)
360 out <<
"%%MatrixMarket matrix array complex general\n";
362 out <<
"%%MatrixMarket matrix array real general\n";
363 out <<
mat.rows() <<
" "<<
mat.cols() <<
"\n";
void putDenseElt(std::complex< Scalar > value, std::ofstream &out)
◆ saveMarketVector()
template<typename VectorType >
bool Eigen::saveMarketVector |
( |
const VectorType & |
vec, |
|
|
const std::string & |
filename |
|
) |
| |
Same functionality as saveMarketDense, deprecated.
Definition at line 378 of file MarketIO.h.