Skip to content

Commit

Permalink
chore: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
kpbaks committed Mar 4, 2024
1 parent 0e4a6b7 commit 8991546
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# pixi environments
.pixi

*.png
*.dot
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gbp_multivariate_normal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ ndarray-inverse = "0.1.9"
ndarray.workspace = true
thiserror.workspace = true

[dev-dependencies]
pretty_assertions = "1.4.0"


[lints]
workspace = true
1 change: 1 addition & 0 deletions gbpplanner-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gbp_linalg = { path = "../gbp_linalg" }
# gbp-rs = { path = "../gbp-rs" }
# gbp-linalg = { path = "../gbp-linalg" }
# bevy = { version = "0.12.1", default-features = true, features = [
Expand Down
101 changes: 3 additions & 98 deletions gbpplanner-rs/src/planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,109 +12,14 @@ pub use factorgraph::NodeIndex;
pub use robot::RobotId;
pub use robot::RobotState;

pub type Timestep = u32;

// pub trait Scalar: num_traits::Float + Copy + std::fmt::Debug {}
// impl Scalar for f32 {}
// impl Scalar for f64 {}

// only available on nightly :(
// pub type Vector<T> = ndarray::Array1<T: Scalar>;
// pub type Matrix<T> = ndarray::Array2<T: Scalar>;
pub type Vector<T> = ndarray::Array1<T>;
pub type Matrix<T> = ndarray::Array2<T>;
use gbp_linalg::*;

// TODO: finish and implement
pub trait VectorNorm {
type Scalar: NdFloat;
fn euclidean_norm(&self) -> Self::Scalar;
fn l1_norm(&self) -> Self::Scalar;

#[inline(always)]
fn l2_norm(&self) -> Self::Scalar {
self.euclidean_norm()
}
}

macro_rules! vector_norm_impl {
($float:ty) => {
impl VectorNorm for Vector<$float> {
type Scalar = $float;
fn euclidean_norm(&self) -> Self::Scalar {
<$float>::sqrt(self.fold(0.0, |acc, x| acc + x * x))
// self.dot(&self).sqrt()
}
fn l1_norm(&self) -> Self::Scalar {
self.fold(0.0, |acc, x| acc + x.abs())
}
}
};
}

vector_norm_impl!(f32);
vector_norm_impl!(f64);

pub trait NdarrayVectorExt: Clone {
type Scalar: NdFloat;
fn normalize(&mut self);
fn normalized(self) -> Self {
let mut copy = self.clone();
copy.normalize();
copy
}
// fn euclidian_norm(&self) -> Self::Scalar;
}

macro_rules! ndarray_vector_ext_impl {
($float:ty) => {
impl NdarrayVectorExt for Vector<$float> {
type Scalar = $float;
fn normalize(&mut self) {
let len = self.len() as $float;
self.map_mut(|x| *x / len);
}
}
};
}

// TODO: write test cases for impls
ndarray_vector_ext_impl!(f32);
ndarray_vector_ext_impl!(f64);

// impl NdarrayVectorExt for Vector<f32> {
// type Scalar = f32;
// fn normalize(self) -> Self {
// let len = self.len() as f32;
// self.mapv_into(|x| x / len)
// }
// }

// pub trait NdarrayVectorExt<T>
// where
// T: NdFloat,
// {
// fn normalize(self) -> Self {
// // Provide a default implementation using generics
// let norm = self.dot(self).sqrt();
// self.mapv_into(|x| x / norm)
// }
// }

// impl<T> NdarrayVectorExt<T> for Vector<T> where T: NdFloat {}

// impl<T> TryFrom<Vector<T>> for bevy::math::Vec2 {
// type Error = &'static str;

// fn try_from(value: Vector<T>) -> Result<Self, Self::Error> {
// todo!()
// }
// }
pub type Timestep = u32;

use self::robot::RobotPlugin;
use self::spawner::SpawnerPlugin;
use bevy::prelude::*;
use ndarray::NdFloat;
// use ndarray_linalg::Lapack;
// use ndarray::NdFloat;

pub struct PlannerPlugin;

Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ blank_lines_lower_bound = 1
format_code_in_doc_comments = true
format_strings = true
hex_literal_case = "Upper"
max_width = 90
max_width = 100
imports_granularity = "Crate"
normalize_comments = true
normalize_doc_attributes = true
Expand Down

0 comments on commit 8991546

Please sign in to comment.