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]
# Use f32 as precision, default is f64
f32 = []
fast-float = []
sparse = ["sprs"]
serde1 = ["serde", "ndarray/serde"]

View File

@ -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<const M: usize, const N: usize, const D: u
prev: &[Float],
fut: &mut [Float],
) {
#[cfg(feature = "fast-float")]
let (block, endblock, diag, prev, fut) = {
use std::mem::transmute;
let block = unsafe { transmute::<_, &Matrix<FastFloat, M, N>>(block) };
let endblock = unsafe { transmute::<_, &Matrix<FastFloat, M, N>>(endblock) };
let diag = unsafe { transmute::<_, &RowVector<FastFloat, D>>(diag) };
let prev = unsafe { transmute::<_, &[FastFloat]>(prev) };
let fut = unsafe { transmute::<_, &mut [FastFloat]>(fut) };
unsafe {
(
transmute::<_, &Matrix<FastFloat, M, N>>(block),
transmute::<_, &Matrix<FastFloat, M, N>>(endblock),
transmute::<_, &RowVector<FastFloat, D>>(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<const M: usize, const N: usize, const D: u
1.0 / (nx - 1) as Float
};
let idx = 1.0 / dx;
#[cfg(feature = "fast-float")]
let idx = FastFloat::from(idx);
use std::convert::TryInto;