99use crate :: error:: { from_kind, ErrorKind , ShapeError } ;
1010use crate :: imp_prelude:: * ;
1111
12+ /// Stack arrays along the new axis.
13+ ///
14+ /// ***Errors*** if the arrays have mismatching shapes.
15+ /// ***Errors*** if `arrays` is empty, if `axis` is out of bounds,
16+ /// if the result is larger than is possible to represent.
17+ ///
18+ /// ```
19+ /// extern crate ndarray;
20+ ///
21+ /// use ndarray::{arr2, arr3, stack, Axis};
22+ ///
23+ /// # fn main() {
24+ ///
25+ /// let a = arr2(&[[2., 2.],
26+ /// [3., 3.]]);
27+ /// assert!(
28+ /// stack(Axis(0), &[a.view(), a.view()])
29+ /// == Ok(arr3(&[[[2., 2.],
30+ /// [3., 3.]],
31+ /// [[2., 2.],
32+ /// [3., 3.]]]))
33+ /// );
34+ /// # }
35+ /// ```
36+ pub fn stack < A , D > (
37+ axis : Axis ,
38+ arrays : & [ ArrayView < A , D > ] ,
39+ ) -> Result < Array < A , D :: Larger > , ShapeError >
40+ where
41+ A : Copy ,
42+ D : Dimension ,
43+ D :: Larger : RemoveAxis ,
44+ {
45+ stack_new_axis ( axis, arrays)
46+ }
47+
1248/// Concatenate arrays along the given axis.
1349///
1450/// ***Errors*** if the arrays have mismatching shapes, apart from along `axis`.
@@ -17,23 +53,19 @@ use crate::imp_prelude::*;
1753/// if the result is larger than is possible to represent.
1854///
1955/// ```
20- /// use ndarray::{arr2, Axis, stack };
56+ /// use ndarray::{arr2, Axis, concatenate };
2157///
2258/// let a = arr2(&[[2., 2.],
2359/// [3., 3.]]);
2460/// assert!(
25- /// stack (Axis(0), &[a.view(), a.view()])
61+ /// concatenate (Axis(0), &[a.view(), a.view()])
2662/// == Ok(arr2(&[[2., 2.],
2763/// [3., 3.],
2864/// [2., 2.],
2965/// [3., 3.]]))
3066/// );
3167/// ```
32- #[ deprecated(
33- since = "0.13.2" ,
34- note = "Please use the `concatenate` function instead"
35- ) ]
36- pub fn stack < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
68+ pub fn concatenate < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
3769where
3870 A : Copy ,
3971 D : RemoveAxis ,
@@ -77,35 +109,6 @@ where
77109 Ok ( res)
78110}
79111
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- #[ allow( deprecated) ]
101- pub fn concatenate < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
102- where
103- A : Copy ,
104- D : RemoveAxis ,
105- {
106- stack ( axis, arrays)
107- }
108-
109112/// Stack arrays along the new axis.
110113///
111114/// ***Errors*** if the arrays have mismatching shapes.
@@ -173,7 +176,7 @@ where
173176 Ok ( res)
174177}
175178
176- /// Concatenate arrays along the given axis.
179+ /// Stack arrays along the new axis.
177180///
178181/// Uses the [`stack`][1] function, calling `ArrayView::from(&a)` on each
179182/// argument `a`.
@@ -183,25 +186,23 @@ where
183186/// ***Panics*** if the `stack` function would return an error.
184187///
185188/// ```
186- /// use ndarray::{arr2, stack, Axis};
189+ /// extern crate ndarray;
190+ ///
191+ /// use ndarray::{arr2, arr3, stack, Axis};
187192///
188193/// # fn main() {
189194///
190195/// let a = arr2(&[[2., 2.],
191196/// [3., 3.]]);
192197/// assert!(
193198/// stack![Axis(0), a, a]
194- /// == arr2(& [[2., 2.],
195- /// [3., 3.],
196- /// [2., 2.],
197- /// [3., 3.]])
199+ /// == arr3(&[ [[2., 2.],
200+ /// [3., 3.] ],
201+ /// [[ 2., 2.],
202+ /// [3., 3.] ]])
198203/// );
199204/// # }
200205/// ```
201- #[ deprecated(
202- since = "0.13.2" ,
203- note = "Please use the `concatenate!` macro instead"
204- ) ]
205206#[ macro_export]
206207macro_rules! stack {
207208 ( $axis: expr, $( $array: expr ) ,+ ) => {
0 commit comments