6#include <initializer_list>
36 std::vector<T> flatMatrix;
37 void validation(std::vector<std::vector<T>>
v) {
38 for (
const auto&
row :
v)
39 if (
static_cast<int>(
row.size()) != cols)
40 throw std::invalid_argument(
"All rows must have the same size");
44 if (
v.empty() ||
v[0].empty()) {
45 throw std::invalid_argument(
"Matrix is empty");
52 flatMatrix.reserve(rows * cols);
53 for (
const auto&
row :
v) {
54 flatMatrix.insert(flatMatrix.end(),
63 if(
r == 0 ||
c == 0) {
64 throw std::invalid_argument(
"rows or cols params is 0");
69 throw std::invalid_argument(
"wrong size");
72 flatMatrix = std::move(
m);
75 FlatMatrix(std::initializer_list<std::initializer_list<T>>
v){
77 cols =
v.begin()->size();
80 flatMatrix.reserve(rows * cols);
82 for (
const auto&
row :
v) {
83 if(
row.size()!=cols) {
84 throw std::invalid_argument(
"All rows must have the same size");
86 flatMatrix.insert(flatMatrix.end(),
row.begin(),
row.end());
104 return flatMatrix[
i * cols +
j];
109 return flatMatrix[
i * cols +
j];
127 for(
int i = 0;
i < cols;
i++) {
128 for (
int j = 0;
j < rows;
j++) {
129 result.flatMatrix[
j*cols +
i] = flatMatrix[
i*cols +
j];
139 const int size = rows * cols;
140 for (
int i = 0;
i <
size;
i++) {
148 if(cols !=
B.getCols()) {
149 throw std::invalid_argument(
"num columns A not equal num rows B");
156 for (
int i = 0;
i < rows;
i +=
bs) {
157 for (
int k = 0;
k < cols;
k +=
bs) {
168 flatMatrix[
ii*cols+
kk] *
B.flatMatrix[
kk*cols+
jj];
182 for(
int i =0;
i < rows; ++
i) {
183 for(
int j = 0;
j < rows; ++
j) {
Examples:
Definition FlatMatrix.hpp:33
int getCols() const
Definition FlatMatrix.hpp:98
int getRows() const
Definition FlatMatrix.hpp:94
FlatMatrix(int r, int c, std::vector< T > &m)
Definition FlatMatrix.hpp:62
FlatMatrix(int r, int c)
Definition FlatMatrix.hpp:91
FlatMatrix< T > operator+(const FlatMatrix< T > &B) const
FlatMatrix(std::initializer_list< std::initializer_list< T > > v)
Definition FlatMatrix.hpp:75
FlatMatrix< T > operator*(const FlatMatrix< T > &B) const
Definition FlatMatrix.hpp:147
FlatMatrix(const std::vector< std::vector< T > > &v)
Definition FlatMatrix.hpp:43
T & operator()(int i, int j)
Definition FlatMatrix.hpp:102
const T & operator()(int i, int j) const
Definition FlatMatrix.hpp:107
friend std::ostream & operator<<(std::ostream &os, FlatMatrix< U > &m)
Definition FlatMatrix.hpp:179
FlatMatrix< T > operator~() const
Definition FlatMatrix.hpp:124
Examples:
Definition VectorMatrix.hpp:32
VectorMatrix()
Definition VectorMatrix.hpp:61
Definition DecomposeLU.hpp:9
std::ostream & operator<<(std::ostream &os, FlatMatrix< U > &m)
Definition FlatMatrix.hpp:179