Skip to content

Commit 54c3a85

Browse files
committed
Demonstration - BroadcastShape<Self> as "supertrait" for Dimension
1 parent 979d6df commit 54c3a85

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/dimension/broadcast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141
Ok(out)
4242
}
4343

44-
pub trait BroadcastShape<Other: Dimension>: Dimension {
44+
pub trait BroadcastShape<Other: Dimension> {
4545
/// The resulting dimension type after broadcasting.
4646
type BroadcastOutput: Dimension;
4747

@@ -52,7 +52,8 @@ pub trait BroadcastShape<Other: Dimension>: Dimension {
5252
/// Uses the [NumPy broadcasting rules]
5353
/// (https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html#general-broadcasting-rules).
5454
fn broadcast_shape(&self, other: &Other) -> Result<Self::BroadcastOutput, ShapeError> {
55-
broadcast_shape::<Self, Other, Self::BroadcastOutput>(self, other)
55+
panic!()
56+
//broadcast_shape::<Self, Other, Self::BroadcastOutput>(self, other)
5657
}
5758
}
5859

src/dimension/dimension_trait.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::IntoDimension;
2020
use crate::RemoveAxis;
2121
use crate::{ArrayView1, ArrayViewMut1};
2222
use crate::{Dim, Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, IxDynImpl, Ixs, SliceOrIndex};
23+
use crate::dimension::broadcast::BroadcastShape;
2324

2425
/// Array shape and index trait.
2526
///
@@ -46,6 +47,8 @@ pub trait Dimension:
4647
+ MulAssign
4748
+ for<'x> MulAssign<&'x Self>
4849
+ MulAssign<usize>
50+
+ BroadcastShape<Self, BroadcastOutput=Self>
51+
+ BroadcastShape<Ix0, BroadcastOutput=Self>
4952
{
5053
/// For fixed-size dimension representations (e.g. `Ix2`), this should be
5154
/// `Some(ndim)`, and for variable-size dimension representations (e.g.

src/numeric/impl_numeric.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,10 @@ where
283283
/// a.mean_axis(Axis(0)).unwrap().mean_axis(Axis(0)).unwrap() == aview0(&3.5)
284284
/// );
285285
/// ```
286-
pub fn mean_axis(&self, axis: Axis) -> Option<Array<A, <D::Smaller as BroadcastShape<Ix0>>::BroadcastOutput>>
286+
pub fn mean_axis(&self, axis: Axis) -> Option<Array<A, D::Smaller>>
287287
where
288288
A: Clone + Zero + FromPrimitive + Add<Output = A> + Div<Output = A>,
289289
D: RemoveAxis,
290-
D::Smaller: BroadcastShape<Ix0>,
291290
{
292291
let axis_length = self.len_of(axis);
293292
if axis_length == 0 {

0 commit comments

Comments
 (0)