_internal.pyi 1.0 KB

123456789101112131415161718192021222324252627282930
  1. from typing import Any, TypeVar, overload, Generic
  2. import ctypes as ct
  3. from numpy import ndarray
  4. from numpy.ctypeslib import c_intp
  5. _CastT = TypeVar("_CastT", bound=ct._CanCastTo) # Copied from `ctypes.cast`
  6. _CT = TypeVar("_CT", bound=ct._CData)
  7. _PT = TypeVar("_PT", bound=None | int)
  8. # TODO: Let the likes of `shape_as` and `strides_as` return `None`
  9. # for 0D arrays once we've got shape-support
  10. class _ctypes(Generic[_PT]):
  11. @overload
  12. def __new__(cls, array: ndarray[Any, Any], ptr: None = ...) -> _ctypes[None]: ...
  13. @overload
  14. def __new__(cls, array: ndarray[Any, Any], ptr: _PT) -> _ctypes[_PT]: ...
  15. @property
  16. def data(self) -> _PT: ...
  17. @property
  18. def shape(self) -> ct.Array[c_intp]: ...
  19. @property
  20. def strides(self) -> ct.Array[c_intp]: ...
  21. @property
  22. def _as_parameter_(self) -> ct.c_void_p: ...
  23. def data_as(self, obj: type[_CastT]) -> _CastT: ...
  24. def shape_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...
  25. def strides_as(self, obj: type[_CT]) -> ct.Array[_CT]: ...