nx_matrix.nx
buildroot/runtime/nx_matrix.nx
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
imports: syscalls.nxnx_isqrt.nx
imported by: nx_appliedmath_gate.nxnx_matrix_eig_gate.nxnx_matrix_test.nxnx_swcompare_bench.nx
structs
| 30 | struct Matrix |
consts
| 28 | const NX_MATRIX_Q: i64 = 16384 // Q14 |
| 159 | const NXM_EIG_OK: i64 = 0 |
| 160 | const NXM_EIG_ERR_NOT_SQUARE: i64 = 0 - 1 |
| 161 | const NXM_EIG_ERR_EMPTY: i64 = 0 - 2 |
| 162 | const NXM_EIG_ERR_ASYMMETRIC: i64 = 0 - 3 // Jacobi is only valid for symmetric input; refuse, never guess |
| 163 | const NXM_EIG_SWEEPS_DEFAULT: i64 = 12 |
| 166 | const NXM_EIG_TOL: i64 = 1 |
| 318 | const NXM_SVD_OK: i64 = 0 |
| 319 | const NXM_SVD_ERR_EMPTY: i64 = 0 - 2 |
| 320 | const NXM_SVD_ERR_DIMS: i64 = 0 - 4 // u must be m x n and v must be n x n |
functions
| 38 | func nx_matrix_alloc(rows: i64, cols: i64) -> *Matrix |
| 51 | func nx_matrix_set(m: *Matrix, r: i64, c: i64, v: i64) -> i64 |
| 56 | func nx_matrix_get(m: *Matrix, r: i64, c: i64) -> i64 |
| 60 | func nx_matrix_fill(m: *Matrix, v: i64) -> i64 |
| 72 | func nx_matrix_identity(m: *Matrix, unit_value: i64) -> i64 |
| 87 | func nx_matrix_transpose(a: *Matrix) -> *Matrix |
| 106 | func nx_matrix_multiply(a: *Matrix, b: *Matrix, c: *Matrix) -> i64 |
| 168 | func nxm_fmul(a: i64, b: i64) -> i64 { return (a * b) / NX_MATRIX_Q } |
| 170 | func nxm_fdiv(a: i64, b: i64) -> i64 |
| 177 | func nxm_fsqrt(x: i64) -> i64 |
| 182 | func nxm_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 186 | func nx_matrix_is_symmetric(m: *Matrix) -> i64 |
| 202 | func nx_matrix_eig_sym(a: *Matrix, evals: *i64, v: *Matrix, sweeps: i64) -> i64 |
| 278 | func nx_matrix_residual(a: *Matrix, v: *Matrix, evals: *i64) -> i64 |
| 325 | func nxm_ata(a: *Matrix, out: *Matrix) -> i64 |
| 343 | func nx_matrix_svd(a: *Matrix, u: *Matrix, sv: *i64, v: *Matrix, sweeps: i64) -> i64 called by 1: main calls 8: nx_matrix_allocnxm_atanx_matrix_eig_symnxm_fsqrtnx_matrix_getnx_matrix_set+2 |
| 410 | func nx_matrix_svd_residual(a: *Matrix, u: *Matrix, sv: *i64, v: *Matrix) -> i64 |
| 433 | func nx_matrix_det_2x2(m: *Matrix) -> i64 |
| 440 | func nx_matrix_det_3x3(m: *Matrix) -> i64 |
| 467 | func nx_matrix_inv_2x2(m: *Matrix, out: *Matrix) -> i64 |
| 486 | func nx_matrix_inv_3x3(m: *Matrix, out: *Matrix) -> i64 |