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

Return the length of this iterator, measured in scalar elements.

Return the current position of this iterator, measured in scalar elements.

Pack and return a vector containing the next self.width() elements of the iterator, or return None if there aren't enough elements left

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

Important traits for PackedMap<I, F>

Return an iterator which calls func on vectors of elements.

Pack and consume the iterator, running func once on each packed vector.

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

This example is not tested
[ 2.0 | 2.0 | 2.0 | 2.0 ]

and the result of the reduction is

This example is not tested
[ 50.0 | 50.0 | 50.0 | 50.0 ]

whereas on a machine with 8-element vectors, the last call is passed

This example is not tested
[ 2.0 | 2.0 | 2.0 | 2.0 | 0.0 | 0.0 | 0.0 | 0.0 ]

and the result of the reduction is

This example is not tested
[ 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