From 06e61458831fd41db61ee614df6102583b04d1cd Mon Sep 17 00:00:00 2001 From: andrei-papou Date: Fri, 25 Sep 2020 11:46:39 +0300 Subject: [PATCH] Updated `stack_new_axis`, deprecated `stack!` macro. --- src/stacking.rs | 34 +++++++++++++++++++++++++++++++--- tests/stacking.rs | 8 ++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/stacking.rs b/src/stacking.rs index 822b4b56d..e31581679 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -30,7 +30,7 @@ use crate::imp_prelude::*; /// ); /// ``` #[deprecated( - since = "0.13.1", + since = "0.13.2", note = "Please use the `concatenate` function instead" )] pub fn stack(axis: Axis, arrays: &[ArrayView]) -> Result, ShapeError> @@ -106,9 +106,33 @@ where stack(axis, arrays) } +/// Stack arrays along the new axis. +/// +/// ***Errors*** if the arrays have mismatching shapes. +/// ***Errors*** if `arrays` is empty, if `axis` is out of bounds, +/// if the result is larger than is possible to represent. +/// +/// ``` +/// extern crate ndarray; +/// +/// use ndarray::{arr2, arr3, stack_new_axis, Axis}; +/// +/// # fn main() { +/// +/// let a = arr2(&[[2., 2.], +/// [3., 3.]]); +/// assert!( +/// stack_new_axis(Axis(0), &[a.view(), a.view()]) +/// == Ok(arr3(&[[[2., 2.], +/// [3., 3.]], +/// [[2., 2.], +/// [3., 3.]]])) +/// ); +/// # } +/// ``` pub fn stack_new_axis( axis: Axis, - arrays: Vec>, + arrays: &[ArrayView], ) -> Result, ShapeError> where A: Copy, @@ -176,6 +200,10 @@ where /// ); /// # } /// ``` +#[deprecated( + since = "0.13.2", + note = "Please use the `concatenate!` macro instead" +)] #[macro_export] macro_rules! stack { ($axis:expr, $( $array:expr ),+ ) => { @@ -247,6 +275,6 @@ macro_rules! concatenate { #[macro_export] macro_rules! stack_new_axis { ($axis:expr, $( $array:expr ),+ ) => { - $crate::stack_new_axis($axis, vec![ $($crate::ArrayView::from(&$array) ),* ]).unwrap() + $crate::stack_new_axis($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap() } } diff --git a/tests/stacking.rs b/tests/stacking.rs index 27d36d0f3..94077def2 100644 --- a/tests/stacking.rs +++ b/tests/stacking.rs @@ -52,16 +52,16 @@ fn concatenating() { #[test] fn stacking() { let a = arr2(&[[2., 2.], [3., 3.]]); - let b = ndarray::stack_new_axis(Axis(0), vec![a.view(), a.view()]).unwrap(); + let b = ndarray::stack_new_axis(Axis(0), &[a.view(), a.view()]).unwrap(); assert_eq!(b, arr3(&[[[2., 2.], [3., 3.]], [[2., 2.], [3., 3.]]])); let c = arr2(&[[3., 2., 3.], [2., 3., 2.]]); - let res = ndarray::stack_new_axis(Axis(1), vec![a.view(), c.view()]); + let res = ndarray::stack_new_axis(Axis(1), &[a.view(), c.view()]); assert_eq!(res.unwrap_err().kind(), ErrorKind::IncompatibleShape); - let res = ndarray::stack_new_axis(Axis(3), vec![a.view(), a.view()]); + let res = ndarray::stack_new_axis(Axis(3), &[a.view(), a.view()]); assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds); - let res: Result, _> = ndarray::stack_new_axis::<_, Ix1>(Axis(0), vec![]); + let res: Result, _> = ndarray::stack_new_axis::<_, Ix1>(Axis(0), &[]); assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported); }