code wiki / (root) / nx_f32_softmax.nx

nx_f32_softmax.nx

buildroot/runtime/nx_f32_softmax.nx

2474 B87 linesdepth 5pulls 7 transitivereach 95 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_softmax.nx -- bits-up f32 numerically-stable softmax. L7 / L8 composition brick. Composes L4 mul/add/sub/div + L6 exp. Algorithm (numerically stable via max-subtraction): m = max_i x[i] shifted_i = x[i] - m exps_i = exp(shifted_i) (each in (0, 1]) sum_exp = sum_i exps_i out[i] = exps_i / sum_exp Max-subtraction guards against exp overflow without changing the final probabilities (numerator+denominator scale by the same 1/exp(m) factor, which cancels). References absorbed clean-room: Bridle 1990 (original softmax) Standard logsumexp / max-subtract trick (numerical canon) genealogy_id: bridle_1990_softmax + logsumexp_max_subtract lineage_id: substrate_f32_softmax_v1_stable

dependencies 5 imports · 11 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_div.nx nx_f32_exp.nx nx_f32_softmax.nx nx_f32_attention.nx nx_f32_attn_multi.nx nx_f32_attn_multi_test.nx nx_f32_mha.nx nx_f32_mha_test.nx nx_f32_softmax_test.nx nx_f32_transformer.nx nx_lowrank_attn.nx nx_moe.nx nx_moe_gate.nx

diagram shows first 10 each side; +0 more imports, +1 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_div.nxnx_f32_exp.nx

imported by: nx_f32_attention.nxnx_f32_attn_multi.nxnx_f32_attn_multi_test.nxnx_f32_mha.nxnx_f32_mha_test.nxnx_f32_softmax_test.nxnx_f32_transformer.nxnx_lowrank_attn.nxnx_moe.nxnx_moe_gate.nxnx_vit_encoder_layer.nx

structs

none

consts

29const NX_F32_SM_OK: nx_int = 0
30const NX_F32_SM_ERR_BAD_DIM: nx_int = 1
31const NX_F32_SM_N_VERDICTS: nx_int = 2

functions

33func nx_f32_sm_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
42func _f32_gt(a: i64, b: i64) -> nx_int
58func nx_f32_softmax(x: *i64, n: nx_int, out: *i64) -> nx_int