Skip to content

Commit 35e0bf2

Browse files
committed
There seems to be need to support dimensionalities of more than 32 for InvertedAxes as NumPy does not support it in the first place.
1 parent ca4a49e commit 35e0bf2

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

src/array.rs

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -358,46 +358,25 @@ impl<T, D> PyArray<T, D> {
358358
}
359359
}
360360

361-
enum InvertedAxes {
362-
Short(u32),
363-
Long(Vec<usize>),
364-
}
361+
struct InvertedAxes(u32);
365362

366363
impl InvertedAxes {
367364
fn new(len: usize) -> Self {
368-
if len <= 32 {
369-
Self::Short(0)
370-
} else {
371-
Self::Long(Vec::new())
372-
}
365+
assert!(len <= 32, "Only dimensionalities of up to 32 are supported");
366+
Self(0)
373367
}
374368

375369
fn push(&mut self, axis: usize) {
376-
match self {
377-
Self::Short(axes) => {
378-
debug_assert!(axis < 32);
379-
*axes |= 1 << axis;
380-
}
381-
Self::Long(axes) => {
382-
axes.push(axis);
383-
}
384-
}
370+
debug_assert!(axis < 32);
371+
self.0 |= 1 << axis;
385372
}
386373

387-
fn invert<S: RawData, D: Dimension>(self, array: &mut ArrayBase<S, D>) {
388-
match self {
389-
Self::Short(mut axes) => {
390-
while axes != 0 {
391-
let axis = axes.trailing_zeros() as usize;
392-
axes &= !(1 << axis);
393-
array.invert_axis(Axis(axis));
394-
}
395-
}
396-
Self::Long(axes) => {
397-
for axis in axes {
398-
array.invert_axis(Axis(axis));
399-
}
400-
}
374+
fn invert<S: RawData, D: Dimension>(mut self, array: &mut ArrayBase<S, D>) {
375+
while self.0 != 0 {
376+
let axis = self.0.trailing_zeros() as usize;
377+
self.0 &= !(1 << axis);
378+
379+
array.invert_axis(Axis(axis));
401380
}
402381
}
403382
}

0 commit comments

Comments
 (0)