#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, double *x, double b, double *y) ; 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