Skip to content

Rename genrows/gencolumns to rows/columns #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn iter_sum_2d_by_row(bench: &mut test::Bencher) {
let a = black_box(a);
bench.iter(|| {
let mut sum = 0;
for row in a.genrows() {
for row in a.rows() {
for &elt in row {
sum += elt;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ fn iter_sum_2d_cutout_outer_iter(bench: &mut test::Bencher) {
let a = black_box(av);
bench.iter(|| {
let mut sum = 0;
for row in a.genrows() {
for row in a.rows() {
for &elt in row {
sum += elt;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn turn_on_corners(z: &mut Board) {
}

fn render(a: &Board) {
for row in a.genrows() {
for row in a.rows() {
for &x in row {
if x > 0 {
print!("#");
Expand Down
12 changes: 0 additions & 12 deletions src/impl_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ where
self.len_of(Axis(0))
}

/// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
#[deprecated(note = "Renamed to .nrows(), please use the new name")]
pub fn rows(&self) -> usize {
self.nrows()
}

/// Return an array view of column `index`.
///
/// **Panics** if `index` is out of bounds.
Expand Down Expand Up @@ -108,12 +102,6 @@ where
self.len_of(Axis(1))
}

/// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.
#[deprecated(note = "Renamed to .ncols(), please use the new name")]
pub fn cols(&self) -> usize {
self.ncols()
}

/// Return true if the array is square, false otherwise.
///
/// # Examples
Expand Down
56 changes: 48 additions & 8 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,12 @@ where
/// [[ 6, 7, 8], // -- row 1, 0
/// [ 9, 10, 11]]]); // -- row 1, 1
///
/// // `genrows` will yield the four generalized rows of the array.
/// for row in a.genrows() {
/// // `rows` will yield the four generalized rows of the array.
/// for row in a.rows() {
/// /* loop body */
/// }
/// ```
pub fn genrows(&self) -> Lanes<'_, A, D::Smaller>
pub fn rows(&self) -> Lanes<'_, A, D::Smaller>
where
S: Data,
{
Expand All @@ -827,11 +827,19 @@ where
Lanes::new(self.view(), Axis(n - 1))
}

#[deprecated(note="Renamed to .rows()", since="0.15.0")]
pub fn genrows(&self) -> Lanes<'_, A, D::Smaller>
where
S: Data,
{
self.rows()
}

/// Return a producer and iterable that traverses over the *generalized*
/// rows of the array and yields mutable array views.
///
/// Iterator element is `ArrayView1<A>` (1D read-write array view).
pub fn genrows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
pub fn rows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
where
S: DataMut,
{
Expand All @@ -842,6 +850,14 @@ where
LanesMut::new(self.view_mut(), Axis(n - 1))
}

#[deprecated(note="Renamed to .rows_mut()", since="0.15.0")]
pub fn genrows_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
where
S: DataMut,
{
self.rows_mut()
}

/// Return a producer and iterable that traverses over the *generalized*
/// columns of the array. For a 2D array these are the regular columns.
///
Expand All @@ -863,29 +879,53 @@ where
/// let a = arr3(&[[[ 0, 1, 2], [ 3, 4, 5]],
/// [[ 6, 7, 8], [ 9, 10, 11]]]);
///
/// // Here `gencolumns` will yield the six generalized columns of the array.
/// for row in a.gencolumns() {
/// // Here `columns` will yield the six generalized columns of the array.
/// for row in a.columns() {
/// /* loop body */
/// }
/// ```
pub fn gencolumns(&self) -> Lanes<'_, A, D::Smaller>
pub fn columns(&self) -> Lanes<'_, A, D::Smaller>
where
S: Data,
{
Lanes::new(self.view(), Axis(0))
}

/// Return a producer and iterable that traverses over the *generalized*
/// columns of the array. For a 2D array these are the regular columns.
///
/// Renamed to `.columns()`
#[deprecated(note="Renamed to .columns()", since="0.15.0")]
pub fn gencolumns(&self) -> Lanes<'_, A, D::Smaller>
where
S: Data,
{
self.columns()
}

/// Return a producer and iterable that traverses over the *generalized*
/// columns of the array and yields mutable array views.
///
/// Iterator element is `ArrayView1<A>` (1D read-write array view).
pub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
pub fn columns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
where
S: DataMut,
{
LanesMut::new(self.view_mut(), Axis(0))
}

/// Return a producer and iterable that traverses over the *generalized*
/// columns of the array and yields mutable array views.
///
/// Renamed to `.columns_mut()`
#[deprecated(note="Renamed to .columns_mut()", since="0.15.0")]
pub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, D::Smaller>
where
S: DataMut,
{
self.columns_mut()
}

/// Return a producer and iterable that traverses over all 1D lanes
/// pointing in the direction of `axis`.
///
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,24 @@ pub type Ixs = isize;
///
/// The `outer_iter` and `axis_iter` are one dimensional producers.
///
/// ## `.genrows()`, `.gencolumns()` and `.lanes()`
/// ## `.rows()`, `.columns()` and `.lanes()`
///
/// [`.genrows()`][gr] is a producer (and iterable) of all rows in an array.
/// [`.rows()`][gr] is a producer (and iterable) of all rows in an array.
///
/// ```
/// use ndarray::Array;
///
/// // 1. Loop over the rows of a 2D array
/// let mut a = Array::zeros((10, 10));
/// for mut row in a.genrows_mut() {
/// for mut row in a.rows_mut() {
/// row.fill(1.);
/// }
///
/// // 2. Use Zip to pair each row in 2D `a` with elements in 1D `b`
/// use ndarray::Zip;
/// let mut b = Array::zeros(a.nrows());
///
/// Zip::from(a.genrows())
/// Zip::from(a.rows())
/// .and(&mut b)
/// .apply(|a_row, b_elt| {
/// *b_elt = a_row[a.ncols() - 1] - a_row[0];
Expand All @@ -448,21 +448,21 @@ pub type Ixs = isize;
/// has *a m* rows. It's composed of *a* times the previous array, so it
/// has *a* times as many rows.
///
/// All methods: [`.genrows()`][gr], [`.genrows_mut()`][grm],
/// [`.gencolumns()`][gc], [`.gencolumns_mut()`][gcm],
/// All methods: [`.rows()`][gr], [`.rows_mut()`][grm],
/// [`.columns()`][gc], [`.columns_mut()`][gcm],
/// [`.lanes(axis)`][l], [`.lanes_mut(axis)`][lm].
///
/// [gr]: #method.genrows
/// [grm]: #method.genrows_mut
/// [gc]: #method.gencolumns
/// [gcm]: #method.gencolumns_mut
/// [gr]: #method.rows
/// [grm]: #method.rows_mut
/// [gc]: #method.columns
/// [gcm]: #method.columns_mut
/// [l]: #method.lanes
/// [lm]: #method.lanes_mut
///
/// Yes, for 2D arrays `.genrows()` and `.outer_iter()` have about the same
/// Yes, for 2D arrays `.rows()` and `.outer_iter()` have about the same
/// effect:
///
/// + `genrows()` is a producer with *n* - 1 dimensions of 1 dimensional items
/// + `rows()` is a producer with *n* - 1 dimensions of 1 dimensional items
/// + `outer_iter()` is a producer with 1 dimension of *n* - 1 dimensional items
///
/// ## Slicing
Expand Down
4 changes: 2 additions & 2 deletions src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
/// let mut totals = Array1::zeros(a.nrows());
///
/// Zip::from(&mut totals)
/// .and(a.genrows())
/// .and(a.rows())
/// .apply(|totals, row| *totals = row.sum());
///
/// // Check the result against the built in `.sum_axis()` along axis 1.
Expand All @@ -570,7 +570,7 @@ impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D> {
///
/// // Example 3: Recreate Example 2 using apply_collect to make a new array
///
/// let mut totals2 = Zip::from(a.genrows()).apply_collect(|row| row.sum());
/// let mut totals2 = Zip::from(a.rows()).apply_collect(|row| row.sum());
///
/// // Check the result against the previous example.
/// assert_eq!(totals, totals2);
Expand Down
4 changes: 2 additions & 2 deletions src/zip/zipmacro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
/// // entry in `totals` with the sum across each row.
/// //
/// // The row is an array view; it doesn't need to be dereferenced.
/// let mut totals = Array1::zeros(a.rows());
/// azip!((totals in &mut totals, row in a.genrows()) *totals = row.sum());
/// let mut totals = Array1::zeros(a.nrows());
/// azip!((totals in &mut totals, row in a.rows()) *totals = row.sum());
///
/// // Check the result against the built in `.sum_axis()` along axis 1.
/// assert_eq!(totals, a.sum_axis(Axis(1)));
Expand Down
2 changes: 1 addition & 1 deletion tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ fn test_f_order() {
assert_eq!(c.strides(), &[3, 1]);
assert_eq!(f.strides(), &[1, 2]);
itertools::assert_equal(f.iter(), c.iter());
itertools::assert_equal(f.genrows(), c.genrows());
itertools::assert_equal(f.rows(), c.rows());
itertools::assert_equal(f.outer_iter(), c.outer_iter());
itertools::assert_equal(f.axis_iter(Axis(0)), c.axis_iter(Axis(0)));
itertools::assert_equal(f.axis_iter(Axis(1)), c.axis_iter(Axis(1)));
Expand Down
22 changes: 11 additions & 11 deletions tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn inner_iter() {
// [8, 9],
// ...
assert_equal(
a.genrows(),
a.rows(),
vec![
aview1(&[0, 1]),
aview1(&[2, 3]),
Expand All @@ -156,7 +156,7 @@ fn inner_iter() {
b.swap_axes(0, 2);
b.assign(&a);
assert_equal(
b.genrows(),
b.rows(),
vec![
aview1(&[0, 1]),
aview1(&[2, 3]),
Expand All @@ -171,21 +171,21 @@ fn inner_iter() {
#[test]
fn inner_iter_corner_cases() {
let a0 = ArcArray::<i32, _>::zeros(());
assert_equal(a0.genrows(), vec![aview1(&[0])]);
assert_equal(a0.rows(), vec![aview1(&[0])]);

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

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

#[test]
fn inner_iter_size_hint() {
// Check that the size hint is correctly computed
let a = ArcArray::from_iter(0..24).reshape((2, 3, 4));
let mut len = 6;
let mut it = a.genrows().into_iter();
let mut it = a.rows().into_iter();
assert_eq!(it.len(), len);
while len > 0 {
it.next();
Expand Down Expand Up @@ -223,7 +223,7 @@ fn outer_iter() {
found_rows.push(row);
}
}
assert_equal(a.genrows(), found_rows.clone());
assert_equal(a.rows(), found_rows.clone());

let mut found_rows_rev = Vec::new();
for sub in b.outer_iter().rev() {
Expand Down Expand Up @@ -251,7 +251,7 @@ fn outer_iter() {
}
}
println!("{:#?}", found_rows);
assert_equal(a.genrows(), found_rows);
assert_equal(a.rows(), found_rows);
}

#[test]
Expand Down Expand Up @@ -370,7 +370,7 @@ fn outer_iter_mut() {
found_rows.push(row);
}
}
assert_equal(a.genrows(), found_rows);
assert_equal(a.rows(), found_rows);
}

#[test]
Expand Down Expand Up @@ -747,8 +747,8 @@ fn iterators_are_send_sync() {
_send_sync(&a.iter_mut());
_send_sync(&a.indexed_iter());
_send_sync(&a.indexed_iter_mut());
_send_sync(&a.genrows());
_send_sync(&a.genrows_mut());
_send_sync(&a.rows());
_send_sync(&a.rows_mut());
_send_sync(&a.outer_iter());
_send_sync(&a.outer_iter_mut());
_send_sync(&a.axis_iter(Axis(1)));
Expand Down