File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
Expand file tree Collapse file tree 2 files changed +24
-4
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 many b with fixed A
9+ fn factorize ( ) -> Result < ( ) , error:: LinalgError > {
10+ let a: Array2 < f64 > = random ( ( 3 , 3 ) ) ;
11+ let f = a. factorize_into ( ) ?; // LU factorize A (A is consumed)
12+ for _ in 0 ..10 {
13+ let b: Array1 < f64 > = random ( 3 ) ;
14+ let x = f. solve ( Transpose :: No , b) ?; // solve Ax=b using factorized L, U
15+ }
16+ Ok ( ( ) )
17+ }
18+
19+ fn main ( ) {
20+ factorize ( ) . unwrap ( ) ;
21+ }
Original file line number Diff line number Diff line change @@ -75,14 +75,13 @@ where
7575 }
7676}
7777
78- impl < A , Si , So > Factorize < So > for ArrayBase < Si , Ix2 >
78+ impl < A , Si > Factorize < OwnedRepr < A > > for ArrayBase < Si , Ix2 >
7979where
8080 A : Scalar ,
8181 Si : Data < Elem = A > ,
82- So : DataOwned < Elem = A > + DataMut ,
8382{
84- fn factorize ( & self ) -> Result < Factorized < So > > {
85- let mut a: ArrayBase < So , Ix2 > = replicate ( self ) ;
83+ fn factorize ( & self ) -> Result < Factorized < OwnedRepr < A > > > {
84+ let mut a: Array2 < A > = replicate ( self ) ;
8685 let ipiv = unsafe { A :: lu ( a. layout ( ) ?, a. as_allocated_mut ( ) ?) ? } ;
8786 Ok ( Factorized { a : a, ipiv : ipiv } )
8887 }
You can’t perform that action at this time.
0 commit comments