File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ extern crate ndarray;
3
+ extern crate ndarray_linalg;
4
+
5
+ use ndarray:: * ;
6
+ use ndarray_linalg:: * ;
7
+
8
+ // Solve `Ax=b` for Hermite matrix A
9
+ fn solve ( ) -> Result < ( ) , error:: LinalgError > {
10
+ let a: Array2 < c64 > = random_hermite ( 3 ) ; // complex Hermite positive definite matrix
11
+ let b: Array1 < c64 > = random ( 3 ) ;
12
+ println ! ( "b = {:?}" , & b) ;
13
+ let f = a. factorizeh ( ) ?; // DK factorize
14
+ let x = f. solveh ( b) ?;
15
+ println ! ( "Ax = {:?}" , a. dot( & x) ) ; ;
16
+ Ok ( ( ) )
17
+ }
18
+
19
+ // Solve `Ax=b` for many b with fixed A
20
+ fn factorize ( ) -> Result < ( ) , error:: LinalgError > {
21
+ let a: Array2 < f64 > = random_hpd ( 3 ) ;
22
+ let f = a. factorizeh_into ( ) ?;
23
+ // once factorized, you can use it several times:
24
+ for _ in 0 ..10 {
25
+ let b: Array1 < f64 > = random ( 3 ) ;
26
+ let _x = f. solveh ( b) ?;
27
+ }
28
+ Ok ( ( ) )
29
+ }
30
+
31
+ fn main ( ) {
32
+ solve ( ) . unwrap ( ) ;
33
+ factorize ( ) . unwrap ( ) ;
34
+ }
You can’t perform that action at this time.
0 commit comments