1- #![ feature( proc_macro, proc_macro_path_invoc , specialization) ]
1+ #![ feature( proc_macro, specialization) ]
22
33extern crate ndarray;
44extern crate numpy;
55extern crate pyo3;
66
77use ndarray:: * ;
88use numpy:: * ;
9- use pyo3:: { py, PyModule , PyObject , PyResult , Python } ;
9+ use pyo3:: { py:: modinit as pymodinit , PyModule , PyResult , Python } ;
1010
11- #[ py :: modinit ( rust_ext ) ]
11+ #[ pymodinit ( _rust_ext ) ]
1212fn 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+
1318 // immutable example
1419 fn axpy ( a : f64 , x : ArrayViewD < f64 > , y : ArrayViewD < f64 > ) -> ArrayD < f64 > {
1520 a * & x + & y
@@ -22,19 +27,19 @@ fn init_module(py: Python, m: &PyModule) -> PyResult<()> {
2227
2328 // wrapper of `axpy`
2429 #[ 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 > {
2631 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" ) ?;
2934 Ok ( axpy ( a, x, y) . into_pyarray ( py, & np) )
3035 }
3136
3237 // wrapper of `mult`
3338 #[ 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" ) ?;
3641 mult ( a, x) ;
37- Ok ( py . None ( ) ) // Python function must returns
42+ Ok ( ( ) )
3843 }
3944
4045 Ok ( ( ) )
0 commit comments