-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
59 lines (52 loc) · 1.04 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
59
#ifndef MATRIX_H
#define MATRIX_H
#include <string>
#include <vector>
using namespace std;
typedef vector<float> vector1d;
typedef vector<vector1d> vector2d;
enum dev {cpu, cuda};
class Matrix {
private:
public:
// initialize
Matrix();
Matrix(vector2d& input);
Matrix(int x, int y);
~Matrix();
// attributes
vector2d data;
Matrix* grad;
float* array;
float* cuda_array;
bool requires_grad = false;
dev device = cpu;
// reshape
Matrix cols(int a, int b);
// initialize
void init_grad();
void ones();
void uniform(float a, float b);
// self operations
Matrix tanh();
Matrix square();
Matrix transpose();
// scalar operations
Matrix mul(float other);
// aggregate operations
float sum();
// matrix operations
void mulip(Matrix* other);
Matrix add(Matrix other);
Matrix matmul(Matrix& other);
// size and data
void to_arrays();
void from_cuda_array();
vector<int> size();
string size_str();
void print_size();
void print_data();
void print_array(int N);
void print_cuda(int N);
};
#endif