@@ -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 , PyArrayModule };
48
+ use numpy :: {IntoPyResult , PyArray , get_array_module };
49
49
use pyo3 :: prelude :: {ObjectProtocol , PyDict , PyResult , Python };
50
50
51
51
fn main () -> Result <(), ()> {
@@ -59,9 +59,9 @@ fn main() -> Result<(), ()> {
59
59
}
60
60
61
61
fn main_ <'py >(py : Python <'py >) -> PyResult <()> {
62
- let np = PyArrayModule :: import (py )? ;
62
+ let np = get_array_module (py )? ;
63
63
let dict = PyDict :: new (py );
64
- dict . set_item (" np" , np . as_pymodule () )? ;
64
+ dict . set_item (" np" , np )? ;
65
65
let pyarray : & PyArray <i32 > = py
66
66
. eval (" np.array([1, 2, 3], dtype='int32')" , Some (& dict ), None )?
67
67
. extract ()? ;
@@ -95,16 +95,11 @@ extern crate numpy;
95
95
extern crate pyo3;
96
96
97
97
use ndarray :: {ArrayD , ArrayViewD , ArrayViewMutD };
98
- use numpy :: {IntoPyArray , IntoPyResult , PyArray , PyArrayModule };
98
+ use numpy :: {IntoPyArray , IntoPyResult , PyArray };
99
99
use pyo3 :: prelude :: {pymodinit, PyModule , PyResult , Python };
100
100
101
101
#[pymodinit]
102
- fn rust_ext (py : Python , m : & PyModule ) -> PyResult <()> {
103
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
104
- // You **must** write this statement for the PyArray type checker to work correctly
105
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
106
- let _np = PyArrayModule :: import (py )? ;
107
-
102
+ fn rust_ext (_py : Python , m : & PyModule ) -> PyResult <()> {
108
103
// immutable example
109
104
fn axpy (a : f64 , x : ArrayViewD <f64 >, y : ArrayViewD <f64 >) -> ArrayD <f64 > {
110
105
a * & x + & y
@@ -118,10 +113,9 @@ fn rust_ext(py: Python, m: &PyModule) -> PyResult<()> {
118
113
// wrapper of `axpy`
119
114
#[pyfn(m, " axpy" )]
120
115
fn axpy_py (py : Python , a : f64 , x : & PyArray <f64 >, y : & PyArray <f64 >) -> PyResult <PyArray <f64 >> {
121
- let np = PyArrayModule :: import (py )? ;
122
116
let x = x . as_array (). into_pyresult (" x must be f64 array" )? ;
123
117
let y = y . as_array (). into_pyresult (" y must be f64 array" )? ;
124
- Ok (axpy (a , x , y ). into_pyarray (py , & np ))
118
+ Ok (axpy (a , x , y ). into_pyarray (py ) . to_owned ( py ))
125
119
}
126
120
127
121
// wrapper of `mult`
@@ -143,6 +137,12 @@ We need your feedback. Don't hesitate to open [issues](https://github.com/termos
143
137
144
138
Version
145
139
--------
140
+ - v0.4.0(Coming soon)
141
+ - Duplicate ` PyArrayModule ` and import Numpy API automatically
142
+
143
+ - v0.3.1, v0.3.2
144
+ - Just update dependencies
145
+
146
146
- v0.3.0
147
147
- Breaking Change: Migrated to pyo3 from rust-cpython
148
148
- Some api addition
0 commit comments