Skip to content

Commit dd22664

Browse files
committed
Add PyArray0
1 parent 877ba28 commit dd22664

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/array.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ use crate::slice_box::SliceBox;
7777
/// ```
7878
pub struct PyArray<T, D>(PyAny, PhantomData<T>, PhantomData<D>);
7979

80+
/// Zero-dimensional array.
81+
pub type PyArray0<T> = PyArray<T, Ix0>;
8082
/// One-dimensional array.
8183
pub type PyArray1<T> = PyArray<T, Ix1>;
8284
/// Two-dimensional array.
@@ -592,8 +594,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
592594
}
593595

594596
/// Get dynamic dimensioned array from fixed dimension array.
595-
///
596-
/// See [get](#method.get) for usage.
597597
pub fn to_dyn(&self) -> &PyArray<T, IxDyn> {
598598
let python = self.py();
599599
unsafe { PyArray::from_borrowed_ptr(python, self.as_ptr()) }
@@ -708,6 +708,13 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
708708
}
709709
}
710710

711+
impl<T: Copy + Element> PyArray<T, Ix0> {
712+
/// Get the element of zero-dimensional PyArray.
713+
pub fn item(&self) -> T {
714+
unsafe { *self.data() }
715+
}
716+
}
717+
711718
impl<T: Element> PyArray<T, Ix1> {
712719
/// Construct one-dimension PyArray from slice.
713720
///

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ mod slice_box;
4646
mod sum_products;
4747

4848
pub use crate::array::{
49-
get_array_module, PyArray, PyArray1, PyArray2, PyArray3, PyArray4, PyArray5, PyArray6,
50-
PyArrayDyn,
49+
get_array_module, PyArray, PyArray0, PyArray1, PyArray2, PyArray3, PyArray4, PyArray5,
50+
PyArray6, PyArrayDyn,
5151
};
5252
pub use crate::convert::{IntoPyArray, NpyIndex, ToNpyDims, ToPyArray};
5353
pub use crate::dtype::{c32, c64, DataType, Element, PyArrayDescr};

0 commit comments

Comments
 (0)