-
Notifications
You must be signed in to change notification settings - Fork 3
/
matrix.h
132 lines (130 loc) · 7.77 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
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "utilities.h"
#include "Arduino.h"
#pragma once
class Matrix {
public:
const float jitter = 1.0e-10f;
float* int_to_float(int *m, int nx);
float** int_to_float(int **m, int nx, int ny);
float*** int_to_float(int ***m, int nx, int ny, int nz);
float* int_to_float(float *m_float, int16_t *m, int nx);
float** int_to_float(float **m_float, int16_t **m, int nx, int ny);
float*** int_to_float(float ***m_float, int16_t ***m, int nx, int ny, int nz);
float* copy(float *m, int nx);
float** copy(float **m, int nx, int ny);
float*** copy(float ***m, int nx, int ny, int nz);
int* copy_to_existing(int *m1, int *m2, int nx);
int** copy_to_existing(int **m1, int **m2, int nx, int ny);
int*** copy_to_existing(int ***m1, int ***m2, int nx, int ny, int nz);
int16_t* copy_to_existing(int16_t *m1, int16_t *m2, int nx);
int16_t** copy_to_existing(int16_t **m1, int16_t **m2, int nx, int ny);
int16_t*** copy_to_existing(int16_t ***m1, int16_t ***m2, int nx, int ny, int nz);
float* copy_to_existing(float *m1, float *m2, int nx);
float** copy_to_existing(float **m1, float **m2, int nx, int ny);
float*** copy_to_existing(float ***m1, float ***m2, int nx, int ny, int nz);
bool compare_mat(int *m1, int *m2, int nx);
bool compare_mat(int **m1, int **m2, int nx, int ny);
bool compare_mat(int ***m1, int ***m2, int nx, int ny, int nz);
bool compare_mat(int16_t *m1, int16_t *m2, int nx);
bool compare_mat(int16_t **m1, int16_t **m2, int nx, int ny);
bool compare_mat(int16_t ***m1, int16_t ***m2, int nx, int ny, int nz);
float* sub_mat(float *m, int nx1, int nx2);
float** sub_mat(float **m, int nx1, int nx2, int ny1, int ny2);
float*** sub_mat(float ***m, int nx1, int nx2, int ny1, int ny2, int nz1, int nz2);
float* transpose(float *m_T, float *m, int nx);
float** transpose(float **m_T, float **m, int nx, int ny);
float* add_scalar(float *m, float val, int nx);
float** add_scalar(float **m, float val, int nx, int ny);
float*** add_scalar(float ***m, float val, int nx, int ny, int nz);
float* add_mat(float *sum, float *m1, float *m2, int nx);
float** add_mat(float **sum, float **m1, float **m2, int nx, int ny);
float*** add_mat(float ***sum, float ***m1, float ***m2, int nx, int ny, int nz);
int* subtract_mat(int *diff, int *m1, int *m2, int nx);
int** subtract_mat(int **diff, int **m1, int **m2, int nx, int ny);
int*** subtract_mat(int ***diff, int ***m1, int ***m2, int nx, int ny, int nz);
int16_t* subtract_mat(int16_t *diff, int16_t *m1, int16_t *m2, int nx);
int16_t** subtract_mat(int16_t **diff, int16_t **m1, int16_t **m2, int nx, int ny);
int16_t*** subtract_mat(int16_t ***diff, int16_t ***m1, int16_t ***m2, int nx, int ny, int nz);
float* subtract_mat(float *diff, float *m1, float *m2, int nx);
float** subtract_mat(float **diff, float **m1, float **m2, int nx, int ny);
float*** subtract_mat(float ***diff, float ***m1, float ***m2, int nx, int ny, int nz);
float* multiply_scalar(float *mul, float *m, float val, int nx);
float** multiply_scalar(float **mul, float **m, float val, int nx, int ny);
float*** multiply_scalar(float ***mul, float ***m, float val, int nx, int ny, int nz);
float* multiply_element_mat(float *mul, float *m1, float *m2, int nx);
float** multiply_element_mat(float **mul, float **m1, float **m2, int nx, int ny);
float*** multiply_element_mat(float ***mul, float ***m1, float ***m2, int nx, int ny, int nz);
float dot_mat(float *m1, float *m2, int nx);
float* dot_mat(float *dot, float **m1, float **m2, int nx, int ny);
float** dot_mat(float **dot, float ***m1, float ***m2, int nx, int ny, int nz);
float** multiply_mat(float **matmul, float **m1, int nx1, int ny1, float **m2, int nx2, int ny2);
float* divide_scalar(float *m, float val, int nx);
float** divide_scalar(float **m, float val, int nx, int ny);
float*** divide_scalar(float ***m, float val, int nx, int ny, int nz);
float* divide_element_mat(float *divs, float *m1, float *m2, int nx);
float** divide_element_mat(float **divs, float **m1, float **m2, int nx, int ny);
float*** divide_element_mat(float ***divs, float ***m1, float ***m2, int nx, int ny, int nz);
float* tanh_mat(float *tanhmat, float *m, int nx);
float** tanh_mat(float **tanhmat, float **m, int nx, int ny);
float*** tanh_mat(float ***tanhmat, float ***m, int nx, int ny, int nz);
float* grad_tanh_mat(float *gtanh, float *m, int nx);
float** grad_tanh_mat(float **gtanh, float **m, int nx, int ny);
float*** grad_tanh_mat(float ***gtanh, float ***m, int nx, int ny, int nz);
float* relu_mat(float *relumat, float *m, int nx);
float** relu_mat(float **relumat, float **m, int nx, int ny);
float*** relu_mat(float ***relumat, float ***m, int nx, int ny, int nz);
float* grad_relu_mat(float *grelu, float *m, int nx);
float** grad_relu_mat(float **grelu, float **m, int nx, int ny);
float*** grad_relu_mat(float ***grelu, float ***m, int nx, int ny, int nz);
float* sigmoid_mat(float *sigmoidmat, float *m, int nx);
float** sigmoid_mat(float **sigmoidmat, float **m, int nx, int ny);
float*** sigmoid_mat(float ***sigmoidmat, float ***m, int nx, int ny, int nz);
float* grad_sigmoid_mat(float *gsigmoid, float *m, int nx);
float** grad_sigmoid_mat(float **gsigmoid, float **m, int nx, int ny);
float*** grad_sigmoid_mat(float ***gsigmoid, float ***m, int nx, int ny, int nz);
float* softmax_mat(float *softmaxmat, float *m, int nx);
float** softmax_mat(float **softmaxmat, float **m, int nx, int ny);
float*** softmax_mat(float ***softmaxmat, float ***m, int nx, int ny, int nz);
float* grad_softmax_mat(float *gsoftmax, float *m, int nx);
float** grad_softmax_mat(float **gsoftmax, float **m, int nx, int ny);
float*** grad_softmax_mat(float ***gsoftmax, float ***m, int nx, int ny, int nz);
float l2norm_mat(float *m, int nx);
float l2norm_mat(float **m, int nx, int ny);
float l2norm_mat(float ***m, int nx, int ny, int nz);
float max_mat(float *m, int nx);
float max_mat(float **m, int nx, int ny);
float max_mat(float ***m, int nx, int ny, int nz);
int max_idx_mat(float *m, int nx);
int* max_idx_mat(int *idx, float **m, int nx, int ny);
int* max_idx_mat(int *idx, float ***m, int nx, int ny, int nz);
void print_mat(int16_t *m, int nx);
void print_mat(int16_t **m, int nx, int ny);
void print_mat(int16_t ***m, int nx, int ny, int nz);
void print_mat(int *m, int nx);
void print_mat(int **m, int nx, int ny);
void print_mat(int ***m, int nx, int ny, int nz);
void print_mat(float *m, int nx);
void print_mat(float **m, int nx, int ny);
void print_mat(float ***m, int nx, int ny, int nz);
float* ones_mat(float *ones, int nx);
float** ones_mat(float **ones, int nx, int ny);
float*** ones_mat(float ***ones, int nx, int ny, int nz);
float* zeros_mat(float *zeros, int nx);
float** zeros_mat(float **zeros, int nx, int ny);
float*** zeros_mat(float ***zeros, int nx, int ny, int nz);
float* log_mat(float *logmat, float *m, int nx);
float** log_mat(float **logmat, float **m, int nx, int ny);
float*** log_mat(float ***logmat, float ***m, int nx, int ny, int nz);
float mean_mat(float *m, int nx);
float** mean_mat(float **mean, float **m ,int nx, int ny);
float*** mean_mat(float ***mean, float ***m, int nx, int ny, int nz);
float std_mat(float *m, int nx);
float** std_mat(float **std, float **m, int nx, int ny);
float*** std_mat(float ***std, float ***m, int nx, int ny, int nz);
float* normalize_mat(float *m, int nx);
float** normalize_mat(float **m, int nx);
float*** normalize_mat(float ***m, int nx);
};