Skip to content

Commit 8dffea0

Browse files
committed
Add special case impls for RemoveAxis for 1d, 2d
1 parent 582af1f commit 8dffea0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/dimension.rs

+18
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ pub trait RemoveAxis : Dimension {
639639
}
640640

641641
macro_rules! impl_shrink(
642+
($_a:ident, ) => {}; // implement this case manually below
643+
($_a:ident, $_b:ident, ) => {}; // implement this case manually below
642644
($from:ident, $($more:ident,)*) => (
643645
impl RemoveAxis for ($from $(,$more)*)
644646
{
@@ -665,6 +667,22 @@ impl RemoveAxis for ($from $(,$more)*)
665667
)
666668
);
667669

670+
impl RemoveAxis for Ix {
671+
type Smaller = ();
672+
#[inline]
673+
fn remove_axis(&self, _: Axis) { }
674+
}
675+
676+
impl RemoveAxis for (Ix, Ix) {
677+
type Smaller = Ix;
678+
#[inline]
679+
fn remove_axis(&self, axis: Axis) -> Ix {
680+
let axis = axis.axis();
681+
debug_assert!(axis < self.ndim());
682+
if axis == 0 { self.1 } else { self.0 }
683+
}
684+
}
685+
668686
macro_rules! impl_shrink_recursive(
669687
($ix:ident, ) => (impl_shrink!($ix,););
670688
($ix1:ident, $($ix:ident,)*) => (

0 commit comments

Comments
 (0)