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