1 #include<DD-AVX_internal.hpp>
8 #define MM_BANNER "%%MatrixMarket"
9 #define MM_MAT "matrix"
10 #define MM_VEC "vector"
11 #define MM_FMT "coordinate"
12 #define MM_TYPE_REAL "real"
13 #define MM_TYPE_GENERAL "general"
14 #define MM_TYPE_SYMM "symmetric"
18 std::string banner, buf;
19 std::string mm, mat, fmt, dtype, dstruct;
22 std::ifstream ifs(filename);
24 std::cerr <<
"Matrix.input: cannot open file " << filename << std::endl;
30 std::istringstream bn(banner);
31 bn >> mm >> mat >> fmt >> dtype >> dstruct;
34 std::cerr <<
"Matrix.input: This matrix is not MM format:" << mm << std::endl;
37 if (mat != std::string(
MM_MAT)) {
38 std::cerr <<
"Matrix.input: This matrix is not matrix type:" << mat << std::endl;
41 if (fmt != std::string(
MM_FMT)) {
42 std::cerr <<
"Matrix.input: This matrix is not coodinate format:" << fmt << std::endl;
46 std::cerr <<
"Matrix.input: This matrix is not real:" << dtype << std::endl;
50 std::cerr <<
"Matrix.input: This matrix is not general:" << dstruct << std::endl;
57 }
while (buf[0] ==
'%');
62 std::istringstream
data(buf);
63 data >> rowN >> colN >> NNZ;
67 std::cerr <<
"Matrix.input: Matrix is not square" << std::endl;
70 if (colN <= 0 || NNZ < 0) {
71 std::cerr <<
"Matrix.input: Matrix size should be positive" << std::endl;
84 for (
int i = 0; i < NNZ; i++) {
89 std::istringstream
data(buf);
90 data >> idx >> jdx >> value;
92 if (idx < 1 || idx > rowN || jdx < 1 || jdx > colN) {
93 std::cerr <<
"Matrix.input: Invalid index" << std::endl;
115 std::cerr <<
"This matrix is brank" << std::endl;
118 for(
int i = 0; i <
row; i++){
120 std::cout << i+1 <<
"\t" <<
col_ind[j]+1 <<
"\t" <<
val[j] << std::endl;
127 std::ofstream out(filename);
128 out << std::scientific;
129 out << std::setprecision(std::numeric_limits<double>::max_digits10);
132 out <<
row <<
" " <<
row <<
" " <<
nnz << std::endl;
134 for(
int i = 0; i <
row; i++){
136 out << i+1 <<
" " <<
col_ind[j]+1 <<
" " <<
val[j] << std::endl;
std::vector< double >::reference data()
get CRS value array
std::vector< int > col_ind
void input_mm(const char *filename)
input matrix from matrix market format
void output_mm(const char *filename)
output matrix to matrix market format
void output()
output matrix to standard I/O
std::vector< int > row_ptr
std::vector< double > val