From be1330ec02e1c3aaa97d1698b2b447693cec3f97 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 22 Mar 2021 16:24:32 +0100 Subject: [PATCH] Add constrmatrix as separate crate --- Cargo.toml | 1 + sbp/Cargo.toml | 1 + sbp/src/operators/algos.rs | 1 - utils/constmatrix/Cargo.toml | 10 ++++++++++ .../constmatrix/src/lib.rs | 19 ++++++++++--------- 5 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 utils/constmatrix/Cargo.toml rename sbp/src/operators/algos/constmatrix.rs => utils/constmatrix/src/lib.rs (96%) diff --git a/Cargo.toml b/Cargo.toml index f5bbeac..3824197 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "gridgeneration", "heat-equation", "utils/float", + "utils/constmatrix", ] default-members = ["sbp", "euler", "maxwell", "shallow_water"] diff --git a/sbp/Cargo.toml b/sbp/Cargo.toml index 552b73d..7933215 100644 --- a/sbp/Cargo.toml +++ b/sbp/Cargo.toml @@ -13,6 +13,7 @@ sprs = { version = "0.10.0", optional = true, default-features = false } serde = { version = "1.0.115", optional = true, default-features = false, features = ["derive"] } num-traits = "0.2.14" float = { path = "../utils/float" } +constmatrix = { path = "../utils/constmatrix" } [features] # Use f32 as precision, default is f64 diff --git a/sbp/src/operators/algos.rs b/sbp/src/operators/algos.rs index 23a4e82..b075447 100644 --- a/sbp/src/operators/algos.rs +++ b/sbp/src/operators/algos.rs @@ -2,7 +2,6 @@ use super::*; use ndarray::s; use num_traits::Zero; -pub(crate) mod constmatrix; pub(crate) use constmatrix::{ColVector, Matrix, RowVector}; #[cfg(feature = "fast-float")] diff --git a/utils/constmatrix/Cargo.toml b/utils/constmatrix/Cargo.toml new file mode 100644 index 0000000..524e7b3 --- /dev/null +++ b/utils/constmatrix/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "constmatrix" +version = "0.1.0" +authors = ["Magnus Ulimoen "] +edition = "2018" + +[dependencies] +approx = { version = "0.4.0", optional = true } +float = { path = "../float" } +num-traits = "0.2.14" diff --git a/sbp/src/operators/algos/constmatrix.rs b/utils/constmatrix/src/lib.rs similarity index 96% rename from sbp/src/operators/algos/constmatrix.rs rename to utils/constmatrix/src/lib.rs index 1cf2429..7de31c3 100644 --- a/sbp/src/operators/algos/constmatrix.rs +++ b/utils/constmatrix/src/lib.rs @@ -1,5 +1,6 @@ -#![allow(unused)] +#![feature(const_fn_floating_point_arithmetic)] +use float::Float; use num_traits::identities::Zero; /// A row-major matrix @@ -178,7 +179,7 @@ where #[cfg(test)] mod tests { - use super::{super::*, *}; + use super::*; #[test] fn construct_copy_type() { let _m0 = Matrix::::default(); @@ -209,6 +210,7 @@ mod tests { } } +#[cfg(feature = "approx")] mod approx { use super::Matrix; use ::approx::{AbsDiffEq, RelativeEq, UlpsEq}; @@ -262,8 +264,8 @@ mod approx { } } -impl Matrix { - pub(crate) const fn flip_ud(&self) -> Self { +impl Matrix { + pub const fn flip_ud(&self) -> Self { let mut m = Self::new([[0.0; N]; M]); let mut i = 0; while i < M { @@ -273,7 +275,7 @@ impl Matrix { m } - pub(crate) const fn flip_lr(&self) -> Self { + pub const fn flip_lr(&self) -> Self { let mut m = Self::new([[0.0; N]; M]); let mut i = 0; while i < M { @@ -288,7 +290,7 @@ impl Matrix { } /// Flip all sign bits - pub(crate) const fn flip_sign(&self) -> Self { + pub const fn flip_sign(&self) -> Self { let mut m = Self::new([[0.0; N]; M]); let mut i = 0; while i < M { @@ -303,9 +305,7 @@ impl Matrix { } /// Zero extends if larger than self - pub(crate) const fn resize( - &self, - ) -> Matrix { + pub const fn resize(&self) -> Matrix { let mut m = Matrix::new([[0.0; N2]; M2]); let m_min = if M < M2 { M } else { M2 }; @@ -325,6 +325,7 @@ impl Matrix { } } +#[cfg(test)] mod flipping { use super::*;