_internal.pyi 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import ctypes as ct
  2. import re
  3. from collections.abc import Callable, Iterable
  4. from typing import Any, Final, Generic, overload
  5. from typing_extensions import Self, TypeVar, deprecated
  6. import numpy as np
  7. import numpy.typing as npt
  8. from numpy.ctypeslib import c_intp
  9. _CastT = TypeVar("_CastT", bound=ct._CanCastTo)
  10. _T_co = TypeVar("_T_co", covariant=True)
  11. _CT = TypeVar("_CT", bound=ct._CData)
  12. _PT_co = TypeVar("_PT_co", bound=int | None, default=None, covariant=True)
  13. ###
  14. IS_PYPY: Final[bool] = ...
  15. format_re: Final[re.Pattern[str]] = ...
  16. sep_re: Final[re.Pattern[str]] = ...
  17. space_re: Final[re.Pattern[str]] = ...
  18. ###
  19. # TODO: Let the likes of `shape_as` and `strides_as` return `None`
  20. # for 0D arrays once we've got shape-support
  21. class _ctypes(Generic[_PT_co]):
  22. @overload
  23. def __init__(self: _ctypes[None], /, array: npt.NDArray[Any], ptr: None = None) -> None: ...
  24. @overload
  25. def __init__(self, /, array: npt.NDArray[Any], ptr: _PT_co) -> None: ...
  26. #
  27. @property
  28. def data(self) -> _PT_co: ...
  29. @property
  30. def shape(self) -> ct.Array[c_intp]: ...
  31. @property
  32. def strides(self) -> ct.Array[c_intp]: ...
  33. @property
  34. def _as_parameter_(self) -> ct.c_void_p: ...
  35. #
  36. def data_as(self, /, obj: type[_CastT]) -> _CastT: ...
  37. def shape_as(self, /, obj: type[_CT]) -> ct.Array[_CT]: ...
  38. def strides_as(self, /, obj: type[_CT]) -> ct.Array[_CT]: ...
  39. #
  40. @deprecated('"get_data" is deprecated. Use "data" instead')
  41. def get_data(self, /) -> _PT_co: ...
  42. @deprecated('"get_shape" is deprecated. Use "shape" instead')
  43. def get_shape(self, /) -> ct.Array[c_intp]: ...
  44. @deprecated('"get_strides" is deprecated. Use "strides" instead')
  45. def get_strides(self, /) -> ct.Array[c_intp]: ...
  46. @deprecated('"get_as_parameter" is deprecated. Use "_as_parameter_" instead')
  47. def get_as_parameter(self, /) -> ct.c_void_p: ...
  48. class dummy_ctype(Generic[_T_co]):
  49. _cls: type[_T_co]
  50. def __init__(self, /, cls: type[_T_co]) -> None: ...
  51. def __eq__(self, other: Self, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  52. def __ne__(self, other: Self, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  53. def __mul__(self, other: object, /) -> Self: ...
  54. def __call__(self, /, *other: object) -> _T_co: ...
  55. def array_ufunc_errmsg_formatter(dummy: object, ufunc: np.ufunc, method: str, *inputs: object, **kwargs: object) -> str: ...
  56. def array_function_errmsg_formatter(public_api: Callable[..., object], types: Iterable[str]) -> str: ...
  57. def npy_ctypes_check(cls: type) -> bool: ...