From c66ab0ade209a76b86cc03cb7f1ba8a32d69d353 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 28 Apr 2026 13:30:49 +0100 Subject: [PATCH] Add `matrix_inverse_gauss_jordan` `matrix_inverse_lu_decomposition` `matrix_determinant_generic` --- core/math/linalg/general.odin | 179 ++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/core/math/linalg/general.odin b/core/math/linalg/general.odin index cd191b2b2..c30f8ef25 100644 --- a/core/math/linalg/general.odin +++ b/core/math/linalg/general.odin @@ -500,8 +500,48 @@ matrix4x4_determinant :: proc "contextless" (m: $M/matrix[4, 4]$T) -> (det: T) # return } +@(require_results) +matrix_determinant_generic :: proc "contextless" (a: $M/matrix[$N, N]$T) -> T #no_bounds_check { + a := a + det: T = 1 + for col in 0.. pivot_val { + pivot_val = val + pivot_row = row + } + } + if pivot_val == 0 { + return 0 + } + + if pivot_row != col { + for k in 0.. (y: M) #no_bounds_check { @@ -722,3 +762,142 @@ matrix4x4_inverse :: proc "contextless" (x: $M/matrix[4, 4]$T) -> (y: M) #no_bou } return } + +@(private="file") +swap :: #force_inline proc "contextless" (a, b: ^$T) { + t := a^ + a^ = b^ + b^ = t +} + +@(require_results) +matrix_inverse_gauss_jordan :: proc "contextless" (A: $M/matrix[$N, N]$T) -> (b: M, non_singular: bool) #no_bounds_check { + a := A + b = 1 + + for col in 0.. pivot_val { + pivot_val = val + pivot_row = row + } + } + + if pivot_val == 0 { + return + } + + if pivot_row != col { + for k in 0.. (b: M, non_singular: bool) #no_bounds_check { + // LU decomposition with partial pivoting + a := A + pivot: [N]int = --- + for i in 0.. pivot_val { + pivot_val = val + pivot_row = row + } + } + + if pivot_val == 0 { + return + } + + // Swap pivot indices + if pivot_row != col { + t := pivot[col] + pivot[col] = pivot[pivot_row] + pivot[pivot_row] = t + + for k in 0..