Repository navigation
Expand file tree
/
Copy pathMatrix.h
More file actions
83 lines (63 loc) · 2.25 KB
/
Copy pathMatrix.h
File metadata and controls
83 lines (63 loc) · 2.25 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
#include <cmath>
// SimiLinearAlgebraLibrary
namespace SimiLAL {
template<typename T>
class Matrix {
public:
Matrix() : Matrix(0)
{}
Matrix(size_t size) : Matrix(size, size)
{}
Matrix(size_t rowCount, size_t colCount) : rowCount(rowCount),
colCount(colCount),
data(rowCount, std::vector<T>(colCount))
{}
Matrix(const std::vector<std::vector<T>> &input) : data(input),
rowCount(input.size()),
colCount(input[0].size())
{}
// Linear Algebra
void add(const Matrix& other);
void sub(const Matrix& other);
void mult(const Matrix& other);
void add(T value);
void sub(T value);
void mult(T value);
void div(T value);
bool isSquare();
Matrix transpose();
Matrix submatrix(size_t iPos, size_t jPos);
double determinantLeibnitz();
double determinantLU();
// Iterators
using RowIterator = std::vector<T>::iterator;
using ColIterator = std::vector<std::reference_wrapper<T>>::iterator;
RowIterator rowBegin(size_t index);
RowIterator rowEnd(size_t index);
ColIterator colBegin(size_t index);
ColIterator colEnd(size_t index);
// Utility
std::vector<T>& operator[](size_t index);
void insert(T element);
void resize(size_t newRowCount, size_t newColCount);
// Debug
void print();
private:
size_t rowCount, colCount;
std::vector<std::vector<T>> data;
// Iterator
std::vector<std::reference_wrapper<T>> colVector;
// Insert element; does NOT change matrix dimensions
size_t currentInsertIPos = 0, currentInsertJPos = 0;
// Helper
void parseAllData(T value, T (*func)(const T&));
void parseAllData(const Matrix& other, T (*func)(const T&, const T&));
double determinantLeibnitzHelper(Matrix& self);
};
}