47 #ifndef MUI_MATRIX_IO_INFO_H_
48 #define MUI_MATRIX_IO_INFO_H_
65 template<
typename ITYPE,
typename VTYPE>
67 for (ITYPE i = 0; i < rows_; ++i) {
69 for (ITYPE j = 0; j < cols_; ++j){
70 std::cout << this->get_value(i,j) <<
" ";
72 std::cout << std::endl;
77 template<
typename ITYPE,
typename VTYPE>
79 if (matrix_format_ == format::COO) {
80 std::cout <<
"The Value vector of matrix in COO format: " << std::endl;
82 for (
const auto& element : matrix_coo.values_) {
83 std::cout << element <<
" ";
85 std::cout << std::endl;
87 std::cout <<
"The Row Index vector of matrix in COO format: " << std::endl;
89 for (
const auto& element : matrix_coo.row_indices_) {
90 std::cout << element <<
" ";
92 std::cout << std::endl;
94 std::cout <<
"The Column Index vector of matrix in COO format: " << std::endl;
96 for (
const auto& element : matrix_coo.col_indices_) {
97 std::cout << element <<
" ";
99 std::cout << std::endl;
100 }
else if (matrix_format_ == format::CSR) {
101 std::cout <<
"The Value vector of matrix in CSR format: " << std::endl;
103 for (
const auto& element : matrix_csr.values_) {
104 std::cout << element <<
" ";
106 std::cout << std::endl;
108 std::cout <<
"The Row Pointers vector of matrix in CSR format: " << std::endl;
110 for (
const auto& element : matrix_csr.row_ptrs_) {
111 std::cout << element <<
" ";
113 std::cout << std::endl;
115 std::cout <<
"The Column Index vector of matrix in CSR format: " << std::endl;
117 for (
const auto& element : matrix_csr.col_indices_) {
118 std::cout << element <<
" ";
120 std::cout << std::endl;
121 }
else if (matrix_format_ == format::CSC) {
122 std::cout <<
"The Value vector of matrix in CSC format: " << std::endl;
124 for (
const auto& element : matrix_csc.values_) {
125 std::cout << element <<
" ";
127 std::cout << std::endl;
129 std::cout <<
"The Row Index vector of matrix in CSC format: " << std::endl;
131 for (
const auto& element : matrix_csc.row_indices_) {
132 std::cout << element <<
" ";
134 std::cout << std::endl;
136 std::cout <<
"The Column Pointers vector of matrix in CSC format: " << std::endl;
138 for (
const auto& element : matrix_csc.col_ptrs_) {
139 std::cout << element <<
" ";
141 std::cout << std::endl;
143 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix print_vectors >>" << std::endl;
144 std::cerr <<
" Please set the matrix_format_ as:" << std::endl;
145 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
146 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
147 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
153 template<
typename ITYPE,
typename VTYPE>
162 if ((val_file_name.empty()) || (row_file_name.empty()) || (col_file_name.empty())) {
163 ffn = format_file_name +
"_format.dat";
164 vfn = format_file_name +
"_value.dat";
165 rfn = format_file_name +
"_row.dat";
166 cfn = format_file_name +
"_column.dat";
168 ffn = format_file_name;
174 std::ofstream formatFile(ffn);
175 std::ofstream valueFile(vfn);
176 std::ofstream rowFile(rfn);
177 std::ofstream columnFile(cfn);
181 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening format output files in write_vectors_to_file()." << std::endl;
185 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening value vector output files in write_vectors_to_file()." << std::endl;
189 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening row vector output files in write_vectors_to_file()." << std::endl;
193 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening column vector output files in write_vectors_to_file()." << std::endl;
199 if (matrix_format_ == format::COO) {
200 formatFile <<
"COO" <<
"\n";
201 formatFile << rows_ <<
"\n";
202 formatFile << cols_ <<
"\n";
204 for (ITYPE i = 0; i < matrix_coo.values_.size(); ++i) {
205 valueFile << matrix_coo.values_[i] <<
"\n";
206 rowFile << matrix_coo.row_indices_[i] <<
"\n";
207 columnFile << matrix_coo.col_indices_[i] <<
"\n";
209 }
else if (matrix_format_ == format::CSR) {
210 formatFile <<
"CSR" <<
"\n";
211 formatFile << rows_ <<
"\n";
212 formatFile << cols_ <<
"\n";
214 for (ITYPE i = 0; i < matrix_csr.values_.size(); ++i) {
215 valueFile << matrix_csr.values_[i] <<
"\n";
216 columnFile << matrix_csr.col_indices_[i] <<
"\n";
218 for (ITYPE i = 0; i < (rows_+1); ++i) {
219 rowFile << matrix_csr.row_ptrs_[i] <<
"\n";
221 }
else if (matrix_format_ == format::CSC) {
222 formatFile <<
"CSC" <<
"\n";
223 formatFile << rows_ <<
"\n";
224 formatFile << cols_ <<
"\n";
226 for (ITYPE i = 0; i < matrix_csc.values_.size(); ++i) {
227 valueFile << matrix_csc.values_[i] <<
"\n";
228 rowFile << matrix_csc.row_indices_[i] <<
"\n";
230 for (ITYPE i = 0; i < (cols_+1); ++i) {
231 columnFile << matrix_csc.col_ptrs_[i] <<
"\n";
234 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix write_vectors_to_file() >>" << std::endl;
235 std::cerr <<
" Please set the matrix_format_ as:" << std::endl;
236 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
237 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
238 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
251 template<
typename ITYPE,
typename VTYPE>
260 if ((val_file_name.empty()) || (row_file_name.empty()) || (col_file_name.empty())) {
261 ffn = format_file_name +
"_format.dat";
262 vfn = format_file_name +
"_value.dat";
263 rfn = format_file_name +
"_row.dat";
264 cfn = format_file_name +
"_column.dat";
266 ffn = format_file_name;
272 std::ifstream formatFile(ffn);
273 std::ifstream valueFile(vfn);
274 std::ifstream rowFile(rfn);
275 std::ifstream columnFile(cfn);
279 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening format input files in read_vectors_from_file()." << std::endl;
283 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening value vector input files in read_vectors_from_file()." << std::endl;
287 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening row vector input files in read_vectors_from_file()." << std::endl;
291 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening column vector input files in read_vectors_from_file()." << std::endl;
295 assert((this->empty()) &&
296 "MUI Error [matrix_io_info.h]: read_vectors_from_file() can only takes in null matrix or empty (all-zero) matrix");
298 format format_store = this->matrix_format_;
300 std::string file_matrix_format;
302 formatFile >> file_matrix_format;
309 if (file_matrix_format_trim ==
"COO") {
310 this->clear_vectors();
313 while (valueFile >> val) {
314 matrix_coo.values_.reserve(matrix_coo.values_.size()+1);
315 matrix_coo.values_.emplace_back(val);
318 while (rowFile >> row_idx) {
319 matrix_coo.row_indices_.reserve(matrix_coo.row_indices_.size()+1);
320 matrix_coo.row_indices_.emplace_back(row_idx);
323 while (columnFile >> col_idx) {
324 matrix_coo.col_indices_.reserve(matrix_coo.col_indices_.size()+1);
325 matrix_coo.col_indices_.emplace_back(col_idx);
327 matrix_format_ = format::COO;
328 nnz_ = matrix_coo.values_.size();
329 }
else if (file_matrix_format_trim ==
"CSR") {
330 this->clear_vectors();
333 while (valueFile >> val) {
334 matrix_csr.values_.reserve(matrix_csr.values_.size()+1);
335 matrix_csr.values_.emplace_back(val);
339 while (rowFile >> row_ptr) {
340 matrix_csr.row_ptrs_.reserve(matrix_csr.row_ptrs_.size()+1);
341 matrix_csr.row_ptrs_.emplace_back(row_ptr);
345 while (columnFile >> col_idx) {
346 matrix_csr.col_indices_.reserve(matrix_csr.col_indices_.size()+1);
347 matrix_csr.col_indices_.emplace_back(col_idx);
350 matrix_format_ = format::CSR;
351 nnz_ = matrix_csr.values_.size();
353 }
else if (file_matrix_format_trim ==
"CSC") {
354 this->clear_vectors();
357 while (valueFile >> val) {
358 matrix_csc.values_.reserve(matrix_csc.values_.size()+1);
359 matrix_csc.values_.emplace_back(val);
362 while (rowFile >> row_idx) {
363 matrix_csc.row_indices_.reserve(matrix_csc.row_indices_.size()+1);
364 matrix_csc.row_indices_.emplace_back(row_idx);
367 while (columnFile >> col_ptr) {
368 matrix_csc.col_ptrs_.reserve(matrix_csc.col_ptrs_.size()+1);
369 matrix_csc.col_ptrs_.emplace_back(col_ptr);
371 matrix_format_ = format::CSC;
372 nnz_ = matrix_csc.values_.size();
374 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format: " << file_matrix_format_trim <<
" for matrix read_vectors_from_file() >>" << std::endl;
375 std::cerr <<
" Please set the matrix format as:" << std::endl;
376 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
377 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
378 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
388 this->assert_valid_vector_size(
"matrix_io_info.h",
"read_vectors_from_file()");
390 if (format_store != matrix_format_) {
391 if (format_store == format::COO) {
392 this->format_conversion(
"COO",
true,
true,
"overwrite");
393 }
else if (format_store == format::CSR) {
394 this->format_conversion(
"CSR",
true,
true,
"overwrite");
395 }
else if (format_store == format::CSC) {
396 this->format_conversion(
"CSC",
true,
true,
"overwrite");
398 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix write_vectors_to_file()" << std::endl;
399 std::cerr <<
" Please set the format_store as:" << std::endl;
400 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
401 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
402 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
409 template<
typename ITYPE,
typename VTYPE>
414 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening output files in overloaded << operator." << std::endl;
418 for (ITYPE i = 0; i < exist_mat.
get_rows(); ++i) {
419 for (ITYPE j = 0; j < exist_mat.
get_cols(); ++j) {
420 if (j == (exist_mat.
get_cols() - 1)) {
423 ofile << exist_mat.
get_value(i,j) <<
",";
426 if (i != (exist_mat.
get_rows() - 1)) {
434 template<
typename ITYPE,
typename VTYPE>
439 std::cerr <<
"MUI Error [matrix_io_info.h]: Error opening output files in overloaded >> operator." << std::endl;
443 assert((exist_mat.
empty()) &&
444 "MUI Error [matrix_io_info.h]: Overloading >> operator can only takes in null matrix or empty (all-zero) matrix");
446 std::string format_store = exist_mat.
get_format();
450 std::vector<ITYPE> tempRowIndex;
451 std::vector<ITYPE> tempColIndex;
452 std::vector<VTYPE> tempValue;
456 while (std::getline(ifile, rawLine)) {
457 std::string line =
trim(rawLine);
459 if (( line[0] ==
'/' && line[1] ==
'/' ) || (line.empty()))
continue;
460 std::stringstream ss(line);
463 while (std::getline(ss, value,
',')) {
464 VTYPE val =
static_cast<VTYPE
>(std::stod(value));
466 tempRowIndex.reserve(tempRowIndex.size()+1);
467 tempColIndex.reserve(tempColIndex.size()+1);
468 tempValue.reserve(tempValue.size()+1);
469 tempRowIndex.emplace_back(row);
470 tempColIndex.emplace_back(colCount);
471 tempValue.emplace_back(val);
478 if (col != colCount) {
479 std::cout <<
"MUI Warning [matrix_io_info.h]: The number of columns of the matrix read in at row " <<
480 row <<
" is " << colCount <<
", which is different from previous row (i.e. " <<
481 col <<
" columns!" << std::endl;
489 exist_mat.
resize(row, col);
491 exist_mat.
copy(temp_matrix);
495 "MUI Error [matrix_io_info.h]: Matrix size mismatching between existing matrix and read in matrix in overloading >> operator ");
498 exist_mat.
copy(temp_matrix);
503 if (format_store ==
"COO") {
505 }
else if (format_store ==
"CSR") {
507 }
else if (format_store ==
"CSC") {
510 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format: " << format_store <<
" for matrix operator >>" << std::endl;
511 std::cerr <<
" Please set the format_store as:" << std::endl;
512 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
513 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
514 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
522 template<
typename ITYPE,
typename VTYPE>
524 assert(((r < rows_) && (r >= 0) && (c < cols_) && (c >= 0)) &&
525 "MUI Error [matrix_io_info.h]: Matrix index out of range in get_value function");
527 if (matrix_format_ == format::COO) {
528 for (ITYPE i = 0; i < static_cast<ITYPE>(matrix_coo.row_indices_.size()); ++i) {
529 if (matrix_coo.row_indices_[i] == r && matrix_coo.col_indices_[i] == c) {
530 return matrix_coo.values_[i];
534 return static_cast<VTYPE
>(0);
535 }
else if (matrix_format_ == format::CSR) {
537 ITYPE row_start = matrix_csr.row_ptrs_[r];
538 ITYPE row_end = matrix_csr.row_ptrs_[r + 1];
541 auto it = std::lower_bound(matrix_csr.col_indices_.begin()+row_start, matrix_csr.col_indices_.begin()+row_end, c);
544 if (it != matrix_csr.col_indices_.begin()+row_end && *it == c) {
545 ITYPE index = std::distance(matrix_csr.col_indices_.begin(), it);
546 return matrix_csr.values_[index];
549 return static_cast<VTYPE
>(0);
550 }
else if (matrix_format_ == format::CSC) {
552 ITYPE col_start = matrix_csc.col_ptrs_[c];
553 ITYPE col_end = matrix_csc.col_ptrs_[c + 1];
556 auto it = std::lower_bound(matrix_csc.row_indices_.begin()+col_start, matrix_csc.row_indices_.begin()+col_end, r);
559 if (it != matrix_csc.row_indices_.begin()+col_end && *it == r) {
560 ITYPE index = std::distance(matrix_csc.row_indices_.begin(), it);
561 return matrix_csc.values_[index];
564 return static_cast<VTYPE
>(0);
567 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix get_value" << std::endl;
568 std::cerr <<
" Please set the matrix_format_ as:" << std::endl;
569 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
570 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
571 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
578 template<
typename ITYPE,
typename VTYPE>
584 template<
typename ITYPE,
typename VTYPE>
590 template<
typename ITYPE,
typename VTYPE>
592 std::vector<std::pair<ITYPE, ITYPE>> vec_temp;
593 if (matrix_format_ == format::COO) {
594 vec_temp.reserve(matrix_coo.values_.size());
595 for (ITYPE i = 0; i < matrix_coo.values_.size(); ++i) {
596 vec_temp.emplace_back(std::make_pair(matrix_coo.row_indices_[i], matrix_coo.col_indices_[i]));
598 }
else if (matrix_format_ == format::CSR) {
599 vec_temp.reserve(matrix_csr.values_.size());
600 for (ITYPE row = 0; row < matrix_csr.row_ptrs_.size()-1; ++row) {
601 ITYPE row_start = matrix_csr.row_ptrs_[row];
602 ITYPE row_end = matrix_csr.row_ptrs_[row + 1];
605 for (ITYPE i = row_start; i < row_end; ++i) {
606 ITYPE column = matrix_csr.col_indices_[i];
607 vec_temp.emplace_back(std::make_pair(row, column));
610 }
else if (matrix_format_ == format::CSC) {
611 vec_temp.reserve(matrix_csc.values_.size());
612 for (ITYPE column = 0; column < matrix_csc.col_ptrs_.size()-1; ++column) {
613 ITYPE col_start = matrix_csc.col_ptrs_[column];
614 ITYPE col_end = matrix_csc.col_ptrs_[column + 1];
617 for (ITYPE i = col_start; i < col_end; ++i) {
618 ITYPE row = matrix_csc.row_indices_[i];
619 vec_temp.emplace_back(std::make_pair(row, column));
623 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix operator >>" << std::endl;
624 std::cerr <<
" Please set the matrix_format_ as:" << std::endl;
625 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
626 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
627 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
634 template<
typename ITYPE,
typename VTYPE>
636 if (matrix_format_ == format::COO) {
637 if (nnz_ !=
static_cast<ITYPE
>(matrix_coo.values_.size())) {
638 std::cerr <<
"MUI Error [matrix_io_info.h]: Mismatch matrix_coo.values_ size (" << matrix_coo.values_.size() <<
") with number of non-zeros (" << nnz_ <<
") in non_zero_elements_count()" << std::endl;
641 }
else if (matrix_format_ == format::CSR) {
642 if (nnz_ !=
static_cast<ITYPE
>(matrix_csr.values_.size())) {
643 std::cerr <<
"MUI Error [matrix_io_info.h]: Mismatch matrix_csr.values_ size (" << matrix_csr.values_.size() <<
") with number of non-zeros (" << nnz_ <<
") in non_zero_elements_count()" << std::endl;
646 }
else if (matrix_format_ == format::CSC) {
647 if (nnz_ !=
static_cast<ITYPE
>(matrix_csc.values_.size())) {
648 std::cerr <<
"MUI Error [matrix_io_info.h]: Mismatch matrix_csc.values_ size (" << matrix_csc.values_.size() <<
") with number of non-zeros (" << nnz_ <<
") in non_zero_elements_count()" << std::endl;
652 std::cerr <<
"MUI Error [matrix_io_info.h]: Unrecognised matrix format for matrix non_zero_elements_count()" << std::endl;
653 std::cerr <<
" Please set the matrix_format_ as:" << std::endl;
654 std::cerr <<
" format::COO: COOrdinate format" << std::endl;
655 std::cerr <<
" format::CSR (default): Compressed Sparse Row format" << std::endl;
656 std::cerr <<
" format::CSC: Compressed Sparse Column format" << std::endl;
664 template<
typename ITYPE,
typename VTYPE>
666 if ((matrix_coo.values_.empty()) &&
667 (matrix_coo.row_indices_.empty()) &&
668 (matrix_coo.col_indices_.empty()) &&
669 (matrix_csr.values_.empty()) &&
670 (matrix_csr.col_indices_.empty()) &&
671 (matrix_csc.values_.empty()) &&
672 (matrix_csc.row_indices_.empty())) {
680 template<
typename ITYPE,
typename VTYPE>
683 std::string matrix_format;
685 if (matrix_format_ == format::COO) {
686 matrix_format =
"COO";
687 }
else if (matrix_format_ == format::CSR) {
688 matrix_format =
"CSR";
689 }
else if (matrix_format_ == format::CSC) {
690 matrix_format =
"CSC";
692 std::cerr <<
"MUI Error [matrix_io_info.h]: unknown matrix format" << std::endl;
696 return matrix_format;
700 template<
typename ITYPE,
typename VTYPE>
703 std::string file_name;
704 std::string function_name;
706 if (file_name_input.empty()) {
707 file_name =
"matrix_io_info.h";
709 file_name = file_name_input;
712 if (function_name_input.empty()) {
713 function_name =
"is_sorted_unique()";
715 function_name = function_name_input;
718 if (matrix_format_ == format::COO) {
719 return this->is_coo_sorted_unique(file_name, function_name);
720 }
else if (matrix_format_ == format::CSR) {
721 return this->is_csr_sorted_unique(file_name, function_name);
722 }
else if (matrix_format_ == format::CSC) {
723 return this->is_csc_sorted_unique(file_name, function_name);
725 std::cerr <<
"MUI Error [matrix_io_info.h]: unknown matrix format" << std::endl;
735 template<
typename ITYPE,
typename VTYPE>
738 std::string file_name;
739 std::string function_name;
741 if (file_name_input.empty()) {
742 file_name =
"matrix_io_info.h";
744 file_name = file_name_input;
747 if (function_name_input.empty()) {
748 function_name =
"is_coo_sorted_unique()";
750 function_name = function_name_input;
753 ITYPE numEntries = matrix_coo.values_.size();
755 if (numEntries > 1) {
756 for (ITYPE i = 1; i < numEntries; ++i) {
758 if (matrix_coo.row_indices_[i] < matrix_coo.row_indices_[i - 1]) {
761 std::cout <<
"MUI [" << file_name <<
"]: The COO type matrix is not sorted (sorted row index check failed) in " << function_name << std::endl;
764 }
else if (matrix_coo.row_indices_[i] == matrix_coo.row_indices_[i - 1]) {
766 if (matrix_coo.col_indices_[i] < matrix_coo.col_indices_[i - 1]) {
769 std::cout <<
"MUI [" << file_name <<
"]: The COO type matrix is not sorted (sorted column index check failed) in " << function_name << std::endl;
772 }
else if (matrix_coo.col_indices_[i] == matrix_coo.col_indices_[i - 1]) {
775 std::cout <<
"MUI [" << file_name <<
"]: The COO type matrix exists duplicated elements (unique column index check failed) in " << function_name << std::endl;
786 template<
typename ITYPE,
typename VTYPE>
789 std::string file_name;
790 std::string function_name;
792 if (file_name_input.empty()) {
793 file_name =
"matrix_io_info.h";
795 file_name = file_name_input;
798 if (function_name_input.empty()) {
799 function_name =
"is_csr_sorted_unique()";
801 function_name = function_name_input;
804 ITYPE numEntries = matrix_csr.values_.size();
806 if (numEntries > 1) {
807 for(ITYPE i = 0; i < rows_; ++i){
808 if (matrix_csr.row_ptrs_[i] > matrix_csr.row_ptrs_[i+1]) {
811 std::cout <<
"MUI [" << file_name <<
"]: The CSR type matrix is not sorted (sorted row pointers check failed) in " << function_name << std::endl;
815 for(ITYPE j = matrix_csr.row_ptrs_[i] + 1; j < matrix_csr.row_ptrs_[i+1]; ++j){
816 if(matrix_csr.col_indices_[j-1] > matrix_csr.col_indices_[j]){
819 std::cout <<
"MUI [" << file_name <<
"]: The CSR type matrix is not sorted (sorted column index check failed) in " << function_name << std::endl;
822 }
else if (matrix_csr.col_indices_[j-1] == matrix_csr.col_indices_[j]) {
825 std::cout <<
"MUI [" << file_name <<
"]: The CSR type matrix is not unique (deduplicated column index check failed) in " << function_name << std::endl;
836 template<
typename ITYPE,
typename VTYPE>
839 std::string file_name;
840 std::string function_name;
842 if (file_name_input.empty()) {
843 file_name =
"matrix_io_info.h";
845 file_name = file_name_input;
848 if (function_name_input.empty()) {
849 function_name =
"is_csc_sorted_unique()";
851 function_name = function_name_input;
854 ITYPE numEntries = matrix_csc.values_.size();
856 if (numEntries > 1) {
857 for(ITYPE i = 0; i < cols_; ++i){
858 if (matrix_csc.col_ptrs_[i] > matrix_csc.col_ptrs_[i+1]) {
861 std::cout <<
"MUI [" << file_name <<
"]: The CSC type matrix is not sorted (sorted column pointers check failed) in " << function_name << std::endl;
865 for(ITYPE j = matrix_csc.col_ptrs_[i] + 1; j < matrix_csc.col_ptrs_[i+1]; ++j){
866 if(matrix_csc.row_indices_[j-1] > matrix_csc.row_indices_[j]){
869 std::cout <<
"MUI [" << file_name <<
"]: The CSC type matrix is not sorted (sorted row index check failed) in " << function_name << std::endl;
872 }
else if (matrix_csc.row_indices_[j-1] == matrix_csc.row_indices_[j]) {
875 std::cout <<
"MUI [" << file_name <<
"]: The CSC type matrix is not unique (deduplicated row index check failed) in " << function_name << std::endl;
ITYPE get_rows() const
Definition: matrix_io_info.h:579
bool is_sorted_unique(const std::string &={}, const std::string &={}) const
Definition: matrix_io_info.h:701
void print() const
Definition: matrix_io_info.h:66
bool is_csc_sorted_unique(const std::string &={}, const std::string &={}) const
Definition: matrix_io_info.h:837
void set_zero()
Definition: matrix_manipulation.h:418
ITYPE non_zero_elements_count() const
Definition: matrix_io_info.h:635
void print_vectors() const
Definition: matrix_io_info.h:78
bool is_csr_sorted_unique(const std::string &={}, const std::string &={}) const
Definition: matrix_io_info.h:787
bool is_coo_sorted_unique(const std::string &={}, const std::string &={}) const
Definition: matrix_io_info.h:736
VTYPE get_value(ITYPE, ITYPE) const
Definition: matrix_io_info.h:523
void write_vectors_to_file(const std::string &, const std::string &={}, const std::string &={}, const std::string &={}) const
Definition: matrix_io_info.h:154
std::string get_format() const
Definition: matrix_io_info.h:681
void read_vectors_from_file(const std::string &, const std::string &={}, const std::string &={}, const std::string &={})
Definition: matrix_io_info.h:252
void resize(ITYPE, ITYPE)
Definition: matrix_manipulation.h:62
ITYPE get_cols() const
Definition: matrix_io_info.h:585
void copy(const sparse_matrix< ITYPE, VTYPE > &)
Definition: matrix_manipulation.h:79
void format_conversion(const std::string &="COO", bool=true, bool=false, const std::string &="overwrite")
Definition: matrix_manipulation.h:639
bool empty() const
Definition: matrix_io_info.h:665
std::vector< std::pair< ITYPE, ITYPE > > get_non_zero_elements() const
Definition: matrix_io_info.h:591
u u u u u u min
Definition: dim.h:289
std::istream & operator>>(std::istream &ifile, sparse_matrix< ITYPE, VTYPE > &exist_mat)
Definition: matrix_io_info.h:435
std::ostream & operator<<(std::ostream &ofile, const sparse_matrix< ITYPE, VTYPE > &exist_mat)
Definition: matrix_io_info.h:410
std::string trim(const std::string &s)
Definition: linalg_util.h:73
std::string string_to_upper(const std::string &s)
Definition: linalg_util.h:85