From 6300d343566390120defa1190e84e92a457d31c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 13 Jun 2020 10:06:48 +0200 Subject: [PATCH 1/6] Add the ::ith constructor for vectors. This initializes a vectors to zero except the i-th element set to a given value. --- src/base/construction.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/base/construction.rs b/src/base/construction.rs index ae8c10d49..f810acdf2 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -1011,6 +1011,14 @@ where N: Scalar + Zero + One, DefaultAllocator: Allocator, { + /// The column vector with `val` as its i-th component. + #[inline] + pub fn ith(i: usize, val: N) -> Self { + let mut res = Self::zeros(); + res[i] = val; + res + } + /// The column vector with a 1 as its first component, and zero elsewhere. #[inline] pub fn x() -> Self From 7c69cbf3261bb6e30cd3bf8aaf4f44bf7edbc47f Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Sun, 12 Jul 2020 10:47:16 +0200 Subject: [PATCH 2/6] Don't depend on serde_derive explicitly. --- Cargo.toml | 5 ++--- src/lib.rs | 14 ++++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7ea6f8bad..d7576d62e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ default = [ "std" ] std = [ "matrixmultiply", "rand/std", "rand_distr", "simba/std" ] stdweb = [ "rand/stdweb" ] arbitrary = [ "quickcheck" ] -serde-serialize = [ "serde", "serde_derive", "num-complex/serde" ] +serde-serialize = [ "serde", "num-complex/serde" ] abomonation-serialize = [ "abomonation" ] sparse = [ ] debug = [ "approx/num-complex", "rand/std" ] @@ -44,8 +44,7 @@ simba = { version = "0.1", default-features = false } alga = { version = "0.9", default-features = false, optional = true } rand_distr = { version = "0.2", optional = true } matrixmultiply = { version = "0.2", optional = true } -serde = { version = "1.0", optional = true } -serde_derive = { version = "1.0", optional = true } +serde = { version = "1.0", features = [ "derive" ], optional = true } abomonation = { version = "0.7", optional = true } mint = { version = "0.5", optional = true } quickcheck = { version = "0.9", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 9db176bfd..fbc0a27da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,11 +90,9 @@ an optimized set of tools for computer graphics and physics. Those features incl #[cfg(feature = "arbitrary")] extern crate quickcheck; -#[cfg(feature = "serde")] -extern crate serde; -#[cfg(feature = "serde")] +#[cfg(feature = "serde-serialize")] #[macro_use] -extern crate serde_derive; +extern crate serde; #[cfg(feature = "abomonation-serialize")] extern crate abomonation; @@ -190,9 +188,7 @@ pub fn zero() -> T { /// The range must not be empty. #[inline] pub fn wrap(mut val: T, min: T, max: T) -> T -where - T: Copy + PartialOrd + ClosedAdd + ClosedSub, -{ +where T: Copy + PartialOrd + ClosedAdd + ClosedSub { assert!(min < max, "Invalid wrapping bounds."); let width = max - min; @@ -392,9 +388,7 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// * [distance_squared](fn.distance_squared.html) #[inline] pub fn center(p1: &Point, p2: &Point) -> Point -where - DefaultAllocator: Allocator, -{ +where DefaultAllocator: Allocator { ((&p1.coords + &p2.coords) * convert::<_, N>(0.5)).into() } From 46d1cf22314f85cc4f8ad83481b61c090a8ab3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 25 Aug 2020 20:44:03 +0200 Subject: [PATCH 3/6] Add a libm and libm-force feature to transitively enable the corresponding simba feature. --- Cargo.toml | 6 +++--- src/linalg/mod.rs | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7576d62e..9ed76264c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,9 @@ debug = [ "approx/num-complex", "rand/std" ] alloc = [ ] io = [ "pest", "pest_derive" ] compare = [ "matrixcompare-core" ] +libm = [ "simba/libm" ] +libm-force = [ "simba/libm_force" ] + [dependencies] typenum = "1.11" @@ -75,6 +78,3 @@ path = "benches/lib.rs" [profile.bench] lto = true - -#[patch.crates-io] -#simba = { path = "../simba" } \ No newline at end of file diff --git a/src/linalg/mod.rs b/src/linalg/mod.rs index f96cef0c3..4a1edbcf6 100644 --- a/src/linalg/mod.rs +++ b/src/linalg/mod.rs @@ -5,6 +5,10 @@ mod bidiagonal; mod cholesky; mod convolution; mod determinant; +// FIXME: this should not be needed. However, the exp uses +// explicit float operations on `f32` and `f64`. We need to +// get rid of these to allow exp to be used on a no-std context. +#[cfg(feature = "std")] mod exp; mod full_piv_lu; pub mod givens; @@ -27,6 +31,7 @@ mod symmetric_tridiagonal; pub use self::bidiagonal::*; pub use self::cholesky::*; pub use self::convolution::*; +#[cfg(feature = "std")] pub use self::exp::*; pub use self::full_piv_lu::*; pub use self::hessenberg::*; From a6962dfadcefb4b45279760c5e2b3e5ce783347c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 25 Aug 2020 20:45:25 +0200 Subject: [PATCH 4/6] Bump the simba dependency version. --- Cargo.toml | 2 +- nalgebra-glm/Cargo.toml | 2 +- nalgebra-lapack/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ed76264c..6705c2225 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ num-traits = { version = "0.2", default-features = false } num-complex = { version = "0.2", default-features = false } num-rational = { version = "0.2", default-features = false } approx = { version = "0.3", default-features = false } -simba = { version = "0.1", default-features = false } +simba = { version = "0.2", default-features = false } alga = { version = "0.9", default-features = false, optional = true } rand_distr = { version = "0.2", optional = true } matrixmultiply = { version = "0.2", optional = true } diff --git a/nalgebra-glm/Cargo.toml b/nalgebra-glm/Cargo.toml index b72e2988a..2bc296136 100644 --- a/nalgebra-glm/Cargo.toml +++ b/nalgebra-glm/Cargo.toml @@ -24,5 +24,5 @@ abomonation-serialize = [ "nalgebra/abomonation-serialize" ] [dependencies] num-traits = { version = "0.2", default-features = false } approx = { version = "0.3", default-features = false } -simba = { version = "0.1", default-features = false } +simba = { version = "0.2", default-features = false } nalgebra = { path = "..", version = "0.21", default-features = false } diff --git a/nalgebra-lapack/Cargo.toml b/nalgebra-lapack/Cargo.toml index b262e8b93..712c19e7c 100644 --- a/nalgebra-lapack/Cargo.toml +++ b/nalgebra-lapack/Cargo.toml @@ -26,7 +26,7 @@ intel-mkl = ["lapack-src/intel-mkl"] nalgebra = { version = "0.21", path = ".." } num-traits = "0.2" num-complex = { version = "0.2", default-features = false } -simba = "0.1" +simba = "0.2" serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } lapack = { version = "0.16", default-features = false } From a8f73cb7b20fd67cd6caccf439b32211e98e762b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 25 Aug 2020 20:47:07 +0200 Subject: [PATCH 5/6] Run cargo fmt. --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fbc0a27da..681163340 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,7 +188,9 @@ pub fn zero() -> T { /// The range must not be empty. #[inline] pub fn wrap(mut val: T, min: T, max: T) -> T -where T: Copy + PartialOrd + ClosedAdd + ClosedSub { +where + T: Copy + PartialOrd + ClosedAdd + ClosedSub, +{ assert!(min < max, "Invalid wrapping bounds."); let width = max - min; @@ -388,7 +390,9 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// * [distance_squared](fn.distance_squared.html) #[inline] pub fn center(p1: &Point, p2: &Point) -> Point -where DefaultAllocator: Allocator { +where + DefaultAllocator: Allocator, +{ ((&p1.coords + &p2.coords) * convert::<_, N>(0.5)).into() } From b96181f6c40ed0a4b95f5c54b0824ef81796157b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 25 Aug 2020 21:04:37 +0200 Subject: [PATCH 6/6] CI: don't eanble --all-features when running the tests. This would enable the libm_force feature which results in less accurate results causing some tests to fail. --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ee64d7717..b21798d97 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,10 +47,10 @@ jobs: - checkout - run: name: test - command: cargo test --all-features + command: cargo test --features arbitrary --features serde-serialize --features abomonation-serialize --features sparse --features debug --features io --features compare --features libm - run: name: test nalgebra-glm - command: cargo test -p nalgebra-glm --all-features + command: cargo test -p nalgebra-glm --features arbitrary --features serde-serialize --features abomonation-serialize --features sparse --features debug --features io --features compare --features libm build-wasm: executor: rust-executor steps: