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

Fixes #86

Merged
merged 17 commits into from
Feb 3, 2024
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
498 changes: 257 additions & 241 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]

resolver= "2"
members = ["fastiron", "fastiron-stats"]

[profile.release]
Expand Down
8 changes: 4 additions & 4 deletions fastiron-stats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "fastiron-stats"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version="4.3.5", features=["cargo", "derive"]}
csv = "1.2.2"
gnuplot = "0.0.38"
clap = { version = "*", features = ["cargo", "derive"] }
csv = "*"
gnuplot = "*"
6 changes: 3 additions & 3 deletions fastiron-stats/src/structures/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TalliedVariable {
}
}

/// Returns the covariance of two given [FiniteDiscreteRV].
/// Returns the covariance of two given [TalliedVariable].
pub fn covariance(x: &TalliedVariable, y: &TalliedVariable) -> f64 {
assert_eq!(x.n_val(), y.n_val());
let iter = zip(x.values.iter(), y.values.iter());
Expand All @@ -128,11 +128,11 @@ pub fn covariance(x: &TalliedVariable, y: &TalliedVariable) -> f64 {
cov
}

/// Returns the correlation coefficient of two given [FiniteDiscreteRV].
/// Returns the correlation coefficient of two given [TalliedVariable].
///
/// The function checks if `x` and `y` have non-zero variance. If this is the case,
/// 0 is returned. It means variables are independent. While this may be technically
/// false, it allows for generic computations
/// false, it allows for generic computations.
pub fn correlation(x: &TalliedVariable, y: &TalliedVariable) -> f64 {
if (x.variance == 0.0) | (y.variance == 0.0) {
//
Expand Down
28 changes: 16 additions & 12 deletions fastiron/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "fastiron"
version = "1.3.0"
version = "1.3.2"
edition = "2021"

# DEPENDENCIES

[dependencies]
clap = {version="4.3.5", features=["cargo", "derive"]}
serde_yaml = {version="0.9.21", features=[]}
num = {version="0.4.0"}
rand = {version="0.8.5", features=["small_rng"]}
tinyvec = {version="1.6.0"}
rayon= {version="1.7.0"}
atomic = {version="0.5.3"}
hwloc2 = {version="2.2.0"}
libc = {version="0.2.146"}
rustc-hash = {version="1.1.0"}
clap = { version = "*", features = ["cargo", "derive"] }
serde_yaml = { version = "*", features = [] }
num = { version = "*" }
rand = { version = "*", features = ["small_rng"] }
tinyvec = { version = "*" }
rayon = { version = "*" }
atomic = { version = "0.5.3" } # further upgrade == breaking change
hwloc2 = { version = "2.2.0" }
libc = { version = "*" }
rustc-hash = { version = "*" }

[dev-dependencies]
criterion = {version="0.5.1", features=["html_reports"]}
criterion = { version = "*", features = ["html_reports"] }

# FEATURES
[features]
Expand All @@ -33,3 +33,7 @@ harness = false
[[bench]]
name = "mct_cross_product"
harness = false

[[bench]]
name = "snap_turtle"
harness = false
87 changes: 87 additions & 0 deletions fastiron/benches/snap_turtle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use fastiron::constants::Tuple3;

// Define the routines that are tested

fn manual_snap(times: usize) {
let bounds: (usize, usize, usize) = (10, 10, 10);
fn snap(bounds: (usize, usize, usize), tt: (i32, i32, i32)) -> Tuple3 {
(
(tt.0.max(0) as usize).min(bounds.0 - 1),
(tt.1.max(0) as usize).min(bounds.1 - 1),
(tt.2.max(0) as usize).min(bounds.2 - 1),
)
}
let tt1 = (1, 3, 2); // nothing to snap
let tt2 = (-1, 3, 2); // 1 element
let tt3 = (-1, 11, 2); // 2 elements
let tt4 = (-1, 11, -1); // 3 elements
(0..times).for_each(|_| {
let res = snap(bounds, tt1);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt2);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt3);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt4);
black_box(res);
});
}

fn clamp_snap(times: usize) {
let bounds: (usize, usize, usize) = (10, 10, 10);
fn snap(bounds: (usize, usize, usize), tt: (i32, i32, i32)) -> Tuple3 {
(
tt.0.clamp(0, (bounds.0 - 1) as i32) as usize,
tt.1.clamp(0, (bounds.1 - 1) as i32) as usize,
tt.2.clamp(0, (bounds.2 - 1) as i32) as usize,
)
}
let tt1 = (1, 3, 2); // nothing to snap
let tt2 = (-1, 3, 2); // 1 element
let tt3 = (-1, 11, 2); // 2 elements
let tt4 = (-1, 11, -1); // 3 elements
(0..times).for_each(|_| {
let res = snap(bounds, tt1);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt2);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt3);
black_box(res);
});
(0..times).for_each(|_| {
let res = snap(bounds, tt4);
black_box(res);
});
}

pub fn criterion_benchmark(c: &mut Criterion) {
// Generate/Define the input
let n_iter: usize = 1000;

let mut group = c.benchmark_group("snap turtle implementation");
group.bench_with_input(
BenchmarkId::new("manual snap", "number of iterations/4"),
&n_iter,
|b, &n| b.iter(|| manual_snap(n)),
);
group.bench_with_input(
BenchmarkId::new("clamp snap", "number of iterations/4"),
&n_iter,
|b, &n| b.iter(|| clamp_snap(n)),
);
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading
Loading