Skip to content

IntoNdProducer for &mut &mut ArrayBase #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ impl<'a, A: 'a, S, D> IntoNdProducer for &'a ArrayBase<S, D>
}
}

/// An array reference is an n-dimensional producer of element references
/// (like ArrayView).
impl<'a, 'b, A: 'a + 'b, S, D> IntoNdProducer for &'b &'a ArrayBase<S, D>
where D: Dimension,
S: Data<Elem=A>,
{
type Item = &'a A;
type Dim = D;
type Output = ArrayView<'a, A, D>;
fn into_producer(self) -> Self::Output {
self.view()
}
}

/// A mutable array reference is an n-dimensional producer of mutable element
/// references (like ArrayViewMut).
impl<'a, A: 'a, S, D> IntoNdProducer for &'a mut ArrayBase<S, D>
Expand All @@ -234,6 +248,21 @@ impl<'a, A: 'a, S, D> IntoNdProducer for &'a mut ArrayBase<S, D>
}
}

/// A mutable array reference is an n-dimensional producer of mutable element
/// references (like ArrayViewMut).
impl<'a, 'b, A: 'a + 'b, S, D> IntoNdProducer for &'a mut &'b mut ArrayBase<S, D>
where D: Dimension,
S: DataMut<Elem=A>,
'b: 'a
{
type Item = &'a mut A;
type Dim = D;
type Output = ArrayViewMut<'a, A, D>;
fn into_producer(self) -> Self::Output {
self.view_mut()
}
}

/// A slice is a one-dimensional producer
impl<'a, A: 'a> IntoNdProducer for &'a [A] {
type Item = <Self::Output as NdProducer>::Item;
Expand Down
9 changes: 9 additions & 0 deletions tests/zip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use ndarray::{azip, ArrayBase, Data, DataMut, Dimension};

#[allow(unused)]
fn zip_ref_ref<Sa, Sb, D: Dimension>(mut a: &mut ArrayBase<Sa, D>, b: &ArrayBase<Sb, D>)
where Sa: DataMut<Elem = f64>,
Sb: Data<Elem = f64>
{
azip!(mut a, b in { *a = 2.0*b });
}