@@ -45,8 +45,8 @@ numpy = "0.15"
45
45
46
46
``` rust
47
47
use numpy :: ndarray :: {ArrayD , ArrayViewD , ArrayViewMutD };
48
- use numpy :: {IntoPyArray , PyArrayDyn , PyReadonlyArrayDyn };
49
- use pyo3 :: prelude :: {pymodule, PyModule , PyResult , Python };
48
+ use numpy :: {Complex64 , IntoPyArray , PyArrayDyn , PyReadonlyArrayDyn };
49
+ use pyo3 :: {pymodule, types :: PyModule , PyResult , Python };
50
50
51
51
#[pymodule]
52
52
fn rust_ext (_py : Python <'_ >, m : & PyModule ) -> PyResult <()> {
@@ -61,7 +61,8 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
61
61
}
62
62
63
63
// wrapper of `axpy`
64
- #[pyfn(m, " axpy" )]
64
+ #[pyfn(m)]
65
+ #[pyo3(name = " axpy" )]
65
66
fn axpy_py <'py >(
66
67
py : Python <'py >,
67
68
a : f64 ,
@@ -70,15 +71,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
70
71
) -> & 'py PyArrayDyn <f64 > {
71
72
let x = x . as_array ();
72
73
let y = y . as_array ();
73
- axpy (a , x , y ). into_pyarray (py )
74
+ let z = axpy (a , x , y );
75
+ z . into_pyarray (py )
74
76
}
75
77
76
78
// wrapper of `mult`
77
- #[pyfn(m, " mult" )]
78
- fn mult_py (_py : Python <'_ >, a : f64 , x : & PyArrayDyn <f64 >) -> PyResult <()> {
79
+ #[pyfn(m)]
80
+ #[pyo3(name = " mult" )]
81
+ fn mult_py (_py : Python <'_ >, a : f64 , x : & PyArrayDyn <f64 >) {
79
82
let x = unsafe { x . as_array_mut () };
80
83
mult (a , x );
81
- Ok (())
82
84
}
83
85
84
86
Ok (())
@@ -98,8 +100,7 @@ numpy = "0.15"
98
100
99
101
``` rust
100
102
use numpy :: PyArray1 ;
101
- use pyo3 :: prelude :: {PyResult , Python };
102
- use pyo3 :: types :: IntoPyDict ;
103
+ use pyo3 :: {types :: IntoPyDict , PyResult , Python };
103
104
104
105
fn main () -> PyResult <()> {
105
106
Python :: with_gil (| py | {
0 commit comments