28namespace EigenIO_MatrixMarket {
32 Eigen::VectorXd output;
34 bool success = Eigen::loadMarketVector(output, filename);
36 throw std::runtime_error(
"Loading Vector from " + filename +
" failed");
41void WriteVector(
const std::string& filename,
const Eigen::VectorXd& output) {
42 bool success = Eigen::saveMarketVector(output, filename);
44 throw std::runtime_error(
"Writing Vector to " + filename +
" failed");
48void WriteMatrix(
const std::string& filename,
const Eigen::MatrixXd& output) {
51 ofs.open(filename, std::ofstream::out);
53 throw std::runtime_error(
"Could not create " + filename);
56 ofs <<
"%%MatrixMarket matrix array real general\n";
57 ofs << output.rows() <<
" " << output.cols() <<
"\n";
58 const Eigen::Map<const Eigen::VectorXd> temp(output.data(), output.size());
65 bool iscomplex =
false;
67 bool isvector =
false;
68 bool success = Eigen::getMarketHeader(filename, sym, iscomplex, isvector);
70 throw std::runtime_error(
"Could not read " + filename);
73 throw std::runtime_error(
"Only supports reading in general matrices");
76 throw std::runtime_error(
77 "Only supports reading in matrices with real numbers");
81 throw std::runtime_error(
82 "Use the eigen method `loadMarket` for sparse data");
85 std::ifstream in(filename, std::ios::in);
87 throw std::runtime_error(
"Could not open " + filename);
94 std::getline(in, line);
96 }
while (line[0] ==
'%');
97 std::istringstream newline(line);
98 newline >> rows >> cols;
99 assert(rows > 0 && cols > 0);
102 Index n = rows * cols;
103 std::vector<double> entries;
106 while (std::getline(in, line) && (i < n)) {
107 std::istringstream newline2(line);
109 entries.push_back(value);
114 return Eigen::Map<Eigen::MatrixXd>(entries.data(), rows, cols);
base class for all analysis tools