1
- #![ feature( proc_macro, proc_macro_path_invoc , specialization) ]
1
+ #![ feature( proc_macro, specialization) ]
2
2
3
3
extern crate ndarray;
4
4
extern crate numpy;
5
5
extern crate pyo3;
6
6
7
7
use ndarray:: * ;
8
8
use numpy:: * ;
9
- use pyo3:: { py, PyModule , PyObject , PyResult , Python } ;
9
+ use pyo3:: { py:: modinit as pymodinit , PyModule , PyResult , Python } ;
10
10
11
- #[ py :: modinit ( rust_ext ) ]
11
+ #[ pymodinit ( _rust_ext ) ]
12
12
fn init_module ( py : Python , m : & PyModule ) -> PyResult < ( ) > {
13
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14
+ // You **must** write this sentence for PyArray type checker working correctly
15
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
+ let _np = PyArrayModule :: import ( py) ?;
17
+
13
18
// immutable example
14
19
fn axpy ( a : f64 , x : ArrayViewD < f64 > , y : ArrayViewD < f64 > ) -> ArrayD < f64 > {
15
20
a * & x + & y
@@ -22,19 +27,19 @@ fn init_module(py: Python, m: &PyModule) -> PyResult<()> {
22
27
23
28
// wrapper of `axpy`
24
29
#[ pyfn( m, "axpy" ) ]
25
- fn axpy_py ( py : Python , a : f64 , x : PyArray , y : PyArray ) -> PyResult < PyArray > {
30
+ fn axpy_py ( py : Python , a : f64 , x : & PyArray , y : & PyArray ) -> PyResult < PyArray > {
26
31
let np = PyArrayModule :: import ( py) ?;
27
- let x = x. as_array ( ) . into_pyresult ( py , "x must be f64 array" ) ?;
28
- let y = y. as_array ( ) . into_pyresult ( py , "y must be f64 array" ) ?;
32
+ let x = x. as_array ( ) . into_pyresult ( "x must be f64 array" ) ?;
33
+ let y = y. as_array ( ) . into_pyresult ( "y must be f64 array" ) ?;
29
34
Ok ( axpy ( a, x, y) . into_pyarray ( py, & np) )
30
35
}
31
36
32
37
// wrapper of `mult`
33
38
#[ pyfn( m, "mult" ) ]
34
- fn mult_py ( py : Python , a : f64 , x : PyArray ) -> PyResult < PyObject > {
35
- let x = x. as_array_mut ( ) . into_pyresult ( py , "x must be f64 array" ) ?;
39
+ fn mult_py ( _py : Python , a : f64 , x : & PyArray ) -> PyResult < ( ) > {
40
+ let x = x. as_array_mut ( ) . into_pyresult ( "x must be f64 array" ) ?;
36
41
mult ( a, x) ;
37
- Ok ( py . None ( ) ) // Python function must returns
42
+ Ok ( ( ) )
38
43
}
39
44
40
45
Ok ( ( ) )
0 commit comments