Skip to content

Commit

Permalink
Merge pull request #567 from rustsim/complex
Browse files Browse the repository at this point in the history
Complex number support
  • Loading branch information
sebcrozet committed Mar 31, 2019
2 parents 1e04053 + 94a8bab commit 31bc336
Show file tree
Hide file tree
Showing 220 changed files with 4,980 additions and 3,745 deletions.
18 changes: 16 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "nalgebra"
version = "0.17.2"
version = "0.17.3"
authors = [ "Sébastien Crozet <developer@crozet.re>" ]

description = "Linear algebra library with transformations and statically-sized or dynamically-sized matrices."
Expand All @@ -11,6 +11,7 @@ readme = "README.md"
categories = [ "science" ]
keywords = [ "linear", "algebra", "matrix", "vector", "math" ]
license = "BSD-3-Clause"
edition = "2018"

exclude = ["/ci/*", "/.travis.yml", "/Makefile"]

Expand All @@ -26,7 +27,7 @@ arbitrary = [ "quickcheck" ]
serde-serialize = [ "serde", "serde_derive", "num-complex/serde" ]
abomonation-serialize = [ "abomonation" ]
sparse = [ ]
debug = [ ]
debug = [ "approx/num-complex", "rand/std" ]
alloc = [ ]
io = [ "pest", "pest_derive" ]

Expand All @@ -53,6 +54,19 @@ alga = { git = "https://github.com/rustsim/alga", branch = "dev" }
[dev-dependencies]
serde_json = "1.0"
rand_xorshift = "0.1"
### Uncomment this line before running benchmarks.
### We can't just let this uncommented because that would breack
### compilation for #[no-std] because of the terrible Cargo bug
### https://github.com/rust-lang/cargo/issues/4866
#criterion = "0.2.10"

[workspace]
members = [ "nalgebra-lapack", "nalgebra-glm" ]

[[bench]]
name = "nalgebra_bench"
harness = false
path = "benches/lib.rs"

[profile.bench]
lto = true
42 changes: 18 additions & 24 deletions benches/common/macros.rs
Expand Up @@ -2,56 +2,52 @@

macro_rules! bench_binop(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
a.$binop(b)
})
}));
}
}
);

macro_rules! bench_binop_ref(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
a.$binop(&b)
})
}));
}
}
);

macro_rules! bench_binop_fn(
($name: ident, $t1: ty, $t2: ty, $binop: path) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let a = rng.gen::<$t1>();
let b = rng.gen::<$t2>();

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
$binop(&a, &b)
})
}));
}
}
);

macro_rules! bench_unop_na(
($name: ident, $t: ty, $unop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
const LEN: usize = 1 << 13;

use rand::SeedableRng;
Expand All @@ -60,21 +56,20 @@ macro_rules! bench_unop_na(
let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0;

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
i = (i + 1) & (LEN - 1);

unsafe {
test::black_box(na::$unop(elems.get_unchecked(i)))
}
})
}));
}
}
);

macro_rules! bench_unop(
($name: ident, $t: ty, $unop: ident) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
const LEN: usize = 1 << 13;

use rand::SeedableRng;
Expand All @@ -83,21 +78,20 @@ macro_rules! bench_unop(
let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0;

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
i = (i + 1) & (LEN - 1);

unsafe {
test::black_box(elems.get_unchecked_mut(i).$unop())
}
})
}));
}
}
);

macro_rules! bench_construction(
($name: ident, $constructor: path, $( $args: ident: $types: ty),*) => {
#[bench]
fn $name(bh: &mut Bencher) {
fn $name(bh: &mut criterion::Criterion) {
const LEN: usize = 1 << 13;

use rand::SeedableRng;
Expand All @@ -106,14 +100,14 @@ macro_rules! bench_construction(
$(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.gen::<$types>()).collect();)*
let mut i = 0;

bh.iter(|| {
bh.bench_function(stringify!($name), move |bh| bh.iter(|| {
i = (i + 1) & (LEN - 1);

unsafe {
let res = $constructor($(*$args.get_unchecked(i),)*);
test::black_box(res)
}
})
}));
}
}
);

0 comments on commit 31bc336

Please sign in to comment.