Low-level Interfaces
Within optype.numpy there are several Can* (single-method) and Has*
(single-attribute) protocols, related to the __array_*__ dunders of the
NumPy Python API.
These typing protocols are, just like the optype.Can* and optype.Has* ones,
runtime-checkable and extensible (i.e. not @final).
Tip
All type parameters of these protocols can be omitted, which is equivalent
to passing its upper type bound.
| Protocol type signature |
Implements |
NumPy docs |
class CanArray[
ND: tuple[int, ...] = ...,
ST: np.generic = ...,
]: ...
|
def __array__[RT = ST](
_,
dtype: DType[RT] | None = ...,
) -> Array[ND, RT]
|
User Guide: Interoperability with NumPy
|
|
class CanArrayUFunc[
U: UFunc = ...,
R: object = ...,
]: ...
|
def __array_ufunc__(
_,
ufunc: U,
method: LiteralString,
*args: object,
**kwargs: object,
) -> R: ...
|
NEP 13
|
|
class CanArrayFunction[
F: CanCall[..., object] = ...,
R = object,
]: ...
|
def __array_function__(
_,
func: F,
types: CanIterSelf[type[CanArrayFunction]],
args: tuple[object, ...],
kwargs: Mapping[str, object],
) -> R: ...
|
NEP 18
|
|
class CanArrayFinalize[
T: object = ...,
]: ...
|
def __array_finalize__(_, obj: T): ...
|
User Guide: Subclassing ndarray
|
|
|
|
def __array_wrap__[ND, ST](
_,
array: Array[ND, ST],
context: (...) | None = ...,
return_scalar: bool = ...,
) -> Self | Array[ND, ST]
|
API: Standard array subclasses
|
|
class HasArrayInterface[
V: Mapping[str, object] = ...,
]: ...
|
|
API: The array interface protocol
|
|
class HasArrayPriority: ...
|
__array_priority__: float
|
API: Standard array subclasses
|
|
class HasDType[
DT: DType = ...,
]: ...
|
|
API: Specifying and constructing data types
|