add fast-float feature

This commit is contained in:
Magnus Ulimoen 2021-01-29 00:14:56 +01:00
parent 4c2daf5933
commit 3d34f2e7a0
2 changed files with 16 additions and 6 deletions

View File

@ -16,6 +16,7 @@ serde = { version = "1.0.115", optional = true, default-features = false, featur
[features] [features]
# Use f32 as precision, default is f64 # Use f32 as precision, default is f64
f32 = [] f32 = []
fast-float = []
sparse = ["sprs"] sparse = ["sprs"]
serde1 = ["serde", "ndarray/serde"] serde1 = ["serde", "ndarray/serde"]

View File

@ -319,6 +319,7 @@ mod fastfloat {
} }
} }
} }
#[cfg(feature = "fast-float")]
use fastfloat::FastFloat; use fastfloat::FastFloat;
#[inline(always)] #[inline(always)]
@ -330,12 +331,19 @@ pub(crate) fn diff_op_1d_slice_matrix<const M: usize, const N: usize, const D: u
prev: &[Float], prev: &[Float],
fut: &mut [Float], fut: &mut [Float],
) { ) {
#[cfg(feature = "fast-float")]
let (block, endblock, diag, prev, fut) = {
use std::mem::transmute; use std::mem::transmute;
let block = unsafe { transmute::<_, &Matrix<FastFloat, M, N>>(block) }; unsafe {
let endblock = unsafe { transmute::<_, &Matrix<FastFloat, M, N>>(endblock) }; (
let diag = unsafe { transmute::<_, &RowVector<FastFloat, D>>(diag) }; transmute::<_, &Matrix<FastFloat, M, N>>(block),
let prev = unsafe { transmute::<_, &[FastFloat]>(prev) }; transmute::<_, &Matrix<FastFloat, M, N>>(endblock),
let fut = unsafe { transmute::<_, &mut [FastFloat]>(fut) }; transmute::<_, &RowVector<FastFloat, D>>(diag),
transmute::<_, &[FastFloat]>(prev),
transmute::<_, &mut [FastFloat]>(fut),
)
}
};
assert_eq!(prev.len(), fut.len()); assert_eq!(prev.len(), fut.len());
let nx = prev.len(); let nx = prev.len();
@ -350,6 +358,7 @@ pub(crate) fn diff_op_1d_slice_matrix<const M: usize, const N: usize, const D: u
1.0 / (nx - 1) as Float 1.0 / (nx - 1) as Float
}; };
let idx = 1.0 / dx; let idx = 1.0 / dx;
#[cfg(feature = "fast-float")]
let idx = FastFloat::from(idx); let idx = FastFloat::from(idx);
use std::convert::TryInto; use std::convert::TryInto;