Skip to content

Commit b39593e

Browse files
committed
FIX: Rename BroadcastShape to DimMax
For consistency with other dimension traits (to come); with <A as DimMax<B>>, Output is the maximum of A and B.
1 parent 16f382b commit b39593e

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

src/dimension/broadcast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn co_broadcast<D1, D2, Output>(shape1: &D1, shape2: &D2) -> Result<Output, Shap
3434
Ok(out)
3535
}
3636

37-
pub trait BroadcastShape<Other: Dimension> {
37+
pub trait DimMax<Other: Dimension> {
3838
/// The resulting dimension type after broadcasting.
3939
type Output: Dimension;
4040

@@ -46,8 +46,8 @@ pub trait BroadcastShape<Other: Dimension> {
4646

4747
/// Dimensions of the same type remain unchanged when co_broadcast.
4848
/// So you can directly use D as the resulting type.
49-
/// (Instead of <D as BroadcastShape<D>>::BroadcastOutput)
50-
impl<D: Dimension> BroadcastShape<D> for D {
49+
/// (Instead of <D as DimMax<D>>::BroadcastOutput)
50+
impl<D: Dimension> DimMax<D> for D {
5151
type Output = D;
5252

5353
fn broadcast_shape(&self, other: &D) -> Result<Self::Output, ShapeError> {
@@ -57,15 +57,15 @@ impl<D: Dimension> BroadcastShape<D> for D {
5757

5858
macro_rules! impl_broadcast_distinct_fixed {
5959
($smaller:ty, $larger:ty) => {
60-
impl BroadcastShape<$larger> for $smaller {
60+
impl DimMax<$larger> for $smaller {
6161
type Output = $larger;
6262

6363
fn broadcast_shape(&self, other: &$larger) -> Result<Self::Output, ShapeError> {
6464
co_broadcast::<Self, $larger, Self::Output>(self, other)
6565
}
6666
}
6767

68-
impl BroadcastShape<$smaller> for $larger {
68+
impl DimMax<$smaller> for $larger {
6969
type Output = $larger;
7070

7171
fn broadcast_shape(&self, other: &$smaller) -> Result<Self::Output, ShapeError> {

src/dimension/dimension_trait.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::axes_of;
1515
use super::conversion::Convert;
1616
use super::{stride_offset, stride_offset_checked};
1717
use crate::itertools::{enumerate, zip};
18-
use crate::{Axis, BroadcastShape};
18+
use crate::{Axis, DimMax};
1919
use crate::IntoDimension;
2020
use crate::RemoveAxis;
2121
use crate::{ArrayView1, ArrayViewMut1};
@@ -46,11 +46,11 @@ pub trait Dimension:
4646
+ MulAssign
4747
+ for<'x> MulAssign<&'x Self>
4848
+ MulAssign<usize>
49-
+ BroadcastShape<Ix0, Output=Self>
50-
+ BroadcastShape<Self, Output=Self>
51-
+ BroadcastShape<IxDyn, Output=IxDyn>
52-
+ BroadcastShape<<Self as Dimension>::Smaller, Output=Self>
53-
+ BroadcastShape<<Self as Dimension>::Larger, Output=<Self as Dimension>::Larger>
49+
+ DimMax<Ix0, Output=Self>
50+
+ DimMax<Self, Output=Self>
51+
+ DimMax<IxDyn, Output=IxDyn>
52+
+ DimMax<<Self as Dimension>::Smaller, Output=Self>
53+
+ DimMax<<Self as Dimension>::Larger, Output=<Self as Dimension>::Larger>
5454
{
5555
/// For fixed-size dimension representations (e.g. `Ix2`), this should be
5656
/// `Some(ndim)`, and for variable-size dimension representations (e.g.

src/dimension/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use num_integer::div_floor;
1212

1313
pub use self::axes::{axes_of, Axes, AxisDescription};
1414
pub use self::axis::Axis;
15-
pub use self::broadcast::BroadcastShape;
15+
pub use self::broadcast::DimMax;
1616
pub use self::conversion::IntoDimension;
1717
pub use self::dim::*;
1818
pub use self::dimension_trait::Dimension;

src/impl_methods.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rawpointer::PointerExt;
1414

1515
use crate::imp_prelude::*;
1616

17-
use crate::{arraytraits, BroadcastShape};
17+
use crate::{arraytraits, DimMax};
1818
use crate::dimension;
1919
use crate::dimension::IntoDimension;
2020
use crate::dimension::{
@@ -1771,11 +1771,11 @@ where
17711771
///
17721772
/// Return `ShapeError` if their shapes can not be broadcast together.
17731773
pub(crate) fn broadcast_with<'a, 'b, B, S2, E>(&'a self, other: &'b ArrayBase<S2, E>) ->
1774-
Result<(ArrayView<'a, A, <D as BroadcastShape<E>>::Output>, ArrayView<'b, B, <D as BroadcastShape<E>>::Output>), ShapeError>
1774+
Result<(ArrayView<'a, A, <D as DimMax<E>>::Output>, ArrayView<'b, B, <D as DimMax<E>>::Output>), ShapeError>
17751775
where
17761776
S: Data<Elem=A>,
17771777
S2: Data<Elem=B>,
1778-
D: Dimension + BroadcastShape<E>,
1778+
D: Dimension + DimMax<E>,
17791779
E: Dimension,
17801780
{
17811781
let shape = self.dim.broadcast_shape(&other.dim)?;

src/impl_ops.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use crate::dimension::BroadcastShape;
9+
use crate::dimension::DimMax;
1010
use crate::Zip;
1111
use num_complex::Complex;
1212

@@ -68,10 +68,10 @@ where
6868
B: Clone,
6969
S: DataOwned<Elem=A> + DataMut,
7070
S2: Data<Elem=B>,
71-
D: Dimension + BroadcastShape<E>,
71+
D: Dimension + DimMax<E>,
7272
E: Dimension,
7373
{
74-
type Output = ArrayBase<S, <D as BroadcastShape<E>>::Output>;
74+
type Output = ArrayBase<S, <D as DimMax<E>>::Output>;
7575
fn $mth(self, rhs: ArrayBase<S2, E>) -> Self::Output
7676
{
7777
self.$mth(&rhs)
@@ -95,14 +95,14 @@ where
9595
B: Clone,
9696
S: DataOwned<Elem=A> + DataMut,
9797
S2: Data<Elem=B>,
98-
D: Dimension + BroadcastShape<E>,
98+
D: Dimension + DimMax<E>,
9999
E: Dimension,
100100
{
101-
type Output = ArrayBase<S, <D as BroadcastShape<E>>::Output>;
101+
type Output = ArrayBase<S, <D as DimMax<E>>::Output>;
102102
fn $mth(self, rhs: &ArrayBase<S2, E>) -> Self::Output
103103
{
104104
if self.ndim() == rhs.ndim() && self.shape() == rhs.shape() {
105-
let mut out = self.into_dimensionality::<<D as BroadcastShape<E>>::Output>().unwrap();
105+
let mut out = self.into_dimensionality::<<D as DimMax<E>>::Output>().unwrap();
106106
out.zip_mut_with_same_shape(rhs, clone_iopf(A::$mth));
107107
out
108108
} else {
@@ -130,14 +130,14 @@ where
130130
S: Data<Elem=A>,
131131
S2: DataOwned<Elem=B> + DataMut,
132132
D: Dimension,
133-
E: Dimension + BroadcastShape<D>,
133+
E: Dimension + DimMax<D>,
134134
{
135-
type Output = ArrayBase<S2, <E as BroadcastShape<D>>::Output>;
135+
type Output = ArrayBase<S2, <E as DimMax<D>>::Output>;
136136
fn $mth(self, rhs: ArrayBase<S2, E>) -> Self::Output
137137
where
138138
{
139139
if self.ndim() == rhs.ndim() && self.shape() == rhs.shape() {
140-
let mut out = rhs.into_dimensionality::<<E as BroadcastShape<D>>::Output>().unwrap();
140+
let mut out = rhs.into_dimensionality::<<E as DimMax<D>>::Output>().unwrap();
141141
out.zip_mut_with_same_shape(self, clone_iopf_rev(A::$mth));
142142
out
143143
} else {
@@ -162,10 +162,10 @@ where
162162
B: Clone,
163163
S: Data<Elem=A>,
164164
S2: Data<Elem=B>,
165-
D: Dimension + BroadcastShape<E>,
165+
D: Dimension + DimMax<E>,
166166
E: Dimension,
167167
{
168-
type Output = Array<A, <D as BroadcastShape<E>>::Output>;
168+
type Output = Array<A, <D as DimMax<E>>::Output>;
169169
fn $mth(self, rhs: &'a ArrayBase<S2, E>) -> Self::Output {
170170
let (lhs, rhs) = self.broadcast_with(rhs).unwrap();
171171
Zip::from(&lhs).and(&rhs).map_collect(clone_opf(A::$mth))

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ use std::marker::PhantomData;
134134
use alloc::sync::Arc;
135135

136136
pub use crate::dimension::dim::*;
137-
pub use crate::dimension::BroadcastShape;
137+
pub use crate::dimension::DimMax;
138138
pub use crate::dimension::{Axis, AxisDescription, Dimension, IntoDimension, RemoveAxis};
139139

140140
pub use crate::dimension::IxDynImpl;

tests/dimension.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use defmac::defmac;
44

55
use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, Ix0, IxDyn, IxDynImpl, RemoveAxis,
6-
ErrorKind, ShapeError, BroadcastShape};
6+
ErrorKind, ShapeError, DimMax};
77

88
use std::hash::{Hash, Hasher};
99

@@ -347,9 +347,9 @@ fn test_broadcast_shape() {
347347
fn test_co<D1, D2>(
348348
d1: &D1,
349349
d2: &D2,
350-
r: Result<<D1 as BroadcastShape<D2>>::Output, ShapeError>,
350+
r: Result<<D1 as DimMax<D2>>::Output, ShapeError>,
351351
) where
352-
D1: Dimension + BroadcastShape<D2>,
352+
D1: Dimension + DimMax<D2>,
353353
D2: Dimension,
354354
{
355355
let d = d1.broadcast_shape(d2);

0 commit comments

Comments
 (0)