Skip to content

Commit

Permalink
Merge pull request #1 from SuperFluffy/2018_edition
Browse files Browse the repository at this point in the history
2018 edition
  • Loading branch information
SuperFluffy authored Mar 12, 2019
2 parents 0319445 + d449fd3 commit b14723c
Show file tree
Hide file tree
Showing 9 changed files with 643 additions and 635 deletions.
20 changes: 8 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "gramschmidt"
version = "0.4.1"
version = "0.5.0"
edition = "2018"
authors = ["Richard Janis Goldschmidt <[email protected]>"]
license = "MIT"
description = "Classical, Modified, Reorthogonalized Gram Schmidt Orthogonalization and QR decompostion"
Expand All @@ -10,16 +11,11 @@ repository = "https://github.com/SuperFluffy/gramschmidt-rs"
readme = "README.md"

[dependencies]
ndarray = "0.11"

[dependencies.cblas]
version = "0.1.5"
default-features = false
cblas = "0.2.0"
ndarray = "0.12.1"

[dev-dependencies]
lazy_static = "1.0"
ndarray-rand = "0.7"
rand = "0.4"

[dev-dependencies.openblas-src]
version = "0.5.6"
lazy_static = "1.3.0"
ndarray-rand = "0.9.0"
openblas-src = "0.7.0"
rand = "0.6.5"
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ This crate provides the following methods:
# Usage

```rust
extern crate gramschmidt;
extern crate ndarray;

// Import openblas_src or another blas source to have the linker find all symbols.
extern crate openblas_src;

fn main() {
use gramschmidt::{
GramSchmidt,
Reorthogonalized,
Result,
};
use ndarray::arr2;

fn main() -> Result<()> {
let small_matrix = arr2(
&[[2.0, 0.5, 0.0, 0.0],
[0.0, 0.3, 0.0, 0.0],
[0.0, 1.0, 0.7, 0.0],
[0.0, 0.0, 0.0, 3.0]]
);
let mut cgs2 = ReorthogonalizedGramSchmidt::from_matrix(&small_matrix);
cgs2.compute(&small_matrix);
let mut cgs2 = Reorthogonalized::from_matrix(&small_matrix)?;
cgs2.compute(&small_matrix)?;
assert!(small_matrix.all_close(&cgs2.q().dot(cgs2.r()), 1e-14));
Ok(())
}
```

# Recent versions

+ `0.5.0`: Refactored the library and updated for edition 2018
+ the Gram Schmidt factorizations are now all implemented via the `GramSchmidt` trait;
+ introduce some error handling;
+ provide convenience functions `cgs`, `cgs2`, and `mgs`.
+ `0.4.1`: Fixed doc tests and expanded + simplified tests.
+ `0.4.0`: Major rework of the library structure:
+ The algorithms are now configured via structs, the traits are dropped.
Expand Down
45 changes: 23 additions & 22 deletions benches/matrix_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

#![allow(non_snake_case)]

extern crate gram_schmidt;
extern crate ndarray;
// extern crate gram_schmidt;
// extern crate ndarray;
extern crate openblas_src;

extern crate test; // Built-in crate for benchmarking.

use gram_schmidt::{
ClassicalGramSchmidt,
ModifiedGramSchmidt,
ReorthogonalizedGramSchmidt,
use gramschmidt::{
GramSchmidt,
Classical,
Modified,
Reorthogonalized,
};

use ndarray::prelude::*;
Expand Down Expand Up @@ -51,61 +52,61 @@ use ndarray::prelude::*;
// }

macro_rules! create_bench {
(c $n:expr, $name:ident, $method_constructor:path) => {
(c $n:expr, $name:ident, $method:ty) => {
#[bench]
fn $name(bench: &mut test::Bencher) {
let n = $n;

let matrix = Array2::eye(n);
let mut method = $method_constructor(&matrix);
let mut method = <$method>::from_matrix(&matrix).unwrap();
let method = test::black_box(&mut method);

bench.iter(|| {
method.compute(&matrix);
method.compute(&matrix).unwrap();
});
}
};

(f $n:expr, $name:ident, $method_constructor:path) => {
(f $n:expr, $name:ident, $method:ty) => {
#[bench]
fn $name(bench: &mut test::Bencher) {
let n = $n;

let matrix = Array2::eye(n).reversed_axes();
let mut method = $method_constructor(&matrix);
let mut method = <$method>::from_matrix(&matrix).unwrap();
let method = test::black_box(&mut method);

bench.iter(|| {
method.compute(&matrix);
method.compute(&matrix).unwrap();
});
}
};
}

macro_rules! bench_sizes {
(c $n:expr, $name_cgs:ident, $name_mgs: ident, $name_cgs2: ident) => {
create_bench!(c $n, $name_cgs, ClassicalGramSchmidt::from_matrix);
create_bench!(c $n, $name_cgs2, ReorthogonalizedGramSchmidt::from_matrix);
create_bench!(c $n, $name_mgs, ModifiedGramSchmidt::from_matrix);
create_bench!(c $n, $name_cgs, Classical);
create_bench!(c $n, $name_cgs2, Reorthogonalized);
create_bench!(c $n, $name_mgs, Modified);
};

(f $n:expr, $name_cgs:ident, $name_mgs: ident, $name_cgs2: ident) => {
create_bench!(f $n, $name_cgs, ClassicalGramSchmidt::from_matrix);
create_bench!(f $n, $name_cgs2, ReorthogonalizedGramSchmidt::from_matrix);
create_bench!(f $n, $name_mgs, ModifiedGramSchmidt::from_matrix);
create_bench!(f $n, $name_cgs, Classical);
create_bench!(f $n, $name_cgs2, Reorthogonalized);
create_bench!(f $n, $name_mgs, Modified);
};
}

bench_sizes!(c 256, c_cgs__256, c_mgs__256, c_cgs2__256);
bench_sizes!(c 512, c_cgs__512, c_mgs__512, c_cgs2__512);
bench_sizes!(c 768, c_cgs__768, c_mgs__768, c_cgs2__768);
bench_sizes!(c 1024, c_cgs_1024, c_mgs_1024, c_cgs2_1024);
// bench_sizes!(c 768, c_cgs__768, c_mgs__768, c_cgs2__768);
// bench_sizes!(c 1024, c_cgs_1024, c_mgs_1024, c_cgs2_1024);
// bench_sizes!(c 1536, c_cgs_1536, c_mgs_1536, c_cgs2_1536);
// bench_sizes!(c 2048, c_cgs_2048, c_mgs_2048, c_cgs2_2048);

bench_sizes!(f 256, f_cgs__256, f_mgs__256, f_cgs2__256);
bench_sizes!(f 512, f_cgs__512, f_mgs__512, f_cgs2__512);
bench_sizes!(f 768, f_cgs__768, f_mgs__768, f_cgs2__768);
bench_sizes!(f 1024, f_cgs_1024, f_mgs_1024, f_cgs2_1024);
// bench_sizes!(f 768, f_cgs__768, f_mgs__768, f_cgs2__768);
// bench_sizes!(f 1024, f_cgs_1024, f_mgs_1024, f_cgs2_1024);
// bench_sizes!(f 1536, f_cgs_1536, f_mgs_1536, f_cgs2_1536);
// bench_sizes!(f 2048, f_cgs_2048, f_mgs_2048, f_cgs2_2048);
Loading

0 comments on commit b14723c

Please sign in to comment.