Skip to content

Commit

Permalink
feat: merge factorgraph refactor onto main
Browse files Browse the repository at this point in the history
  • Loading branch information
kpbaks committed Apr 14, 2024
2 parents 3d1e741 + b883a30 commit 52a469a
Show file tree
Hide file tree
Showing 48 changed files with 2,926 additions and 3,677 deletions.
60 changes: 60 additions & 0 deletions Cargo.lock

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

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ cargo-features = [

[workspace]
resolver = "2" # Important! wgpu/bevy needs this!
members = [ "crates/angle",
members = [
"crates/angle",
"crates/min_len_vec",
"crates/percentage",
"crates/unit_interval",
Expand All @@ -13,7 +14,11 @@ members = [ "crates/angle",
# "crates/bevy_undo_redo",
"crates/gbpplanner-rs",
"crates/bevy_notify",
"crates/units", "crates/repeating_array",
"crates/units",
"crates/repeating_array",
"crates/units",
"crates/units",
"crates/bevy_fullscreen",
]

[workspace.package]
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_notify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod prelude {
/// Adds event `ToastEvent` to be used in systems.
/// Uses a `Update` system to render the toasts on the screen at the specified
/// anchor
#[derive(Debug)]
pub struct NotifyPlugin {
/// Anchor for where to render the toasts in the main window
/// Defaults to `Anchor::TopCenter`
Expand Down Expand Up @@ -108,7 +109,7 @@ impl Toasts {
}

/// Event for creating a toast
#[derive(Event)]
#[derive(Debug, Event)]
pub struct ToastEvent {
/// The caption of the toast
pub caption: String,
Expand Down
11 changes: 10 additions & 1 deletion crates/gbp_linalg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod pretty_print;
/// `use gbp_linalg::prelude::*` to import all the common symbols from this
/// crate
pub mod prelude {
// pub use ndarray::{array, concatenate, s, Axis};

pub use super::{
pretty_print::*, Float, GbpFloat, Matrix, MatrixView, NdarrayVectorExt, Vector, VectorNorm,
VectorView,
Expand Down Expand Up @@ -41,12 +43,16 @@ pub type VectorView<'a, T> = ndarray::ArrayView1<'a, T>;
/// Type alias for `ndarray::ArrayView2<T>`
pub type MatrixView<'a, T> = ndarray::ArrayView2<'a, T>;

///
/// Trait for vector norms
pub trait VectorNorm {
/// The scalar type of the vector
type Scalar: GbpFloat;
/// Calculate the Euclidean norm of the vector
fn euclidean_norm(&self) -> Self::Scalar;
/// Calculate the L1 norm of the vector
fn l1_norm(&self) -> Self::Scalar;

/// Calculate the L2 norm of the vector
#[inline(always)]
fn l2_norm(&self) -> Self::Scalar {
self.euclidean_norm()
Expand All @@ -73,8 +79,11 @@ macro_rules! vector_norm_trait_impl {
vector_norm_trait_impl!(f32);
vector_norm_trait_impl!(f64);

/// Extension trait for `ndarray::Array1<T>`
pub trait NdarrayVectorExt: Clone + VectorNorm {
/// The scalar type of the vector
type Scalar: GbpFloat;
/// Normalize the vector in place.
fn normalize(&mut self);
/// Return a normalized copy of the vector.
fn normalized(&self) -> Self {
Expand Down
9 changes: 9 additions & 0 deletions crates/gbp_linalg/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub fn num_of_integral_digits(mut f: f64) -> Option<usize> {
Some(count)
}

/// Map a floating point number to a ansi color string.
fn float_color(f: f64) -> &'static str {
if f.is_nan() {
MAGENTA_TEXT
Expand Down Expand Up @@ -190,6 +191,8 @@ pub fn _pretty_print_matrix<T, M>(
);
}

/// Internal function to pretty print a vector
/// Use by the [`pretty_print_vector!`] macro
pub fn _pretty_print_vector<T, V>(
vector: &V,
name: Option<&str>,
Expand Down Expand Up @@ -302,13 +305,15 @@ pub fn _pretty_print_vector<T, V>(
);
}

/// Extension trait that adds a [`pretty_print`] method to vectors
pub trait PrettyPrintVector<T: GbpFloat>: Sized {
/// Returns the length of the vector.
#[allow(clippy::len_without_is_empty)]
fn len(&self) -> usize;
/// Returns the element at index `i`.
fn at(&self, i: usize) -> T;

/// Pretty prints the vector.
#[inline(always)]
fn pretty_print(&self) {
_pretty_print_vector(self, None, None, None);
Expand All @@ -326,12 +331,14 @@ impl<T: GbpFloat> PrettyPrintVector<T> for Vector<T> {
self[i]
}
}
/// Extension trait that adds a [`pretty_print`] method to matrices
pub trait PrettyPrintMatrix<T: GbpFloat>: Sized {
/// Returns the shape of the matrix as a tuple `(nrows, ncols)`.
fn shape(&self) -> (usize, usize);
/// Returns the element at index `(i, j)`.
fn at(&self, i: usize, j: usize) -> T;

/// Pretty prints the matrix.
#[inline(always)]
fn pretty_print(&self) {
_pretty_print_matrix(self, None, None, None);
Expand All @@ -350,6 +357,7 @@ impl<T: GbpFloat> PrettyPrintMatrix<T> for Matrix<T> {
}
}

/// Pretty prints a vector
#[macro_export]
macro_rules! pretty_print_vector {
($name:expr) => {
Expand All @@ -370,6 +378,7 @@ macro_rules! pretty_print_vector {
};
}

/// Pretty prints a matrix
#[macro_export]
macro_rules! pretty_print_matrix {
($name:expr) => {
Expand Down
14 changes: 13 additions & 1 deletion crates/gbp_multivariate_normal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
// #![warn(missing_docs)]
//! Multivariate normal distribution type
use gbp_linalg::{Float, Matrix, Vector};
use ndarray_inverse::Inverse;

/// Error type use by this module
#[derive(Debug, thiserror::Error)]
pub enum MultivariateNormalError {
/// The precision matrix is not square
#[error("the precision matrix is not square, it has shape {0}x{1}")]
NonSquarePrecisionMatrix(usize, usize),
#[error(
"the length of the information vector ({0}) is not equal to the number of rows ({1}) or \
columns ({2}) of the precision matrix"
)]
/// The length of the information vector is not equal to the number of rows
/// or columns of the precision matrix
VectorLengthNotEqualMatrixShape(usize, usize, usize),
#[error(
"the covariance matrix is not invertible, which is required to calculate the precision \
matrix"
)]
/// The covariance matrix is not invertible
NonInvertibleCovarianceMatrix,
#[error(
"the precision matrix is not invertible, which is required to calculate the covariance \
matrix"
)]
/// The precision matrix is not invertible
NonInvertiblePrecisionMatrix,
}

/// Result type used by this module
pub type Result<T> = std::result::Result<T, MultivariateNormalError>;

/// Multivariate normal distribution stored in information form
#[allow(clippy::len_without_is_empty)]
#[derive(Debug, Clone)]
pub struct MultivariateNormal {
Expand Down Expand Up @@ -145,11 +153,15 @@ impl MultivariateNormal {
&self.precision
}

/// Set the information vector of the multivariate normal distribution
/// Updates the cached mean internally.
pub fn update_information_vector(&mut self, value: &Vector<Float>) {
self.information.clone_from(value);
self.update();
}

/// Set the precision matrix of the multivariate normal distribution
/// Updates the cached mean internally.
pub fn update_precision_matrix(&mut self, value: &Matrix<Float>) -> Result<()> {
// if value.det() == Float::zero() {
if value.det() == 0.0 {
Expand Down
7 changes: 6 additions & 1 deletion crates/gbpplanner-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ bevy = { version = "0.13.0", default-features = true, features = [
# "wayland",
# "dynamic_linking",
] }

bevy-inspector-egui = "0.23.2"
bevy_egui = "0.26.0"
bevy_egui = "0.26.0"
egui_dock = "0.11.4"
egui_tiles = "0.7.2"

# bevy_egui = { git = "https://github.com/mvlabat/bevy_egui", branch = "main" } # 0.26 does not support egui 0.27, which egui-notify needs

Expand Down Expand Up @@ -104,6 +107,8 @@ serde_yaml = "0.9.34"
colored = "2.1.0"
directories = "5.0.1"
chrono = "0.4.37"


# font-kit = { version = "0.13.0", features = ["freetype"] }

dark-light = "1.1.1"
Expand Down
23 changes: 23 additions & 0 deletions crates/gbpplanner-rs/src/bevy_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,26 @@ impl BevyPluginExt for bevy::app::App {
self
}
}

pub mod run_conditions {
use bevy::{
ecs::system::Res,
input::{keyboard::KeyCode, ButtonInput},
};

// pub fn any_input_just_pressed(
// // inputs: impl IntoIterator<Item = ButtonInput<KeyCode>>,
// // inputs: impl IntoIterator<Item = KeyCode>,
// // inputs: Vec<KeyCode>,
// ) -> impl Fn(Res<ButtonInput<KeyCode>>) -> bool
// // where
// // T: Copy + Eq + Send + Sync + 'static,
// {
// move |keyboard_input: Res<ButtonInput<KeyCode>>|
// keyboard_input.any_pressed(inputs)

// // move |keyboard_input: Res<ButtonInput<T>>| {
// // inputs.into_iter().any(|it|
// keyboard_input.just_pressed(it)) // }
// }
}
2 changes: 2 additions & 0 deletions crates/gbpplanner-rs/src/bin/console.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use bevy::{log::LogPlugin, prelude::*};
use bevy_dev_console::prelude::*;

Expand Down
18 changes: 0 additions & 18 deletions crates/gbpplanner-rs/src/bin/derive_more.rs

This file was deleted.

2 changes: 2 additions & 0 deletions crates/gbpplanner-rs/src/bin/draw2d.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use bevy::{prelude::*, window::WindowResized};
// use std::f32::consts::{PI, TAU};

Expand Down
2 changes: 1 addition & 1 deletion crates/gbpplanner-rs/src/bin/gizmos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(dead_code, unused_macros)]
#![allow(dead_code, unused_macros, missing_docs)]

use bevy::{prelude::*, window::WindowResized};
// use std::f32::consts::{PI, TAU};
Expand Down
Loading

0 comments on commit 52a469a

Please sign in to comment.