From 6091b267fd9cae1fbbc28feb3ccf2181385fe728 Mon Sep 17 00:00:00 2001 From: hauke strasdat Date: Fri, 10 Nov 2023 09:02:40 -0800 Subject: [PATCH 1/2] update dfdx to latest / rebased --- .gitmodules | 0 Cargo.lock | 220 +++++++++++++++++++---- Cargo.toml | 2 +- src/calculus/batch_types.rs | 22 +-- src/calculus/curves.rs | 8 +- src/calculus/make.rs | 2 +- src/calculus/matrix_valued_maps.rs | 4 +- src/calculus/points.rs | 20 +-- src/calculus/region.rs | 10 +- src/calculus/scalar_valued_maps.rs | 4 +- src/calculus/tensor_asserts.rs | 34 ++-- src/calculus/vector_valued_maps.rs | 4 +- src/lie/group.rs | 6 +- src/lie/isometry2.rs | 2 +- src/lie/isometry3.rs | 2 +- src/lie/rotation2.rs | 18 +- src/lie/rotation3.rs | 12 +- src/lie/traits.rs | 2 +- src/lie/translation_group_product.rs | 6 +- src/manifold/traits.rs | 8 +- src/opt/block.rs | 2 +- src/opt/cost_args.rs | 10 +- src/opt/example_problems/simple_prior.rs | 4 +- 23 files changed, 277 insertions(+), 125 deletions(-) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/Cargo.lock b/Cargo.lock index b921968..0f958bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,9 +86,23 @@ checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" [[package]] name = "bytemuck" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] [[package]] name = "byteorder" @@ -168,17 +182,16 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "cudarc" -version = "0.9.13" +version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d03df00acea5c14967753a8c94275df7ef311fd9c5afe5984858ac8bbef0ad" +checksum = "f1871a911a2b9a3f66a285896a719159985683bf9903aa2cf89e0c9f53e14552" [[package]] -name = "dfdx" +name = "dfdx-core" version = "0.13.0" -source = "git+https://github.com/farm-ng/dfdx#ac85e1c991334ee93c21fb40ee499f7750338bb6" dependencies = [ "cudarc", - "gemm", + "gemm 0.16.14", "libm", "num-traits", "rand", @@ -196,6 +209,16 @@ dependencies = [ "reborrow", ] +[[package]] +name = "dyn-stack" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e53799688f5632f364f8fb387488dd05db9fe45db7011be066fc20e7027f8b" +dependencies = [ + "bytemuck", + "reborrow", +] + [[package]] name = "either" version = "1.9.0" @@ -245,11 +268,11 @@ dependencies = [ "assert2", "bytemuck", "coe-rs", - "dyn-stack", - "gemm", + "dyn-stack 0.9.0", + "gemm 0.15.4", "num-complex 0.4.3", "num-traits", - "pulp", + "pulp 0.13.1", "rayon", "reborrow", "seq-macro", @@ -261,13 +284,13 @@ version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf05244e1ab5f098f2303bb1cedc1d7ca17e8cb9cb8b08040c8233cf10fc6ec" dependencies = [ - "dyn-stack", - "gemm-c32", - "gemm-c64", - "gemm-common", - "gemm-f16", - "gemm-f32", - "gemm-f64", + "dyn-stack 0.9.0", + "gemm-c32 0.15.4", + "gemm-c64 0.15.4", + "gemm-common 0.15.4", + "gemm-f16 0.15.4", + "gemm-f32 0.15.4", + "gemm-f64 0.15.4", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -277,14 +300,34 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c90e866771c2adff6c4603108bb531ea36979b62a23b5e193b9311199182ccc9" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-c32 0.16.14", + "gemm-c64 0.16.14", + "gemm-common 0.16.14", + "gemm-f16 0.16.14", + "gemm-f32 0.16.14", + "gemm-f64 0.16.14", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "seq-macro", +] + [[package]] name = "gemm-c32" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d84942bd86c6e176f33f80d96311e078097cd93039cc5feec1b43ddefae749f" dependencies = [ - "dyn-stack", - "gemm-common", + "dyn-stack 0.9.0", + "gemm-common 0.15.4", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -294,14 +337,29 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-c32" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5ffc8e9a442172ec223d4e536f93b59f1d2b34164b37e462e6886d76699e71" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-common 0.16.14", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "seq-macro", +] + [[package]] name = "gemm-c64" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2bcdc95440f12836640e8fd4df0050a2c4b34a0c01d92f8050ae886557761fc" dependencies = [ - "dyn-stack", - "gemm-common", + "dyn-stack 0.9.0", + "gemm-common 0.15.4", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -311,13 +369,28 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-c64" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45cd8172c8ee8beed35cdb7254bec535ddc83cde78d2eeefeae43cfd57fef3d8" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-common 0.16.14", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "seq-macro", +] + [[package]] name = "gemm-common" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "912249fe0356806062ab2672c9cf340521732ef8d317d851d122ae6922ddd71c" dependencies = [ - "dyn-stack", + "dyn-stack 0.9.0", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -327,15 +400,34 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-common" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c022dd4893afa781d1ba9912796af63a9a91ac8d8fdadd449483bbabaf7c47c6" +dependencies = [ + "bytemuck", + "dyn-stack 0.10.0", + "half", + "num-complex 0.4.3", + "num-traits", + "once_cell", + "paste", + "pulp 0.16.4", + "raw-cpuid", + "rayon", + "seq-macro", +] + [[package]] name = "gemm-f16" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6820d54fd53eead15a3024c06f403a1eb082a77e0670eb78d89ad22d6f5ad9a" dependencies = [ - "dyn-stack", - "gemm-common", - "gemm-f32", + "dyn-stack 0.9.0", + "gemm-common 0.15.4", + "gemm-f32 0.15.4", "half", "lazy_static", "num-complex 0.4.3", @@ -346,14 +438,32 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-f16" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efb4c26de6ddd1125d966dffa48eb609448566a2bd2dd589ea2798f17f689b5" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-common 0.16.14", + "gemm-f32 0.16.14", + "half", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "rayon", + "seq-macro", +] + [[package]] name = "gemm-f32" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc60558103e48ad7c953cee1334c30f3efb47f63105882ff6346d7418a6ca2fc" dependencies = [ - "dyn-stack", - "gemm-common", + "dyn-stack 0.9.0", + "gemm-common 0.15.4", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -363,14 +473,29 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-f32" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a78fca5a0ef41202015e099e45e0bdda83e7f49318de3322d58c215a3fec334a" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-common 0.16.14", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "seq-macro", +] + [[package]] name = "gemm-f64" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e7cf971e94e5e86729881f1a9b6d4e55a74207daf5f466a936d6ab4e014a861" dependencies = [ - "dyn-stack", - "gemm-common", + "dyn-stack 0.9.0", + "gemm-common 0.15.4", "lazy_static", "num-complex 0.4.3", "num-traits", @@ -380,6 +505,21 @@ dependencies = [ "seq-macro", ] +[[package]] +name = "gemm-f64" +version = "0.16.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f18516a29ab14fa4b1714c93ffa36a89a65418f0a2fba702206d4b421061b48" +dependencies = [ + "dyn-stack 0.10.0", + "gemm-common 0.16.14", + "num-complex 0.4.3", + "num-traits", + "paste", + "raw-cpuid", + "seq-macro", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -397,6 +537,7 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" dependencies = [ + "bytemuck", "cfg-if", "crunchy", "num-traits", @@ -433,9 +574,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libm" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" @@ -545,9 +686,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", "libm", @@ -617,6 +758,17 @@ dependencies = [ "num-complex 0.4.3", ] +[[package]] +name = "pulp" +version = "0.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb0a2934e77dd9aabb33fedcd3bf6ea1d6d3cacd4c5bc07b9a916f7b101c6b7" +dependencies = [ + "bytemuck", + "libm", + "num-complex 0.4.3", +] + [[package]] name = "quote" version = "1.0.32" @@ -798,7 +950,7 @@ version = "0.1.0" dependencies = [ "approx 0.5.1", "assertables", - "dfdx", + "dfdx-core", "enum_dispatch", "faer-core", "nalgebra", diff --git a/Cargo.toml b/Cargo.toml index 1fd0fee..969163a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ num-traits = "0.2.15" nalgebra = "0.32" approx = "0.5.1" enum_dispatch = "0.3.6" -dfdx = { git = "https://github.com/farm-ng/dfdx" } +dfdx-core = { path = "../dfdx/dfdx-core" } tuple_list = "0.1.3" sprs = "0.11" sprs-ldl = "0.10" diff --git a/src/calculus/batch_types.rs b/src/calculus/batch_types.rs index 3ef45eb..3b6e096 100644 --- a/src/calculus/batch_types.rs +++ b/src/calculus/batch_types.rs @@ -1,8 +1,8 @@ -use dfdx::{shapes::*, tensor::*}; +use dfdx_core::{shapes::*, tensor::*}; pub type SharedTape = std::sync::Arc>>; -pub trait SophusTape :dfdx::tensor::Tape + std::fmt::Debug + Clone{ +pub trait SophusTape :dfdx_core::tensor::Tape + std::fmt::Debug + Clone{ } impl SophusTape for NoneTape {} @@ -51,7 +51,7 @@ pub type GenVFromM< const OUTROWS: usize, const OUTCOLS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; // Batched vector-valued function from matrix - with generic tape: rank4 tensor // f_b: rank2 -> rank1; M_b := f(V_b) [b in 0..BATCH] pub type GenFromV< @@ -60,7 +60,7 @@ pub type GenFromV< const INCOLS: usize, const OUTROWS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; // Batched vector-valued function from matrix - with generic tape: rank5 tensor // f_b: rank2 -> rank2; M_b := f(M_b) [b in 0..BATCH] pub type GenMFromM< @@ -70,7 +70,7 @@ pub type GenMFromM< const OUTROWS: usize, const OUTCOLS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; // Batched vector-valued function from vector - with generic tape; rank3 tensor // f_b: rank1 -> rank1; V_b := f(V_b) [b in 0..BATCH] @@ -83,7 +83,7 @@ pub type VFromM< const INROWS: usize, const OUTROWS: usize, const OUTCOLS: usize, -> = Tensor, f64, Cpu, NoneTape>; +> = Tensor, f64, Cpu, NoneTape>; // Batched vector-valued function from matrix - with generic tape: rank4 tensor // f_b: rank2 -> rank1; M_b := f(V_b) [b in 0..BATCH] pub type MFromV< @@ -91,7 +91,7 @@ pub type MFromV< const INROWS: usize, const INCOLS: usize, const OUTROWS: usize, -> = Tensor, f64, Cpu, NoneTape>; +> = Tensor, f64, Cpu, NoneTape>; // Batched vector-valued function from matrix - with generic tape: rank4 tensor // f_b: rank2 -> rank2; M_b := f(M_b) [b in 0..BATCH] pub type MFromM< @@ -100,7 +100,7 @@ pub type MFromM< const INCOLS: usize, const OUTROWS: usize, const OUTCOLS: usize, -> = Tensor, f64, Cpu, NoneTape>; +> = Tensor, f64, Cpu, NoneTape>; // Batched vector-valued function from vector - with tape; rank3 tensor // f_b: rank1 -> rank1; V_b := f(V_b) [b in 0..BATCH] @@ -118,7 +118,7 @@ pub type TapedVFromM< const OUTROWS: usize, const OUTCOLS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; // Batched vector-valued function from matrix - with tape: rank4 tensor // f_b: rank2 -> rank1; M_b := f(V_b) [b in 0..BATCH] pub type TapedFromV< @@ -127,7 +127,7 @@ pub type TapedFromV< const INCOLS: usize, const OUTROWS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; // Batched vector-valued function from matrix - with tape: rank5 tensor // f_b: rank2 -> rank2; M_b := f(M_b) [b in 0..BATCH] pub type TapedMFromM< @@ -137,7 +137,7 @@ pub type TapedMFromM< const OUTROWS: usize, const OUTCOLS: usize, MaybeTape, -> = Tensor, f64, Cpu, MaybeTape>; +> = Tensor, f64, Cpu, MaybeTape>; pub type IV = Tensor, i64, Cpu>; diff --git a/src/calculus/curves.rs b/src/calculus/curves.rs index 2c2a806..740262a 100644 --- a/src/calculus/curves.rs +++ b/src/calculus/curves.rs @@ -1,5 +1,5 @@ use super::batch_types::*; -use dfdx::prelude::*; +use dfdx_core::prelude::*; // A smooth curve in ℝ. // // This is a function which takes a scalar and returns a scalar: @@ -185,7 +185,7 @@ mod test { use super::ScalarValuedCurve; use crate::{assert_tensors_relative_eq_rank1, calculus::curves::*}; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); const BATCH: usize = 4; @@ -213,7 +213,7 @@ mod test { use crate::calculus::make::*; use crate::{assert_tensors_relative_eq_rank2, calculus::curves::*}; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); const BATCH: usize = 4; @@ -242,7 +242,7 @@ mod test { use crate::calculus::make::*; use crate::{assert_tensors_relative_eq_rank3, calculus::curves::*}; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); const BATCH: usize = 4; diff --git a/src/calculus/make.rs b/src/calculus/make.rs index bbbb9fc..4bf083c 100644 --- a/src/calculus/make.rs +++ b/src/calculus/make.rs @@ -1,4 +1,4 @@ -use dfdx::{shapes::*, tensor::*, tensor_ops::*}; +use dfdx_core::{shapes::*, tensor::*, tensor_ops::*}; use super::batch_types::*; diff --git a/src/calculus/matrix_valued_maps.rs b/src/calculus/matrix_valued_maps.rs index 9afb5dd..03844d9 100644 --- a/src/calculus/matrix_valued_maps.rs +++ b/src/calculus/matrix_valued_maps.rs @@ -2,7 +2,7 @@ use super::{ make::*, vector_valued_maps::*, batch_types::*, }; -use dfdx::{shapes::*, tensor::*, tensor_ops::*}; +use dfdx_core::{shapes::*, tensor::*, tensor_ops::*}; // Matrix-valued map on a vector space. // @@ -288,7 +288,7 @@ mod test { use crate::assert_tensors_relative_eq_rank5; use super::*; - use dfdx::tensor::Cpu; + use dfdx_core::tensor::Cpu; #[allow(dead_code)] fn test_batched_matrix_valued_map_from_vector() { diff --git a/src/calculus/points.rs b/src/calculus/points.rs index 989cf57..3a221ca 100644 --- a/src/calculus/points.rs +++ b/src/calculus/points.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use num_traits::Bounded; use super::{batch_types::*, make::*}; @@ -24,13 +24,13 @@ impl PointTraits for V { fn smallest() -> Self { let s: f64 = f64::min_value(); - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); dev.ones() * s } fn largest() -> Self { let l: f64 = f64::max_value(); - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); dev.ones() * l } } @@ -46,17 +46,17 @@ impl PointTraits for IV fn smallest() -> Self { let s: i64 = i64::min_value(); - dfdx::tensor::Cpu::default().tensor([[s; D]; BATCH]) + dfdx_core::tensor::Cpu::default().tensor([[s; D]; BATCH]) } fn largest() -> Self { let l: i64 = i64::max_value(); - dfdx::tensor::Cpu::default().tensor([[l; D]; BATCH]) + dfdx_core::tensor::Cpu::default().tensor([[l; D]; BATCH]) } } pub fn tutil_point_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![ dev.zeros(), dev.ones() * 0.5, @@ -68,7 +68,7 @@ pub fn tutil_point_examples() -> Vec( ) -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![ dev.zeros(), dev.ones() * 0.5, @@ -103,7 +103,7 @@ pub fn cross, RhsTape: } pub fn unit_x() -> V { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let o: V = dev.zeros(); let l: V = dev.ones(); @@ -111,7 +111,7 @@ pub fn unit_x() -> V { } pub fn unit_y() -> V { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let o: V = dev.zeros(); let l: V = dev.ones(); @@ -119,7 +119,7 @@ pub fn unit_y() -> V { } pub fn unit_z() -> V { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let o: V = dev.zeros(); let l: V = dev.ones(); diff --git a/src/calculus/region.rs b/src/calculus/region.rs index de9a5a3..c2441ff 100644 --- a/src/calculus/region.rs +++ b/src/calculus/region.rs @@ -1,5 +1,5 @@ use super::{points::*, batch_types::*}; -use dfdx::{tensor::*, tensor_ops::*}; +use dfdx_core::{tensor::*, tensor_ops::*}; #[derive(Debug, Clone)] pub struct Region { @@ -120,7 +120,7 @@ impl RegionTraits for Region V { - let mut p: V = dfdx::tensor::Cpu::default().zeros(); + let mut p: V = dfdx_core::tensor::Cpu::default().zeros(); if self.is_empty() { return p; } @@ -211,7 +211,7 @@ impl RegionTraits for IRegion IV { - let mut p: IV = dfdx::tensor::Cpu::default().zeros(); + let mut p: IV = dfdx_core::tensor::Cpu::default().zeros(); if self.is_empty() { return p; } @@ -221,7 +221,7 @@ impl RegionTraits for IRegion IV { - let half_range = self.range().to_dtype() * 0.5; + let half_range = self.range().to_dtype::() * 0.5; (self.min().clone().to_dtype() + half_range).to_dtype() } @@ -240,7 +240,7 @@ mod tests { use super::*; fn batched_region() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let empty_f64 = Region::::empty(); assert!(empty_f64.is_empty()); diff --git a/src/calculus/scalar_valued_maps.rs b/src/calculus/scalar_valued_maps.rs index c8f7c71..b3f9a9e 100644 --- a/src/calculus/scalar_valued_maps.rs +++ b/src/calculus/scalar_valued_maps.rs @@ -1,5 +1,5 @@ use super::batch_types::*; -use dfdx::{shapes::*, tensor::*, tensor_ops::*}; +use dfdx_core::{shapes::*, tensor::*, tensor_ops::*}; // Scalar-valued map on a vector space. // @@ -177,7 +177,7 @@ mod test { use crate::calculus::make::*; use super::*; - use dfdx::tensor::Cpu; + use dfdx_core::tensor::Cpu; #[allow(dead_code)] fn test_batched_scalar_valued_map_from_vector() { diff --git a/src/calculus/tensor_asserts.rs b/src/calculus/tensor_asserts.rs index 51894da..4087361 100644 --- a/src/calculus/tensor_asserts.rs +++ b/src/calculus/tensor_asserts.rs @@ -1,4 +1,4 @@ -use dfdx::shapes::{Rank0, Rank1, Rank2, Rank3, Rank4, Rank5}; +use dfdx_core::shapes::{Rank0, Rank1, Rank2, Rank3, Rank4, Rank5}; pub trait ShapeRank { fn rank(&self) -> usize; @@ -90,7 +90,7 @@ macro_rules! assert_tensors_relative_eq_rank1 { ($t1:expr, $t2:expr, $eps:literal) => {{ use crate::calculus::tensor_asserts::ShapeRank; use approx::relative_eq; - use dfdx::shapes::HasShape; + use dfdx_core::shapes::HasShape; if !($t1.shape().dims() == $t2.shape().dims()) { panic!( "assert_tensors_relative_eq_rank1 FAILED: tensor shapes are not equal: {:?} != {:?}", @@ -127,7 +127,7 @@ macro_rules! assert_tensors_relative_eq_rank2 { ($t1:expr, $t2:expr, $eps:literal) => {{ use crate::calculus::tensor_asserts::ShapeRank; use approx::relative_eq; - use dfdx::shapes::HasShape; + use dfdx_core::shapes::HasShape; if !($t1.shape().dims() == $t2.shape().dims()) { panic!( "assert_tensors_relative_eq_rank2 FAILED: tensor shapes are not equal: {:?} != {:?}", @@ -168,7 +168,7 @@ macro_rules! assert_tensors_relative_eq_rank3 { ($t1:expr, $t2:expr, $eps:literal) => {{ use crate::calculus::tensor_asserts::ShapeRank; use approx::relative_eq; - use dfdx::shapes::HasShape; + use dfdx_core::shapes::HasShape; if !($t1.shape().dims() == $t2.shape().dims()) { panic!( "assert_tensors_relative_eq_rank3 FAILED: tensor shapes are not equal: {:?} != {:?}", @@ -212,7 +212,7 @@ macro_rules! assert_tensors_relative_eq_rank4 { ($t1:expr, $t2:expr, $eps:literal) => {{ use crate::calculus::tensor_asserts::ShapeRank; use approx::relative_eq; - use dfdx::shapes::HasShape; + use dfdx_core::shapes::HasShape; if !($t1.shape().dims() == $t2.shape().dims()) { panic!( "assert_tensors_relative_eq_rank4 FAILED: tensor shapes are not equal: {:?} != {:?}", @@ -257,7 +257,7 @@ macro_rules! assert_tensors_relative_eq_rank5 { ($t1:expr, $t2:expr, $eps:literal) => {{ use crate::calculus::tensor_asserts::ShapeRank; use approx::relative_eq; - use dfdx::shapes::HasShape; + use dfdx_core::shapes::HasShape; if !($t1.shape().dims() == $t2.shape().dims()) { panic!( "assert_tensors_relative_eq_rank5 FAILED: tensor shapes are not equal: {:?} != {:?}", @@ -304,12 +304,12 @@ macro_rules! assert_tensors_relative_eq_rank5 { mod tests { use super::*; use crate::assert_tensors_relative_eq_rank1; - use dfdx::prelude::*; + use dfdx_core::prelude::*; #[test] #[should_panic(expected = "assert_tensors_relative_eq_rank0 FAILED")] fn test_assert_tensors_relative_eq_rank0() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1 = dev.tensor(1.0); let t2 = dev.tensor(2.0); assert_tensors_relative_eq_rank0!(t1, t2, 0.00001); @@ -317,7 +317,7 @@ mod tests { #[test] fn test_assert_tensors_relative_eq_rank0_passes() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1 = dev.tensor(1.0); let t2 = dev.tensor(1.0); assert_tensors_relative_eq_rank0!(t1, t2, 0.00001); @@ -326,7 +326,7 @@ mod tests { #[test] #[should_panic(expected = "assert_tensors_relative_eq_rank1 FAILED")] fn test_assert_tensors_relative_eq_rank1() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1 = dev.tensor([1.0, 2.0, 3.0]); let t2 = dev.tensor([1.0, 2.0, 4.0]); assert_tensors_relative_eq_rank1!(t1, t2, 0.00001); @@ -334,7 +334,7 @@ mod tests { #[test] fn test_assert_tensors_relative_eq_rank1_passes() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1 = dev.tensor([1.0, 2.0, 3.0]); let t2 = dev.tensor([1.0, 2.0, 3.0]); assert_tensors_relative_eq_rank1!(t1, t2, 0.00001); @@ -343,7 +343,7 @@ mod tests { #[test] #[should_panic(expected = "assert_tensors_relative_eq_rank2 FAILED")] fn test_assert_tensors_relative_eq_rank2() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]); let t2: Tensor, f64, Cpu> = dev.tensor([[1.0, 2.0, 1.0], [4.0, 4.0, 1.0]]); assert_tensors_relative_eq_rank2!(t1, t2, 0.00001); @@ -351,7 +351,7 @@ mod tests { #[test] fn test_assert_tensors_relative_eq_rank2_passes() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]); let t2: Tensor, f64, Cpu> = dev.tensor([[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]); assert_tensors_relative_eq_rank2!(t1, t2, 0.00001); @@ -360,7 +360,7 @@ mod tests { #[test] #[should_panic(expected = "assert_tensors_relative_eq_rank3 FAILED")] fn test_assert_tensors_relative_eq_rank3() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]]); let t2: Tensor, f64, Cpu> = dev.tensor([[[1.0, 2.0, 1.0], [4.0, 4.0, 1.0]]]); assert_tensors_relative_eq_rank3!(t1, t2, 0.00001); @@ -368,7 +368,7 @@ mod tests { #[test] fn test_assert_tensors_relative_eq_rank3_passes() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]]); let t2: Tensor, f64, Cpu> = dev.tensor([[[1.0, 2.0, 1.0], [3.0, 4.0, 1.0]]]); assert_tensors_relative_eq_rank3!(t1, t2, 0.00001); @@ -377,7 +377,7 @@ mod tests { #[test] #[should_panic(expected = "assert_tensors_relative_eq_rank4 FAILED")] fn test_assert_tensors_relative_eq_rank4() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]]); let t2: Tensor, f64, Cpu> = @@ -387,7 +387,7 @@ mod tests { #[test] fn test_assert_tensors_relative_eq_rank4_passes() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let t1: Tensor, f64, Cpu> = dev.tensor([[[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]]); let t2: Tensor, f64, Cpu> = diff --git a/src/calculus/vector_valued_maps.rs b/src/calculus/vector_valued_maps.rs index 85ddd70..a89709a 100644 --- a/src/calculus/vector_valued_maps.rs +++ b/src/calculus/vector_valued_maps.rs @@ -2,7 +2,7 @@ use super::{ scalar_valued_maps::*, batch_types::*, }; -use dfdx::{shapes::*, tensor::*, tensor_ops::*}; +use dfdx_core::{shapes::*, tensor::*, tensor_ops::*}; // Vector-valued map on a vector space. // @@ -210,7 +210,7 @@ mod test { use crate::*; use crate::calculus::batch_types::*; use super::*; - use dfdx::tensor::Cpu; + use dfdx_core::tensor::Cpu; #[allow(dead_code)] fn test_batched_vector_valued_map_from_vector() { diff --git a/src/lie/group.rs b/src/lie/group.rs index 2f27577..5ca6d20 100644 --- a/src/lie/group.rs +++ b/src/lie/group.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::matrix_valued_maps::*; @@ -197,7 +197,7 @@ impl< } fn test_preservability() { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); if G::IS_ORIGIN_PRESERVING { for g in Self::tutil_element_examples() { let o: M = dev.zeros(); @@ -571,7 +571,7 @@ impl< // // TODO: reactivate this // pub fn exp_jacobian_tests() { -// let device = dfdx::tensor::Cpu::default(); +// let device = dfdx_core::tensor::Cpu::default(); // let dxfx = Self::dx_exp_x_at_0(); // for b in 0..B { diff --git a/src/lie/isometry2.rs b/src/lie/isometry2.rs index b9d4cb7..556adf4 100644 --- a/src/lie/isometry2.rs +++ b/src/lie/isometry2.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::make::*; diff --git a/src/lie/isometry3.rs b/src/lie/isometry3.rs index 6d6c555..504b404 100644 --- a/src/lie/isometry3.rs +++ b/src/lie/isometry3.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::points::*; diff --git a/src/lie/rotation2.rs b/src/lie/rotation2.rs index 5fb82a1..dc6cb39 100644 --- a/src/lie/rotation2.rs +++ b/src/lie/rotation2.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::make::*; @@ -19,7 +19,7 @@ impl ParamsTestUtils for Rotation2Impl { let mut params = vec![]; for i in 2..10 { let angle = Into::into(i as f64 * std::f64::consts::PI / 5.0); - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let mut batch = dev.zeros(); for i in 0..BATCH { batch[[i, 0]] = angle; @@ -31,7 +31,7 @@ impl ParamsTestUtils for Rotation2Impl { } fn tutil_invalid_params_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![dev.zeros(), dev.ones() * 0.5, dev.ones().negate() * 0.5] } } @@ -48,7 +48,7 @@ impl ParamsImpl for Rotation2Impl { impl TangentTestUtil for Rotation2Impl { fn tutil_tangent_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![ dev.zeros(), dev.ones(), @@ -70,7 +70,7 @@ impl LieGroupImplTrait for Rotation2Impl< fn identity_params() -> V { let zero = 0.0; let one = 1.0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); dev.tensor([one, zero]).broadcast() } @@ -87,7 +87,7 @@ impl LieGroupImplTrait for Rotation2Impl< fn into_log(params: GenV) -> GenV { let x = params.clone().slice((.., 0..1)); let y = params.slice((.., 1..2)); - y.atan2(x).realize() + atan2(y,x).realize() } fn hat(omega: GenV) -> GenM { @@ -166,11 +166,11 @@ impl LieGroupImplTrait for Rotation2Impl< } fn algebra_adjoint(_tangent: V) -> M { - dfdx::tensor::Cpu::default().zeros() + dfdx_core::tensor::Cpu::default().zeros() } fn dx_exp_x_at_0() -> M { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let zero: V = dev.zeros().retaped(); let one: V = dev.ones().retaped(); [zero, one].stack().permute::<_, Axes3<1, 0, 2>>() @@ -192,7 +192,7 @@ impl LieGroupImplTrait for Rotation2Impl< } fn dx_log_exp_x_times_self_at_0(_params: &V) -> M { - dfdx::tensor::Cpu::default().ones() + dfdx_core::tensor::Cpu::default().ones() } } diff --git a/src/lie/rotation3.rs b/src/lie/rotation3.rs index a1d9bbf..961b484 100644 --- a/src/lie/rotation3.rs +++ b/src/lie/rotation3.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::make::*; @@ -21,7 +21,7 @@ impl ParamsTestUtils for Rotation3Impl { fn tutil_params_examples() -> Vec> { let mut params = vec![]; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let o: V = dev.ones(); let l: V = dev.ones(); @@ -97,7 +97,7 @@ impl ParamsTestUtils for Rotation3Impl { } fn tutil_invalid_params_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![dev.zeros(), dev.ones() * 0.5, dev.ones().negate() * 0.5] } } @@ -114,7 +114,7 @@ impl ParamsImpl for Rotation3Impl { impl TangentTestUtil for Rotation3Impl { fn tutil_tangent_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); vec![ dev.zeros(), dev.ones(), @@ -136,7 +136,7 @@ impl LieGroupImplTrait for Rotation3Impl< fn identity_params() -> V { let zero = 0.0; let one = 1.0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); dev.tensor([zero, zero, zero, one]).broadcast() } @@ -185,7 +185,7 @@ impl LieGroupImplTrait for Rotation3Impl< let w_is_positive = w.le(1e-6); let mod_n = w_is_positive.clone().choose(n.clone(), n.clone().negate()); let mod_w = w_is_positive.choose(w.clone(), w.clone().negate()); - let atan_nbyw = mod_n.atan2(mod_w); + let atan_nbyw = atan2(mod_n, mod_w); let n_is_small = squared_n.le(1e-6); diff --git a/src/lie/traits.rs b/src/lie/traits.rs index 21ee807..217413d 100644 --- a/src/lie/traits.rs +++ b/src/lie/traits.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::batch_types::*; use crate::calculus::params::*; diff --git a/src/lie/translation_group_product.rs b/src/lie/translation_group_product.rs index d8f0934..2cc3470 100644 --- a/src/lie/translation_group_product.rs +++ b/src/lie/translation_group_product.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use crate::calculus::make::*; use crate::calculus::params::*; @@ -81,7 +81,7 @@ impl< } fn tutil_invalid_params_examples() -> Vec> { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); let mut examples = vec![]; for factor_group_params in Factor::tutil_invalid_params_examples() { @@ -220,7 +220,7 @@ impl< const IS_ORIGIN_PRESERVING: bool = false; fn identity_params() -> V { - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); Self::params_from(dev.zeros(), Factor::identity_params()) } diff --git a/src/manifold/traits.rs b/src/manifold/traits.rs index e213a3c..2e7e73b 100644 --- a/src/manifold/traits.rs +++ b/src/manifold/traits.rs @@ -1,5 +1,5 @@ -use dfdx::shapes::Unit; -use dfdx::tensor::NoneTape; +use dfdx_core::shapes::Unit; +use dfdx_core::tensor::NoneTape; use crate::calculus::batch_types::*; use crate::calculus::params::*; @@ -14,8 +14,8 @@ pub trait ManifoldImpl< const PARAMS: usize, const POINT: usize, const AMBIENT_DIM: usize, - D: dfdx::tensor::Storage, - Tape: dfdx::tensor::Tape, + D: dfdx_core::tensor::Storage, + Tape: dfdx_core::tensor::Tape, >: ParamsImpl + TangentTestUtil { fn oplus(params: &GenV, tangent: &GenV) diff --git a/src/opt/block.rs b/src/opt/block.rs index 7003627..a036df1 100644 --- a/src/opt/block.rs +++ b/src/opt/block.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; pub trait SophusAddAssign { // Required method diff --git a/src/opt/cost_args.rs b/src/opt/cost_args.rs index ead5f26..c6d6561 100644 --- a/src/opt/cost_args.rs +++ b/src/opt/cost_args.rs @@ -4,7 +4,7 @@ use std::mem::swap; use crate::calculus::batch_types::*; use crate::lie::isometry2::*; use crate::manifold::traits::*; -use dfdx::prelude::*; +use dfdx_core::prelude::*; //use sophus_macros::create_impl; #[derive(Copy, Clone, Debug)] @@ -145,7 +145,7 @@ impl ManifoldV for CostFnArg<1, V<1, 1>, AT> { fn update(&mut self, delta: &[f64]) { assert!(self.v.len() * Self::DOF == delta.len()); let mut i = 0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); for e in self.v.iter_mut() { let u: Tensor<(Const<1>, _), _, _> = dev.tensor_from_vec( delta[i * Self::DOF..(i + 1) * Self::DOF].to_vec(), @@ -176,7 +176,7 @@ impl ManifoldV for CostFnArg<2, V<1, 2>, AT> { fn update(&mut self, delta: &[f64]) { assert!(self.v.len() * Self::DOF == delta.len()); let mut i = 0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); for e in self.v.iter_mut() { let u: Tensor<(Const<1>, _), _, _> = dev.tensor_from_vec( delta[i * Self::DOF..(i + 1) * Self::DOF].to_vec(), @@ -208,7 +208,7 @@ impl ManifoldV for CostFnArg<3, V<1, 3>, AT> { fn update(&mut self, delta: &[f64]) { assert!(self.v.len() * Self::DOF == delta.len()); let mut i = 0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); for e in self.v.iter_mut() { let u: Tensor<(Const<1>, _), _, _> = dev.tensor_from_vec( delta[i * Self::DOF..(i + 1) * Self::DOF].to_vec(), @@ -240,7 +240,7 @@ impl ManifoldV for CostFnArg<3, Isometry2<1>, AT> { fn update(&mut self, delta: &[f64]) { assert!(self.v.len() * Self::DOF == delta.len()); let mut i = 0; - let dev = dfdx::tensor::Cpu::default(); + let dev = dfdx_core::tensor::Cpu::default(); for e in self.v.iter_mut() { let u: Tensor<(Const<1>, _), _, _> = dev.tensor_from_vec( delta[i * Self::DOF..(i + 1) * Self::DOF].to_vec(), diff --git a/src/opt/example_problems/simple_prior.rs b/src/opt/example_problems/simple_prior.rs index 6d4dc2e..b0c0463 100644 --- a/src/opt/example_problems/simple_prior.rs +++ b/src/opt/example_problems/simple_prior.rs @@ -1,4 +1,4 @@ -use dfdx::prelude::*; +use dfdx_core::prelude::*; use tuple_list::*; use crate::{ @@ -64,7 +64,7 @@ impl ResidualFn<6, 1> for SimplePrior { let residual: S<3> = residual.reshape(); - let zeros: V<1, 3> = dfdx::tensor::Cpu::default().zeros(); + let zeros: V<1, 3> = dfdx_core::tensor::Cpu::default().zeros(); let dx_res = VectorValuedMapFromVector::sym_diff_quotient_from_taped(dx_res_fn, zeros, 1e-5); let dx_res: V<3, 3> = dx_res.reshape(); From ac28fd411fd95636117c4cbd677a9f0d22ef9b2f Mon Sep 17 00:00:00 2001 From: hauke strasdat Date: Fri, 10 Nov 2023 10:35:49 -0800 Subject: [PATCH 2/2] feat: adjoint 'n ci --- .github/workflows/main.yml | 35 ++--- .gitmodules | 3 + Cargo.lock | 211 ++++++--------------------- Cargo.toml | 4 +- dfdx | 1 + src/calculus/points.rs | 2 +- src/lie/group.rs | 40 ++++- src/lie/isometry2.rs | 38 ++--- src/lie/isometry3.rs | 46 ++---- src/lie/translation_group_product.rs | 2 +- 10 files changed, 123 insertions(+), 259 deletions(-) create mode 160000 dfdx diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3c5e726..aab2056 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,33 +15,16 @@ jobs: submodules: "recursive" - uses: actions-rs/toolchain@v1 with: - profile: minimal toolchain: stable - - name: cargo test - uses: actions-rs/cargo@v1 - with: - command: test - - name: cargo check - uses: actions-rs/cargo@v1 - with: - command: check - - name: cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - name: cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings - - name: maturin + - name: cargo run: | - cd py - python3 -m venv .env - source .env/bin/activate - pip3 install maturin numpy - maturin develop - python3 -m test + rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu + rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu + cargo fmt + cargo check + cargo clippy + cargo test + + diff --git a/.gitmodules b/.gitmodules index e69de29..6d553da 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dfdx"] + path = dfdx + url = git@github.com:farm-ng/dfdx.git diff --git a/Cargo.lock b/Cargo.lock index 0f958bb..2d9d978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,12 +13,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "aligned-vec" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" - [[package]] name = "approx" version = "0.3.2" @@ -191,7 +185,7 @@ name = "dfdx-core" version = "0.13.0" dependencies = [ "cudarc", - "gemm 0.16.14", + "gemm", "libm", "num-traits", "rand", @@ -199,16 +193,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "dyn-stack" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24269739c7c175bc12130622ef1a60b9ab2d5b30c0b9ce5110cd406d7fd497bc" -dependencies = [ - "bytemuck", - "reborrow", -] - [[package]] name = "dyn-stack" version = "0.10.0" @@ -260,44 +244,39 @@ dependencies = [ [[package]] name = "faer-core" -version = "0.9.1" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e36300510f89c8c2c87b8b27a915956b83dcc82e6018302cbf63425add0bec8" +checksum = "09e9ad4c2acfd0e0c911cbd7276b8fb6a7e22ccbd998b4080e148cf001f2b267" dependencies = [ - "aligned-vec", "assert2", "bytemuck", "coe-rs", - "dyn-stack 0.9.0", - "gemm 0.15.4", + "dyn-stack", + "faer-entity", + "gemm", + "matrixcompare-core", "num-complex 0.4.3", "num-traits", - "pulp 0.13.1", + "paste", + "pulp 0.17.1", "rayon", "reborrow", "seq-macro", ] [[package]] -name = "gemm" -version = "0.15.4" +name = "faer-entity" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf05244e1ab5f098f2303bb1cedc1d7ca17e8cb9cb8b08040c8233cf10fc6ec" +checksum = "f5241a0fce43ff8bda51d8ecb4427e152a75b2340edb97b308b63021ed2a1967" dependencies = [ - "dyn-stack 0.9.0", - "gemm-c32 0.15.4", - "gemm-c64 0.15.4", - "gemm-common 0.15.4", - "gemm-f16 0.15.4", - "gemm-f32 0.15.4", - "gemm-f64 0.15.4", - "lazy_static", + "bytemuck", + "coe-rs", + "libm", "num-complex 0.4.3", "num-traits", - "paste", - "raw-cpuid", - "rayon", - "seq-macro", + "pulp 0.17.1", + "reborrow", ] [[package]] @@ -306,34 +285,17 @@ version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c90e866771c2adff6c4603108bb531ea36979b62a23b5e193b9311199182ccc9" dependencies = [ - "dyn-stack 0.10.0", - "gemm-c32 0.16.14", - "gemm-c64 0.16.14", - "gemm-common 0.16.14", - "gemm-f16 0.16.14", - "gemm-f32 0.16.14", - "gemm-f64 0.16.14", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "seq-macro", -] - -[[package]] -name = "gemm-c32" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d84942bd86c6e176f33f80d96311e078097cd93039cc5feec1b43ddefae749f" -dependencies = [ - "dyn-stack 0.9.0", - "gemm-common 0.15.4", - "lazy_static", + "dyn-stack", + "gemm-c32", + "gemm-c64", + "gemm-common", + "gemm-f16", + "gemm-f32", + "gemm-f64", "num-complex 0.4.3", "num-traits", "paste", "raw-cpuid", - "rayon", "seq-macro", ] @@ -343,29 +305,12 @@ version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5ffc8e9a442172ec223d4e536f93b59f1d2b34164b37e462e6886d76699e71" dependencies = [ - "dyn-stack 0.10.0", - "gemm-common 0.16.14", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "seq-macro", -] - -[[package]] -name = "gemm-c64" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2bcdc95440f12836640e8fd4df0050a2c4b34a0c01d92f8050ae886557761fc" -dependencies = [ - "dyn-stack 0.9.0", - "gemm-common 0.15.4", - "lazy_static", + "dyn-stack", + "gemm-common", "num-complex 0.4.3", "num-traits", "paste", "raw-cpuid", - "rayon", "seq-macro", ] @@ -375,8 +320,8 @@ version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45cd8172c8ee8beed35cdb7254bec535ddc83cde78d2eeefeae43cfd57fef3d8" dependencies = [ - "dyn-stack 0.10.0", - "gemm-common 0.16.14", + "dyn-stack", + "gemm-common", "num-complex 0.4.3", "num-traits", "paste", @@ -384,22 +329,6 @@ dependencies = [ "seq-macro", ] -[[package]] -name = "gemm-common" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912249fe0356806062ab2672c9cf340521732ef8d317d851d122ae6922ddd71c" -dependencies = [ - "dyn-stack 0.9.0", - "lazy_static", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "rayon", - "seq-macro", -] - [[package]] name = "gemm-common" version = "0.16.14" @@ -407,7 +336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c022dd4893afa781d1ba9912796af63a9a91ac8d8fdadd449483bbabaf7c47c6" dependencies = [ "bytemuck", - "dyn-stack 0.10.0", + "dyn-stack", "half", "num-complex 0.4.3", "num-traits", @@ -419,34 +348,15 @@ dependencies = [ "seq-macro", ] -[[package]] -name = "gemm-f16" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6820d54fd53eead15a3024c06f403a1eb082a77e0670eb78d89ad22d6f5ad9a" -dependencies = [ - "dyn-stack 0.9.0", - "gemm-common 0.15.4", - "gemm-f32 0.15.4", - "half", - "lazy_static", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "rayon", - "seq-macro", -] - [[package]] name = "gemm-f16" version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efb4c26de6ddd1125d966dffa48eb609448566a2bd2dd589ea2798f17f689b5" dependencies = [ - "dyn-stack 0.10.0", - "gemm-common 0.16.14", - "gemm-f32 0.16.14", + "dyn-stack", + "gemm-common", + "gemm-f32", "half", "num-complex 0.4.3", "num-traits", @@ -456,31 +366,14 @@ dependencies = [ "seq-macro", ] -[[package]] -name = "gemm-f32" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60558103e48ad7c953cee1334c30f3efb47f63105882ff6346d7418a6ca2fc" -dependencies = [ - "dyn-stack 0.9.0", - "gemm-common 0.15.4", - "lazy_static", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "rayon", - "seq-macro", -] - [[package]] name = "gemm-f32" version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a78fca5a0ef41202015e099e45e0bdda83e7f49318de3322d58c215a3fec334a" dependencies = [ - "dyn-stack 0.10.0", - "gemm-common 0.16.14", + "dyn-stack", + "gemm-common", "num-complex 0.4.3", "num-traits", "paste", @@ -488,31 +381,14 @@ dependencies = [ "seq-macro", ] -[[package]] -name = "gemm-f64" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e7cf971e94e5e86729881f1a9b6d4e55a74207daf5f466a936d6ab4e014a861" -dependencies = [ - "dyn-stack 0.9.0", - "gemm-common 0.15.4", - "lazy_static", - "num-complex 0.4.3", - "num-traits", - "paste", - "raw-cpuid", - "rayon", - "seq-macro", -] - [[package]] name = "gemm-f64" version = "0.16.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f18516a29ab14fa4b1714c93ffa36a89a65418f0a2fba702206d4b421061b48" dependencies = [ - "dyn-stack 0.10.0", - "gemm-common 0.16.14", + "dyn-stack", + "gemm-common", "num-complex 0.4.3", "num-traits", "paste", @@ -584,6 +460,12 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +[[package]] +name = "matrixcompare-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0bdabb30db18805d5290b3da7ceaccbddba795620b86c02145d688e04900a73" + [[package]] name = "matrixmultiply" version = "0.3.7" @@ -750,19 +632,20 @@ dependencies = [ [[package]] name = "pulp" -version = "0.13.1" +version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35403e0126ec324b0eba8f65254eb07ac9502650711dd3933f4ea5e5a809eaee" +checksum = "dcb0a2934e77dd9aabb33fedcd3bf6ea1d6d3cacd4c5bc07b9a916f7b101c6b7" dependencies = [ "bytemuck", + "libm", "num-complex 0.4.3", ] [[package]] name = "pulp" -version = "0.16.4" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb0a2934e77dd9aabb33fedcd3bf6ea1d6d3cacd4c5bc07b9a916f7b101c6b7" +checksum = "b3bef241cc27671d8dc6425796134738f2d76fd4ebc878130e069a9c1d74e8b0" dependencies = [ "bytemuck", "libm", diff --git a/Cargo.toml b/Cargo.toml index 969163a..8fcf072 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,11 @@ num-traits = "0.2.15" nalgebra = "0.32" approx = "0.5.1" enum_dispatch = "0.3.6" -dfdx-core = { path = "../dfdx/dfdx-core" } +dfdx-core = { path = "dfdx/dfdx-core" } tuple_list = "0.1.3" sprs = "0.11" sprs-ldl = "0.10" -faer-core = "0.9.1" +faer-core = "0.14.1" [dev-dependencies.proptest] version = "1.1.0" diff --git a/dfdx b/dfdx new file mode 160000 index 0000000..610b3e1 --- /dev/null +++ b/dfdx @@ -0,0 +1 @@ +Subproject commit 610b3e1eb919f50360f55dc4788495abd13ac528 diff --git a/src/calculus/points.rs b/src/calculus/points.rs index 3a221ca..ecf64bf 100644 --- a/src/calculus/points.rs +++ b/src/calculus/points.rs @@ -126,7 +126,7 @@ pub fn unit_z() -> V { make_blockvec3(o.clone(), o, l) } -pub fn Identity3() -> M { +pub fn identity3() -> M { make_3colvec_mat(unit_x(), unit_y(), unit_z()) diff --git a/src/lie/group.rs b/src/lie/group.rs index 5ca6d20..9082d8b 100644 --- a/src/lie/group.rs +++ b/src/lie/group.rs @@ -1,3 +1,6 @@ +use std::collections::HashMap; +use std::time::Instant; + use dfdx_core::prelude::*; use crate::calculus::batch_types::*; @@ -62,7 +65,6 @@ pub type LieGroup< G, > = GenTapedLieGroup; - impl< const B: usize, const DOF: usize, @@ -79,7 +81,8 @@ impl< let (params, tape) = params.split_tape(); assert!( G::are_params_valid(¶ms.clone()), - "Invalid parameters for:\n{:?}", params.array(), + "Invalid parameters for:\n{:?}", + params.array(), ); GenTapedLieGroup:: { params: params.put_tape(tape), @@ -374,25 +377,51 @@ impl< } pub fn test_mul_inverse() { - let g_vec = Self::tutil_element_examples(); - + let mut g_vec = Self::tutil_element_examples(); + g_vec.truncate(10); let mut i = 0; + + let mut map = HashMap::new(); + for g1 in g_vec.clone() { println!("g1 = {:?}", i); i += 1; for g2 in g_vec.clone() { + let before = Instant::now(); + let g1_times_g2 = Self::mul(g1.clone(), g2.clone()); + let dt = before.elapsed().as_secs_f64(); + map.entry("g1_times_g2").or_insert(vec![dt]).push(dt); + for g3 in g_vec.clone() { + let b0 = Instant::now(); let g2_times_g3 = Self::mul(g2.clone(), g3.clone()); + let dt = b0.elapsed().as_secs_f64(); + map.entry("g2_times_g3").or_insert(vec![dt]).push(dt); + + let b1 = Instant::now(); + let left_hugging = Self::mul(g1_times_g2.clone(), g3.clone()).compact(); + let dt = b1.elapsed().as_secs_f64(); + map.entry("left_hugging").or_insert(vec![dt]).push(dt); - let left_hugging = Self::mul(g1_times_g2.clone(), (g3.clone())).compact(); + let b2 = Instant::now(); let right_hugging = Self::mul(g1.clone(), g2_times_g3).compact(); + let dt = b2.elapsed().as_secs_f64(); + map.entry("right_hugging").or_insert(vec![dt]).push(dt); + + let b3 = Instant::now(); assert_tensors_relative_eq_rank3!(left_hugging, right_hugging, 1e-3); + let dt = b3.elapsed().as_secs_f64(); + map.entry("assert_tensors_relative_eq_rank3").or_insert(vec![dt]).push(dt); } } } + for pair in map { + let sum = pair.1.iter().sum::(); + println!("Elapsed time: {} {}", pair.0, sum / pair.1.len() as f64); + } let mut i = 0; for g1 in g_vec.clone() { i += 1; @@ -549,7 +578,6 @@ impl< // Self::test_exp_log_taped(); // Self::test_mul_inverse_taped(); // Self::test_point_action_taped(); - } pub fn test_suite() { diff --git a/src/lie/isometry2.rs b/src/lie/isometry2.rs index 556adf4..5062d45 100644 --- a/src/lie/isometry2.rs +++ b/src/lie/isometry2.rs @@ -9,15 +9,12 @@ use crate::lie::translation_group_product::*; use crate::manifold::traits::Manifold; impl FactorGroupImplTrait for Rotation2Impl { - fn mat_v< - ParamsTape:SophusTape + std::fmt::Debug + Merge, - Tape:SophusTape, - >( + fn mat_v, Tape: SophusTape>( params: GenV, tangent: GenV, ) -> GenM where - Tape:SophusTape + Merge, + Tape: SophusTape + Merge, { let p0: GenV = params.clone().slice((.., 0..1)).realize(); let p1: GenV = params.clone().slice((.., 1..2)).realize(); @@ -71,15 +68,12 @@ impl FactorGroupImplTrait for Rotation2Im ) } - fn mat_v_inverse< - ParamsTape:SophusTape + std::fmt::Debug + Merge, - Tape, - >( + fn mat_v_inverse, Tape>( params: GenV, tangent: GenV, ) -> GenM where - Tape:SophusTape + Merge, + Tape: SophusTape + Merge, { let halftheta: GenS = (tangent.clone() * 0.5).reshape(); @@ -103,27 +97,17 @@ impl FactorGroupImplTrait for Rotation2Im } fn group_adjoint_of_translation< - ParamsTape:SophusTape + std::fmt::Debug + Merge, - Tape:SophusTape, + ParamsTape: SophusTape + std::fmt::Debug + Merge, + Tape: SophusTape, >( - params: GenV, + _params: GenV, point: GenV, ) -> GenM { - let params_tape = params.split_tape().1; - let (point, tape) = point.split_tape(); - let tape = params_tape.merge(tape); + let point: GenV = point.retaped(); + let px: GenV = point.clone().slice((.., 0..1)).realize(); + let py: GenV = point.slice((.., 1..2)).realize(); - let (neg_px, tape) = point - .clone() - .put_tape(tape) - .negate() - .slice((.., 0..1)) - .realize() - .split_tape(); - let py: GenV = point.put_tape(tape).slice((.., 1..2)).realize(); - [py, neg_px.retaped()] - .stack() - .permute::<_, Axes3<1, 0, 2>>() + make_vec2::(py.reshape(), px.negate().reshape()).reshape() } fn algebra_adjoint_of_translation(point: V) -> M { diff --git a/src/lie/isometry3.rs b/src/lie/isometry3.rs index 504b404..5ab8bb5 100644 --- a/src/lie/isometry3.rs +++ b/src/lie/isometry3.rs @@ -1,6 +1,7 @@ use dfdx_core::prelude::*; use crate::calculus::batch_types::*; +use crate::calculus::make::make_2blockcol_mat; use crate::calculus::points::*; use crate::lie::group::*; use crate::lie::rotation3::*; @@ -34,8 +35,9 @@ impl FactorGroupImplTrait for Rotation3Im let factor1 = is_theta_sq_small.clone().choose(small_factor1, factor1); let factor2 = is_theta_sq_small.choose(small_factor2, factor2); - let mat_v: GenM = - Identity3().retaped() + factor1.broadcast() * mat_omega + factor2.broadcast() * mat_omega_sq; + let mat_v: GenM = identity3().retaped() + + factor1.broadcast() * mat_omega + + factor2.broadcast() * mat_omega_sq; mat_v } @@ -67,8 +69,9 @@ impl FactorGroupImplTrait for Rotation3Im let factor1 = is_theta_sq_small.clone().choose(small_factor1, factor1); let factor2 = is_theta_sq_small.choose(small_factor2, factor2); - let inv_mat_v: GenM = - Identity3().retaped() - factor1.broadcast() * mat_omega + factor2.broadcast() * mat_omega_sq; + let inv_mat_v: GenM = identity3().retaped() + - factor1.broadcast() * mat_omega + + factor2.broadcast() * mat_omega_sq; inv_mat_v } @@ -77,35 +80,16 @@ impl FactorGroupImplTrait for Rotation3Im ParamsTape: SophusTape + std::fmt::Debug + Merge, Tape: SophusTape, >( - _params: GenV, - _point: GenV, + params: GenV, + point: GenV, ) -> GenM { - // let params_tape = params.split_tape().1; - // let (point, tape) = point.split_tape(); - // let tape = params_tape.merge(tape); - - // let (neg_px, tape) = point - // .clone() - // .put_tape(tape) - // .negate() - // .slice((.., 0..1)) - // .realize() - // .split_tape(); - // let py: GenV = point.put_tape(tape).slice((.., 1..2)).realize(); - // [py, neg_px.retaped()] - // .stack() - // .permute::<_, Axes3<1, 0, 2>>() - - todo!() + Rotation3Impl::::hat(point) + .retaped() + .matmul(Rotation3Impl::::into_matrix(params)) } - fn algebra_adjoint_of_translation(_point: V) -> M { - // let px: V = point.clone().slice((.., 0..1)).realize(); - // let py: V = point.slice((.., 1..2)).realize(); - - // make_vec2::(py.reshape(), px.negate().reshape()).reshape() - - todo!() + fn algebra_adjoint_of_translation(point: V) -> M { + Rotation3Impl::::hat(point).retaped() } } @@ -124,8 +108,6 @@ pub type Isometry3 = GenTapedIsometry3; mod tests { use super::Isometry3; - - #[test] fn isometry3_batch_tests() { Isometry3::<1>::test_suite(); diff --git a/src/lie/translation_group_product.rs b/src/lie/translation_group_product.rs index 2cc3470..e804ce3 100644 --- a/src/lie/translation_group_product.rs +++ b/src/lie/translation_group_product.rs @@ -18,7 +18,7 @@ pub struct TranslationGroupProductImpl< const SPARAMS: usize, Factor: FactorGroupImplTrait, > { - phantom: std::marker::PhantomData<(Factor)>, + phantom: std::marker::PhantomData, } impl<