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

Integrate min-const-generics. #820

Merged
merged 17 commits into from
Apr 12, 2021
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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ no_unsound_assume_init = [ ]
# Conversion
convert-mint = [ "mint" ]
convert-glam = [ "glam" ]
convert-glam-unchecked = [ "convert-glam" ] # Unable edgy conversions like Mat4 -> Isometry3
convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-bytemuck = [ "bytemuck" ]

# Serialization
Expand All @@ -54,7 +54,6 @@ slow-tests = []

[dependencies]
typenum = "1.12"
generic-array = "0.14"
rand-package = { package = "rand", version = "0.8", optional = true, default-features = false }
num-traits = { version = "0.2", default-features = false }
num-complex = { version = "0.3", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

-----

## Gold sponsors
## Platinum sponsors
Rapier is supported by:
<p>
<a href="https://embark-studios.com">
<img src="https://www.embark.dev/img/logo_black.png" width="301px">
<img src="https://www.embark.dev/img/logo_black.png" width="401px">
</a>
</p>
6 changes: 3 additions & 3 deletions benches/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! bench_unop_na(
i = (i + 1) & (LEN - 1);

unsafe {
test::black_box(na::$unop(elems.get_unchecked(i)))
std::hint::black_box(na::$unop(elems.get_unchecked(i)))
}
}));
}
Expand All @@ -82,7 +82,7 @@ macro_rules! bench_unop(
i = (i + 1) & (LEN - 1);

unsafe {
test::black_box(elems.get_unchecked_mut(i).$unop())
std::hint::black_box(elems.get_unchecked_mut(i).$unop())
}
}));
}
Expand All @@ -105,7 +105,7 @@ macro_rules! bench_construction(

unsafe {
let res = $constructor($(*$args.get_unchecked(i),)*);
test::black_box(res)
std::hint::black_box(res)
}
}));
}
Expand Down
8 changes: 4 additions & 4 deletions benches/core/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10};
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, Vector2, Vector3, Vector4, U10};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
Expand Down Expand Up @@ -116,8 +116,8 @@ fn mat10_mul_mat10(bench: &mut criterion::Criterion) {
}

fn mat10_mul_mat10_static(bench: &mut criterion::Criterion) {
let a = MatrixN::<f64, U10>::new_random();
let b = MatrixN::<f64, U10>::new_random();
let a = OMatrix::<f64, U10, U10>::new_random();
let b = OMatrix::<f64, U10, U10>::new_random();

bench.bench_function("mat10_mul_mat10_static", move |bh| bh.iter(|| &a * &b));
}
Expand Down Expand Up @@ -198,7 +198,7 @@ fn mat_mul_mat(bench: &mut criterion::Criterion) {

bench.bench_function("mat_mul_mat", move |bh| {
bh.iter(|| {
test::black_box(a.mul_to(&b, &mut ab));
std::hint::black_box(a.mul_to(&b, &mut ab));
})
});
}
Expand Down
17 changes: 8 additions & 9 deletions benches/core/vector.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
use na::{DVector, SVector, Vector2, Vector3, Vector4};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
use typenum::U10000;

#[path = "../common/macros.rs"]
mod macros;
Expand Down Expand Up @@ -45,8 +44,8 @@ bench_unop!(vec2_normalize, Vector2<f32>, normalize);
bench_unop!(vec3_normalize, Vector3<f32>, normalize);
bench_unop!(vec4_normalize, Vector4<f32>, normalize);

bench_binop_ref!(vec10000_dot_f64, VectorN<f64, U10000>, VectorN<f64, U10000>, dot);
bench_binop_ref!(vec10000_dot_f32, VectorN<f32, U10000>, VectorN<f32, U10000>, dot);
bench_binop_ref!(vec10000_dot_f64, SVector<f64, 10000>, SVector<f64, 10000>, dot);
bench_binop_ref!(vec10000_dot_f32, SVector<f32, 10000>, SVector<f32, 10000>, dot);

