@@ -206,29 +206,50 @@ impl<A> Array<A, Ix2> {
206
206
impl < A , D > Array < A , D >
207
207
where D : Dimension
208
208
{
209
- /// Append a row to an array with row major memory layout.
209
+ /// Append an array to the array
210
+ ///
211
+ /// The axis-to-append-to `axis` must be the array's "growing axis" for this operation
212
+ /// to succeed. The growing axis is the outermost or last-visited when elements are visited in
213
+ /// memory order:
214
+ ///
215
+ /// `axis` must be the growing axis of the current array, an axis with length 0 or 1.
216
+ ///
217
+ /// - This is the 0th axis for standard layout arrays
218
+ /// - This is the *n*-1 th axis for fortran layout arrays
219
+ /// - If the array is empty (the axis or any other has length 0) or if `axis`
220
+ /// has length 1, then the array can always be appended.
210
221
///
211
222
/// ***Errors*** with a layout error if the array is not in standard order or
212
223
/// if it has holes, even exterior holes (from slicing). <br>
213
224
/// ***Errors*** with shape error if the length of the input row does not match
214
225
/// the length of the rows in the array. <br>
215
226
///
216
- /// The memory layout matters, since it determines in which direction the array can easily
217
- /// grow. Notice that an empty array is compatible both ways. The amortized average
218
- /// complexity of the append is O(m) where *m* is the length of the row.
227
+ /// The memory layout of the `self` array matters, since it determines in which direction the
228
+ /// array can easily grow. Notice that an empty array is compatible both ways. The amortized
229
+ /// average complexity of the append is O(m) where *m* is the number of elements in the
230
+ /// array-to-append (equivalent to how `Vec::extend` works).
231
+ ///
232
+ /// The memory layout of the argument `array` does not matter.
219
233
///
220
234
/// ```rust
221
- /// use ndarray::{Array, ArrayView, array};
235
+ /// use ndarray::{Array, ArrayView, array, Axis };
222
236
///
223
237
/// // create an empty array and append
224
238
/// let mut a = Array::zeros((0, 4));
225
- /// a.try_append_row(ArrayView::from(&[1., 2., 3., 4.])).unwrap();
226
- /// a.try_append_row(ArrayView::from(&[0., -2., -3., -4.])).unwrap();
239
+ /// let ones = ArrayView::from(&[1.; 8]).into_shape((2, 4)).unwrap();
240
+ /// let zeros = ArrayView::from(&[0.; 8]).into_shape((2, 4)).unwrap();
241
+ /// a.try_append_array(Axis(0), ones).unwrap();
242
+ /// a.try_append_array(Axis(0), zeros).unwrap();
243
+ /// a.try_append_array(Axis(0), ones).unwrap();
227
244
///
228
245
/// assert_eq!(
229
246
/// a,
230
- /// array![[1., 2., 3., 4.],
231
- /// [0., -2., -3., -4.]]);
247
+ /// array![[1., 1., 1., 1.],
248
+ /// [1., 1., 1., 1.],
249
+ /// [0., 0., 0., 0.],
250
+ /// [0., 0., 0., 0.],
251
+ /// [1., 1., 1., 1.],
252
+ /// [1., 1., 1., 1.]]);
232
253
/// ```
233
254
pub fn try_append_array ( & mut self , axis : Axis , array : ArrayView < A , D > )
234
255
-> Result < ( ) , ShapeError >
0 commit comments