Skip to content

Commit 7240b1d

Browse files
authored
Merge pull request #66 from termoshtt/refactor_solve
Refactor solve
2 parents 71ad0ba + 50c6d3f commit 7240b1d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

examples/solve.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/solve.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff 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>
7979
where
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
}

0 commit comments

Comments
 (0)