-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.h
58 lines (49 loc) · 1.58 KB
/
Matrix.h
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
// Matrix.h
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <cmath>
#include <cstring>
#define PPRINT_VALUE 0.1
#define DIM_ERROR "Invalid matrix dimension."
#define INDEX_ERROR "Index out of bounds."
// You don't have to use the struct. Can help you with MlpNetwork.h
struct matrix_dims {
int rows;
int cols;
};
// Insert Matrix class here...
class Matrix {
public:
Matrix(int rows, int cols);
Matrix();
Matrix(const Matrix& m);
~Matrix();
int get_rows() const;
int get_cols() const;
Matrix& transpose();
Matrix& vectorize();
void plain_print() const;
Matrix dot(const Matrix& rhs) const;
float norm() const;
Matrix rref() const;
int argmax() const;
float sum() const;
Matrix& operator+= (const Matrix& rhs);
Matrix operator+ (const Matrix& rhs);
Matrix& operator= (const Matrix& rhs);
Matrix operator* (const Matrix& rhs) const;
Matrix operator* (float scalar) const;
float operator() (int row, int col) const;
float& operator()(int row, int col);
float operator[] (int index) const;
float& operator[] (int index);
friend std::istream& operator>> (std::istream& is, Matrix& m);
friend std::ostream& operator<< (std::ostream& os, const Matrix& m);
private:
matrix_dims _dims{};
float *_data;
void swap(Matrix& other) noexcept;
};
Matrix operator*(float scalar, const Matrix& rhs);
#endif //MATRIX_H