arrayterator.pyi 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from collections.abc import Generator
  2. from typing import (
  3. Any,
  4. TypeVar,
  5. Union,
  6. overload,
  7. )
  8. from numpy import ndarray, dtype, generic
  9. from numpy._typing import DTypeLike
  10. # TODO: Set a shape bound once we've got proper shape support
  11. _Shape = TypeVar("_Shape", bound=Any)
  12. _DType = TypeVar("_DType", bound=dtype[Any])
  13. _ScalarType = TypeVar("_ScalarType", bound=generic)
  14. _Index = Union[
  15. Union[ellipsis, int, slice],
  16. tuple[Union[ellipsis, int, slice], ...],
  17. ]
  18. __all__: list[str]
  19. # NOTE: In reality `Arrayterator` does not actually inherit from `ndarray`,
  20. # but its ``__getattr__` method does wrap around the former and thus has
  21. # access to all its methods
  22. class Arrayterator(ndarray[_Shape, _DType]):
  23. var: ndarray[_Shape, _DType] # type: ignore[assignment]
  24. buf_size: None | int
  25. start: list[int]
  26. stop: list[int]
  27. step: list[int]
  28. @property # type: ignore[misc]
  29. def shape(self) -> tuple[int, ...]: ...
  30. @property
  31. def flat( # type: ignore[override]
  32. self: ndarray[Any, dtype[_ScalarType]]
  33. ) -> Generator[_ScalarType, None, None]: ...
  34. def __init__(
  35. self, var: ndarray[_Shape, _DType], buf_size: None | int = ...
  36. ) -> None: ...
  37. @overload
  38. def __array__(self, dtype: None = ...) -> ndarray[Any, _DType]: ...
  39. @overload
  40. def __array__(self, dtype: DTypeLike) -> ndarray[Any, dtype[Any]]: ...
  41. def __getitem__(self, index: _Index) -> Arrayterator[Any, _DType]: ...
  42. def __iter__(self) -> Generator[ndarray[Any, _DType], None, None]: ...