Skip to content

Commit da10c42

Browse files
committed
DOC: Update doc comment for try_append_array
1 parent 61b0466 commit da10c42

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/impl_owned_array.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,18 @@ impl<A> Array<A, Ix2> {
208208
impl<A, D> Array<A, D>
209209
where D: Dimension
210210
{
211-
/// Append a row to an array with row major memory layout.
211+
/// Append an array to the array
212+
///
213+
/// The axis-to-append-to `axis` must be the array's "growing axis" for this operation
214+
/// to succeed. The growing axis is the outermost or last-visited when elements are visited in
215+
/// memory order:
216+
///
217+
/// `axis` must be the growing axis of the array, or have length 0 or 1.
218+
///
219+
/// - This is the 0th axis for standard layout arrays
220+
/// - This is the *n*-1 th axis for fortran layout arrays
221+
/// - If the array is empty (the axis or any other has length 0) or if `axis`
222+
/// has length 1, then the array can always be appended.
212223
///
213224
/// ***Errors*** with a layout error if the array is not in standard order or
214225
/// if it has holes, even exterior holes (from slicing). <br>
@@ -217,20 +228,28 @@ impl<A, D> Array<A, D>
217228
///
218229
/// The memory layout matters, since it determines in which direction the array can easily
219230
/// grow. Notice that an empty array is compatible both ways. The amortized average
220-
/// complexity of the append is O(m) where *m* is the length of the row.
231+
/// complexity of the append is O(m) where *m* is the number of elements in the
232+
/// array-to-append (equivalent to how `Vec::extend` works).
221233
///
222234
/// ```rust
223-
/// use ndarray::{Array, ArrayView, array};
235+
/// use ndarray::{Array, ArrayView, array, Axis};
224236
///
225237
/// // create an empty array and append
226238
/// let mut a = Array::zeros((0, 4));
227-
/// a.try_append_row(ArrayView::from(&[1., 2., 3., 4.])).unwrap();
228-
/// 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();
229244
///
230245
/// assert_eq!(
231246
/// a,
232-
/// array![[1., 2., 3., 4.],
233-
/// [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.]]);
234253
/// ```
235254
pub fn try_append_array(&mut self, axis: Axis, array: ArrayView<A, D>)
236255
-> Result<(), ShapeError>

0 commit comments

Comments
 (0)