Skip to content
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

Sort singular values #46

Merged
merged 13 commits into from
Sep 24, 2016
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ license = "MIT"
[dependencies]
num = {version = "0.1.34", default-features = false }
matrixmultiply = "0.1.8"

[dev-dependencies]
rand = "0.3"
2 changes: 2 additions & 0 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

extern crate rulinalg;
extern crate test;
extern crate rand;

mod linalg {
mod matrix;
mod svd;
}
29 changes: 29 additions & 0 deletions benches/linalg/svd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use test::Bencher;
use rand;
use rand::{Rng, SeedableRng};
use rulinalg::matrix::Matrix;

fn reproducible_random_matrix(rows: usize, cols: usize) -> Matrix<f64> {
const STANDARD_SEED: [usize; 4] = [12, 2049, 4000, 33];
let mut rng = rand::StdRng::from_seed(&STANDARD_SEED);
let elements: Vec<_> = rng.gen_iter::<f64>().take(rows * cols).collect();
Matrix::new(rows, cols, elements)
}

#[bench]
fn svd_10_10(b: &mut Bencher) {
let mat = reproducible_random_matrix(10, 10);

b.iter(||
mat.clone().svd()
)
}

#[bench]
fn svd_100_100(b: &mut Bencher) {
let mat = reproducible_random_matrix(100, 100);

b.iter(||
mat.clone().svd()
)
}
24 changes: 24 additions & 0 deletions src/epsilon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use libnum::Float;
use std::f32;
use std::f64;

/// Expose the machine epsilon of floating point numbers.
/// This trait should only need to exist for a short time,
/// until the Float trait from the Num crate has the same
/// capabilities.
pub trait MachineEpsilon: Float {
/// Returns the machine epsilon for the given Float type.
fn epsilon() -> Self;
}

impl MachineEpsilon for f32 {
fn epsilon() -> f32 {
f32::EPSILON
}
}

impl MachineEpsilon for f64 {
fn epsilon() -> f64 {
f64::EPSILON
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub mod error;
pub mod utils;
pub mod vector;

// Remove this module once epsilon() makes it into the num crate.
mod epsilon;
pub use epsilon::MachineEpsilon;

/// Trait for linear algebra metrics.
///
/// Currently only implements basic euclidean norm.
Expand Down
Loading