Trait vrl::SIMDVector
source · pub trait SIMDVector<const N: usize>: SIMDBase<N> + Neg<Output = Self> + Arithmetic + ArithmeticAssign<Self> + Arithmetic<Self::Element> + ArithmeticAssign<Self::Element> + PartialEq + Into<Self::Underlying> + Into<[Self::Element; N]> + for<'a> From<&'a [Self::Element; N]> + SIMDPartialLoad<Self::Element> + SIMDPartialStore<Self::Element> + SIMDFusedCalc + Default + Copy + Clone + Debug + Index<usize> + IndexMut<usize> + Sum + Productwhere
[Self::Element; N]: Into<Self>,
Self::Element: Arithmetic<Self, Self>,
Self::Underlying: Into<Self>,{ }
Expand description
Represents a packed vector containing N
values of type Element
.
Default::default
initializes all elements of vector with zero.
All arithmetic operations (Neg
, Add
, etc) are applied vertically, i.e. “elementwise”.
§extract
vs index
index
(aka operator []
) extracts index
-th element of the vector. If value of the vector is expected to be
in a register consider using extract
. Use this function if only the vector is probably stored in memory.
In the following example the vector is stored in the heap. Using []
-indexing in
the case is as efficient as dereferencing the corresponding pointer.
let many_vectors = vec![Vec4f::new(1.0, 2.0, 3.0, 4.0); 128];
assert_eq!(many_vectors.index(64)[2], 3.0);
Here is an example of inefficient usage of index
. The vector wouldn’t even reach memory
and would stay in a register without that [1]
. extract
should be used instead.
let mut vec = Vec4f::new(1.0, 2.0, 3.0, 4.0);
vec *= 3.0;
vec -= 2.0;
let second_value = vec[1];
assert_eq!(second_value, 4.0);
Object Safety§
This trait is not object safe.