Skip to content

Commit d7d0d4d

Browse files
committed
Address clippy warnings
1 parent dc80631 commit d7d0d4d

File tree

8 files changed

+67
-104
lines changed

8 files changed

+67
-104
lines changed

src/array.rs

Lines changed: 48 additions & 83 deletions
Large diffs are not rendered by default.

src/convert.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ use crate::npyffi::npy_intp;
1717
/// **you cannot use some destructive methods like `resize`.**
1818
/// # Example
1919
/// ```
20-
/// # fn main() {
2120
/// use numpy::{PyArray, IntoPyArray};
2221
/// let gil = pyo3::Python::acquire_gil();
2322
/// let py_array = vec![1, 2, 3].into_pyarray(gil.python());
2423
/// assert_eq!(py_array.as_slice().unwrap(), &[1, 2, 3]);
2524
/// assert!(py_array.resize(100).is_err()); // You can't resize owned-by-rust array.
26-
/// # }
2725
/// ```
2826
pub trait IntoPyArray {
2927
type Item: TypeNum;
@@ -132,7 +130,7 @@ where
132130
let array = PyArray::<A, _>::new_(py, dim, strides.as_ptr(), 0);
133131
let data_ptr = array.data();
134132
for (i, item) in self.iter().enumerate() {
135-
data_ptr.offset(i as isize).write(*item);
133+
data_ptr.add(i).write(*item);
136134
}
137135
array
138136
}
@@ -166,7 +164,7 @@ where
166164
{
167165
fn npy_strides(&self) -> NpyStrides {
168166
NpyStrides::new(
169-
self.strides().into_iter().map(|&x| x as npyffi::npy_intp),
167+
self.strides().iter().map(|&x| x as npyffi::npy_intp),
170168
mem::size_of::<A>(),
171169
)
172170
}
@@ -199,7 +197,7 @@ impl NpyStrides {
199197
Self::new(
200198
dim.default_strides()
201199
.slice()
202-
.into_iter()
200+
.iter()
203201
.map(|&x| x as npyffi::npy_intp),
204202
type_size,
205203
)
@@ -266,7 +264,7 @@ impl<D: IntoDimension> NpyIndex for D {
266264
if indices.len() != dims.len() {
267265
return None;
268266
}
269-
if indices.into_iter().zip(dims).any(|(i, d)| i >= d) {
267+
if indices.iter().zip(dims).any(|(i, d)| i >= d) {
270268
return None;
271269
}
272270
Some(get_unchecked_impl(

src/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ pub enum ErrorKind {
6464
}
6565

6666
impl ErrorKind {
67-
pub(crate) fn to_rust(
68-
from_t: i32,
69-
from_d: usize,
70-
to_t: NpyDataType,
71-
to_d: Option<usize>,
67+
pub(crate) fn py_to_rust(
68+
from_type: i32,
69+
from_dim: usize,
70+
to_type: NpyDataType,
71+
to_dim: Option<usize>,
7272
) -> Self {
7373
ErrorKind::PyToRust {
7474
from: ArrayDim {
75-
dim: Some(from_d),
76-
dtype: NpyDataType::from_i32(from_t),
75+
dim: Some(from_dim),
76+
dtype: NpyDataType::from_i32(from_type),
7777
},
7878
to: ArrayDim {
79-
dim: to_d,
80-
dtype: to_t,
79+
dim: to_dim,
80+
dtype: to_type,
8181
},
8282
}
8383
}

src/lib.rs

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::missing_safety_doc, clippy::too_many_arguments)] // FIXME
2+
13
//! `rust-numpy` provides Rust interfaces for [NumPy C APIs](https://numpy.org/doc/stable/reference/c-api),
24
//! especially for [ndarray](https://numpy.org/doc/stable/reference/arrays.ndarray.html) class.
35
//!

src/npyffi/array.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ const CAPSULE_NAME: &str = "_ARRAY_API";
1818
///
1919
/// # Example
2020
/// ```
21-
/// # fn main() {
2221
/// use numpy::{PyArray, npyffi::types::NPY_SORTKIND, PY_ARRAY_API};
2322
/// use pyo3::Python;
2423
/// let gil = Python::acquire_gil();
2524
/// let array = PyArray::from_slice(gil.python(), &[3, 2, 4]);
2625
/// unsafe {
2726
/// PY_ARRAY_API.PyArray_Sort(array.as_array_ptr(), 0, NPY_SORTKIND::NPY_QUICKSORT);
2827
/// }
29-
/// assert_eq!(array.as_slice().unwrap(), &[2, 3, 4])
30-
/// # }
28+
/// assert_eq!(array.as_slice().unwrap(), &[2, 3, 4]);
3129
/// ```
3230
pub static PY_ARRAY_API: PyArrayAPI = PyArrayAPI::new();
3331

tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn from_vec2() {
116116
let gil = pyo3::Python::acquire_gil();
117117
let pyarray = PyArray::from_vec2(gil.python(), &vec2).unwrap();
118118
assert_eq!(pyarray.as_array(), array![[1, 2, 3], [1, 2, 3]]);
119-
assert!(PyArray::from_vec2(gil.python(), &vec![vec![1], vec![2, 3]]).is_err());
119+
assert!(PyArray::from_vec2(gil.python(), &[vec![1], vec![2, 3]]).is_err());
120120
}
121121

122122
#[test]

tests/py_to_rs.rs

Whitespace-only changes.

tests/to_py.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn to_pyarray_array() {
1717
let gil = pyo3::Python::acquire_gil();
1818

1919
let a = Array3::<f64>::zeros((3, 4, 2));
20-
let shape = a.shape().iter().cloned().collect::<Vec<_>>();
20+
let shape = a.shape().to_vec();
2121
let strides = a.strides().iter().map(|d| d * 8).collect::<Vec<_>>();
2222
println!("a.shape = {:?}", a.shape());
2323
println!("a.strides = {:?}", a.strides());
@@ -94,7 +94,7 @@ fn into_pyarray_vec() {
9494
fn into_pyarray_array() {
9595
let gil = pyo3::Python::acquire_gil();
9696
let arr = Array3::<f64>::zeros((3, 4, 2));
97-
let shape = arr.shape().iter().cloned().collect::<Vec<_>>();
97+
let shape = arr.shape().to_vec();
9898
let strides = arr.strides().iter().map(|d| d * 8).collect::<Vec<_>>();
9999
let py_arr = arr.into_pyarray(gil.python());
100100
assert_eq!(py_arr.shape(), shape.as_slice());

0 commit comments

Comments
 (0)