nalgebra/src/base/matrix_simba.rs

63 lines
1.3 KiB
Rust
Raw Normal View History

2020-03-21 19:16:46 +08:00
use simba::simd::SimdValue;
use crate::base::allocator::Allocator;
use crate::base::dimension::Dim;
2021-04-11 17:00:38 +08:00
use crate::base::{DefaultAllocator, OMatrix, Scalar};
2020-03-21 19:16:46 +08:00
/*
*
* Simd structures.
*
*/
2021-04-11 17:00:38 +08:00
impl<T, R, C> SimdValue for OMatrix<T, R, C>
2020-03-21 19:16:46 +08:00
where
2021-04-11 17:00:38 +08:00
T: Scalar + SimdValue,
2020-03-21 19:16:46 +08:00
R: Dim,
C: Dim,
2021-04-11 17:00:38 +08:00
T::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
2020-03-21 19:16:46 +08:00
{
2021-04-11 17:00:38 +08:00
type Element = OMatrix<T::Element, R, C>;
type SimdBool = T::SimdBool;
2020-03-21 19:16:46 +08:00
#[inline]
fn lanes() -> usize {
2021-04-11 17:00:38 +08:00
T::lanes()
2020-03-21 19:16:46 +08:00
}
#[inline]
fn splat(val: Self::Element) -> Self {
2021-04-11 17:00:38 +08:00
val.map(T::splat)
2020-03-21 19:16:46 +08:00
}
#[inline]
fn extract(&self, i: usize) -> Self::Element {
self.map(|e| e.extract(i))
}
#[inline]
unsafe fn extract_unchecked(&self, i: usize) -> Self::Element {
self.map(|e| e.extract_unchecked(i))
}
#[inline]
fn replace(&mut self, i: usize, val: Self::Element) {
self.zip_apply(&val, |mut a, b| {
a.replace(i, b);
a
})
}
#[inline]
unsafe fn replace_unchecked(&mut self, i: usize, val: Self::Element) {
self.zip_apply(&val, |mut a, b| {
a.replace_unchecked(i, b);
a
})
}
fn select(self, cond: Self::SimdBool, other: Self) -> Self {
self.zip_map(&other, |a, b| a.select(cond, b))
}
}