-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.cpp
More file actions
32 lines (28 loc) · 758 Bytes
/
matrix.cpp
File metadata and controls
32 lines (28 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "matrix.hpp"
#include <cstdlib>
Matrix::Matrix(size_t size, bool invert) {
SIZE = size;
//Allocate size rows with size elements each
theMatrix.resize(SIZE*SIZE);
//Inversion for random initialization matters if we
// want consistent results for a given seed.
if (!invert) {
for (size_t i = 0; i < size; i++) {
for (size_t j = 0; j < size; j++) {
(*this)[i][j] = float(rand() % 100);
}
}
} else {
for (size_t i = 0; i < size; i++) {
for (size_t j = 0; j < size; j++) {
(*this)[j][i] = float(rand() % 100);
}
}
}
}
Matrix::Row Matrix::operator[](size_t i) {
return &theMatrix[i*SIZE];
}
Matrix::ConstRow Matrix::operator[](size_t i) const {
return &theMatrix[i*SIZE];
}