Skip to content

Commit e874dd2

Browse files
committed
Add documentation to PY_ARRAY_API
1 parent 8f46870 commit e874dd2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ We need your feedback. Don't hesitate to open [issues](https://github.com/termos
137137

138138
Version
139139
--------
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+
140146
- v0.3.0
141147
- Breaking Change: Migrated to pyo3 from rust-cpython
142148
- Some api addition

src/npyffi/array.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,33 @@ use npyffi::*;
1010
pub(crate) const MOD_NAME: &str = "numpy.core.multiarray";
1111
const CAPSULE_NAME: &str = "_ARRAY_API";
1212

13+
/// A global variable which stores a ['capsule'](https://docs.python.org/3/c-api/capsule.html)
14+
/// pointer to [Numpy Array API](https://docs.scipy.org/doc/numpy/reference/c-api.array.html).
15+
///
16+
/// You can acceess raw c APIs via this variable and its Deref implementation.
17+
///
18+
/// See [PyArrayAPI](struct.PyArrayAPI.html) for what methods you can use via this variable.
19+
///
20+
/// # Example
21+
/// ```
22+
/// # extern crate pyo3; extern crate numpy; fn main() {
23+
/// use numpy::{PyArray, npyffi::types::NPY_SORTKIND, PY_ARRAY_API};
24+
/// use pyo3::Python;
25+
/// let gil = Python::acquire_gil();
26+
/// let array: &PyArray<i32> = PyArray::arange(gil.python(), 2.0, 5.0, 1.0);
27+
/// array.as_slice_mut().unwrap().swap(0, 1);
28+
/// assert_eq!(array.as_slice().unwrap(), &[3, 2, 4]);
29+
/// unsafe {
30+
/// PY_ARRAY_API.PyArray_Sort(array.as_array_ptr(), 0, NPY_SORTKIND::NPY_QUICKSORT);
31+
/// }
32+
/// assert_eq!(array.as_slice().unwrap(), &[2, 3, 4])
33+
/// # }
34+
/// ```
1335
pub static PY_ARRAY_API: PyArrayAPI = PyArrayAPI {
1436
__private_field: (),
1537
};
1638

39+
///
1740
pub struct PyArrayAPI {
1841
__private_field: (),
1942
}
@@ -33,7 +56,6 @@ impl Deref for PyArrayAPI {
3356
}
3457

3558
#[allow(non_camel_case_types)]
36-
#[doc(hidden)]
3759
pub struct PyArrayAPI_Inner(*const *const c_void);
3860

3961
impl PyArrayAPI_Inner {

src/npyffi/ufunc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl Deref for PyUFuncAPI {
3636
}
3737

3838
#[allow(non_camel_case_types)]
39-
#[doc(hidden)]
4039
pub struct PyUFuncAPI_Inner(*const *const c_void);
4140

4241
impl PyUFuncAPI_Inner {

0 commit comments

Comments
 (0)