made template function for flattening matrix

This commit is contained in:
2020-03-29 20:15:49 -06:00
parent aee43fd658
commit 9aec6ce511
13 changed files with 59 additions and 9 deletions

33
HW10/ParseMatrixForMPI.h Normal file
View File

@@ -0,0 +1,33 @@
//
// Created by Brady Bodily on 3/29/20.
//
#include <vector>
#ifndef HW10_PARSEMATRIXFORMPI_H
#define HW10_PARSEMATRIXFORMPI_H
namespace matrixTools
{
template <typename T>
std::vector<std::vector<T>> UnflattenMatrix(std::vector<T> origianlVector, int rowSize, int columnSize)
{
std::vector<std::vector<T>> matrix(columnSize, std::vector<T>(rowSize, 0));
for (int i = 0; i < columnSize; i++) {
for (int j = 0; j < rowSize; j++) {
matrix[i][j] = origianlVector[i + j];
}
}
return matrix;
}
template <typename T>
std::vector<T> FlattenMatrix(std::vector<std::vector<T>> matrix)
{
std::vector<T> rVector(matrix.size() * matrix[0].size(), 0);
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[0].size(); j++) {
rVector[i + j] = matrix[i][j];
}
}
return rVector;
}
}
#endif //HW10_PARSEMATRIXFORMPI_H