code wiki / (root) / nx_matrix.nx

nx_matrix.nx

buildroot/runtime/nx_matrix.nx

20257 B522 linesdepth 3pulls 4 transitivereach 4 importersview sourcekind librarytopic matrix
docsdependenciesstructsconstsfunctions

about

nx_matrix.nx -- general matrix algebra (i64, row-major). Closes the gap that nx_kalman / nx_cam / nx_pc currently bridge with inline matrix arithmetic. Provides: + alloc / set / get / copy + identity / zeros / fill + transpose + multiply (C = A * B) + 2x2 + 3x3 determinant + 2x2 + 3x3 inverse (in Q14) Entries are pure i64. For fractional operations (inverse), gains are emitted in Q14 fixed-point so subsequent multiplications can be divided by NX_MATRIX_Q. genealogy_id: classical_linear_algebra + cramer_1750_determinant lineage_id: row_major_matrix + cofactor_expansion

dependencies 2 imports · 4 importers

syscalls.nx nx_isqrt.nx nx_matrix.nx nx_appliedmath_gate.nx nx_matrix_eig_gate.nx nx_matrix_test.nx nx_swcompare_bench.nx

imports: syscalls.nxnx_isqrt.nx

imported by: nx_appliedmath_gate.nxnx_matrix_eig_gate.nxnx_matrix_test.nxnx_swcompare_bench.nx

structs

30struct Matrix

consts

28const NX_MATRIX_Q: i64 = 16384 // Q14
159const NXM_EIG_OK: i64 = 0
160const NXM_EIG_ERR_NOT_SQUARE: i64 = 0 - 1
161const NXM_EIG_ERR_EMPTY: i64 = 0 - 2
162const NXM_EIG_ERR_ASYMMETRIC: i64 = 0 - 3 // Jacobi is only valid for symmetric input; refuse, never guess
163const NXM_EIG_SWEEPS_DEFAULT: i64 = 12
166const NXM_EIG_TOL: i64 = 1
318const NXM_SVD_OK: i64 = 0
319const NXM_SVD_ERR_EMPTY: i64 = 0 - 2
320const NXM_SVD_ERR_DIMS: i64 = 0 - 4 // u must be m x n and v must be n x n

functions

38func nx_matrix_alloc(rows: i64, cols: i64) -> *Matrix
51func nx_matrix_set(m: *Matrix, r: i64, c: i64, v: i64) -> i64
56func nx_matrix_get(m: *Matrix, r: i64, c: i64) -> i64
60func nx_matrix_fill(m: *Matrix, v: i64) -> i64
72func nx_matrix_identity(m: *Matrix, unit_value: i64) -> i64
87func nx_matrix_transpose(a: *Matrix) -> *Matrix
106func nx_matrix_multiply(a: *Matrix, b: *Matrix, c: *Matrix) -> i64
168func nxm_fmul(a: i64, b: i64) -> i64 { return (a * b) / NX_MATRIX_Q }
170func nxm_fdiv(a: i64, b: i64) -> i64
177func nxm_fsqrt(x: i64) -> i64
182func nxm_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
186func nx_matrix_is_symmetric(m: *Matrix) -> i64
202func nx_matrix_eig_sym(a: *Matrix, evals: *i64, v: *Matrix, sweeps: i64) -> i64
278func nx_matrix_residual(a: *Matrix, v: *Matrix, evals: *i64) -> i64
called by 1: main calls 3: nxm_fmulnx_matrix_getnxm_abs
325func nxm_ata(a: *Matrix, out: *Matrix) -> i64
343func nx_matrix_svd(a: *Matrix, u: *Matrix, sv: *i64, v: *Matrix, sweeps: i64) -> i64
410func nx_matrix_svd_residual(a: *Matrix, u: *Matrix, sv: *i64, v: *Matrix) -> i64
called by 1: main calls 3: nxm_fmulnx_matrix_getnxm_abs
433func nx_matrix_det_2x2(m: *Matrix) -> i64
440func nx_matrix_det_3x3(m: *Matrix) -> i64
467func nx_matrix_inv_2x2(m: *Matrix, out: *Matrix) -> i64
486func nx_matrix_inv_3x3(m: *Matrix, out: *Matrix) -> i64