Skip to content

Commit

Permalink
Insertion of code for reading and writing list of matrices.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Jan 6, 2024
1 parent 12a2833 commit 5aec696
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src_matrix/MAT_Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ template <typename T> MyMatrix<T> ReadMatrixFile(std::string const &file_name) {
return ReadMatrix<T>(is);
}

template<typename T>
std::vector<MyMatrix<T>> ReadListMatrix(std::istream & is) {
int n_mat;
is >> n_mat;
std::vector<MyMatrix<T>> ListMat;
for (int i_mat = 0; i_mat < n_mat; i_mat++) {
MyMatrix<T> eMat = ReadMatrix<T>(is);
ListMat.push_back(eMat);
}
return ListMat;
}



template <typename T>
std::vector<MyMatrix<T>> ReadListMatrixFile(std::string const &eFile) {
if (!IsExistingFile(eFile)) {
Expand All @@ -240,16 +254,23 @@ std::vector<MyMatrix<T>> ReadListMatrixFile(std::string const &eFile) {
throw TerminalException{1};
}
std::ifstream is(eFile);
int n_mat;
is >> n_mat;
std::vector<MyMatrix<T>> ListMat;
for (int i_mat = 0; i_mat < n_mat; i_mat++) {
MyMatrix<T> eMat = ReadMatrix<T>(is);
ListMat.push_back(eMat);
return ReadListMatrix<T>(is);
}

template<typename T>
void WriteListMatrix(std::ostream &os, std::vector<MyMatrix<T>> const &ListMat) {
size_t n_mat = ListMat.size();
os << n_mat << "\n";
for (size_t i_mat=0; i_mat<n_mat; i_mat++) {
WriteMatrix(os, ListMat[i_mat]);
}
return ListMat;
}

template<typename T>
void WriteListMatrixFile(std::string const &eFile, std::vector<MyMatrix<T>> const &ListMat) {
std::ofstream os(eFile);
WriteListMatrix(os, ListMat);
}

template <typename T> std::pair<bool, T> ReadMatrixInfo(std::istream &is) {
T eVal;
Expand Down

0 comments on commit 5aec696

Please sign in to comment.