Skip to content

Commit 46bb9d0

Browse files
committed
WIP WIP WIP WIP Scaled
1 parent 1c87a36 commit 46bb9d0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/impl_ops.rs

+24
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,28 @@ mod assign_ops {
355355
"Perform `self <<= rhs` as elementwise left shift (in place).\n");
356356
impl_assign_op!(ShrAssign, shr_assign,
357357
"Perform `self >>= rhs` as elementwise right shift (in place).\n");
358+
359+
use LinalgScalar;
360+
use Scaled;
361+
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
362+
///
363+
/// **Panics** if broadcasting isn’t possible.
364+
///
365+
/// **Requires crate feature `"assign_ops"`**
366+
impl<'a, A, S, S2, D, E> AddAssign<Scaled<'a, S2, E>> for ArrayBase<S, D>
367+
where A: LinalgScalar,
368+
S: DataMut<Elem=A>,
369+
S2: Data<Elem=A>,
370+
D: Dimension,
371+
E: Dimension,
372+
{
373+
fn add_assign(&mut self, rhs: Scaled<'a, S2, E>) {
374+
self.zip_mut_with(rhs.1, |x, y| {
375+
*x = x.clone() + rhs.0 * y.clone();
376+
});
377+
}
378+
}
379+
380+
381+
358382
}

src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,16 @@ enum ElementsRepr<S, C> {
722722
Slice(S),
723723
Counted(C),
724724
}
725+
726+
pub struct Scaled<'a, S, D>(pub S::Elem, pub &'a ArrayBase<S, D>)
727+
where S: 'a + Data,
728+
D: 'a;
729+
730+
impl<'a, S, D> Clone for Scaled<'a, S, D> where S::Elem: Clone, S: Data {
731+
#[inline]
732+
fn clone(&self) -> Self {
733+
Scaled(self.0.clone(), self.1)
734+
}
735+
}
736+
impl<'a, S, D> Copy for Scaled<'a, S, D> where S::Elem: Copy, S: Data { }
737+

0 commit comments

Comments
 (0)