Trait faster::iters::PackedIterator
[−]
[src]
pub trait PackedIterator: Sized + ExactSizeIterator { type Scalar: Packable; type Vector: Packed<Scalar = Self::Scalar>; fn scalar_len(&self) -> usize; fn scalar_position(&self) -> usize; fn next_vector(&mut self) -> Option<Self::Vector>; fn next_partial(
&mut self,
default: Self::Vector
) -> Option<(Self::Vector, usize)>; fn width(&self) -> usize { ... } fn simd_map<A, B, F>(
self,
default: Self::Vector,
func: F
) -> PackedMap<Self, F>
where
F: FnMut(Self::Vector) -> A,
A: Packed<Scalar = B>,
B: Packable, { ... } fn simd_for_each<F>(&mut self, default: Self::Vector, func: F)
where
F: FnMut(Self::Vector), { ... } fn simd_reduce<A, F>(
&mut self,
start: A,
default: Self::Vector,
func: F
) -> A
where
F: FnMut(A, Self::Vector) -> A, { ... } }
An iterator which automatically packs the values it iterates over into SIMD vectors.
Associated Types
Required Methods
fn scalar_len(&self) -> usize
Return the length of this iterator, measured in scalar elements.
fn scalar_position(&self) -> usize
Return the current position of this iterator, measured in scalar elements.
fn next_vector(&mut self) -> Option<Self::Vector>
Pack and return a vector containing the next self.width()
elements
of the iterator, or return None if there aren't enough elements left
fn next_partial(
&mut self,
default: Self::Vector
) -> Option<(Self::Vector, usize)>
&mut self,
default: Self::Vector
) -> Option<(Self::Vector, usize)>
Pack and return a partially full vector containing upto the next
self.width()
of the iterator, or None if no elements are left.
Elements which are not filled are instead initialized to default.
Provided Methods
fn width(&self) -> usize
fn simd_map<A, B, F>(self, default: Self::Vector, func: F) -> PackedMap<Self, F> where
F: FnMut(Self::Vector) -> A,
A: Packed<Scalar = B>,
B: Packable,
F: FnMut(Self::Vector) -> A,
A: Packed<Scalar = B>,
B: Packable,
Return an iterator which calls func
on vectors of elements.
fn simd_for_each<F>(&mut self, default: Self::Vector, func: F) where
F: FnMut(Self::Vector),
F: FnMut(Self::Vector),
Pack and consume the iterator, running func
once on each packed
vector.
fn simd_reduce<A, F>(&mut self, start: A, default: Self::Vector, func: F) -> A where
F: FnMut(A, Self::Vector) -> A,
F: FnMut(A, Self::Vector) -> A,
Return a vector generated by reducing func
over accumulator start
and the values of this iterator, initializing all vectors to default
before populating them with elements of the iterator.
Examples
extern crate faster; use faster::*; let reduced = (&[2.0f32; 100][..]).simd_iter() .simd_reduce(f32s::splat(0.0), f32s::splat(0.0), |acc, v| acc + v);
In this example, on a machine with 4-element vectors, the argument to the last call of the closure is
[ 2.0 | 2.0 | 2.0 | 2.0 ]
and the result of the reduction is
[ 50.0 | 50.0 | 50.0 | 50.0 ]
whereas on a machine with 8-element vectors, the last call is passed
[ 2.0 | 2.0 | 2.0 | 2.0 | 0.0 | 0.0 | 0.0 | 0.0 ]
and the result of the reduction is
[ 26.0 | 26.0 | 26.0 | 26.0 | 24.0 | 24.0 | 24.0 | 24.0 ]
Footgun Warning
The results of simd_reduce
are not portable, and it is your
responsibility to interepret the result in such a way that the it is
consistent across different architectures. See Packed::sum
and
Packed::product
for built-in functions which may be helpful.
Implementors
impl<'a, T> PackedIterator for PackedIter<'a, T> where
T: Packable, type Vector = <T as Packable>::Vector; type Scalar = T;impl<'a, A, B, I, F> PackedIterator for PackedMap<I, F> where
I: PackedIterator<Scalar = <I as Iterator>::Item>,
<I as Iterator>::Item: Packable,
F: FnMut(I::Vector) -> A,
A: Packed<Scalar = B>,
B: Packable, type Vector = A; type Scalar = B;impl<I, F, A> PackedIterator for PackedZipMap<I, F> where
I: PackedZippedIterator,
F: FnMut(I::Vectors) -> A,
A: Packed, type Vector = A; type Scalar = A::Scalar;impl<'a, T> PackedIterator for PackedStripe<'a, T> where
T: Packable, type Scalar = T; type Vector = <T as Packable>::Vector;