-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.h
More file actions
70 lines (37 loc) · 1.31 KB
/
Matrix.h
File metadata and controls
70 lines (37 loc) · 1.31 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
#pragma once
#include <cstdint>
#include <vector>
#include <ostream>
#include <functional>
#include <stdexcept>
#include <sstream>
class Matrix;
Matrix operator*(const Matrix &m, double scalar);
Matrix operator*(double scalar, const Matrix &m);
Matrix operator*(const Matrix &m1, const Matrix &m2);
Matrix operator+(const Matrix &m1, const Matrix &m2);
Matrix operator-(const Matrix &m1, const Matrix &m2);
class Matrix
{
public:
Matrix();
Matrix(uint32_t r, uint32_t c);
Matrix(const std::vector<std::vector<double>> &data);
Matrix(std::vector<std::vector<double>> &&data);
bool addRow(const std::vector<double> &row);
bool addRow(std::vector<double> &&row);
bool addCol(const std::vector<double> &col);
uint32_t getRowCount() const;
uint32_t getColCount() const;
double operator()(uint32_t r, uint32_t c) const;
double &operator()(uint32_t r, uint32_t c);
Matrix &operator+=(const Matrix &other);
Matrix &operator-=(const Matrix &other);
Matrix &operator*=(double scalar);
friend std::ostream &operator<<(std::ostream &os, const Matrix &matrix);
void apply(std::function<double(double)> func);
private:
bool addRowImpl(std::vector<double> &&row);
bool isValid(uint32_t r, uint32_t c) const;
std::vector<std::vector<double>> matrix_;
};