-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathla.hpp
More file actions
54 lines (35 loc) · 1.05 KB
/
la.hpp
File metadata and controls
54 lines (35 loc) · 1.05 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
#pragma once
#include <vector>
struct Vec
{
std::vector<double> buf;
explicit Vec(int len);
void Debug(const char* name);
double At(int i) const;
double& At(int i);
Vec& operator+=(const Vec& rhs);
friend Vec operator+(Vec lhs, const Vec& rhs);
Vec& operator*=(const double c);
friend Vec operator*(Vec lhs, const double c);
friend Vec operator*(const double c, Vec rhs);
Vec& operator*=(const Vec& rhs);
friend Vec operator*(Vec lhs, const Vec& rhs);
void Zero();
inline std::size_t Size() const { return buf.size(); }
};
struct Mat
{
int r, c;
std::vector<double> buf;
explicit Mat(int r_, int c_);
void Debug(const char* name);
double At(int row, int col) const;
double& At(int row, int col);
friend Vec operator*(Mat mat, const Vec& vec);
friend Mat operator*(const Mat& lhs, Mat rhs);
void Transpose();
void Zero();
inline std::size_t Rows() const { return r; }
inline std::size_t Cols() const { return c; }
static Vec Solve(Mat mat, Vec bvec);
};