Skip to content

Commit ea7cead

Browse files
committed
Rewrite drop_{upper,lower} for ArrayBase<S, Ix2>
1 parent a61196e commit ea7cead

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/triangular.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
use ndarray::{Ix2, Array};
2+
use ndarray::{Ix2, Array, NdFloat, ArrayBase, DataMut};
33

44
use matrix::{Matrix, MFloat};
55
use square::SquareMatrix;
@@ -32,19 +32,23 @@ impl<A: MFloat> TriangularMatrix for Array<A, Ix2> {
3232
}
3333
}
3434

35-
pub fn drop_upper(mut a: Array<f64, Ix2>) -> Array<f64, Ix2> {
35+
pub fn drop_upper<A: NdFloat, S>(mut a: ArrayBase<S, Ix2>) -> ArrayBase<S, Ix2>
36+
where S: DataMut<Elem = A>
37+
{
3638
for ((i, j), val) in a.indexed_iter_mut() {
3739
if i < j {
38-
*val = 0.0;
40+
*val = A::zero();
3941
}
4042
}
4143
a
4244
}
4345

44-
pub fn drop_lower(mut a: Array<f64, Ix2>) -> Array<f64, Ix2> {
46+
pub fn drop_lower<A: NdFloat, S>(mut a: ArrayBase<S, Ix2>) -> ArrayBase<S, Ix2>
47+
where S: DataMut<Elem = A>
48+
{
4549
for ((i, j), val) in a.indexed_iter_mut() {
4650
if i > j {
47-
*val = 0.0;
51+
*val = A::zero();
4852
}
4953
}
5054
a

0 commit comments

Comments
 (0)