diff --git a/sbp/Cargo.toml b/sbp/Cargo.toml index a1ba176..2dd2b22 100644 --- a/sbp/Cargo.toml +++ b/sbp/Cargo.toml @@ -16,6 +16,7 @@ serde = { version = "1.0.115", optional = true, default-features = false, featur [features] # Use f32 as precision, default is f64 f32 = [] +fast-float = [] sparse = ["sprs"] serde1 = ["serde", "ndarray/serde"] diff --git a/sbp/src/operators/algos.rs b/sbp/src/operators/algos.rs index 917d9e0..88c92e7 100644 --- a/sbp/src/operators/algos.rs +++ b/sbp/src/operators/algos.rs @@ -319,6 +319,7 @@ mod fastfloat { } } } +#[cfg(feature = "fast-float")] use fastfloat::FastFloat; #[inline(always)] @@ -330,12 +331,19 @@ pub(crate) fn diff_op_1d_slice_matrix>(block) }; - let endblock = unsafe { transmute::<_, &Matrix>(endblock) }; - let diag = unsafe { transmute::<_, &RowVector>(diag) }; - let prev = unsafe { transmute::<_, &[FastFloat]>(prev) }; - let fut = unsafe { transmute::<_, &mut [FastFloat]>(fut) }; + #[cfg(feature = "fast-float")] + let (block, endblock, diag, prev, fut) = { + use std::mem::transmute; + unsafe { + ( + transmute::<_, &Matrix>(block), + transmute::<_, &Matrix>(endblock), + transmute::<_, &RowVector>(diag), + transmute::<_, &[FastFloat]>(prev), + transmute::<_, &mut [FastFloat]>(fut), + ) + } + }; assert_eq!(prev.len(), fut.len()); let nx = prev.len(); @@ -350,6 +358,7 @@ pub(crate) fn diff_op_1d_slice_matrix