Skip to content

Commit 43d088a

Browse files
committed
Allow ops on arrays with elems of different types
The implementations of operations for `&'a ArrayBase<S, D>` are still unnecessarily restrictive in the `Output` element type, but the implementations are now more general than they were before this commit.
1 parent 03552e2 commit 43d088a

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/impl_ops.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ macro_rules! impl_binary_op(
6060
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
6161
///
6262
/// **Panics** if broadcasting isn’t possible.
63-
impl<A, S, S2, D, E> $trt<ArrayBase<S2, E>> for ArrayBase<S, D>
64-
where A: Clone + $trt<A, Output=A>,
65-
S: DataOwned<Elem=A> + DataMut,
66-
S2: Data<Elem=A>,
67-
D: Dimension,
68-
E: Dimension,
63+
impl<A, B, S, S2, D, E> $trt<ArrayBase<S2, E>> for ArrayBase<S, D>
64+
where
65+
A: Clone + $trt<B, Output=A>,
66+
B: Clone,
67+
S: DataOwned<Elem=A> + DataMut,
68+
S2: Data<Elem=B>,
69+
D: Dimension,
70+
E: Dimension,
6971
{
7072
type Output = ArrayBase<S, D>;
7173
fn $mth(self, rhs: ArrayBase<S2, E>) -> ArrayBase<S, D>
@@ -82,12 +84,14 @@ impl<A, S, S2, D, E> $trt<ArrayBase<S2, E>> for ArrayBase<S, D>
8284
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
8385
///
8486
/// **Panics** if broadcasting isn’t possible.
85-
impl<'a, A, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
86-
where A: Clone + $trt<A, Output=A>,
87-
S: DataOwned<Elem=A> + DataMut,
88-
S2: Data<Elem=A>,
89-
D: Dimension,
90-
E: Dimension,
87+
impl<'a, A, B, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
88+
where
89+
A: Clone + $trt<B, Output=A>,
90+
B: Clone,
91+
S: DataOwned<Elem=A> + DataMut,
92+
S2: Data<Elem=B>,
93+
D: Dimension,
94+
E: Dimension,
9195
{
9296
type Output = ArrayBase<S, D>;
9397
fn $mth(mut self, rhs: &ArrayBase<S2, E>) -> ArrayBase<S, D>
@@ -107,12 +111,14 @@ impl<'a, A, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
107111
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
108112
///
109113
/// **Panics** if broadcasting isn’t possible.
110-
impl<'a, A, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for &'a ArrayBase<S, D>
111-
where A: Clone + $trt<A, Output=A>,
112-
S: Data<Elem=A>,
113-
S2: Data<Elem=A>,
114-
D: Dimension,
115-
E: Dimension,
114+
impl<'a, A, B, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for &'a ArrayBase<S, D>
115+
where
116+
A: Clone + $trt<B, Output=A>,
117+
B: Clone,
118+
S: Data<Elem=A>,
119+
S2: Data<Elem=B>,
120+
D: Dimension,
121+
E: Dimension,
116122
{
117123
type Output = Array<A, D>;
118124
fn $mth(self, rhs: &'a ArrayBase<S2, E>) -> Array<A, D> {

0 commit comments

Comments
 (0)