@@ -24,42 +24,11 @@ Rust bindings for the NumPy C-API.
24
24
25
25
## Example
26
26
27
- ### Execute a Python program from Rust and get results
28
-
29
- ``` toml
30
- [package ]
31
- name = " numpy-test"
32
-
33
- [dependencies ]
34
- pyo3 = { version = " 0.15" , features = [" auto-initialize" ] }
35
- numpy = " 0.15"
36
- ```
37
-
38
- ``` rust
39
- use numpy :: PyArray1 ;
40
- use pyo3 :: prelude :: {PyResult , Python };
41
- use pyo3 :: types :: IntoPyDict ;
42
-
43
- fn main () -> PyResult <()> {
44
- Python :: with_gil (| py | {
45
- let np = py . import (" numpy" )? ;
46
- let locals = [(" np" , np )]. into_py_dict (py );
47
- let pyarray : & PyArray1 <i32 > = py
48
- . eval (" np.absolute(np.array([-1, -2, -3], dtype='int32'))" , Some (locals ), None )?
49
- . extract ()? ;
50
- let readonly = pyarray . readonly ();
51
- let slice = readonly . as_slice ()? ;
52
- assert_eq! (slice , & [1 , 2 , 3 ]);
53
- Ok (())
54
- })
55
- }
56
-
57
- ```
58
-
59
27
### Write a Python module in Rust
60
28
61
29
Please see the [ simple-extension] ( https://github.com/PyO3/rust-numpy/tree/main/examples/simple-extension )
62
30
directory for the complete example.
31
+
63
32
Also, we have an example project with [ ndarray-linalg] ( https://github.com/PyO3/rust-numpy/tree/main/examples/linalg ) .
64
33
65
34
``` toml
@@ -114,6 +83,38 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
114
83
}
115
84
```
116
85
86
+ ### Execute a Python program from Rust and get results
87
+
88
+ ``` toml
89
+ [package ]
90
+ name = " numpy-test"
91
+
92
+ [dependencies ]
93
+ pyo3 = { version = " 0.15" , features = [" auto-initialize" ] }
94
+ numpy = " 0.15"
95
+ ```
96
+
97
+ ``` rust
98
+ use numpy :: PyArray1 ;
99
+ use pyo3 :: prelude :: {PyResult , Python };
100
+ use pyo3 :: types :: IntoPyDict ;
101
+
102
+ fn main () -> PyResult <()> {
103
+ Python :: with_gil (| py | {
104
+ let np = py . import (" numpy" )? ;
105
+ let locals = [(" np" , np )]. into_py_dict (py );
106
+ let pyarray : & PyArray1 <i32 > = py
107
+ . eval (" np.absolute(np.array([-1, -2, -3], dtype='int32'))" , Some (locals ), None )?
108
+ . extract ()? ;
109
+ let readonly = pyarray . readonly ();
110
+ let slice = readonly . as_slice ()? ;
111
+ assert_eq! (slice , & [1 , 2 , 3 ]);
112
+ Ok (())
113
+ })
114
+ }
115
+
116
+ ```
117
+
117
118
## Dependency on ndarray
118
119
119
120
This crate uses types from ` ndarray ` in its public API. ` ndarray ` is re-exported
@@ -141,6 +142,7 @@ cargo update ---package ndarray:0.15.3 --precise 0.13.1
141
142
to achieve a single dependency on version ` 0.13.1 ` of ` ndarray ` .
142
143
143
144
## Contributing
145
+
144
146
We welcome [ issues] ( https://github.com/PyO3/rust-numpy/issues )
145
147
and [ pull requests] ( https://github.com/PyO3/rust-numpy/pulls ) .
146
148
0 commit comments