Skip to content

Commit 901cfe4

Browse files
committed
impl core::ops::Sub for Dim types
1 parent 4722a99 commit 901cfe4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

dfdx-core/src/shapes/shape.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ where
6969
}
7070
}
7171

72+
impl<const N: usize> core::ops::Sub<Const<N>> for usize {
73+
type Output = usize;
74+
fn sub(self, _: Const<N>) -> Self::Output {
75+
self.size() - N
76+
}
77+
}
78+
impl<const N: usize> core::ops::Sub<usize> for Const<N> {
79+
type Output = usize;
80+
fn sub(self, rhs: usize) -> Self::Output {
81+
N - rhs.size()
82+
}
83+
}
84+
85+
#[cfg(feature = "nightly")]
86+
impl<const N: usize, const M: usize> core::ops::Sub<Const<N>> for Const<M>
87+
where
88+
Const<{ M - N }>: Sized,
89+
{
90+
type Output = Const<{ M - N }>;
91+
fn sub(self, _: Const<N>) -> Self::Output {
92+
Const
93+
}
94+
}
95+
7296
impl<const N: usize> core::ops::Mul<Const<N>> for usize {
7397
type Output = usize;
7498
fn mul(self, _: Const<N>) -> Self::Output {

0 commit comments

Comments
 (0)