Struct ndarray::Zip
[−]
[src]
pub struct Zip<Parts, D> { /* fields omitted */ }
Lock step function application across several arrays or other producers.
Zip allows matching several arrays to each other elementwise and applying a function over all tuples of elements (one element from each input at a time).
In general, the zip uses a tuple of producers
(NdProducer
trait) that all have to be of the same
shape. The NdProducer implementation defines what its element type is
(for example if it's a shared reference, mutable reference or an array
view etc).
If all the input arrays are of the same memory order the zip performs much better and the compiler can usually vectorize the loop (if applicable).
The order elements are visited is not specified. The producers don’t have to have the same element type.
The Zip
has two methods for function application: apply
and
fold_while
. The zip object can be split, which allows parallelization.
A read-only zip object (no mutable producers) can be cloned.
See also the azip!()
macro which offers a convenient shorthand
to common ways to use Zip
.
use ndarray::Zip; use ndarray::Array2; type M = Array2<f64>; let mut a = M::zeros((64, 64)); let b = M::zeros((64, 64)); let c = M::zeros((64, 64)); let d = M::zeros((64, 64)); Zip::from(&mut a) .and(&b) .and(&c) .and(&d) .apply(|w, &x, &y, &z| { *w += x + y * z; });
Methods
impl<P, D> Zip<(P,), D> where D: Dimension, P: NdProducer<Dim=D>
[src]
fn from<IP>(p: IP) -> Self where IP: IntoNdProducer<Dim=D, Output=P, Item=P::Item>
Create a new Zip
from the input array or other producer p
.
The Zip will take the exact dimension of p
and all inputs
must have the same dimensions (or be broadcast to them).
impl<P, D> Zip<(Indices<D>, P), D> where D: Dimension + Copy,
P: NdProducer<Dim=D>
[src]
P: NdProducer<Dim=D>
fn indexed<IP>(p: IP) -> Self where IP: IntoNdProducer<Dim=D, Output=P, Item=P::Item>
Create a new Zip
with an index producer and the producer p
.
The Zip will take the exact dimension of p
and all inputs
must have the same dimensions (or be broadcast to them).
Note: Indexed zip has overhead.
impl<Parts, D> Zip<Parts, D> where D: Dimension
[src]
impl<D: Dimension, P1: NdProducer<Dim=D>> Zip<(P1,), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn and<P>(self, p: P) -> Zip<(P1, P::Output), D> where P: IntoNdProducer<Dim=D>
Include the producer p
in the Zip.
Panics if p
’s shape doesn’t match the Zip’s exactly.
fn and_broadcast<'a, P, D2, Elem>(self,
p: P)
-> Zip<(P1, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
p: P)
-> Zip<(P1, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
Include the producer p
in the Zip, broadcasting if needed.
If their shapes disagree, rhs
is broadcast to the shape of self
.
Panics if broadcasting isn’t possible.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
impl<D: Dimension, P1: NdProducer<Dim=D>, P2: NdProducer<Dim=D>> Zip<(P1, P2), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item, P2::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item, P2::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn and<P>(self, p: P) -> Zip<(P1, P2, P::Output), D> where P: IntoNdProducer<Dim=D>
Include the producer p
in the Zip.
Panics if p
’s shape doesn’t match the Zip’s exactly.
fn and_broadcast<'a, P, D2, Elem>(self,
p: P)
-> Zip<(P1, P2, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
p: P)
-> Zip<(P1, P2, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
Include the producer p
in the Zip, broadcasting if needed.
If their shapes disagree, rhs
is broadcast to the shape of self
.
Panics if broadcasting isn’t possible.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
impl<D: Dimension, P1: NdProducer<Dim=D>, P2: NdProducer<Dim=D>, P3: NdProducer<Dim=D>> Zip<(P1, P2, P3), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item, P2::Item, P3::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item, P2::Item, P3::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn and<P>(self, p: P) -> Zip<(P1, P2, P3, P::Output), D> where P: IntoNdProducer<Dim=D>
Include the producer p
in the Zip.
Panics if p
’s shape doesn’t match the Zip’s exactly.
fn and_broadcast<'a, P, D2, Elem>(self,
p: P)
-> Zip<(P1, P2, P3, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
p: P)
-> Zip<(P1, P2, P3, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
Include the producer p
in the Zip, broadcasting if needed.
If their shapes disagree, rhs
is broadcast to the shape of self
.
Panics if broadcasting isn’t possible.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
impl<D: Dimension, P1: NdProducer<Dim=D>, P2: NdProducer<Dim=D>, P3: NdProducer<Dim=D>, P4: NdProducer<Dim=D>> Zip<(P1, P2, P3, P4), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item, P2::Item, P3::Item, P4::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item, P2::Item, P3::Item, P4::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn and<P>(self, p: P) -> Zip<(P1, P2, P3, P4, P::Output), D> where P: IntoNdProducer<Dim=D>
Include the producer p
in the Zip.
Panics if p
’s shape doesn’t match the Zip’s exactly.
fn and_broadcast<'a, P, D2, Elem>(self,
p: P)
-> Zip<(P1, P2, P3, P4, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
p: P)
-> Zip<(P1, P2, P3, P4, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
Include the producer p
in the Zip, broadcasting if needed.
If their shapes disagree, rhs
is broadcast to the shape of self
.
Panics if broadcasting isn’t possible.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
impl<D: Dimension, P1: NdProducer<Dim=D>, P2: NdProducer<Dim=D>, P3: NdProducer<Dim=D>, P4: NdProducer<Dim=D>, P5: NdProducer<Dim=D>> Zip<(P1, P2, P3, P4, P5), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item, P2::Item, P3::Item, P4::Item, P5::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item, P2::Item, P3::Item, P4::Item, P5::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn and<P>(self, p: P) -> Zip<(P1, P2, P3, P4, P5, P::Output), D> where P: IntoNdProducer<Dim=D>
Include the producer p
in the Zip.
Panics if p
’s shape doesn’t match the Zip’s exactly.
fn and_broadcast<'a, P, D2, Elem>(self,
p: P)
-> Zip<(P1, P2, P3, P4, P5, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
p: P)
-> Zip<(P1, P2, P3, P4, P5, ArrayView<'a, Elem, D>), D> where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
D2: Dimension
Include the producer p
in the Zip, broadcasting if needed.
If their shapes disagree, rhs
is broadcast to the shape of self
.
Panics if broadcasting isn’t possible.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
impl<D: Dimension, P1: NdProducer<Dim=D>, P2: NdProducer<Dim=D>, P3: NdProducer<Dim=D>, P4: NdProducer<Dim=D>, P5: NdProducer<Dim=D>, P6: NdProducer<Dim=D>> Zip<(P1, P2, P3, P4, P5, P6), D>
[src]
fn apply<F>(self, function: F) where F: FnMut(P1::Item, P2::Item, P3::Item, P4::Item, P5::Item, P6::Item)
Apply a function to all elements of the input arrays, visiting elements in lock step.
fn fold_while<F, Acc>(self, acc: Acc, function: F) -> FoldWhile<Acc> where F: FnMut(Acc, P1::Item, P2::Item, P3::Item, P4::Item, P5::Item, P6::Item) -> FoldWhile<Acc>
Apply a fold function to all elements of the input arrays, visiting elements in lock step.
The fold continues while the return value is a
FoldWhile::Continue
.
fn split(self) -> (Self, Self)
Split the Zip
evenly in two.
It will be split in the way that best preserves element locality.
Trait Implementations
impl<Parts: Debug, D: Debug> Debug for Zip<Parts, D>
[src]
impl<Parts: Clone, D: Clone> Clone for Zip<Parts, D>
[src]
fn clone(&self) -> Zip<Parts, D>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more