nalgebra/base/
matrix_simba.rs

1use simba::simd::SimdValue;
2
3use crate::base::allocator::Allocator;
4use crate::base::dimension::Dim;
5use crate::base::{DefaultAllocator, OMatrix, Scalar};
6
7/*
8 *
9 * Simd structures.
10 *
11 */
12impl<T, R, C> SimdValue for OMatrix<T, R, C>
13where
14    T: Scalar + SimdValue,
15    R: Dim,
16    C: Dim,
17    T::Element: Scalar,
18    DefaultAllocator: Allocator<R, C>,
19{
20    const LANES: usize = T::LANES;
21    type Element = OMatrix<T::Element, R, C>;
22    type SimdBool = T::SimdBool;
23
24    #[inline]
25    fn splat(val: Self::Element) -> Self {
26        val.map(T::splat)
27    }
28
29    #[inline]
30    fn extract(&self, i: usize) -> Self::Element {
31        self.map(|e| e.extract(i))
32    }
33
34    #[inline]
35    unsafe fn extract_unchecked(&self, i: usize) -> Self::Element {
36        self.map(|e| e.extract_unchecked(i))
37    }
38
39    #[inline]
40    fn replace(&mut self, i: usize, val: Self::Element) {
41        self.zip_apply(&val, |a, b| {
42            a.replace(i, b);
43        })
44    }
45
46    #[inline]
47    unsafe fn replace_unchecked(&mut self, i: usize, val: Self::Element) {
48        self.zip_apply(&val, |a, b| {
49            a.replace_unchecked(i, b);
50        })
51    }
52
53    fn select(self, cond: Self::SimdBool, other: Self) -> Self {
54        self.zip_map(&other, |a, b| a.select(cond, b))
55    }
56}