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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#pragma once
// -----------------------------------------------------------------------
// basic macros
#define math·abs(x) (((x) > 0) ? (x) : (-(x)))
#define math·sgn(x) (((x) > 0) ? (+1) : (((x) == 0) ? (0) : (-1) ))
// -----------------------------------------------------------------------
// elementary functions
double math·acos(double);
float math·acosf(float);
double math·acosh(double);
float math·acoshf(float);
double math·asin(double);
float math·asinf(float);
double math·asinh(double);
float math·asinhf(float);
double math·atan(double);
float math·atanf(float);
double math·atan2(double, double);
float math·atan2f(float, float);
double math·atanh(double);
float math·atanhf(float);
double math·cbrt(double);
float math·cbrtf(float);
double math·ceil(double);
float math·ceilf(float);
double math·cos(double);
float math·cosf(float);
double math·cosh(double);
float math·coshf(float);
double math·erf(double);
float math·erff(float);
double math·erfc(double);
float math·erfcf(float);
double math·exp(double);
float math·expf(float);
double math·exp2(double);
float math·exp2f(float);
double math·expm1(double);
float math·expm1f(float);
double math·floor(double);
float math·floorf(float);
int math·ilogb(double);
int math·ilogbf(float);
double math·lgamma(double);
float math·lgammaf(float);
long long math·llrint(double);
long long math·llrintf(float);
long long math·llround(double);
long long math·llroundf(float);
double math·log(double);
float math·logf(float);
double math·log10(double);
float math·log10f(float);
double math·log1p(double);
float math·log1pf(float);
double math·log2(double);
float math·log2f(float);
double math·logb(double);
float math·logbf(float);
long math·lrint(double);
long math·lrintf(float);
long math·lround(double);
long math·lroundf(float);
double math·nan(const char *);
float math·nanf(const char *);
double math·nearbyint(double);
float math·nearbyintf(float);
double math·pow(double, double);
float math·powf(float, float);
double math·rint(double);
float math·rintf(float);
double math·round(double);
float math·roundf(float);
double math·sin(double);
float math·sinf(float);
double math·sinh(double);
float math·sinhf(float);
double math·sqrt(double);
float math·sqrtf(float);
double math·tan(double);
float math·tanf(float);
double math·tanh(double);
float math·tanhf(float);
double math·tgamma(double);
float math·tgammaf(float);
double math·trunc(double);
float math·truncf(float);
// -----------------------------------------------------------------------
// basic linear algebra compute kernels
// TODO: think of better names
enum
{
blas·LowerTri = 1u,
blas·Transpose = 2u,
blas·ConjTranspose = 4u,
blas·DiagOnes = 8u,
blas·LeftSide = 16u,
};
typedef uint32 blas·Flag;
/* level 1 */
void blas·rot(int len, double *x, int incx, double *y, int incy, double cos, double sin);
void blas·rotg(double *a, double *b, double *cos, double *sin);
error blas·rotm(int len, double *x, int incx, double *y, int incy, double p[5]);
void blas·scale(int len, double a, double *x, int inc);
void blas·copy(int len, double *x, int incx, double *y, int incy);
void blas·swap(int len, double *x, int incx, double *y, int incy);
void blas·axpy(int len, double a, double *x, int incx, double *y, int incy);
double blas·dot(int len, double *x, int incx, double *y, int incy);
double blas·norm(int len, double *x, int inc);
double blas·sum(int len, double *x, int inc);
int blas·argmax(int len, double *x, int inc);
int blas·argmin(int len, double *x, int inc);
/* level 2 */
void blas·tpmv(blas·Flag f, int n, double *m, double *x);
error blas·gemv(int nrow, int ncol, double a, double *m, int incm, double *x, int incx, double b, double *y, int incy) ;
void blas·tpsv(blas·Flag f, int n, double *m, double *x);
void blas·ger(int nrow, int ncol, double a, double *x, double *y, double *m);
void blas·her(int n, double a, double *x, double *m);
void blas·syr(int nrow, int ncol, double a, double *x, double *m);
/* level 3 */
void blas·gemm(int n1, int n2, int n3, double a, double *m1, double *m2, double b, double *m3);
void blas·trmm(blas·Flag f, int nrow, int ncol, double a, double *m1, double *m2);
void blas·trsm(blas·Flag f, int nrow, int ncol, double a, double *m1, double *m2);
// -----------------------------------------------------------------------
// higher level linear algebra
typedef struct math·Vector
{
double *data;
int len;
} math·Vector;
#define math·slicev(vec, lo, hi) (struct math·Vector){.len=((hi)-(lo)), .data=((vec).data + (lo))}
typedef struct math·Matrix
{
double *data;
blas·Flag kind;
int dim[2];
} math·Matrix;
// TODO: tensor ala numpy
|