fn vec10000_axpy_f64(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
Expand Down Expand Up @@ -82,8 +81,8 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {

bh.bench_function("vec10000_axpy_f64_slice", move |bh| {
bh.iter(|| {
let mut a = a.fixed_rows_mut::<U10000>(0);
let b = b.fixed_rows::<U10000>(0);
let mut a = a.fixed_rows_mut::<10000>(0);
let b = b.fixed_rows::<10000>(0);

a.axpy(n, &b, 1.0)
})
Expand All @@ -93,11 +92,11 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let mut a = VectorN::<f64, U10000>::new_random();
let b = VectorN::<f64, U10000>::new_random();
let mut a = SVector::<f64, 10000>::new_random();
let b = SVector::<f64, 10000>::new_random();
let n = rng.gen::<f64>();

// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)).
// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(OVector...)).
bh.bench_function("vec10000_axpy_f64_static", move |bh| {
bh.iter(|| a.axpy(n, &b, 1.0))
});
Expand Down
5 changes: 1 addition & 4 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
#![allow(unused_macros)]

extern crate nalgebra as na;
extern crate rand;
extern crate rand_isaac;
extern crate test;
extern crate typenum;
extern crate rand_package as rand;

#[macro_use]
extern crate criterion;
Expand Down
10 changes: 5 additions & 5 deletions benches/linalg/bidiagonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ mod macros;
fn bidiagonalize_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("bidiagonalize_100x100", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

fn bidiagonalize_100x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 500);
bh.bench_function("bidiagonalize_100x500", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

fn bidiagonalize_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("bidiagonalize_4x4", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

fn bidiagonalize_500x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 100);
bh.bench_function("bidiagonalize_500x100", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

fn bidiagonalize_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("bidiagonalize_500x500", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

Expand Down
4 changes: 2 additions & 2 deletions benches/linalg/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn cholesky_100x100(bh: &mut criterion::Criterion) {
let m = &m * m.transpose();

bh.bench_function("cholesky_100x100", move |bh| {
bh.iter(|| test::black_box(Cholesky::new(m.clone())))
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
});
}

Expand All @@ -14,7 +14,7 @@ fn cholesky_500x500(bh: &mut criterion::Criterion) {
let m = &m * m.transpose();

bh.bench_function("cholesky_500x500", move |bh| {
bh.iter(|| test::black_box(Cholesky::new(m.clone())))
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
});
}

Expand Down
18 changes: 9 additions & 9 deletions benches/linalg/full_piv_lu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use na::{DMatrix, DVector, FullPivLU};
fn full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(10, 10);
bh.bench_function("full_piv_lu_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}

fn full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("full_piv_lu_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}

fn full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("full_piv_lu_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}

Expand Down Expand Up @@ -63,7 +63,7 @@ fn full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -72,7 +72,7 @@ fn full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -81,7 +81,7 @@ fn full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_inverse_500x500", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -90,7 +90,7 @@ fn full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_determinant_10x10", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

Expand All @@ -99,7 +99,7 @@ fn full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_determinant_100x100", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

Expand All @@ -108,7 +108,7 @@ fn full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());

bh.bench_function("full_piv_lu_determinant_500x500", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

Expand Down
8 changes: 4 additions & 4 deletions benches/linalg/hessenberg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ mod macros;
fn hessenberg_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("hessenberg_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}

fn hessenberg_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("hessenberg_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}

fn hessenberg_decompose_200x200(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(200, 200);
bh.bench_function("hessenberg_decompose_200x200", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}

fn hessenberg_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("hessenberg_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}

Expand Down
20 changes: 11 additions & 9 deletions benches/linalg/lu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use na::{DMatrix, DVector, LU};
fn lu_decompose_10x10(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(10, 10);
bh.bench_function("lu_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}

fn lu_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("lu_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}

fn lu_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("lu_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}

Expand Down Expand Up @@ -63,7 +63,7 @@ fn lu_inverse_10x10(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());

bh.bench_function("lu_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -72,7 +72,7 @@ fn lu_inverse_100x100(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());

bh.bench_function("lu_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -81,7 +81,7 @@ fn lu_inverse_500x500(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());

bh.bench_function("lu_inverse_500x500", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}

Expand All @@ -90,7 +90,7 @@ fn lu_determinant_10x10(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());

bh.bench_function("lu_determinant_10x10", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

Expand All @@ -99,15 +99,17 @@ fn lu_determinant_100x100(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());

bh.bench_function("lu_determinant_100x100", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

fn lu_determinant_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
let lu = LU::new(m.clone());

bh.bench_function("", move |bh| bh.iter(|| test::black_box(lu.determinant())));
bh.bench_function("", move |bh| {
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

criterion_group!(
Expand Down
Loading