Skip to content

Commit 9703a15

Browse files
committed
Address clippy warnings
1 parent 68135a5 commit 9703a15

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/npyiter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ pub struct NpyMultiIterBuilder<'py, T, S: MultiIterMode> {
371371
was_writables: Vec<bool>,
372372
}
373373

374+
impl<'py, T: Element> Default for NpyMultiIterBuilder<'py, T, ()> {
375+
fn default() -> Self {
376+
Self::new()
377+
}
378+
}
379+
374380
impl<'py, T: Element> NpyMultiIterBuilder<'py, T, ()> {
375381
/// Creates a new builder.
376382
pub fn new() -> Self {

tests/iter.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ use ndarray::array;
22
use numpy::{NpyMultiIterBuilder, NpySingleIterBuilder, PyArray};
33
use pyo3::PyResult;
44

5+
macro_rules! assert_approx_eq {
6+
($x: expr, $y: expr) => {
7+
assert!(($x - $y) <= std::f64::EPSILON);
8+
};
9+
}
10+
511
#[test]
612
fn readonly_iter() -> PyResult<()> {
713
let gil = pyo3::Python::acquire_gil();
@@ -12,7 +18,7 @@ fn readonly_iter() -> PyResult<()> {
1218

1319
// The order of iteration is not specified, so we should restrict ourselves
1420
// to tests that don't verify a given order.
15-
assert_eq!(iter.sum::<f64>(), 15.0);
21+
assert_approx_eq!(iter.sum::<f64>(), 15.0);
1622
Ok(())
1723
}
1824

@@ -24,10 +30,10 @@ fn mutable_iter() -> PyResult<()> {
2430
let arr = PyArray::from_array(gil.python(), &data);
2531
let iter = NpySingleIterBuilder::readwrite(arr).build()?;
2632
for elem in iter {
27-
*elem = *elem * 2.0;
33+
*elem *= 2.0;
2834
}
2935
let iter = NpySingleIterBuilder::readonly(arr.readonly()).build()?;
30-
assert_eq!(iter.sum::<f64>(), 30.0);
36+
assert_approx_eq!(iter.sum::<f64>(), 30.0);
3137
Ok(())
3238
}
3339

@@ -52,7 +58,7 @@ fn multiiter_rr() -> PyResult<()> {
5258
sum += *x * *y;
5359
}
5460

55-
assert_eq!(sum, 145.0);
61+
assert_approx_eq!(sum, 145.0);
5662
Ok(())
5763
}
5864

@@ -80,7 +86,7 @@ fn multiiter_rw() -> PyResult<()> {
8086
.build()?;
8187

8288
for (x, y) in iter {
83-
assert_eq!(*x * 2.0, *y);
89+
assert_approx_eq!(*x * 2.0, *y);
8490
}
8591

8692
Ok(())

0 commit comments

Comments
 (0)