@@ -45,7 +45,7 @@ numpy = "0.3"
45
45
``` rust
46
46
extern crate numpy;
47
47
extern crate pyo3;
48
- use numpy :: {IntoPyResult , PyArray , get_array_module};
48
+ use numpy :: {IntoPyResult , PyArray1 , get_array_module};
49
49
use pyo3 :: prelude :: {ObjectProtocol , PyDict , PyResult , Python };
50
50
51
51
fn main () -> Result <(), ()> {
@@ -62,7 +62,7 @@ fn main_<'py>(py: Python<'py>) -> PyResult<()> {
62
62
let np = get_array_module (py )? ;
63
63
let dict = PyDict :: new (py );
64
64
dict . set_item (" np" , np )? ;
65
- let pyarray : & PyArray <i32 > = py
65
+ let pyarray : & PyArray1 <i32 > = py
66
66
. eval (" np.array([1, 2, 3], dtype='int32')" , Some (& dict ), None )?
67
67
. extract ()? ;
68
68
let slice = pyarray . as_slice (). into_pyresult (" Array Cast failed" )? ;
@@ -95,7 +95,7 @@ extern crate numpy;
95
95
extern crate pyo3;
96
96
97
97
use ndarray :: {ArrayD , ArrayViewD , ArrayViewMutD };
98
- use numpy :: {IntoPyResult , PyArray , ToPyArray };
98
+ use numpy :: {IntoPyResult , PyArrayDyn , ToPyArray };
99
99
use pyo3 :: prelude :: {pymodinit, PyModule , PyResult , Python };
100
100
101
101
#[pymodinit]
@@ -112,15 +112,20 @@ fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
112
112
113
113
// wrapper of `axpy`
114
114
#[pyfn(m, " axpy" )]
115
- fn axpy_py (py : Python , a : f64 , x : & PyArray <f64 >, y : & PyArray <f64 >) -> PyResult <PyArray <f64 >> {
115
+ fn axpy_py (
116
+ py : Python ,
117
+ a : f64 ,
118
+ x : & PyArrayDyn <f64 >,
119
+ y : & PyArrayDyn <f64 >,
120
+ ) -> PyResult <PyArrayDyn <f64 >> {
116
121
let x = x . as_array (). into_pyresult (" x must be f64 array" )? ;
117
122
let y = y . as_array (). into_pyresult (" y must be f64 array" )? ;
118
123
Ok (axpy (a , x , y ). to_pyarray (py ). to_owned (py ))
119
124
}
120
125
121
126
// wrapper of `mult`
122
127
#[pyfn(m, " mult" )]
123
- fn mult_py (_py : Python , a : f64 , x : & PyArray <f64 >) -> PyResult <()> {
128
+ fn mult_py (_py : Python , a : f64 , x : & PyArrayDyn <f64 >) -> PyResult <()> {
124
129
let x = x . as_array_mut (). into_pyresult (" x must be f64 array" )? ;
125
130
mult (a , x );
126
131
Ok (())
0 commit comments