99use crate :: error:: { from_kind, ErrorKind , ShapeError } ;
1010use crate :: imp_prelude:: * ;
1111
12- /// Stack arrays along the given axis.
12+ /// Concatenate arrays along the given axis.
1313///
1414/// ***Errors*** if the arrays have mismatching shapes, apart from along `axis`.
1515/// (may be made more flexible in the future).<br>
@@ -29,6 +29,10 @@ use crate::imp_prelude::*;
2929/// [3., 3.]]))
3030/// );
3131/// ```
32+ #[ deprecated(
33+ since = "0.13.0" ,
34+ note = "Please use the `concatenate` function instead"
35+ ) ]
3236pub fn stack < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
3337where
3438 A : Copy ,
7377 Ok ( res)
7478}
7579
80+ /// Concatenate arrays along the given axis.
81+ ///
82+ /// ***Errors*** if the arrays have mismatching shapes, apart from along `axis`.
83+ /// (may be made more flexible in the future).<br>
84+ /// ***Errors*** if `arrays` is empty, if `axis` is out of bounds,
85+ /// if the result is larger than is possible to represent.
86+ ///
87+ /// ```
88+ /// use ndarray::{arr2, Axis, concatenate};
89+ ///
90+ /// let a = arr2(&[[2., 2.],
91+ /// [3., 3.]]);
92+ /// assert!(
93+ /// concatenate(Axis(0), &[a.view(), a.view()])
94+ /// == Ok(arr2(&[[2., 2.],
95+ /// [3., 3.],
96+ /// [2., 2.],
97+ /// [3., 3.]]))
98+ /// );
99+ /// ```
100+ pub fn concatenate < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
101+ where
102+ A : Copy ,
103+ D : RemoveAxis ,
104+ {
105+ stack ( axis, arrays)
106+ }
107+
76108pub fn stack_new_axis < A , D > (
77109 axis : Axis ,
78110 arrays : Vec < ArrayView < A , D > > ,
@@ -123,7 +155,7 @@ where
123155///
124156/// [1]: fn.stack.html
125157///
126- /// ***Panics*** if the `concatenate ` function would return an error.
158+ /// ***Panics*** if the `stack ` function would return an error.
127159///
128160/// ```
129161/// extern crate ndarray;
@@ -150,6 +182,40 @@ macro_rules! stack {
150182 }
151183}
152184
185+ /// Concatenate arrays along the given axis.
186+ ///
187+ /// Uses the [`concatenate`][1] function, calling `ArrayView::from(&a)` on each
188+ /// argument `a`.
189+ ///
190+ /// [1]: fn.concatenate.html
191+ ///
192+ /// ***Panics*** if the `concatenate` function would return an error.
193+ ///
194+ /// ```
195+ /// extern crate ndarray;
196+ ///
197+ /// use ndarray::{arr2, concatenate, Axis};
198+ ///
199+ /// # fn main() {
200+ ///
201+ /// let a = arr2(&[[2., 2.],
202+ /// [3., 3.]]);
203+ /// assert!(
204+ /// concatenate![Axis(0), a, a]
205+ /// == arr2(&[[2., 2.],
206+ /// [3., 3.],
207+ /// [2., 2.],
208+ /// [3., 3.]])
209+ /// );
210+ /// # }
211+ /// ```
212+ #[ macro_export]
213+ macro_rules! concatenate {
214+ ( $axis: expr, $( $array: expr ) ,+ ) => {
215+ $crate:: concatenate( $axis, & [ $( $crate:: ArrayView :: from( & $array) ) ,* ] ) . unwrap( )
216+ }
217+ }
218+
153219/// Stack arrays along the new axis.
154220///
155221/// Uses the [`stack_new_axis`][1] function, calling `ArrayView::from(&a)` on each
0 commit comments