Trait faster::zip::PackedZippedIterator [] [src]

pub trait PackedZippedIterator: ExactSizeIterator + Sized {
    type Scalars: Copy + Sized;
    type Vectors: Copy + Sized;
    fn width(&self) -> usize;
fn scalar_len(&self) -> usize;
fn scalar_position(&self) -> usize;
fn next_vectors(&mut self) -> Option<Self::Vectors>;
fn next_partials(
        &mut self,
        default: Self::Vectors
    ) -> Option<(Self::Vectors, usize)>;
fn next_splats(&mut self) -> Option<Self::Vectors>; fn simd_map<B, F>(
        self,
        defaults: Self::Vectors,
        func: F
    ) -> PackedZipMap<Self, F>
    where
        F: FnMut(Self::Vectors) -> B
, { ... }
fn simd_reduce<A, F>(
        &mut self,
        start: A,
        default: Self::Vectors,
        func: F
    ) -> A
    where
        F: FnMut(A, Self::Vectors) -> A
, { ... } }

A collection of packed iterators of the same scalar length and vector width, which may be iterated over in lockstep.

Associated Types

Required Methods

Return the width of this iterator's constitutent vectors.

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.

Pack and return a splatted vector containing the next element of the iterator, or None if no elements are left.

Provided Methods

Important traits for PackedZipMap<I, F>

Return an iterator which calls func on vectors of elements.

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