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