1 #include "../../../include/common/monolish_dense.hpp"
2 #include "../../../include/common/monolish_logger.hpp"
3 #include "../../../include/common/monolish_matrix.hpp"
4 #include "../../internal/monolish_internal.hpp"
20 std::cout << std::scientific;
21 std::cout << std::setprecision(std::numeric_limits<T>::max_digits10);
23 for (
size_t i = 0; i < nnz; i++) {
24 std::cout << row_index[i] + 1 <<
" " << col_index[i] + 1 <<
" " << val[i]
35 std::ofstream out(filename);
36 out << std::scientific;
37 out << std::setprecision(std::numeric_limits<T>::max_digits10);
39 for (
size_t i = 0; i < nnz; i++) {
40 out << row_index[i] + 1 <<
" " << col_index[i] + 1 <<
" " << val[i]
51 std::ofstream out(filename);
52 out << std::scientific;
53 out << std::setprecision(std::numeric_limits<T>::max_digits10);
57 out << rowN <<
" " << colN <<
" " << nnz << std::endl;
59 for (
size_t i = 0; i < nnz; i++) {
60 out << row_index[i] + 1 <<
" " << col_index[i] + 1 <<
" " << val[i]
72 std::string banner, buf;
73 std::string mm, mat, fmt, dtype, dstruct;
76 std::ifstream ifs(filename);
78 std::cerr <<
"Matrix.input: cannot open file " << filename << std::endl;
84 std::istringstream bn(banner);
85 bn >> mm >> mat >> fmt >> dtype >> dstruct;
88 std::cerr <<
"Matrix.input: This matrix is not MM format:" << mm
92 if (mat != std::string(
MM_MAT)) {
93 std::cerr <<
"Matrix.input: This matrix is not matrix type:" << mat
97 if (fmt != std::string(
MM_FMT)) {
98 std::cerr <<
"Matrix.input: This matrix is not coodinate format:" << fmt
103 std::cerr <<
"Matrix.input: This matrix is not real:" << dtype << std::endl;
107 std::cerr <<
"Matrix.input: This matrix is not general:" << dstruct
115 }
while (buf[0] ==
'%');
118 size_t rowNN, colNN, NNZ;
120 std::istringstream data(buf);
121 data >> rowNN >> colNN >> NNZ;
123 if (colNN <= 0 || NNZ < 0) {
124 std::cerr <<
"Matrix.input: Matrix size should be positive" << std::endl;
133 row_index.resize(nnz, 0.0);
134 col_index.resize(nnz, 0.0);
135 val.resize(nnz, 0.0);
138 for (
size_t i = 0; i < nnz; i++) {
143 std::istringstream data(buf);
144 data >> ix >> jx >> value;
146 row_index[i] = ix - 1;
147 col_index[i] = jx - 1;