Download include/sk_matrix.h from Snapkitty/snapkitty-mlc: direct link, hf CLI and curl.
- Browser
- Download file 4.58 kB
-
https://huggingface.co/Snapkitty/snapkitty-mlc/resolve/main/include/sk_matrix.h
- Command line
-
hf download hf://Snapkitty/snapkitty-mlc/include/sk_matrix.h
-
curl -L -o sk_matrix.h https://huggingface.co/Snapkitty/snapkitty-mlc/resolve/main/include/sk_matrix.h
4.58 kB
| /* sk_matrix.h β SnapKitty MLC: row-major f32 matrix operations | |
| * | |
| * All operations take an explicit arena for allocation. | |
| * Forward pass and gradient ops are separated. | |
| * No hidden globals; all state is in the passed structs. | |
| * | |
| * Authors: Ahmad Ali Parr, Jessica L. Williams (SNAPKITTYWEST) | |
| * Source: SNAPKITTYAGENT9NOVA/MLC | |
| * License: BSL-1.1 / AGPL-3.0 / MPL-2.0 | |
| */ | |
| /* ββ Matrix βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| typedef struct { | |
| u32 rows; | |
| u32 cols; | |
| f32* data; /* row-major, size = rows Γ cols Γ sizeof(f32) */ | |
| } sk_matrix; | |
| /* ββ Lifecycle ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| sk_matrix* sk_mat_create(sk_arena* arena, u32 rows, u32 cols); | |
| sk_matrix* sk_mat_load(sk_arena* arena, u32 rows, u32 cols, const char* filename); | |
| b32 sk_mat_copy(sk_matrix* dst, const sk_matrix* src); | |
| /* ββ Fill βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| void sk_mat_clear(sk_matrix* mat); | |
| void sk_mat_fill(sk_matrix* mat, f32 x); | |
| void sk_mat_fill_rand(sk_matrix* mat, f32 lower, f32 upper); | |
| /* ββ Reductions βββββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| void sk_mat_scale(sk_matrix* mat, f32 scale); | |
| f32 sk_mat_sum(const sk_matrix* mat); | |
| u64 sk_mat_argmax(const sk_matrix* mat); | |
| /* ββ Element-wise arithmetic ββββββββββββββββββββββββββββββββββββββββ */ | |
| b32 sk_mat_add(sk_matrix* out, const sk_matrix* a, const sk_matrix* b); | |
| b32 sk_mat_sub(sk_matrix* out, const sk_matrix* a, const sk_matrix* b); | |
| /* ββ Matrix multiply | |
| * out = A(α΅?) Γ B(α΅?) zero_out: clear out before accumulating | |
| * transpose_a/b: treat operand as its transpose (no copy) | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| b32 sk_mat_mul( | |
| sk_matrix* out, const sk_matrix* a, const sk_matrix* b, | |
| b8 zero_out, b8 transpose_a, b8 transpose_b | |
| ); | |
| /* ββ Activation functions (forward) ββββββββββββββββββββββββββββββββ */ | |
| b32 sk_mat_relu(sk_matrix* out, const sk_matrix* in); | |
| b32 sk_mat_softmax(sk_matrix* out, const sk_matrix* in); | |
| /* ββ Loss function ββββββββββββββββββββββββββββββββββββββββββββββββββ */ | |
| b32 sk_mat_cross_entropy(sk_matrix* out, const sk_matrix* p, const sk_matrix* q); | |
| /* ββ Gradient accumulation (adds into out, never overwrites) βββββββ */ | |
| b32 sk_mat_relu_add_grad( | |
| sk_matrix* out, const sk_matrix* in, const sk_matrix* grad | |
| ); | |
| b32 sk_mat_softmax_add_grad( | |
| sk_matrix* out, const sk_matrix* softmax_out, const sk_matrix* grad | |
| ); | |
| b32 sk_mat_cross_entropy_add_grad( | |
| sk_matrix* p_grad, sk_matrix* q_grad, | |
| const sk_matrix* p, const sk_matrix* q, const sk_matrix* grad | |
| ); | |
| /* Compatibility aliases */ | |