Skip to content

Commit 3381bb2

Browse files
committed
Add method .axpy()
1 parent d2c2bee commit 3381bb2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/impl_linalg.rs

+20
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ impl<A, S> ArrayBase<S, (Ix, Ix)>
228228
}
229229
}
230230

231+
impl<A, S, D> ArrayBase<S, D>
232+
where S: Data<Elem=A>,
233+
D: Dimension,
234+
{
235+
/// Perform the operation `self += alpha * rhs` efficiently, where
236+
/// *α* is a scalar and `rhs` is another array.
237+
///
238+
/// If their shapes disagree, `rhs` is broadcast to the shape of `self`.
239+
///
240+
/// **Panics** if broadcasting isn’t possible.
241+
pub fn axpy<S2, E>(&mut self, alpha: A, rhs: &ArrayBase<S2, E>)
242+
where S: DataMut,
243+
S2: Data<Elem=A>,
244+
A: LinalgScalar,
245+
E: Dimension,
246+
{
247+
self.zip_mut_with(rhs, move |y, &x| *y = *y + (alpha * x));
248+
}
249+
}
250+
231251
#[cfg(not(feature="blas"))]
232252
use self::mat_mul_general as mat_mul_impl;
233253

0 commit comments

Comments
 (0)