Move Float to separate crate
This commit is contained in:
@@ -12,11 +12,12 @@ rayon = { version = "1.3.0", optional = true }
|
||||
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" }
|
||||
|
||||
[features]
|
||||
# Use f32 as precision, default is f64
|
||||
f32 = []
|
||||
fast-float = []
|
||||
f32 = ["float/f32"]
|
||||
fast-float = ["float/fast-float"]
|
||||
sparse = ["sprs"]
|
||||
serde1 = ["serde", "ndarray/serde"]
|
||||
|
||||
|
||||
@@ -3,20 +3,7 @@
|
||||
#![feature(array_chunks)]
|
||||
#![feature(const_fn_floating_point_arithmetic)]
|
||||
|
||||
/// Type used for floats, configure with the `f32` feature
|
||||
#[cfg(feature = "f32")]
|
||||
pub type Float = f32;
|
||||
#[cfg(not(feature = "f32"))]
|
||||
/// Type used for floats, configure with the `f32` feature
|
||||
pub type Float = f64;
|
||||
|
||||
/// Associated constants for [`Float`]
|
||||
pub mod consts {
|
||||
#[cfg(feature = "f32")]
|
||||
pub use std::f32::consts::*;
|
||||
#[cfg(not(feature = "f32"))]
|
||||
pub use std::f64::consts::*;
|
||||
}
|
||||
pub use float::{consts, Float};
|
||||
|
||||
/// Grid and grid metrics
|
||||
pub mod grid;
|
||||
|
||||
@@ -6,9 +6,7 @@ pub(crate) mod constmatrix;
|
||||
pub(crate) use constmatrix::{ColVector, Matrix, RowVector};
|
||||
|
||||
#[cfg(feature = "fast-float")]
|
||||
mod fastfloat;
|
||||
#[cfg(feature = "fast-float")]
|
||||
use fastfloat::FastFloat;
|
||||
use float::FastFloat;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct DiagonalMatrix<const B: usize> {
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Default)]
|
||||
pub(crate) struct FastFloat(Float);
|
||||
|
||||
use core::intrinsics::{fadd_fast, fdiv_fast, fmul_fast, fsub_fast};
|
||||
|
||||
impl core::ops::Mul for FastFloat {
|
||||
type Output = Self;
|
||||
#[inline(always)]
|
||||
fn mul(self, o: Self) -> Self::Output {
|
||||
unsafe { Self(fmul_fast(self.0, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Mul<Float> for FastFloat {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn mul(self, o: Float) -> Self::Output {
|
||||
unsafe { Self(fmul_fast(self.0, o)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Mul<FastFloat> for Float {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn mul(self, o: FastFloat) -> Self::Output {
|
||||
unsafe { FastFloat(fmul_fast(self, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Add<FastFloat> for FastFloat {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn add(self, o: FastFloat) -> Self::Output {
|
||||
unsafe { Self(fadd_fast(self.0, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Add<Float> for FastFloat {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn add(self, o: Float) -> Self::Output {
|
||||
unsafe { Self(fadd_fast(self.0, o)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Add<FastFloat> for Float {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn add(self, o: FastFloat) -> Self::Output {
|
||||
unsafe { FastFloat(fadd_fast(self, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Sub for FastFloat {
|
||||
type Output = Self;
|
||||
#[inline(always)]
|
||||
fn sub(self, o: FastFloat) -> Self::Output {
|
||||
unsafe { Self(fsub_fast(self.0, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Div for FastFloat {
|
||||
type Output = Self;
|
||||
#[inline(always)]
|
||||
fn div(self, o: FastFloat) -> Self::Output {
|
||||
unsafe { Self(fdiv_fast(self.0, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::MulAssign<FastFloat> for FastFloat {
|
||||
#[inline(always)]
|
||||
fn mul_assign(&mut self, o: FastFloat) {
|
||||
unsafe {
|
||||
self.0 = fmul_fast(self.0, o.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Mul for &FastFloat {
|
||||
type Output = FastFloat;
|
||||
#[inline(always)]
|
||||
fn mul(self, o: Self) -> Self::Output {
|
||||
unsafe { FastFloat(fmul_fast(self.0, o.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Float> for FastFloat {
|
||||
#[inline(always)]
|
||||
fn from(f: Float) -> Self {
|
||||
Self(f)
|
||||
}
|
||||
}
|
||||
impl From<FastFloat> for Float {
|
||||
#[inline(always)]
|
||||
fn from(f: FastFloat) -> Self {
|
||||
f.0
|
||||
}
|
||||
}
|
||||
|
||||
mod numt {
|
||||
use super::{FastFloat, Float};
|
||||
use num_traits::identities::{One, Zero};
|
||||
|
||||
impl One for FastFloat {
|
||||
fn one() -> Self {
|
||||
Self(Float::one())
|
||||
}
|
||||
}
|
||||
impl Zero for FastFloat {
|
||||
fn zero() -> Self {
|
||||
Self(Float::zero())
|
||||
}
|
||||
fn is_zero(&self) -> bool {
|
||||
self.0.is_zero()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user