add inline to remove magic fix

This commit is contained in:
Magnus Ulimoen 2021-01-29 08:32:26 +01:00
parent 14fefe97ab
commit a7660281c8
2 changed files with 8 additions and 7 deletions

View File

@ -60,11 +60,11 @@ pub(crate) mod constmatrix {
pub const fn new(data: [[T; N]; M]) -> Self { pub const fn new(data: [[T; N]; M]) -> Self {
Self { data } Self { data }
} }
#[inline] #[inline(always)]
pub const fn nrows(&self) -> usize { pub const fn nrows(&self) -> usize {
M M
} }
#[inline] #[inline(always)]
pub const fn ncols(&self) -> usize { pub const fn ncols(&self) -> usize {
N N
} }
@ -95,12 +95,15 @@ pub(crate) mod constmatrix {
} }
} }
} }
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = &T> { pub fn iter(&self) -> impl Iterator<Item = &T> {
self.data.iter().flatten() self.data.iter().flatten()
} }
#[inline(always)]
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> { pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
self.data.iter_mut().flatten() self.data.iter_mut().flatten()
} }
#[inline(always)]
pub fn iter_rows( pub fn iter_rows(
&self, &self,
) -> impl ExactSizeIterator<Item = &[T; N]> + DoubleEndedIterator<Item = &[T; N]> { ) -> impl ExactSizeIterator<Item = &[T; N]> + DoubleEndedIterator<Item = &[T; N]> {
@ -122,9 +125,11 @@ pub(crate) mod constmatrix {
} }
impl<T, const N: usize> ColVector<T, N> { impl<T, const N: usize> ColVector<T, N> {
#[inline(always)]
pub fn map_to_col(slice: &[T; N]) -> &ColVector<T, N> { pub fn map_to_col(slice: &[T; N]) -> &ColVector<T, N> {
unsafe { std::mem::transmute::<&[T; N], &Self>(slice) } unsafe { std::mem::transmute::<&[T; N], &Self>(slice) }
} }
#[inline(always)]
pub fn map_to_col_mut(slice: &mut [T; N]) -> &mut ColVector<T, N> { pub fn map_to_col_mut(slice: &mut [T; N]) -> &mut ColVector<T, N> {
unsafe { std::mem::transmute::<&mut [T; N], &mut Self>(slice) } unsafe { std::mem::transmute::<&mut [T; N], &mut Self>(slice) }
} }
@ -143,6 +148,7 @@ pub(crate) mod constmatrix {
where where
for<'f> T: core::ops::MulAssign<&'f T>, for<'f> T: core::ops::MulAssign<&'f T>,
{ {
#[inline(always)]
fn mul_assign(&mut self, other: &T) { fn mul_assign(&mut self, other: &T) {
self.iter_mut().for_each(|x| *x *= other) self.iter_mut().for_each(|x| *x *= other)
} }

View File

@ -90,11 +90,6 @@ impl SbpOperator1d for SBP4 {
} }
fn diff_op_row_local(prev: ndarray::ArrayView2<Float>, mut fut: ndarray::ArrayViewMut2<Float>) { fn diff_op_row_local(prev: ndarray::ArrayView2<Float>, mut fut: ndarray::ArrayViewMut2<Float>) {
// Magic two lines that prevents or enables optimisation
// (doubles instructions when not included)
let mut flipmatrix = SBP4::BLOCK_MATRIX;
flipmatrix *= &-1.0;
for (p, mut f) in prev for (p, mut f) in prev
.axis_iter(ndarray::Axis(0)) .axis_iter(ndarray::Axis(0))
.zip(fut.axis_iter_mut(ndarray::Axis(0))) .zip(fut.axis_iter_mut(ndarray::Axis(0)))