-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmatrix.h
More file actions
133 lines (105 loc) · 4.16 KB
/
Copy pathdmatrix.h
File metadata and controls
133 lines (105 loc) · 4.16 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include "dvector.h"
enum class ORIENT { ROW = 0, COL };
enum SLICE { ROW = 0, COL };
// Matrix of doubles number
class DMatrix
{
private:
DVector *m_matrix = nullptr;
size_t m_nRows = 0;
size_t m_nCols = 0;
size_t m_capacity = 0;
void grow();
public:
DMatrix() = default;
DMatrix(DVector *matrix, size_t nRows);
// Создание матрицы как вектор-строку или вектор-столбец
DMatrix(DVector const &dvec, ORIENT orientation = ORIENT::ROW);
DMatrix(size_t rows, size_t cols, double fill_value = 0);
DMatrix(std::initializer_list<std::initializer_list<double>> const &matrix);
DMatrix(DMatrix const &other);
DMatrix(DMatrix &&other);
DMatrix &operator=(DMatrix other);
~DMatrix();
/* ****** Задание размера через шаблон *******/
template <size_t rows, size_t cols>
static DMatrix Create(double fill_value = 0);
public:
void Clear();
bool Empty();
void Swap(DMatrix &other);
void PushRowBack(DVector const &dvec);
void PushRowBack(std::initializer_list<double> const &init_list);
void PopRowBack();
void PushColBack(DVector const &dvec);
void PushColBack(std::initializer_list<double> const &init_list);
void PopColBack();
void EraseByIndex(size_t index, ORIENT orientation = ORIENT::ROW);
/* ****** ЗАДАНИЕ 1 ****** */
DVector GetDiag() const;
DVector GetRow(size_t index) const;
DVector GetCol(size_t index) const;
/* ****** ЗАДАНИЕ 4 ****** */
DMatrix Dot(DMatrix const &other) const;
DVector Dot(DVector const &dvec) const;
size_t nRows() const;
size_t nCols() const;
size_t Capacity() const;
/* ****** ЗАДАНИЕ 5 ****** */
// модифицирующие операции
void AddNum(double value);
void SubNum(double value);
void AddVec(DVector const &dvec, ORIENT orientation = ORIENT::ROW);
void SubVec(DVector const &dvec, ORIENT orientation = ORIENT::ROW);
/* ****** ЗАДАНИЯ 6 и 7 ****** */
DMatrix T() const;
double Det() const;
double Minor(size_t iIndex, size_t jIndex) const;
DMatrix Adj();
DMatrix Inv();
DVector const &operator[](size_t index) const;
DVector &operator[](size_t index);
/*
Пояснение:
enum SLICE {ROW = 0, COL}, чтобы
1. не писать класс, если в параметрах ROW / COL
2. кастилось к enum SLICE, если в параметрах 0 / 1
*/
/* ****** Slices ****** */
DMatrix operator()(size_t begin, size_t end, int step = 1, uint8_t sliceType = SLICE::ROW) const;
DMatrix SliceRow(size_t begin, size_t end, int step = 1) const;
DMatrix SliceCol(size_t begin, size_t end, int step = 1) const;
};
// matrix *= value
DMatrix &operator/=(DMatrix &matrix, double value);
DMatrix &operator*=(DMatrix &matrix, double value);
// matrix * value
DMatrix operator/(DMatrix matrix, double value);
DMatrix operator*(DMatrix matrix, double value);
// value *= matrix
DMatrix &operator/=(double value, DMatrix &matrix);
DMatrix &operator*=(double value, DMatrix &matrix);
// value * matrix
DMatrix operator/(double value, DMatrix matrix);
DMatrix operator*(double value, DMatrix matrix);
// matrix += matrix
DMatrix &operator+=(DMatrix &left, DMatrix const &right);
DMatrix &operator-=(DMatrix &left, DMatrix const &right);
DMatrix &operator/=(DMatrix &left, DMatrix const &right);
DMatrix &operator*=(DMatrix &left, DMatrix const &right);
// matrix + matrix
DMatrix operator+(DMatrix left, DMatrix const &right);
DMatrix operator-(DMatrix left, DMatrix const &right);
DMatrix operator/(DMatrix left, DMatrix const &right);
DMatrix operator*(DMatrix left, DMatrix const &right);
void Print(DMatrix const &matrix, std::string const &msg = std::string{});
template <size_t rows, size_t cols>
DMatrix DMatrix::Create(double fill_value)
{
if ((rows == 0) ^ (cols == 0))
{
throw std::runtime_error("Creation is impossible");
}
return DMatrix(rows, cols, fill_value);
}