Skip to content

Commit 06e6145

Browse files
author
andrei-papou
committed
Updated stack_new_axis, deprecated stack! macro.
1 parent ef74ac9 commit 06e6145

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/stacking.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::imp_prelude::*;
3030
/// );
3131
/// ```
3232
#[deprecated(
33-
since = "0.13.1",
33+
since = "0.13.2",
3434
note = "Please use the `concatenate` function instead"
3535
)]
3636
pub fn stack<A, D>(axis: Axis, arrays: &[ArrayView<A, D>]) -> Result<Array<A, D>, ShapeError>
@@ -106,9 +106,33 @@ where
106106
stack(axis, arrays)
107107
}
108108

109+
/// Stack arrays along the new axis.
110+
///
111+
/// ***Errors*** if the arrays have mismatching shapes.
112+
/// ***Errors*** if `arrays` is empty, if `axis` is out of bounds,
113+
/// if the result is larger than is possible to represent.
114+
///
115+
/// ```
116+
/// extern crate ndarray;
117+
///
118+
/// use ndarray::{arr2, arr3, stack_new_axis, Axis};
119+
///
120+
/// # fn main() {
121+
///
122+
/// let a = arr2(&[[2., 2.],
123+
/// [3., 3.]]);
124+
/// assert!(
125+
/// stack_new_axis(Axis(0), &[a.view(), a.view()])
126+
/// == Ok(arr3(&[[[2., 2.],
127+
/// [3., 3.]],
128+
/// [[2., 2.],
129+
/// [3., 3.]]]))
130+
/// );
131+
/// # }
132+
/// ```
109133
pub fn stack_new_axis<A, D>(
110134
axis: Axis,
111-
arrays: Vec<ArrayView<A, D>>,
135+
arrays: &[ArrayView<A, D>],
112136
) -> Result<Array<A, D::Larger>, ShapeError>
113137
where
114138
A: Copy,
@@ -176,6 +200,10 @@ where
176200
/// );
177201
/// # }
178202
/// ```
203+
#[deprecated(
204+
since = "0.13.2",
205+
note = "Please use the `concatenate!` macro instead"
206+
)]
179207
#[macro_export]
180208
macro_rules! stack {
181209
($axis:expr, $( $array:expr ),+ ) => {
@@ -247,6 +275,6 @@ macro_rules! concatenate {
247275
#[macro_export]
248276
macro_rules! stack_new_axis {
249277
($axis:expr, $( $array:expr ),+ ) => {
250-
$crate::stack_new_axis($axis, vec![ $($crate::ArrayView::from(&$array) ),* ]).unwrap()
278+
$crate::stack_new_axis($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap()
251279
}
252280
}

tests/stacking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ fn concatenating() {
5252
#[test]
5353
fn stacking() {
5454
let a = arr2(&[[2., 2.], [3., 3.]]);
55-
let b = ndarray::stack_new_axis(Axis(0), vec![a.view(), a.view()]).unwrap();
55+
let b = ndarray::stack_new_axis(Axis(0), &[a.view(), a.view()]).unwrap();
5656
assert_eq!(b, arr3(&[[[2., 2.], [3., 3.]], [[2., 2.], [3., 3.]]]));
5757

5858
let c = arr2(&[[3., 2., 3.], [2., 3., 2.]]);
59-
let res = ndarray::stack_new_axis(Axis(1), vec![a.view(), c.view()]);
59+
let res = ndarray::stack_new_axis(Axis(1), &[a.view(), c.view()]);
6060
assert_eq!(res.unwrap_err().kind(), ErrorKind::IncompatibleShape);
6161

62-
let res = ndarray::stack_new_axis(Axis(3), vec![a.view(), a.view()]);
62+
let res = ndarray::stack_new_axis(Axis(3), &[a.view(), a.view()]);
6363
assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds);
6464

65-
let res: Result<Array2<f64>, _> = ndarray::stack_new_axis::<_, Ix1>(Axis(0), vec![]);
65+
let res: Result<Array2<f64>, _> = ndarray::stack_new_axis::<_, Ix1>(Axis(0), &[]);
6666
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
6767
}

0 commit comments

Comments
 (0)