Skip to content

Commit ee70d9b

Browse files
authored
Merge pull request #65 from kngwyu/remove-dim-for-arrayref
Remove some ToNpyDims implementation
2 parents 7e6f1f6 + f113a8e commit ee70d9b

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

src/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<T> PyArray<T> {
126126
/// # extern crate pyo3; extern crate numpy; fn main() {
127127
/// use numpy::PyArray;
128128
/// let gil = pyo3::Python::acquire_gil();
129-
/// let arr = PyArray::<f64>::new(gil.python(), &[4, 5, 6]);
129+
/// let arr = PyArray::<f64>::new(gil.python(), [4, 5, 6]);
130130
/// assert_eq!(arr.strides(), &[240, 48, 8]);
131131
/// # }
132132
/// ```
@@ -472,7 +472,7 @@ impl<T: TypeNum> PyArray<T> {
472472
/// use numpy::{PyArray, IntoPyArray};
473473
/// let gil = pyo3::Python::acquire_gil();
474474
/// let pyarray_f = PyArray::<f64>::arange(gil.python(), 2.0, 5.0, 1.0);
475-
/// let pyarray_i = PyArray::<i64>::new(gil.python(), &[3]);
475+
/// let pyarray_i = PyArray::<i64>::new(gil.python(), [3]);
476476
/// assert!(pyarray_f.copy_to(pyarray_i).is_ok());
477477
/// assert_eq!(pyarray_i.as_slice().unwrap(), &[2, 3, 4]);
478478
/// # }

src/convert.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<A: TypeNum, D: Dimension> IntoPyArray for Array<A, D> {
5454
.collect();
5555
unsafe {
5656
let data = into_raw(self.into_raw_vec());
57-
PyArray::new_(py, dims, strides.as_mut_ptr(), data)
57+
PyArray::new_(py, &*dims, strides.as_mut_ptr(), data)
5858
}
5959
}
6060
}
@@ -115,26 +115,13 @@ macro_rules! array_dim_impls {
115115
self
116116
}
117117
}
118-
impl<'a> ToNpyDims for &'a [usize; $N] {
119-
fn dims_len(&self) -> c_int {
120-
$N as c_int
121-
}
122-
fn dims_ptr(&self) -> *mut npy_intp {
123-
self.as_ptr() as *mut npy_intp
124-
}
125-
fn dims_ref(&self) -> &[usize] {
126-
*self
127-
}
128-
}
129118
)+
130119
}
131120
}
132121

133122
array_dim_impls! {
134123
0 1 2 3 4 5 6 7 8 9
135-
10 11 12 13 14 15 16 17 18 19
136-
20 21 22 23 24 25 26 27 28 29
137-
30 31 32
124+
10 11 12 13 14 15 16
138125
}
139126

140127
impl<'a> ToNpyDims for &'a [usize] {
@@ -148,27 +135,3 @@ impl<'a> ToNpyDims for &'a [usize] {
148135
*self
149136
}
150137
}
151-
152-
impl ToNpyDims for Vec<usize> {
153-
fn dims_len(&self) -> c_int {
154-
self.len() as c_int
155-
}
156-
fn dims_ptr(&self) -> *mut npy_intp {
157-
self.as_ptr() as *mut npy_intp
158-
}
159-
fn dims_ref(&self) -> &[usize] {
160-
&*self
161-
}
162-
}
163-
164-
impl ToNpyDims for Box<[usize]> {
165-
fn dims_len(&self) -> c_int {
166-
self.len() as c_int
167-
}
168-
fn dims_ptr(&self) -> *mut npy_intp {
169-
self.as_ptr() as *mut npy_intp
170-
}
171-
fn dims_ref(&self) -> &[usize] {
172-
&*self
173-
}
174-
}

tests/array.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fn new() {
1111
let gil = pyo3::Python::acquire_gil();
1212
let n = 3;
1313
let m = 5;
14-
let arr = PyArray::<f64>::new(gil.python(), &[n, m]);
14+
let dim = [n, m];
15+
let arr = PyArray::<f64>::new(gil.python(), dim);
1516
assert!(arr.ndim() == 2);
1617
assert!(arr.dims() == [n, m]);
1718
assert!(arr.strides() == [m as isize * 8, 8]);
@@ -22,12 +23,12 @@ fn zeros() {
2223
let gil = pyo3::Python::acquire_gil();
2324
let n = 3;
2425
let m = 5;
25-
let arr = PyArray::<f64>::zeros(gil.python(), &[n, m], false);
26+
let arr = PyArray::<f64>::zeros(gil.python(), [n, m], false);
2627
assert!(arr.ndim() == 2);
2728
assert!(arr.dims() == [n, m]);
2829
assert!(arr.strides() == [m as isize * 8, 8]);
2930

30-
let arr = PyArray::<f64>::zeros(gil.python(), &[n, m], true);
31+
let arr = PyArray::<f64>::zeros(gil.python(), [n, m], true);
3132
assert!(arr.ndim() == 2);
3233
assert!(arr.dims() == [n, m]);
3334
assert!(arr.strides() == [8, n as isize * 8]);
@@ -45,7 +46,7 @@ fn arange() {
4546
#[test]
4647
fn as_array() {
4748
let gil = pyo3::Python::acquire_gil();
48-
let arr = PyArray::<f64>::zeros(gil.python(), &[3, 2, 4], false);
49+
let arr = PyArray::<f64>::zeros(gil.python(), [3, 2, 4], false);
4950
let a = arr.as_array().unwrap();
5051
assert_eq!(arr.shape(), a.shape());
5152
assert_eq!(
@@ -95,7 +96,7 @@ fn iter_to_pyarray() {
9596
fn is_instance() {
9697
let gil = pyo3::Python::acquire_gil();
9798
let py = gil.python();
98-
let arr = PyArray::<f64>::new(gil.python(), &[3, 5]);
99+
let arr = PyArray::<f64>::new(gil.python(), [3, 5]);
99100
assert!(py.is_instance::<PyArray<f64>, _>(arr).unwrap());
100101
assert!(!py.is_instance::<pyo3::PyList, _>(arr).unwrap());
101102
}

0 commit comments

Comments
 (0)