9
9
use crate :: error:: { from_kind, ErrorKind , ShapeError } ;
10
10
use crate :: imp_prelude:: * ;
11
11
12
- /// Stack arrays along the given axis.
12
+ /// Concatenate arrays along the given axis.
13
13
///
14
14
/// ***Errors*** if the arrays have mismatching shapes, apart from along `axis`.
15
15
/// (may be made more flexible in the future).<br>
@@ -29,6 +29,10 @@ use crate::imp_prelude::*;
29
29
/// [3., 3.]]))
30
30
/// );
31
31
/// ```
32
+ #[ deprecated(
33
+ since = "0.13.0" ,
34
+ note = "Please use the `concatenate` function instead"
35
+ ) ]
32
36
pub fn stack < A , D > ( axis : Axis , arrays : & [ ArrayView < A , D > ] ) -> Result < Array < A , D > , ShapeError >
33
37
where
34
38
A : Copy ,
73
77
Ok ( res)
74
78
}
75
79
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
+
76
108
pub fn stack_new_axis < A , D > (
77
109
axis : Axis ,
78
110
arrays : Vec < ArrayView < A , D > > ,
@@ -123,7 +155,7 @@ where
123
155
///
124
156
/// [1]: fn.stack.html
125
157
///
126
- /// ***Panics*** if the `concatenate ` function would return an error.
158
+ /// ***Panics*** if the `stack ` function would return an error.
127
159
///
128
160
/// ```
129
161
/// extern crate ndarray;
@@ -150,6 +182,40 @@ macro_rules! stack {
150
182
}
151
183
}
152
184
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
+
153
219
/// Stack arrays along the new axis.
154
220
///
155
221
/// Uses the [`stack_new_axis`][1] function, calling `ArrayView::from(&a)` on each
0 commit comments