index_tricks.pyi 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. from collections.abc import Sequence
  2. from typing import (
  3. Any,
  4. TypeVar,
  5. Generic,
  6. overload,
  7. Literal,
  8. SupportsIndex,
  9. )
  10. from numpy import (
  11. # Circumvent a naming conflict with `AxisConcatenator.matrix`
  12. matrix as _Matrix,
  13. ndenumerate as ndenumerate,
  14. ndindex as ndindex,
  15. ndarray,
  16. dtype,
  17. integer,
  18. str_,
  19. bytes_,
  20. bool_,
  21. int_,
  22. float_,
  23. complex_,
  24. intp,
  25. _OrderCF,
  26. _ModeKind,
  27. )
  28. from numpy._typing import (
  29. # Arrays
  30. ArrayLike,
  31. _NestedSequence,
  32. _FiniteNestedSequence,
  33. NDArray,
  34. _ArrayLikeInt,
  35. # DTypes
  36. DTypeLike,
  37. _SupportsDType,
  38. # Shapes
  39. _ShapeLike,
  40. )
  41. from numpy.core.multiarray import (
  42. unravel_index as unravel_index,
  43. ravel_multi_index as ravel_multi_index,
  44. )
  45. _T = TypeVar("_T")
  46. _DType = TypeVar("_DType", bound=dtype[Any])
  47. _BoolType = TypeVar("_BoolType", Literal[True], Literal[False])
  48. _TupType = TypeVar("_TupType", bound=tuple[Any, ...])
  49. _ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
  50. __all__: list[str]
  51. @overload
  52. def ix_(*args: _FiniteNestedSequence[_SupportsDType[_DType]]) -> tuple[ndarray[Any, _DType], ...]: ...
  53. @overload
  54. def ix_(*args: str | _NestedSequence[str]) -> tuple[NDArray[str_], ...]: ...
  55. @overload
  56. def ix_(*args: bytes | _NestedSequence[bytes]) -> tuple[NDArray[bytes_], ...]: ...
  57. @overload
  58. def ix_(*args: bool | _NestedSequence[bool]) -> tuple[NDArray[bool_], ...]: ...
  59. @overload
  60. def ix_(*args: int | _NestedSequence[int]) -> tuple[NDArray[int_], ...]: ...
  61. @overload
  62. def ix_(*args: float | _NestedSequence[float]) -> tuple[NDArray[float_], ...]: ...
  63. @overload
  64. def ix_(*args: complex | _NestedSequence[complex]) -> tuple[NDArray[complex_], ...]: ...
  65. class nd_grid(Generic[_BoolType]):
  66. sparse: _BoolType
  67. def __init__(self, sparse: _BoolType = ...) -> None: ...
  68. @overload
  69. def __getitem__(
  70. self: nd_grid[Literal[False]],
  71. key: slice | Sequence[slice],
  72. ) -> NDArray[Any]: ...
  73. @overload
  74. def __getitem__(
  75. self: nd_grid[Literal[True]],
  76. key: slice | Sequence[slice],
  77. ) -> list[NDArray[Any]]: ...
  78. class MGridClass(nd_grid[Literal[False]]):
  79. def __init__(self) -> None: ...
  80. mgrid: MGridClass
  81. class OGridClass(nd_grid[Literal[True]]):
  82. def __init__(self) -> None: ...
  83. ogrid: OGridClass
  84. class AxisConcatenator:
  85. axis: int
  86. matrix: bool
  87. ndmin: int
  88. trans1d: int
  89. def __init__(
  90. self,
  91. axis: int = ...,
  92. matrix: bool = ...,
  93. ndmin: int = ...,
  94. trans1d: int = ...,
  95. ) -> None: ...
  96. @staticmethod
  97. @overload
  98. def concatenate( # type: ignore[misc]
  99. *a: ArrayLike, axis: SupportsIndex = ..., out: None = ...
  100. ) -> NDArray[Any]: ...
  101. @staticmethod
  102. @overload
  103. def concatenate(
  104. *a: ArrayLike, axis: SupportsIndex = ..., out: _ArrayType = ...
  105. ) -> _ArrayType: ...
  106. @staticmethod
  107. def makemat(
  108. data: ArrayLike, dtype: DTypeLike = ..., copy: bool = ...
  109. ) -> _Matrix[Any, Any]: ...
  110. # TODO: Sort out this `__getitem__` method
  111. def __getitem__(self, key: Any) -> Any: ...
  112. class RClass(AxisConcatenator):
  113. axis: Literal[0]
  114. matrix: Literal[False]
  115. ndmin: Literal[1]
  116. trans1d: Literal[-1]
  117. def __init__(self) -> None: ...
  118. r_: RClass
  119. class CClass(AxisConcatenator):
  120. axis: Literal[-1]
  121. matrix: Literal[False]
  122. ndmin: Literal[2]
  123. trans1d: Literal[0]
  124. def __init__(self) -> None: ...
  125. c_: CClass
  126. class IndexExpression(Generic[_BoolType]):
  127. maketuple: _BoolType
  128. def __init__(self, maketuple: _BoolType) -> None: ...
  129. @overload
  130. def __getitem__(self, item: _TupType) -> _TupType: ... # type: ignore[misc]
  131. @overload
  132. def __getitem__(self: IndexExpression[Literal[True]], item: _T) -> tuple[_T]: ...
  133. @overload
  134. def __getitem__(self: IndexExpression[Literal[False]], item: _T) -> _T: ...
  135. index_exp: IndexExpression[Literal[True]]
  136. s_: IndexExpression[Literal[False]]
  137. def fill_diagonal(a: ndarray[Any, Any], val: Any, wrap: bool = ...) -> None: ...
  138. def diag_indices(n: int, ndim: int = ...) -> tuple[NDArray[int_], ...]: ...
  139. def diag_indices_from(arr: ArrayLike) -> tuple[NDArray[int_], ...]: ...
  140. # NOTE: see `numpy/__init__.pyi` for `ndenumerate` and `ndindex`