pub trait PyArrayDescrMethods<'py>: Sealed {
Show 21 methods
// Required methods
fn as_dtype_ptr(&self) -> *mut PyArray_Descr;
fn into_dtype_ptr(self) -> *mut PyArray_Descr;
fn is_equiv_to(&self, other: &Self) -> bool;
fn typeobj(&self) -> Bound<'py, PyType>;
fn itemsize(&self) -> usize;
fn alignment(&self) -> usize;
fn flags(&self) -> u64;
fn ndim(&self) -> usize;
fn base(&self) -> Bound<'py, PyArrayDescr>;
fn shape(&self) -> Vec<usize>;
fn has_subarray(&self) -> bool;
fn has_fields(&self) -> bool;
fn names(&self) -> Option<Vec<String>>;
fn get_field(
&self,
name: &str,
) -> PyResult<(Bound<'py, PyArrayDescr>, usize)>;
// Provided methods
fn num(&self) -> c_int { ... }
fn byteorder(&self) -> u8 { ... }
fn char(&self) -> u8 { ... }
fn kind(&self) -> u8 { ... }
fn has_object(&self) -> bool { ... }
fn is_aligned_struct(&self) -> bool { ... }
fn is_native_byteorder(&self) -> Option<bool> { ... }
}
Expand description
Implementation of functionality for PyArrayDescr
.
Required Methods§
Sourcefn as_dtype_ptr(&self) -> *mut PyArray_Descr
fn as_dtype_ptr(&self) -> *mut PyArray_Descr
Returns self
as *mut PyArray_Descr
.
Sourcefn into_dtype_ptr(self) -> *mut PyArray_Descr
fn into_dtype_ptr(self) -> *mut PyArray_Descr
Returns self
as *mut PyArray_Descr
while increasing the reference count.
Useful in cases where the descriptor is stolen by the API.
Sourcefn is_equiv_to(&self, other: &Self) -> bool
fn is_equiv_to(&self, other: &Self) -> bool
Returns true if two type descriptors are equivalent.
Sourcefn typeobj(&self) -> Bound<'py, PyType>
fn typeobj(&self) -> Bound<'py, PyType>
Returns the array scalar corresponding to this type descriptor.
Equivalent to numpy.dtype.type
.
Sourcefn itemsize(&self) -> usize
fn itemsize(&self) -> usize
Returns the element size of this type descriptor.
Equivalent to [numpy.dtype.itemsize
][dtype-itemsize].
Sourcefn alignment(&self) -> usize
fn alignment(&self) -> usize
Returns the required alignment (bytes) of this type descriptor according to the compiler.
Equivalent to numpy.dtype.alignment
.
Sourcefn flags(&self) -> u64
fn flags(&self) -> u64
Returns bit-flags describing how this type descriptor is to be interpreted.
Equivalent to numpy.dtype.flags
.
Sourcefn ndim(&self) -> usize
fn ndim(&self) -> usize
Returns the number of dimensions if this type descriptor represents a sub-array, and zero otherwise.
Equivalent to numpy.dtype.ndim
.
Sourcefn base(&self) -> Bound<'py, PyArrayDescr>
fn base(&self) -> Bound<'py, PyArrayDescr>
Returns the type descriptor for the base element of subarrays, regardless of their dimension or shape.
If the dtype is not a subarray, returns self.
Equivalent to numpy.dtype.base
.
Sourcefn shape(&self) -> Vec<usize>
fn shape(&self) -> Vec<usize>
Returns the shape of the sub-array.
If the dtype is not a sub-array, an empty vector is returned.
Equivalent to numpy.dtype.shape
.
Sourcefn has_subarray(&self) -> bool
fn has_subarray(&self) -> bool
Returns true if the type descriptor is a sub-array.
Equivalent to PyDataType_HASSUBARRAY(self).
Sourcefn has_fields(&self) -> bool
fn has_fields(&self) -> bool
Returns true if the type descriptor is a structured type.
Equivalent to PyDataType_HASFIELDS(self).
Sourcefn names(&self) -> Option<Vec<String>>
fn names(&self) -> Option<Vec<String>>
Returns an ordered list of field names, or None
if there are no fields.
The names are ordered according to increasing byte offset.
Equivalent to numpy.dtype.names
.
Sourcefn get_field(&self, name: &str) -> PyResult<(Bound<'py, PyArrayDescr>, usize)>
fn get_field(&self, name: &str) -> PyResult<(Bound<'py, PyArrayDescr>, usize)>
Returns the type descriptor and offset of the field with the given name.
This method will return an error if this type descriptor is not structured, or if it does not contain a field with a given name.
The list of all names can be found via [PyArrayDescr::names
].
Equivalent to retrieving a single item from numpy.dtype.fields
.
Provided Methods§
Sourcefn num(&self) -> c_int
fn num(&self) -> c_int
Returns a unique number for each of the 21 different built-in enumerated types.
These are roughly ordered from least-to-most precision.
Equivalent to numpy.dtype.num
.
Sourcefn byteorder(&self) -> u8
fn byteorder(&self) -> u8
Returns an ASCII character indicating the byte-order of this type descriptor object.
All built-in data-type objects have byteorder either =
or |
.
Equivalent to numpy.dtype.byteorder
.
Sourcefn char(&self) -> u8
fn char(&self) -> u8
Returns a unique ASCII character for each of the 21 different built-in types.
Note that structured data types are categorized as V
(void).
Equivalent to numpy.dtype.char
.
Sourcefn kind(&self) -> u8
fn kind(&self) -> u8
Returns an ASCII character (one of biufcmMOSUV
) identifying the general kind of data.
Note that structured data types are categorized as V
(void).
Equivalent to numpy.dtype.kind
.
Sourcefn has_object(&self) -> bool
fn has_object(&self) -> bool
Returns true if the type descriptor contains any reference-counted objects in any fields or sub-dtypes.
Equivalent to numpy.dtype.hasobject
.
Sourcefn is_aligned_struct(&self) -> bool
fn is_aligned_struct(&self) -> bool
Returns true if the type descriptor is a struct which maintains field alignment.
This flag is sticky, so when combining multiple structs together, it is preserved and produces new dtypes which are also aligned.
Equivalent to numpy.dtype.isalignedstruct
.
Sourcefn is_native_byteorder(&self) -> Option<bool>
fn is_native_byteorder(&self) -> Option<bool>
Returns true if type descriptor byteorder is native, or None
if not applicable.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.