Skip to content

Refactor solve #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/solve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

extern crate ndarray;
extern crate ndarray_linalg;

use ndarray::*;
use ndarray_linalg::*;

// Solve `Ax=b` for many b with fixed A
fn factorize() -> Result<(), error::LinalgError> {
let a: Array2<f64> = random((3, 3));
let f = a.factorize_into()?; // LU factorize A (A is consumed)
for _ in 0..10 {
let b: Array1<f64> = random(3);
let x = f.solve(Transpose::No, b)?; // solve Ax=b using factorized L, U
}
Ok(())
}

fn main() {
factorize().unwrap();
}
7 changes: 3 additions & 4 deletions src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ where
}
}

impl<A, Si, So> Factorize<So> for ArrayBase<Si, Ix2>
impl<A, Si> Factorize<OwnedRepr<A>> for ArrayBase<Si, Ix2>
where
A: Scalar,
Si: Data<Elem = A>,
So: DataOwned<Elem = A> + DataMut,
{
fn factorize(&self) -> Result<Factorized<So>> {
let mut a: ArrayBase<So, Ix2> = replicate(self);
fn factorize(&self) -> Result<Factorized<OwnedRepr<A>>> {
let mut a: Array2<A> = replicate(self);
let ipiv = unsafe { A::lu(a.layout()?, a.as_allocated_mut()?)? };
Ok(Factorized { a: a, ipiv: ipiv })
}
Expand Down