Skip to content

Commit

Permalink
Merge tensor axes before iterating during a transpose
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Apr 4, 2024
1 parent 3df9553 commit 1aed5a4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rten-tensor/src/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use crate::{NdTensorView, TensorView};
/// standard iteration protocol when `x` is non-contiguous and has <= 4
/// dimensions.
fn fast_for_each_element<T, F: FnMut(&T)>(mut x: TensorView<T>, mut f: F) {
// Merge axes to increase the chance that we can use the fast path and
// also maximize the iteration count of the innermost loops.
x.merge_axes();

if x.ndim() > 4 {
x.iter().for_each(f)
} else {
Expand Down

0 comments on commit 1aed5a4

Please sign in to comment.