@@ -77,66 +77,78 @@ where
77
77
///
78
78
/// [`ArrayBase`]: struct.ArrayBase.html
79
79
impl < A > Array < A , Ix2 > {
80
- /// Append a row to an array with row major memory layout.
80
+ /// Append a row to an array
81
81
///
82
- /// ***Errors*** with a layout error if the array is not in standard order or
83
- /// if it has holes, even exterior holes (from slicing). <br>
84
- /// ***Errors*** with shape error if the length of the input row does not match
85
- /// the length of the rows in the array. <br>
82
+ /// ***Errors*** with a shape error if the length of the row does not match the length of the
83
+ /// rows in the array. <br>
86
84
///
87
- /// The memory layout matters, since it determines in which direction the array can easily
88
- /// grow. Notice that an empty array is compatible both ways. The amortized average
89
- /// complexity of the append is O(m) where *m* is the length of the row.
85
+ /// The memory layout of the `self` array matters for ensuring that the append is efficient.
86
+ /// Appending automatically changes memory layout of the array so that it is appended to
87
+ /// along the "growing axis".
88
+ ///
89
+ /// Ensure appending is efficient by for example starting appending an empty array and
90
+ /// always appending along the same axis. For rows, ndarray's default layout is efficient for
91
+ /// appending.
92
+ ///
93
+ /// Notice that an empty array (where it has an axis of length zero) is the simplest starting
94
+ /// point. The amortized average complexity of the append is O(m) where *m* is the length of
95
+ /// the row.
90
96
///
91
97
/// ```rust
92
98
/// use ndarray::{Array, ArrayView, array};
93
99
///
94
100
/// // create an empty array and append
95
101
/// let mut a = Array::zeros((0, 4));
96
- /// a.try_append_row (ArrayView::from(&[ 1., 2., 3., 4.])).unwrap();
97
- /// a.try_append_row (ArrayView::from(&[-1., -2., -3., -4.])).unwrap();
102
+ /// a.append_row (ArrayView::from(&[ 1., 2., 3., 4.])).unwrap();
103
+ /// a.append_row (ArrayView::from(&[-1., -2., -3., -4.])).unwrap();
98
104
///
99
105
/// assert_eq!(
100
106
/// a,
101
107
/// array![[ 1., 2., 3., 4.],
102
108
/// [-1., -2., -3., -4.]]);
103
109
/// ```
104
- pub fn try_append_row ( & mut self , row : ArrayView < A , Ix1 > ) -> Result < ( ) , ShapeError >
110
+ pub fn append_row ( & mut self , row : ArrayView < A , Ix1 > ) -> Result < ( ) , ShapeError >
105
111
where
106
112
A : Clone ,
107
113
{
108
- self . try_append_array ( Axis ( 0 ) , row. insert_axis ( Axis ( 0 ) ) )
114
+ self . append ( Axis ( 0 ) , row. insert_axis ( Axis ( 0 ) ) )
109
115
}
110
116
111
- /// Append a column to an array with column major memory layout.
117
+ /// Append a column to an array
118
+ ///
119
+ /// ***Errors*** with a shape error if the length of the column does not match the length of
120
+ /// the columns in the array.<br>
121
+ ///
122
+ /// The memory layout of the `self` array matters for ensuring that the append is efficient.
123
+ /// Appending automatically changes memory layout of the array so that it is appended to
124
+ /// along the "growing axis".
112
125
///
113
- /// ***Errors*** with a layout error if the array is not in column major order or
114
- /// if it has holes, even exterior holes (from slicing). <br>
115
- /// ***Errors*** with shape error if the length of the input column does not match
116
- /// the length of the columns in the array.<br>
126
+ /// Ensure appending is efficient by for example starting appending an empty array and
127
+ /// always appending along the same axis. For columns, column major ("F") memory layout is
128
+ /// efficient for appending.
117
129
///
118
- /// The memory layout matters, since it determines in which direction the array can easily
119
- /// grow. Notice that an empty array is compatible both ways. The amortized average
120
- /// complexity of the append is O(m) where *m* is the length of the column .
130
+ /// Notice that an empty array (where it has an axis of length zero) is the simplest starting
131
+ /// point. The amortized average complexity of the append is O(m) where *m* is the length of
132
+ /// the row .
121
133
///
122
134
/// ```rust
123
135
/// use ndarray::{Array, ArrayView, array};
124
136
///
125
137
/// // create an empty array and append
126
138
/// let mut a = Array::zeros((2, 0));
127
- /// a.try_append_column (ArrayView::from(&[1., 2.])).unwrap();
128
- /// a.try_append_column (ArrayView::from(&[-1., -2.])).unwrap();
139
+ /// a.append_column (ArrayView::from(&[1., 2.])).unwrap();
140
+ /// a.append_column (ArrayView::from(&[-1., -2.])).unwrap();
129
141
///
130
142
/// assert_eq!(
131
143
/// a,
132
144
/// array![[1., -1.],
133
145
/// [2., -2.]]);
134
146
/// ```
135
- pub fn try_append_column ( & mut self , column : ArrayView < A , Ix1 > ) -> Result < ( ) , ShapeError >
147
+ pub fn append_column ( & mut self , column : ArrayView < A , Ix1 > ) -> Result < ( ) , ShapeError >
136
148
where
137
149
A : Clone ,
138
150
{
139
- self . try_append_array ( Axis ( 1 ) , column. insert_axis ( Axis ( 1 ) ) )
151
+ self . append ( Axis ( 1 ) , column. insert_axis ( Axis ( 1 ) ) )
140
152
}
141
153
}
142
154
@@ -334,7 +346,7 @@ impl<A, D> Array<A, D>
334
346
/// - If the array is empty (the axis or any other has length 0) or if `axis`
335
347
/// has length 1, then the array can always be appended.
336
348
///
337
- /// ***Errors*** with shape error if the shape of self does not match the array-to-append;
349
+ /// ***Errors*** with a shape error if the shape of self does not match the array-to-append;
338
350
/// all axes *except* the axis along which it being appended matter for this check.
339
351
///
340
352
/// The memory layout of the `self` array matters for ensuring that the append is efficient.
@@ -347,7 +359,7 @@ impl<A, D> Array<A, D>
347
359
/// The amortized average complexity of the append, when appending along its growing axis, is
348
360
/// O(*m*) where *m* is the length of the row.
349
361
///
350
- /// The memory layout of the argument `array` does not matter.
362
+ /// The memory layout of the argument `array` does not matter to the same extent .
351
363
///
352
364
/// ```rust
353
365
/// use ndarray::{Array, ArrayView, array, Axis};
@@ -356,9 +368,9 @@ impl<A, D> Array<A, D>
356
368
/// let mut a = Array::zeros((0, 4));
357
369
/// let ones = ArrayView::from(&[1.; 8]).into_shape((2, 4)).unwrap();
358
370
/// let zeros = ArrayView::from(&[0.; 8]).into_shape((2, 4)).unwrap();
359
- /// a.try_append_array (Axis(0), ones).unwrap();
360
- /// a.try_append_array (Axis(0), zeros).unwrap();
361
- /// a.try_append_array (Axis(0), ones).unwrap();
371
+ /// a.append (Axis(0), ones).unwrap();
372
+ /// a.append (Axis(0), zeros).unwrap();
373
+ /// a.append (Axis(0), ones).unwrap();
362
374
///
363
375
/// assert_eq!(
364
376
/// a,
@@ -369,7 +381,7 @@ impl<A, D> Array<A, D>
369
381
/// [1., 1., 1., 1.],
370
382
/// [1., 1., 1., 1.]]);
371
383
/// ```
372
- pub fn try_append_array ( & mut self , axis : Axis , mut array : ArrayView < A , D > )
384
+ pub fn append ( & mut self , axis : Axis , mut array : ArrayView < A , D > )
373
385
-> Result < ( ) , ShapeError >
374
386
where
375
387
A : Clone ,
0 commit comments