Skip to content

Commit 7ebbbb8

Browse files
committed
Remove unnecessary clone in Neg and Not for &Array
1 parent ccbab2c commit 7ebbbb8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/impl_ops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ mod arithmetic_ops {
293293
}
294294

295295
impl<'a, A, S, D> Neg for &'a ArrayBase<S, D>
296-
where A: Clone + Neg<Output=A>,
296+
where &'a A: 'a + Neg<Output=A>,
297297
S: Data<Elem=A>,
298298
D: Dimension
299299
{
300300
type Output = Array<A, D>;
301301
/// Perform an elementwise negation of reference `self` and return the
302302
/// result as a new `Array`.
303303
fn neg(self) -> Array<A, D> {
304-
self.to_owned().neg()
304+
self.map(Neg::neg)
305305
}
306306
}
307307

@@ -321,15 +321,15 @@ mod arithmetic_ops {
321321
}
322322

323323
impl<'a, A, S, D> Not for &'a ArrayBase<S, D>
324-
where A: Clone + Not<Output=A>,
324+
where &'a A: 'a + Not<Output=A>,
325325
S: Data<Elem=A>,
326326
D: Dimension
327327
{
328328
type Output = Array<A, D>;
329329
/// Perform an elementwise unary not of reference `self` and return the
330330
/// result as a new `Array`.
331331
fn not(self) -> Array<A, D> {
332-
self.to_owned().not()
332+
self.map(Not::not)
333333
}
334334
}
335335
}

tests/oper.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32])
3131
test_oper_arr(op, aa.clone(), bb.clone(), cc.clone());
3232
}
3333

34-
fn test_oper_arr<A: NdFloat + fmt::Debug, D: ndarray::Dimension>
35-
(op: &str, mut aa: RcArray<A,D>, bb: RcArray<A, D>, cc: RcArray<A, D>)
36-
{
34+
fn test_oper_arr<D: Dimension>(
35+
op: &str,
36+
mut aa: RcArray<f32, D>,
37+
bb: RcArray<f32, D>,
38+
cc: RcArray<f32, D>,
39+
) {
3740
match op {
3841
"+" => {
3942
assert_eq!(&aa + &bb, cc);

0 commit comments

Comments
 (0)