Skip to content

Commit

Permalink
Refactor and update to edition 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed Mar 12, 2019
1 parent 4e83546 commit bbba1da
Show file tree
Hide file tree
Showing 8 changed files with 618 additions and 571 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ repository = "https://github.com/SuperFluffy/gramschmidt-rs"
readme = "README.md"

[dependencies]
cblas = "0.2.0"
ndarray = "0.12.1"

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

[dev-dependencies]
lazy_static = "1.2.0"
lazy_static = "1.3.0"
ndarray-rand = "0.9.0"
rand = "0.6.5"
openblas-src = "0.7.0"
rand = "0.6.5"
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 bbba1da

Please sign in to comment.