-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from bytesnake/master
Add LOBPCG solver for large symmetric positive definite eigenproblems
- Loading branch information
Showing
13 changed files
with
1,194 additions
and
19 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
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,41 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
|
||
use criterion::Criterion; | ||
use ndarray::*; | ||
use ndarray_linalg::*; | ||
|
||
macro_rules! impl_teig { | ||
($n:expr) => { | ||
paste::item! { | ||
fn [<teig $n>](c: &mut Criterion) { | ||
c.bench_function(&format!("truncated_eig{}", $n), |b| { | ||
let a: Array2<f64> = random(($n, $n)); | ||
let a = a.t().dot(&a); | ||
|
||
b.iter(move || { | ||
let _result = TruncatedEig::new(a.clone(), TruncatedOrder::Largest).decompose(1); | ||
}) | ||
}); | ||
c.bench_function(&format!("truncated_eig{}_t", $n), |b| { | ||
let a: Array2<f64> = random(($n, $n).f()); | ||
let a = a.t().dot(&a); | ||
|
||
b.iter(|| { | ||
let _result = TruncatedEig::new(a.clone(), TruncatedOrder::Largest).decompose(1); | ||
}) | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_teig!(4); | ||
impl_teig!(8); | ||
impl_teig!(16); | ||
impl_teig!(32); | ||
impl_teig!(64); | ||
impl_teig!(128); | ||
|
||
criterion_group!(teig, teig4, teig8, teig16, teig32, teig64, teig128); | ||
criterion_main!(teig); |
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,23 @@ | ||
extern crate ndarray; | ||
extern crate ndarray_linalg; | ||
|
||
use ndarray::*; | ||
use ndarray_linalg::*; | ||
|
||
fn main() { | ||
let n = 10; | ||
let v = random_unitary(n); | ||
|
||
// set eigenvalues in decreasing order | ||
let t = Array1::linspace(n as f64, -(n as f64), n); | ||
|
||
println!("Generate spectrum: {:?}", &t); | ||
|
||
let t = Array2::from_diag(&t); | ||
let a = v.dot(&t.dot(&v.t())); | ||
|
||
// calculate the truncated eigenproblem decomposition | ||
for (val, _) in TruncatedEig::new(a, TruncatedOrder::Largest) { | ||
println!("Found eigenvalue {}", val[0]); | ||
} | ||
} |
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,22 @@ | ||
extern crate ndarray; | ||
extern crate ndarray_linalg; | ||
|
||
use ndarray::*; | ||
use ndarray_linalg::*; | ||
|
||
fn main() { | ||
let a = arr2(&[[3., 2., 2.], [2., 3., -2.]]); | ||
|
||
// calculate the truncated singular value decomposition for 2 singular values | ||
let result = TruncatedSvd::new(a, TruncatedOrder::Largest).decompose(2).unwrap(); | ||
|
||
// acquire singular values, left-singular vectors and right-singular vectors | ||
let (u, sigma, v_t) = result.values_vectors(); | ||
println!("Result of the singular value decomposition A = UΣV^T:"); | ||
println!(" === U ==="); | ||
println!("{:?}", u); | ||
println!(" === Σ ==="); | ||
println!("{:?}", Array2::from_diag(&sigma)); | ||
println!(" === V^T ==="); | ||
println!("{:?}", v_t); | ||
} |
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
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
Oops, something went wrong.