Skip to content

Commit a9dc5f6

Browse files
authored
Merge pull request #872 from rust-ndarray/rename-rows-columns
Rename genrows/gencolumns to rows/columns
2 parents d237595 + a478493 commit a9dc5f6

File tree

9 files changed

+79
-51
lines changed

9 files changed

+79
-51
lines changed

benches/bench1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn iter_sum_2d_by_row(bench: &mut test::Bencher) {
6161
let a = black_box(a);
6262
bench.iter(|| {
6363
let mut sum = 0;
64-
for row in a.genrows() {
64+
for row in a.rows() {
6565
for &elt in row {
6666
sum += elt;
6767
}
@@ -121,7 +121,7 @@ fn iter_sum_2d_cutout_outer_iter(bench: &mut test::Bencher) {
121121
let a = black_box(av);
122122
bench.iter(|| {
123123
let mut sum = 0;
124-
for row in a.genrows() {
124+
for row in a.rows() {
125125
for &elt in row {
126126
sum += elt;
127127
}

examples/life.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn turn_on_corners(z: &mut Board) {
6767
}
6868

6969
fn render(a: &Board) {
70-
for row in a.genrows() {
70+
for row in a.rows() {
7171
for &x in row {
7272
if x > 0 {
7373
print!("#");

src/impl_2d.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ where
5858
self.len_of(Axis(0))
5959
}
6060

61-
/// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
62-
#[deprecated(note = "Renamed to .nrows(), please use the new name")]
63-
pub fn rows(&self) -> usize {
64-
self.nrows()
65-
}
66-
6761
/// Return an array view of column `index`.
6862
///
6963
/// **Panics** if `index` is out of bounds.
@@ -108,12 +102,6 @@ where
108102
self.len_of(Axis(1))
109103
}
110104

111-
/// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.
112-
#[deprecated(note = "Renamed to .ncols(), please use the new name")]
113-
pub fn cols(&self) -> usize {
114-
self.ncols()
115-
}
116-
117105
/// Return true if the array is square, false otherwise.
118106
///
119107
/// # Examples

src/impl_methods.rs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -811,12 +811,12 @@ where
811811
/// [[ 6, 7, 8], // -- row 1, 0
812812
/// [ 9, 10, 11]]]); // -- row 1, 1
813813
///
814-
/// // `genrows` will yield the four generalized rows of the array.
815-
/// for row in a.genrows() {
814+
/// // `rows` will yield the four generalized rows of the array.
815+
/// for row in a.rows() {
816816
/// /* loop body */
817817
/// }
818818
/// ```
819-
pub fn genrows(&self) -> Lanes<'_, A, D::Smaller>
819+
pub fn rows(&self) -> Lanes<'_, A, D::Smaller>
820820
where
821821
S: Data,
822822
{
@@ -827,11 +827,19 @@ where
827827
Lanes::new(self.view(), Axis(n - 1))
828828
}
829829

830+
#[deprecated(note="Renamed to .rows()", since="0.15.0")]
831+
pub fn genrows(&self) -> Lanes<'_, A, D::Smaller>
832+
where
833+
S: Data,
834+
{
835+
self.rows()
836+
}
837+
830838
/// Return a producer and iterable that traverses over the *generalized*
831839
/// rows of the array and yields mutable array views.
832840
///
833841
/// Iterator element is `ArrayView1<A>` (1D read-write array view).
834-
pub fn genrows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
842+
pub fn rows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
835843
where
836844
S: DataMut,
837845
{
@@ -842,6 +850,14 @@ where
842850
LanesMut::new(self.view_mut(), Axis(n - 1))
843851
}
844852

853+
#[deprecated(note="Renamed to .rows_mut()", since="0.15.0")]
854+
pub fn genrows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
855+
where
856+
S: DataMut,
857+
{
858+
self.rows_mut()
859+
}
860+
845861
/// Return a producer and iterable that traverses over the *generalized*
846862
/// columns of the array. For a 2D array these are the regular columns.
847863
///
@@ -863,29 +879,53 @@ where
863879
/// let a = arr3(&[[[ 0, 1, 2], [ 3, 4, 5]],
864880
/// [[ 6, 7, 8], [ 9, 10, 11]]]);
865881
///
866-
/// // Here `gencolumns` will yield the six generalized columns of the array.
867-
/// for row in a.gencolumns() {
882+
/// // Here `columns` will yield the six generalized columns of the array.
883+
/// for row in a.columns() {
868884
/// /* loop body */
869885
/// }
870886
/// ```
871-
pub fn gencolumns(&self) -> Lanes<'_, A, D::Smaller>
887+
pub fn columns(&self) -> Lanes<'_, A, D::Smaller>
872888
where
873889
S: Data,
874890
{
875891
Lanes::new(self.view(), Axis(0))
876892
}
877893

894+
/// Return a producer and iterable that traverses over the *generalized*
895+
/// columns of the array. For a 2D array these are the regular columns.
896+
///
897+
/// Renamed to `.columns()`
898+
#[deprecated(note="Renamed to .columns()", since="0.15.0")]
899+
pub fn gencolumns(&self) -> Lanes<'_, A, D::Smaller>
900+
where
901+
S: Data,
902+
{
903+
self.columns()
904+
}
905+
878906
/// Return a producer and iterable that traverses over the *generalized*
879907
/// columns of the array and yields mutable array views.
880908
///
881909
/// Iterator element is `ArrayView1<A>` (1D read-write array view).
882-
pub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
910+
pub fn columns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
883911
where
884912
S: DataMut,
885913
{
886914
LanesMut::new(self.view_mut(), Axis(0))
887915
}
888916

917+
/// Return a producer and iterable that traverses over the *generalized*
918+
/// columns of the array and yields mutable array views.
919+
///
920+
/// Renamed to `.columns_mut()`
921+
#[deprecated(note="Renamed to .columns_mut()", since="0.15.0")]
922+
pub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
923+
where
924+
S: DataMut,
925+
{
926+
self.columns_mut()
927+
}
928+
889929
/// Return a producer and iterable that traverses over all 1D lanes
890930
/// pointing in the direction of `axis`.
891931
///

src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,24 +413,24 @@ pub type Ixs = isize;
413413
///
414414
/// The `outer_iter` and `axis_iter` are one dimensional producers.
415415
///
416-
/// ## `.genrows()`, `.gencolumns()` and `.lanes()`
416+
/// ## `.rows()`, `.columns()` and `.lanes()`
417417
///
418-
/// [`.genrows()`][gr] is a producer (and iterable) of all rows in an array.
418+
/// [`.rows()`][gr] is a producer (and iterable) of all rows in an array.
419419
///
420420
/// ```
421421
/// use ndarray::Array;
422422
///
423423
/// // 1. Loop over the rows of a 2D array
424424
/// let mut a = Array::zeros((10, 10));
425-
/// for mut row in a.genrows_mut() {
425+
/// for mut row in a.rows_mut() {
426426
/// row.fill(1.);
427427
/// }
428428
///
429429
/// // 2. Use Zip to pair each row in 2D `a` with elements in 1D `b`
430430
/// use ndarray::Zip;
431431
/// let mut b = Array::zeros(a.nrows());
432432
///
433-
/// Zip::from(a.genrows())
433+
/// Zip::from(a.rows())
434434
/// .and(&mut b)
435435
/// .apply(|a_row, b_elt| {
436436
/// *b_elt = a_row[a.ncols() - 1] - a_row[0];
@@ -448,21 +448,21 @@ pub type Ixs = isize;
448448
/// has *a m* rows. It's composed of *a* times the previous array, so it
449449
/// has *a* times as many rows.
450450
///
451-
/// All methods: [`.genrows()`][gr], [`.genrows_mut()`][grm],
452-
/// [`.gencolumns()`][gc], [`.gencolumns_mut()`][gcm],
451+
/// All methods: [`.rows()`][gr], [`.rows_mut()`][grm],
452+
/// [`.columns()`][gc], [`.columns_mut()`][gcm],
453453
/// [`.lanes(axis)`][l], [`.lanes_mut(axis)`][lm].
454454
///
455-
/// [gr]: #method.genrows
456-
/// [grm]: #method.genrows_mut
457-
/// [gc]: #method.gencolumns
458-
/// [gcm]: #method.gencolumns_mut
455+
/// [gr]: #method.rows
456+
/// [grm]: #method.rows_mut
457+
/// [gc]: #method.columns
458+
/// [gcm]: #method.columns_mut
459459
/// [l]: #method.lanes
460460
/// [lm]: #method.lanes_mut
461461
///
462-
/// Yes, for 2D arrays `.genrows()` and `.outer_iter()` have about the same
462+
/// Yes, for 2D arrays `.rows()` and `.outer_iter()` have about the same
463463
/// effect:
464464
///
465-
/// + `genrows()` is a producer with *n* - 1 dimensions of 1 dimensional items
465+
/// + `rows()` is a producer with *n* - 1 dimensions of 1 dimensional items
466466
/// + `outer_iter()` is a producer with 1 dimension of *n* - 1 dimensional items
467467
///
468468
/// ## Slicing

src/zip/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
561561
/// let mut totals = Array1::zeros(a.nrows());
562562
///
563563
/// Zip::from(&mut totals)
564-
/// .and(a.genrows())
564+
/// .and(a.rows())
565565
/// .apply(|totals, row| *totals = row.sum());
566566
///
567567
/// // Check the result against the built in `.sum_axis()` along axis 1.
@@ -570,7 +570,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
570570
///
571571
/// // Example 3: Recreate Example 2 using apply_collect to make a new array
572572
///
573-
/// let mut totals2 = Zip::from(a.genrows()).apply_collect(|row| row.sum());
573+
/// let mut totals2 = Zip::from(a.rows()).apply_collect(|row| row.sum());
574574
///
575575
/// // Check the result against the previous example.
576576
/// assert_eq!(totals, totals2);

src/zip/zipmacro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
/// // entry in `totals` with the sum across each row.
9090
/// //
9191
/// // The row is an array view; it doesn't need to be dereferenced.
92-
/// let mut totals = Array1::zeros(a.rows());
93-
/// azip!((totals in &mut totals, row in a.genrows()) *totals = row.sum());
92+
/// let mut totals = Array1::zeros(a.nrows());
93+
/// azip!((totals in &mut totals, row in a.rows()) *totals = row.sum());
9494
///
9595
/// // Check the result against the built in `.sum_axis()` along axis 1.
9696
/// assert_eq!(totals, a.sum_axis(Axis(1)));

tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ fn test_f_order() {
17011701
assert_eq!(c.strides(), &[3, 1]);
17021702
assert_eq!(f.strides(), &[1, 2]);
17031703
itertools::assert_equal(f.iter(), c.iter());
1704-
itertools::assert_equal(f.genrows(), c.genrows());
1704+
itertools::assert_equal(f.rows(), c.rows());
17051705
itertools::assert_equal(f.outer_iter(), c.outer_iter());
17061706
itertools::assert_equal(f.axis_iter(Axis(0)), c.axis_iter(Axis(0)));
17071707
itertools::assert_equal(f.axis_iter(Axis(1)), c.axis_iter(Axis(1)));

tests/iterators.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn inner_iter() {
142142
// [8, 9],
143143
// ...
144144
assert_equal(
145-
a.genrows(),
145+
a.rows(),
146146
vec![
147147
aview1(&[0, 1]),
148148
aview1(&[2, 3]),
@@ -156,7 +156,7 @@ fn inner_iter() {
156156
b.swap_axes(0, 2);
157157
b.assign(&a);
158158
assert_equal(
159-
b.genrows(),
159+
b.rows(),
160160
vec![
161161
aview1(&[0, 1]),
162162
aview1(&[2, 3]),
@@ -171,21 +171,21 @@ fn inner_iter() {
171171
#[test]
172172
fn inner_iter_corner_cases() {
173173
let a0 = ArcArray::<i32, _>::zeros(());
174-
assert_equal(a0.genrows(), vec![aview1(&[0])]);
174+
assert_equal(a0.rows(), vec![aview1(&[0])]);
175175

176176
let a2 = ArcArray::<i32, _>::zeros((0, 3));
177-
assert_equal(a2.genrows(), vec![aview1(&[]); 0]);
177+
assert_equal(a2.rows(), vec![aview1(&[]); 0]);
178178

179179
let a2 = ArcArray::<i32, _>::zeros((3, 0));
180-
assert_equal(a2.genrows(), vec![aview1(&[]); 3]);
180+
assert_equal(a2.rows(), vec![aview1(&[]); 3]);
181181
}
182182

183183
#[test]
184184
fn inner_iter_size_hint() {
185185
// Check that the size hint is correctly computed
186186
let a = ArcArray::from_iter(0..24).reshape((2, 3, 4));
187187
let mut len = 6;
188-
let mut it = a.genrows().into_iter();
188+
let mut it = a.rows().into_iter();
189189
assert_eq!(it.len(), len);
190190
while len > 0 {
191191
it.next();
@@ -223,7 +223,7 @@ fn outer_iter() {
223223
found_rows.push(row);
224224
}
225225
}
226-
assert_equal(a.genrows(), found_rows.clone());
226+
assert_equal(a.rows(), found_rows.clone());
227227

228228
let mut found_rows_rev = Vec::new();
229229
for sub in b.outer_iter().rev() {
@@ -251,7 +251,7 @@ fn outer_iter() {
251251
}
252252
}
253253
println!("{:#?}", found_rows);
254-
assert_equal(a.genrows(), found_rows);
254+
assert_equal(a.rows(), found_rows);
255255
}
256256

257257
#[test]
@@ -370,7 +370,7 @@ fn outer_iter_mut() {
370370
found_rows.push(row);
371371
}
372372
}
373-
assert_equal(a.genrows(), found_rows);
373+
assert_equal(a.rows(), found_rows);
374374
}
375375

376376
#[test]
@@ -747,8 +747,8 @@ fn iterators_are_send_sync() {
747747
_send_sync(&a.iter_mut());
748748
_send_sync(&a.indexed_iter());
749749
_send_sync(&a.indexed_iter_mut());
750-
_send_sync(&a.genrows());
751-
_send_sync(&a.genrows_mut());
750+
_send_sync(&a.rows());
751+
_send_sync(&a.rows_mut());
752752
_send_sync(&a.outer_iter());
753753
_send_sync(&a.outer_iter_mut());
754754
_send_sync(&a.axis_iter(Axis(1)));

0 commit comments

Comments
 (0)