-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added determinant for refactor (correctly this time (hopefully))
- Loading branch information
1 parent
24d192f
commit 3bf8ea5
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::{assert, get_global_parallelism}; | ||
use crate::internal_prelude::*; | ||
use alloc::vec; | ||
use dyn_stack::MemBuffer; | ||
|
||
#[math] | ||
pub fn determinant<T: ComplexField>(mat: MatRef<'_, T>) -> T::Canonical { | ||
assert!(mat.nrows() == mat.ncols()); | ||
|
||
let par = get_global_parallelism(); | ||
let (m, n) = mat.shape(); | ||
let mut row_perm_fwd = vec![0usize; m]; | ||
let mut row_perm_bwd = vec![0usize; m]; | ||
|
||
let mut factors = mat.to_owned(); | ||
let count = linalg::lu::partial_pivoting::factor::lu_in_place( | ||
factors.as_mat_mut(), | ||
&mut row_perm_fwd, | ||
&mut row_perm_bwd, | ||
par, | ||
MemStack::new(&mut MemBuffer::new( | ||
linalg::lu::partial_pivoting::factor::lu_in_place_scratch::<usize, T>(m, n, par, default()), | ||
)), | ||
default(), | ||
).0.transposition_count; | ||
|
||
let mut det = one(); | ||
for i in 0..factors.nrows() { | ||
det = mul(det, factors.as_mat_ref().read(i, i)); | ||
} | ||
if count % 2 == 0 { | ||
det | ||
} else { | ||
neg(det) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pub mod norm_l2; | |
pub mod norm_l2_sqr; | ||
pub mod norm_max; | ||
pub mod sum; | ||
pub mod determinant; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters