Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/stacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use crate::imp_prelude::*;
/// [3., 3.]]))
/// );
/// ```
pub fn concatenate<A, D>(axis: Axis, arrays: &[ArrayView<A, D>]) -> Result<Array<A, D>, ShapeError>
pub fn concatenate<S, D, A>(axis: Axis, arrays: &[ArrayBase<S, D, A>]) -> Result<Array<A, D>, ShapeError>
Comment thread
nilgoyette marked this conversation as resolved.
Outdated
where
S: Data<Elem = A>,
A: Clone,
D: RemoveAxis,
{
Expand Down Expand Up @@ -66,7 +67,7 @@ where
};

for array in arrays {
res.append(axis, array.clone())?;
res.append(axis, array.view())?;
}
debug_assert_eq!(res.len_of(axis), stacked_dim);
Ok(res)
Expand Down Expand Up @@ -96,8 +97,9 @@ where
/// );
/// # }
/// ```
pub fn stack<A, D>(axis: Axis, arrays: &[ArrayView<A, D>]) -> Result<Array<A, D::Larger>, ShapeError>
pub fn stack<S, D, A>(axis: Axis, arrays: &[ArrayBase<S, D, A>]) -> Result<Array<A, D::Larger>, ShapeError>
where
S: Data<Elem = A>,
A: Clone,
D: Dimension,
D::Larger: RemoveAxis,
Expand Down Expand Up @@ -129,7 +131,7 @@ where
};

for array in arrays {
res.append(axis, array.clone().insert_axis(axis))?;
res.append(axis, array.view().insert_axis(axis))?;
}

debug_assert_eq!(res.len_of(axis), arrays.len());
Expand Down
6 changes: 3 additions & 3 deletions tests/stacking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ndarray::{arr2, arr3, aview1, aview2, concatenate, stack, Array2, Axis, ErrorKind, Ix1};
use ndarray::{arr2, arr3, aview1, aview2, concatenate, stack, Array2, Axis, ErrorKind, Ix1, ViewRepr};

#[test]
fn concatenating()
Expand Down Expand Up @@ -29,7 +29,7 @@ fn concatenating()
let res = ndarray::concatenate(Axis(2), &[a.view(), c.view()]);
assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds);

let res: Result<Array2<f64>, _> = ndarray::concatenate(Axis(0), &[]);
let res: Result<Array2<f64>, _> = ndarray::concatenate::<ViewRepr<&f64>, _, _>(Axis(0), &[]);
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
}

Expand All @@ -50,6 +50,6 @@ fn stacking()
let res = ndarray::stack(Axis(3), &[a.view(), a.view()]);
assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds);

let res: Result<Array2<f64>, _> = ndarray::stack::<_, Ix1>(Axis(0), &[]);
let res: Result<Array2<f64>, _> = ndarray::stack::<ViewRepr<&f64>, Ix1, _>(Axis(0), &[]);
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
}