Skip to content

Commit

Permalink
append: Avoid cloning dim values where possible
Browse files Browse the repository at this point in the history
While this has no effect for low-dimensionality arrays, for dyn dim it
can save some time.
  • Loading branch information
bluss committed May 1, 2021
1 parent cae2544 commit 68c5be0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/impl_owned_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,19 @@ impl<A, D> Array<A, D>
}

let current_axis_len = self.len_of(axis);
let remaining_shape = self.raw_dim().remove_axis(axis);
let array_rem_shape = array.raw_dim().remove_axis(axis);
let self_dim = self.raw_dim();
let array_dim = array.raw_dim();
let remaining_shape = self_dim.remove_axis(axis);
let array_rem_shape = array_dim.remove_axis(axis);

if remaining_shape != array_rem_shape {
return Err(ShapeError::from_kind(ErrorKind::IncompatibleShape));
}

let len_to_append = array.len();

let array_shape = array.raw_dim();
let mut res_dim = self.raw_dim();
res_dim[axis.index()] += array_shape[axis.index()];
let mut res_dim = self_dim;
res_dim[axis.index()] += array_dim[axis.index()];
let new_len = dimension::size_of_shape_checked(&res_dim)?;

if len_to_append == 0 {
Expand Down Expand Up @@ -526,7 +527,7 @@ impl<A, D> Array<A, D>

// With > 0 strides, the current end of data is the correct base pointer for tail_view
let tail_ptr = self.data.as_end_nonnull();
let mut tail_view = RawArrayViewMut::new(tail_ptr, array_shape, tail_strides);
let mut tail_view = RawArrayViewMut::new(tail_ptr, array_dim, tail_strides);

if tail_view.ndim() > 1 {
sort_axes_in_default_order_tandem(&mut tail_view, &mut array);
Expand Down

0 comments on commit 68c5be0

Please sign in to comment.