pyrefly-numpy-stubs 1.4.0.dev4__tar.gz → 1.5.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyrefly-numpy-stubs
3
- Version: 1.4.0.dev4
3
+ Version: 1.5.0.dev1
4
4
  Summary: NumPy type stubs with array-shape tracking, maintained by Pyrefly
5
5
  Project-URL: homepage, https://pyrefly.org
6
6
  Project-URL: documentation, https://pyrefly.org/en/docs/
@@ -34,7 +34,7 @@ Classifier: Programming Language :: Python :: 3
34
34
  Classifier: Typing :: Stubs Only
35
35
  Requires-Python: >=3.12
36
36
  Requires-Dist: numpy
37
- Requires-Dist: pyrefly-shape-extensions==1.4.0.dev4
37
+ Requires-Dist: pyrefly-shape-extensions==1.5.0.dev1
38
38
  Description-Content-Type: text/markdown
39
39
 
40
40
  # pyrefly-numpy-stubs
@@ -6,7 +6,17 @@
6
6
  from builtins import bool as py_bool
7
7
  from collections.abc import Iterator, Sequence
8
8
  from types import EllipsisType
9
- from typing import Any, Final, Literal, Never, overload, SupportsIndex
9
+ from typing import (
10
+ Any,
11
+ Final,
12
+ Generic,
13
+ Literal,
14
+ Never,
15
+ overload,
16
+ Self,
17
+ SupportsIndex,
18
+ TypeVar,
19
+ )
10
20
 
11
21
  import shape_extensions
12
22
  from numpy.__config__ import (
@@ -50,7 +60,6 @@ from numpy._core.fromnumeric import (
50
60
  amax as amax,
51
61
  amin as amin,
52
62
  any as any,
53
- argmax as argmax,
54
63
  argpartition as argpartition,
55
64
  argsort as argsort,
56
65
  around as around,
@@ -206,7 +215,7 @@ from numpy._shapes import (
206
215
  vecdot_shape,
207
216
  vecmat_shape,
208
217
  )
209
- from numpy._typing import ArrayLike
218
+ from numpy._typing import _ArrayLikeInt_co, ArrayLike, DTypeLike
210
219
  from numpy._typing._extended_precision import (
211
220
  complex256 as complex256,
212
221
  float128 as float128,
@@ -250,7 +259,6 @@ from numpy.lib._function_base_impl import (
250
259
  hanning as hanning,
251
260
  i0 as i0,
252
261
  insert as insert,
253
- interp as interp,
254
262
  iterable as iterable,
255
263
  kaiser as kaiser,
256
264
  median as median,
@@ -426,28 +434,169 @@ from . import (
426
434
  )
427
435
 
428
436
  type _Shape = IntTuple
437
+ _ShapeT_co = TypeVar("_ShapeT_co", bound=_Shape, default=_Shape, covariant=True)
429
438
  type _Axis = int | tuple[int, ...] | None
430
439
  type _SingleAxis = int | None
431
440
  type _BasicIndex = int | slice | list[int] | None | EllipsisType
441
+ type _NumberScalar = number | bool_ | int | float | complex
432
442
 
433
443
  class generic:
444
+ @property
445
+ def shape(self) -> tuple[()]: ...
446
+ def __bool__(self, /) -> py_bool: ...
447
+ @overload
448
+ def __array__(self, dtype: None = None, /) -> ndarray[[], _dtype[Self]]: ...
449
+ @overload
450
+ def __array__[DType: _dtype](self, dtype: DType, /) -> ndarray[[], DType]: ...
434
451
  def astype(self, dtype: Any, **kwargs: Any) -> Any: ...
435
452
 
436
- class number(generic): ...
437
- class integer(number): ...
453
+ class number(generic):
454
+ def __neg__(self) -> Self: ...
455
+ def __pos__(self) -> Self: ...
456
+ def __abs__(self) -> number: ...
457
+ # The result dtype depends on both operands.
458
+ def __add__(self, other: _NumberScalar, /) -> number: ...
459
+ def __radd__(self, other: _NumberScalar, /) -> number | complex: ...
460
+ def __sub__(self, other: _NumberScalar, /) -> number: ...
461
+ def __rsub__(self, other: _NumberScalar, /) -> number | complex: ...
462
+ def __mul__(self, other: _NumberScalar, /) -> number: ...
463
+ def __rmul__(self, other: _NumberScalar, /) -> number | complex: ...
464
+ def __truediv__(self, other: _NumberScalar, /) -> number: ...
465
+ def __rtruediv__(self, other: _NumberScalar, /) -> number | complex: ...
466
+ def __pow__(self, other: _NumberScalar, mod: None = None, /) -> number: ...
467
+ def __rpow__(
468
+ self, other: _NumberScalar, mod: None = None, /
469
+ ) -> number | complex: ...
470
+ def __lt__(self, other: _NumberScalar, /) -> bool_: ...
471
+ def __le__(self, other: _NumberScalar, /) -> bool_: ...
472
+ def __gt__(self, other: _NumberScalar, /) -> bool_: ...
473
+ def __ge__(self, other: _NumberScalar, /) -> bool_: ...
474
+ def __int__(self, /) -> int: ...
475
+ def __float__(self, /) -> float: ...
438
476
 
439
- class signedinteger(integer):
440
- # TODO(stroxler): Sequence inputs to scalar constructors can produce arrays.
477
+ class integer(number):
478
+ def __index__(self, /) -> int: ...
479
+ @overload
480
+ def __new__[Shape: _Shape](
481
+ cls: type[Self], value: ndarray[Shape, Any]
482
+ ) -> ndarray[Shape, _dtype[Self]]: ...
483
+ @overload
484
+ def __new__[Shape: _Shape](
485
+ cls: type[Self], value: RegularNestedList[Shape, _ArrayScalar]
486
+ ) -> ndarray[Shape, _dtype[Self]]: ...
487
+ @overload
488
+ def __new__(cls: type[Self], value: _ArrayScalar = ...) -> Self: ...
489
+ @overload
490
+ def __new__(
491
+ cls: type[Self], value: Sequence[Any]
492
+ ) -> ndarray[IntTuple, _dtype[Self]]: ...
493
+ @overload
494
+ def __new__(cls: type[Self], value: object = ...) -> Self: ...
441
495
  def __init__(self, value: object = ...) -> None: ...
442
496
 
497
+ class signedinteger(integer): ...
443
498
  class unsignedinteger(integer): ...
444
499
  class inexact(number): ...
445
- class floating(inexact): ...
446
- class complexfloating(inexact): ...
447
- class bool_(generic): ...
500
+
501
+ class floating(inexact):
502
+ @overload
503
+ def __new__[Shape: _Shape](
504
+ cls: type[Self], value: ndarray[Shape, Any]
505
+ ) -> ndarray[Shape, _dtype[Self]]: ...
506
+ @overload
507
+ def __new__[Shape: _Shape](
508
+ cls: type[Self], value: RegularNestedList[Shape, _ArrayScalar]
509
+ ) -> ndarray[Shape, _dtype[Self]]: ...
510
+ @overload
511
+ def __new__(
512
+ cls: type[Self], value: number | bool_ | int | float | str | bytes = ...
513
+ ) -> Self: ...
514
+ @overload
515
+ def __new__(
516
+ cls: type[Self], value: Sequence[Any]
517
+ ) -> ndarray[IntTuple, _dtype[Self]]: ...
518
+ def __init__(
519
+ self, value: number | bool_ | int | float | str | bytes = ...
520
+ ) -> None: ...
521
+
522
+ class complexfloating(inexact):
523
+ @overload
524
+ def __new__[Shape: _Shape](
525
+ cls: type[Self], value: ndarray[Shape, Any]
526
+ ) -> ndarray[Shape, _dtype[Self]]: ...
527
+ @overload
528
+ def __new__[Shape: _Shape](
529
+ cls: type[Self], value: RegularNestedList[Shape, _ArrayScalar]
530
+ ) -> ndarray[Shape, _dtype[Self]]: ...
531
+ @overload
532
+ def __new__(cls: type[Self], value: _NumberScalar | str | bytes = ...) -> Self: ...
533
+ @overload
534
+ def __new__(
535
+ cls: type[Self], value: Sequence[Any]
536
+ ) -> ndarray[IntTuple, _dtype[Self]]: ...
537
+ def __init__(self, value: _NumberScalar | str | bytes = ...) -> None: ...
538
+ def __complex__(self, /) -> complex: ...
539
+
540
+ class bool_(generic):
541
+ @overload
542
+ def __new__[Shape: _Shape](
543
+ cls: type[Self], value: ndarray[Shape, Any]
544
+ ) -> ndarray[Shape, _dtype[Self]]: ...
545
+ @overload
546
+ def __new__[Shape: _Shape](
547
+ cls: type[Self], value: RegularNestedList[Shape, _ArrayScalar]
548
+ ) -> ndarray[Shape, _dtype[Self]]: ...
549
+ @overload
550
+ def __new__(cls: type[Self], value: _NumberScalar | str | bytes = ...) -> Self: ...
551
+ @overload
552
+ def __new__(
553
+ cls: type[Self], value: Sequence[Any]
554
+ ) -> ndarray[IntTuple, _dtype[Self]]: ...
555
+ def __init__(self, value: _NumberScalar | str | bytes = ...) -> None: ...
556
+ def __int__(self, /) -> int: ...
557
+ def __float__(self, /) -> float: ...
558
+ def __add__(self, other: _NumberScalar, /) -> number | bool_: ...
559
+ def __radd__(self, other: _NumberScalar, /) -> number | bool_: ...
560
+ def __sub__(self, other: number | int | float | complex, /) -> number: ...
561
+ def __rsub__(self, other: number | int | float | complex, /) -> number: ...
562
+ def __mul__(self, other: _NumberScalar, /) -> number | bool_: ...
563
+ def __rmul__(self, other: _NumberScalar, /) -> number | bool_: ...
564
+ def __truediv__(self, other: _NumberScalar, /) -> number: ...
565
+ def __rtruediv__(self, other: _NumberScalar, /) -> number: ...
566
+ def __pow__(self, other: _NumberScalar, mod: None = None, /) -> number: ...
567
+ def __rpow__(self, other: _NumberScalar, mod: None = None, /) -> number: ...
568
+
448
569
  class float16(floating): ...
449
570
  class float32(floating): ...
450
- class float64(floating): ...
571
+
572
+ class float64(floating):
573
+ # Narrow builtin-float support without inheriting float (which
574
+ # rewrites reflected ops like ``1j * float64`` via complex*float).
575
+ @overload
576
+ def __sub__(self, other: float, /) -> float64: ...
577
+ @overload
578
+ def __sub__(self, other: _NumberScalar, /) -> number: ...
579
+ @overload
580
+ def __rsub__(self, other: float, /) -> float64: ...
581
+ @overload
582
+ def __rsub__(self, other: _NumberScalar, /) -> number | complex: ...
583
+ @overload
584
+ def __gt__(self, other: float, /) -> bool_: ...
585
+ @overload
586
+ def __gt__(self, other: _NumberScalar, /) -> bool_: ...
587
+ @overload
588
+ def __ge__(self, other: float, /) -> bool_: ...
589
+ @overload
590
+ def __ge__(self, other: _NumberScalar, /) -> bool_: ...
591
+ @overload
592
+ def __lt__(self, other: float, /) -> bool_: ...
593
+ @overload
594
+ def __lt__(self, other: _NumberScalar, /) -> bool_: ...
595
+ @overload
596
+ def __le__(self, other: float, /) -> bool_: ...
597
+ @overload
598
+ def __le__(self, other: _NumberScalar, /) -> bool_: ...
599
+
451
600
  class longdouble(floating): ...
452
601
  class complex64(complexfloating): ...
453
602
  class complex128(complexfloating): ...
@@ -479,10 +628,15 @@ type _ArrayIndex = (
479
628
  _BasicIndex
480
629
  | _IndexScalar
481
630
  | _IndexSequence
631
+ | _ArrayLikeInt_co
482
632
  | ndarray
483
- | tuple[_BasicIndex | _IndexScalar | _IndexSequence | ndarray, ...]
633
+ | tuple[
634
+ _BasicIndex | _IndexScalar | _IndexSequence | _ArrayLikeInt_co | ndarray,
635
+ ...,
636
+ ]
484
637
  )
485
638
  type _ArrayScalar = None | py_bool | int | float | complex | str | bytes | generic
639
+ _ScalarT_co = TypeVar("_ScalarT_co", bound=generic, default=Any, covariant=True)
486
640
 
487
641
  __version__: Final[str]
488
642
  e: Final[float]
@@ -496,13 +650,15 @@ True_: Final[bool_]
496
650
  newaxis: Final[None] = None
497
651
  test: Final[PytestTester]
498
652
 
499
- class dtype[Scalar = Any]:
653
+ class dtype(Generic[_ScalarT_co]):
500
654
  @overload
501
655
  def __new__[ScalarT: generic](cls, dtype: type[ScalarT]) -> dtype[ScalarT]: ...
502
656
  @overload
503
657
  def __new__(cls, dtype: Any = ...) -> dtype: ...
504
658
  def __init__(self, dtype: Any = ...) -> None: ...
505
659
 
660
+ _DTypeT_co = TypeVar("_DTypeT_co", default=Any, covariant=True)
661
+
506
662
  # `ndarray` declares a `dtype` attribute, which shadows the class above throughout
507
663
  # its body. Annotations inside the class reach the class through this alias.
508
664
  _dtype = dtype
@@ -511,16 +667,16 @@ class _Flags:
511
667
  f_contiguous: py_bool
512
668
  def __getitem__(self, key: str) -> py_bool: ...
513
669
 
514
- class ndarray[Shape: _Shape = _Shape, DType = Any]:
515
- shape: Shape
516
- dtype: DType
670
+ class ndarray(Generic[_ShapeT_co, _DTypeT_co]):
671
+ shape: _ShapeT_co
672
+ dtype: _DTypeT_co
517
673
  flags: _Flags
518
674
  strides: tuple[int, ...]
519
675
  @property
520
676
  def __array_interface__(self) -> Any: ...
521
677
  def __array__(
522
678
  self, dtype: Any = None, copy: py_bool | None = None
523
- ) -> ndarray[Shape]: ...
679
+ ) -> ndarray[_ShapeT_co]: ...
524
680
  def __buffer__(self, flags: int, /) -> memoryview: ...
525
681
  @property
526
682
  def base(self) -> Any: ...
@@ -537,16 +693,31 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
537
693
  @property
538
694
  def size(self) -> int: ...
539
695
  @property
540
- def imag(self) -> ndarray[Shape]: ...
696
+ def imag(self) -> ndarray[_ShapeT_co]: ...
541
697
  @imag.setter
542
698
  def imag(self, value: Any) -> None: ...
543
699
  @property
544
- def real(self) -> ndarray[Shape]: ...
700
+ def real(self) -> ndarray[_ShapeT_co]: ...
545
701
  @real.setter
546
702
  def real(self, value: Any) -> None: ...
547
703
  def __len__[N: IntVar, Rest: _Shape = []](
548
704
  self: ndarray[[N, *Rest]],
549
705
  ) -> Int[N]: ...
706
+ # A gradual rank can match these fixed ranks; scalar-only returns would be unsafe.
707
+ @overload
708
+ def __getitem__[N: IntVar, ScalarT: generic](
709
+ self: ndarray[[N], _dtype[ScalarT]], key: int, /
710
+ ) -> Any: ...
711
+ @overload
712
+ def __getitem__(self: ndarray[[], _DTypeT_co], key: tuple[()], /) -> Any: ...
713
+ @overload
714
+ def __getitem__[N: IntVar](
715
+ self: ndarray[[N], _DTypeT_co], key: tuple[int], /
716
+ ) -> Any: ...
717
+ @overload
718
+ def __getitem__[N: IntVar, M: IntVar](
719
+ self: ndarray[[N, M], _DTypeT_co], key: tuple[int, int], /
720
+ ) -> Any: ...
550
721
  @overload
551
722
  def __getitem__[
552
723
  N: IntVar,
@@ -555,86 +726,117 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
555
726
  RowIndexScalar: (int32, int64, intp),
556
727
  ColumnIndexScalar: (int32, int64, intp),
557
728
  ](
558
- self: ndarray[[N, M], DType],
729
+ self: ndarray[[N, M], _DTypeT_co],
559
730
  key: tuple[
560
731
  ndarray[[I], _dtype[RowIndexScalar]],
561
732
  ndarray[[I], _dtype[ColumnIndexScalar]],
562
733
  ],
563
- ) -> ndarray[[I], DType]: ...
734
+ ) -> ndarray[[I], _DTypeT_co]: ...
564
735
  @overload
565
736
  def __getitem__[I: Index](
566
- self: ndarray[Shape, DType], key: I
567
- ) -> ndarray[index_shape(Shape, I), DType]: ...
737
+ self: ndarray[_ShapeT_co, _DTypeT_co], key: I
738
+ ) -> ndarray[index_shape(_ShapeT_co, I), _DTypeT_co]: ...
568
739
  # TODO(stroxler): Model general array-valued indices precisely enough to
569
740
  # reject non-integer dtypes and incompatible advanced-index shapes.
570
741
  @overload
571
742
  def __getitem__(
572
- self: ndarray[Shape, DType],
743
+ self: ndarray[_ShapeT_co, _DTypeT_co],
573
744
  key: _ArrayIndex,
574
- ) -> ndarray[IntTuple, DType]: ...
745
+ ) -> ndarray[IntTuple, _DTypeT_co]: ...
575
746
  # Assignment preserves the receiver's shape; value broadcasting is gradual.
576
747
  def __setitem__(self, key: _ArrayIndex, value: ArrayLike, /) -> None: ...
748
+ # Unknown-rank arrays may yield scalars, so prefer the gradual overload.
577
749
  @overload
578
- def __iter__[N: IntVar, M: IntVar, Rest: _Shape = []](
579
- self: ndarray[[N, M, *Rest], DType], /
580
- ) -> Iterator[ndarray[[M, *Rest], DType]]: ...
581
- # Iteration over one-dimensional arrays yields NumPy scalars.
750
+ def __iter__[N: IntVar](self: ndarray[[N], _DTypeT_co], /) -> Iterator[Any]: ...
582
751
  @overload
583
- def __iter__[N: IntVar](self: ndarray[[N], DType], /) -> Iterator[Any]: ...
752
+ def __iter__[N: IntVar, M: IntVar, Rest: _Shape = []](
753
+ self: ndarray[[N, M, *Rest], _DTypeT_co], /
754
+ ) -> Iterator[ndarray[[M, *Rest], _DTypeT_co]]: ...
584
755
  def __int__(self: ndarray[[]], /) -> int: ...
756
+ def __index__(self: ndarray[[], _dtype[integer]], /) -> int: ...
585
757
  def __float__(self: ndarray[[]], /) -> float: ...
586
758
  def __complex__(self: ndarray[[]], /) -> complex: ...
587
759
  # Only 2-D transpose is modeled for the NumPy shape-stub MVP.
588
760
  @property
589
761
  def T[N: IntVar, P: IntVar](
590
- self: ndarray[[N, P], DType],
591
- ) -> ndarray[[P, N], DType]: ...
762
+ self: ndarray[[N, P], _DTypeT_co],
763
+ ) -> ndarray[[P, N], _DTypeT_co]: ...
592
764
  # Unpacking preserves gradual array shapes instead of using the scalar default.
765
+ @overload
593
766
  def __add__[OtherShape: _Shape = []](
594
767
  self, other: ndarray[[*OtherShape]] | int | float
595
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
768
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
769
+ @overload
770
+ def __add__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
771
+ @overload
596
772
  def __radd__[OtherShape: _Shape = []](
597
773
  self, other: ndarray[[*OtherShape]] | int | float
598
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
774
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
775
+ @overload
776
+ def __radd__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
777
+ @overload
599
778
  def __sub__[OtherShape: _Shape = []](
600
779
  self, other: ndarray[[*OtherShape]] | int | float
601
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
780
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
781
+ @overload
782
+ def __sub__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
783
+ @overload
602
784
  def __rsub__[OtherShape: _Shape = []](
603
785
  self, other: ndarray[[*OtherShape]] | int | float
604
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
786
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
787
+ @overload
788
+ def __rsub__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
789
+ @overload
605
790
  def __truediv__[OtherShape: _Shape = []](
606
791
  self, other: ndarray[[*OtherShape]] | int | float
607
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
792
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
793
+ @overload
794
+ def __truediv__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
795
+ @overload
608
796
  def __rtruediv__[OtherShape: _Shape = []](
609
797
  self, other: ndarray[[*OtherShape]] | int | float
610
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
798
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
799
+ @overload
800
+ def __rtruediv__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
801
+ @overload
611
802
  def __mul__[OtherShape: _Shape = []](
612
803
  self, other: ndarray[[*OtherShape]] | int | float
613
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
804
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
805
+ @overload
806
+ def __mul__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
807
+ @overload
614
808
  def __rmul__[OtherShape: _Shape = []](
615
809
  self, other: ndarray[[*OtherShape]] | int | float
616
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
810
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
811
+ @overload
812
+ def __rmul__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
617
813
  def __floordiv__[OtherShape: _Shape = []](
618
814
  self, other: ndarray[[*OtherShape]] | int | float
619
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
815
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
620
816
  def __rfloordiv__[OtherShape: _Shape = []](
621
817
  self, other: ndarray[[*OtherShape]] | int | float
622
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
818
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
623
819
  def __mod__[OtherShape: _Shape = []](
624
820
  self, other: ndarray[[*OtherShape]] | int | float
625
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
821
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
626
822
  def __rmod__[OtherShape: _Shape = []](
627
823
  self, other: ndarray[[*OtherShape]] | int | float
628
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
629
- def __neg__(self) -> ndarray[Shape, DType]: ...
630
- def __pos__(self) -> ndarray[Shape, DType]: ...
631
- def __abs__(self, /) -> ndarray[Shape]: ...
824
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
825
+ def __neg__(self) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
826
+ def __pos__(self) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
827
+ def __abs__(self, /) -> ndarray[_ShapeT_co]: ...
828
+ @overload
632
829
  def __pow__[OtherShape: _Shape = []](
633
830
  self, other: ndarray[[*OtherShape]] | int | float
634
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
831
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
832
+ @overload
833
+ def __pow__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
834
+ @overload
635
835
  def __rpow__[OtherShape: _Shape = []](
636
836
  self, other: ndarray[[*OtherShape]] | int | float
637
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
837
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
838
+ @overload
839
+ def __rpow__(self, other: complex | number | bool_) -> ndarray[_ShapeT_co]: ...
638
840
  # Scalar results also satisfy Python's truth-valued comparison protocols.
639
841
  @overload
640
842
  def __lt__(self: ndarray[[]], other: Any, /) -> Any: ...
@@ -643,7 +845,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
643
845
  self,
644
846
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
645
847
  /,
646
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
848
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
647
849
  @overload
648
850
  def __lt__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
649
851
  @overload
@@ -653,7 +855,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
653
855
  self,
654
856
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
655
857
  /,
656
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
858
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
657
859
  @overload
658
860
  def __le__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
659
861
  @overload
@@ -663,7 +865,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
663
865
  self,
664
866
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
665
867
  /,
666
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
868
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
667
869
  @overload
668
870
  def __gt__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
669
871
  @overload
@@ -673,7 +875,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
673
875
  self,
674
876
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
675
877
  /,
676
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
878
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
677
879
  @overload
678
880
  def __ge__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
679
881
  @overload
@@ -683,7 +885,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
683
885
  self,
684
886
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
685
887
  /,
686
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
888
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
687
889
  @overload
688
890
  def __eq__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
689
891
  @overload
@@ -693,55 +895,57 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
693
895
  self,
694
896
  other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
695
897
  /,
696
- ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
898
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape), _dtype[bool_]]: ...
697
899
  @overload
698
900
  def __ne__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
699
- def __invert__(self) -> ndarray[Shape, DType]: ...
901
+ def __invert__(self) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
700
902
  def __and__[OtherShape: _Shape = []](
701
903
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
702
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
904
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
703
905
  def __or__[OtherShape: _Shape = []](
704
906
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
705
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
907
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
706
908
  def __xor__[OtherShape: _Shape = []](
707
909
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
708
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
910
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
709
911
  def __rand__[OtherShape: _Shape = []](
710
912
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
711
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
913
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
712
914
  def __ror__[OtherShape: _Shape = []](
713
915
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
714
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
916
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
715
917
  def __rxor__[OtherShape: _Shape = []](
716
918
  self, other: ndarray[[*OtherShape]] | _IndexScalar, /
717
- ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
919
+ ) -> ndarray[_broadcast_shape(_ShapeT_co, OtherShape)]: ...
718
920
  def __matmul__[OtherShape: _Shape](
719
921
  self, other: ndarray[OtherShape]
720
- ) -> ndarray[matmul_shape(Shape, OtherShape), DType]: ...
922
+ ) -> ndarray[matmul_shape(_ShapeT_co, OtherShape), _DTypeT_co]: ...
721
923
  def mean[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
722
924
  self,
723
925
  axis: Axis = None,
724
926
  *,
725
927
  keepdims: KeepDims = False,
726
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), DType]: ...
928
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _DTypeT_co]: ...
727
929
  def sum[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
728
930
  self,
729
931
  axis: Axis = None,
730
932
  *,
731
933
  keepdims: KeepDims = False,
732
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), DType]: ...
934
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _DTypeT_co]: ...
733
935
  def min[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
734
936
  self,
735
937
  axis: Axis = None,
736
938
  *,
737
939
  keepdims: KeepDims = False,
738
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), DType]: ...
940
+ initial: _ArrayScalar = ...,
941
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _DTypeT_co]: ...
739
942
  def max[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
740
943
  self,
741
944
  axis: Axis = None,
742
945
  *,
743
946
  keepdims: KeepDims = False,
744
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), DType]: ...
947
+ initial: _ArrayScalar = ...,
948
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _DTypeT_co]: ...
745
949
  def all[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
746
950
  self,
747
951
  axis: Axis = None,
@@ -749,7 +953,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
749
953
  keepdims: KeepDims = False,
750
954
  *,
751
955
  where: Any = True,
752
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[bool_]]: ...
956
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _dtype[bool_]]: ...
753
957
  def any[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
754
958
  self,
755
959
  axis: Axis = None,
@@ -757,21 +961,31 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
757
961
  keepdims: KeepDims = False,
758
962
  *,
759
963
  where: Any = True,
760
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[bool_]]: ...
964
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _dtype[bool_]]: ...
965
+ @overload
966
+ def argmax(
967
+ self, axis: None = None, out: None = None, *, keepdims: Literal[False] = False
968
+ ) -> intp: ...
969
+ @overload
761
970
  def argmax[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
762
971
  self,
763
972
  axis: Axis = None,
764
973
  out: Any = None,
765
974
  *,
766
975
  keepdims: KeepDims = False,
767
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[intp]]: ...
976
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _dtype[intp]]: ...
977
+ @overload
978
+ def argmin(
979
+ self, axis: None = None, out: None = None, *, keepdims: Literal[False] = False
980
+ ) -> intp: ...
981
+ @overload
768
982
  def argmin[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
769
983
  self,
770
984
  axis: Axis = None,
771
985
  out: Any = None,
772
986
  *,
773
987
  keepdims: KeepDims = False,
774
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[intp]]: ...
988
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims), _dtype[intp]]: ...
775
989
  def prod[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
776
990
  self,
777
991
  axis: Axis = None,
@@ -781,7 +995,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
781
995
  keepdims: KeepDims = False,
782
996
  initial: Any = None,
783
997
  where: Any = True,
784
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims)]: ...
998
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims)]: ...
785
999
  def std[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
786
1000
  self,
787
1001
  axis: Axis = None,
@@ -793,7 +1007,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
793
1007
  where: Any = True,
794
1008
  mean: Any = None,
795
1009
  correction: Any = None,
796
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims)]: ...
1010
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims)]: ...
797
1011
  def var[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
798
1012
  self,
799
1013
  axis: Axis = None,
@@ -805,7 +1019,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
805
1019
  where: Any = True,
806
1020
  mean: Any = None,
807
1021
  correction: Any = None,
808
- ) -> ndarray[reduce_shape(Shape, Axis, KeepDims)]: ...
1022
+ ) -> ndarray[reduce_shape(_ShapeT_co, Axis, KeepDims)]: ...
809
1023
  @overload
810
1024
  def argpartition(
811
1025
  self,
@@ -821,7 +1035,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
821
1035
  axis: int = -1,
822
1036
  kind: str = "introselect",
823
1037
  order: Any = None,
824
- ) -> ndarray[Shape, _dtype[intp]]: ...
1038
+ ) -> ndarray[_ShapeT_co, _dtype[intp]]: ...
825
1039
  @overload
826
1040
  def argsort(
827
1041
  self,
@@ -841,7 +1055,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
841
1055
  *,
842
1056
  stable: py_bool | None = None,
843
1057
  descending: py_bool | None = None,
844
- ) -> ndarray[Shape, _dtype[intp]]: ...
1058
+ ) -> ndarray[_ShapeT_co, _dtype[intp]]: ...
845
1059
  @overload
846
1060
  def astype[ScalarT: generic](
847
1061
  self,
@@ -850,7 +1064,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
850
1064
  casting: str = "unsafe",
851
1065
  subok: py_bool = True,
852
1066
  copy: py_bool = True,
853
- ) -> ndarray[Shape, _dtype[ScalarT]]: ...
1067
+ ) -> ndarray[_ShapeT_co, _dtype[ScalarT]]: ...
854
1068
  @overload
855
1069
  def astype(
856
1070
  self,
@@ -859,14 +1073,14 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
859
1073
  casting: str = "unsafe",
860
1074
  subok: py_bool = True,
861
1075
  copy: py_bool = True,
862
- ) -> ndarray[Shape]: ...
863
- def byteswap(self, inplace: py_bool = False) -> ndarray[Shape, DType]: ...
1076
+ ) -> ndarray[_ShapeT_co]: ...
1077
+ def byteswap(self, inplace: py_bool = False) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
864
1078
  def clip(
865
1079
  self, min: Any = None, max: Any = None, out: Any = None, **kwargs: Any
866
- ) -> ndarray[Shape, DType]: ...
867
- def conj(self) -> ndarray[Shape, DType]: ...
868
- def conjugate(self) -> ndarray[Shape, DType]: ...
869
- def copy(self, order: str = "C") -> ndarray[Shape, DType]: ...
1080
+ ) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
1081
+ def conj(self) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
1082
+ def conjugate(self) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
1083
+ def copy(self, order: str = "C") -> ndarray[_ShapeT_co, _DTypeT_co]: ...
870
1084
  @overload
871
1085
  def cumprod(
872
1086
  self, axis: None = None, dtype: Any = None, out: Any = None
@@ -874,7 +1088,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
874
1088
  @overload
875
1089
  def cumprod(
876
1090
  self, axis: int, dtype: Any = None, out: Any = None
877
- ) -> ndarray[Shape]: ...
1091
+ ) -> ndarray[_ShapeT_co]: ...
878
1092
  @overload
879
1093
  def cumsum(
880
1094
  self, axis: None = None, dtype: Any = None, out: Any = None
@@ -882,12 +1096,12 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
882
1096
  @overload
883
1097
  def cumsum(
884
1098
  self, axis: int, dtype: Any = None, out: Any = None
885
- ) -> ndarray[Shape]: ...
1099
+ ) -> ndarray[_ShapeT_co]: ...
886
1100
  def dump(self, file: Any) -> None: ...
887
1101
  def dumps(self) -> bytes: ...
888
1102
  def fill(self, value: Any, /) -> None: ...
889
- def flatten(self, order: str = "C") -> ndarray[[int], DType]: ...
890
- def getfield(self, dtype: Any, offset: int = 0) -> ndarray[Shape]: ...
1103
+ def flatten(self, order: str = "C") -> ndarray[[int], _DTypeT_co]: ...
1104
+ def getfield(self, dtype: Any, offset: int = 0) -> ndarray[_ShapeT_co]: ...
891
1105
  def item(self, *args: Any) -> Any: ...
892
1106
  def partition(
893
1107
  self,
@@ -897,7 +1111,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
897
1111
  order: Any = None,
898
1112
  ) -> None: ...
899
1113
  def put(self, indices: Any, values: Any, mode: str = "raise") -> None: ...
900
- def ravel(self, order: str = "C") -> ndarray[[int], DType]: ...
1114
+ def ravel(self, order: str = "C") -> ndarray[[int], _DTypeT_co]: ...
901
1115
  def resize(self, *, not_usable_with_shape_types: Never) -> None:
902
1116
  """Unsupported: resizing changes the receiver's shape in place.
903
1117
 
@@ -905,7 +1119,9 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
905
1119
  Create a new array instead of resizing an existing one.
906
1120
  """
907
1121
  ...
908
- def round(self, decimals: int = 0, out: Any = None) -> ndarray[Shape, DType]: ...
1122
+ def round(
1123
+ self, decimals: int = 0, out: Any = None
1124
+ ) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
909
1125
  def setfield(self, val: Any, dtype: Any, offset: int = 0) -> None: ...
910
1126
  def setflags(
911
1127
  self,
@@ -923,7 +1139,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
923
1139
  ) -> None: ...
924
1140
  def to_device(
925
1141
  self, device: Literal["cpu"], /, *, stream: Any = None
926
- ) -> ndarray[Shape, DType]: ...
1142
+ ) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
927
1143
  def tobytes(self, order: str = "C") -> bytes: ...
928
1144
  def tofile(self, fid: Any, sep: str = "", format: str = "%s") -> None: ...
929
1145
  def tolist(self) -> Any: ...
@@ -946,7 +1162,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
946
1162
  @overload
947
1163
  def compress[Axis: Flag[int | None]](
948
1164
  self, condition: Sequence[int] | ndarray, axis: Axis = None, out: None = None
949
- ) -> ndarray[compress_shape(Shape, Axis), DType]: ...
1165
+ ) -> ndarray[compress_shape(_ShapeT_co, Axis), _DTypeT_co]: ...
950
1166
  @overload
951
1167
  def compress[Out: ndarray](
952
1168
  self,
@@ -966,50 +1182,54 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
966
1182
  def ctypes(self) -> _ctypes[int]: ...
967
1183
  def diagonal[Offset: Flag[int], First: Flag[int], Second: Flag[int]](
968
1184
  self, offset: Offset = 0, axis1: First = 0, axis2: Second = 1
969
- ) -> ndarray[diagonal_shape(Shape, First, Second, True, Offset), DType]: ...
1185
+ ) -> ndarray[
1186
+ diagonal_shape(_ShapeT_co, First, Second, True, Offset), _DTypeT_co
1187
+ ]: ...
970
1188
  @overload
971
1189
  def dot[N: IntVar](
972
- self: ndarray[[N], DType], b: ndarray[[N]], /, out: None = None
1190
+ self: ndarray[[N], _DTypeT_co], b: ndarray[[N]], /, out: None = None
973
1191
  ) -> generic: ...
974
1192
  @overload
975
1193
  def dot(self: ndarray[[]], b: _ArrayScalar, /, out: None = None) -> generic: ...
976
1194
  @overload
977
1195
  def dot[Right: IntTuple](
978
1196
  self, b: ndarray[Right], /, out: None = None
979
- ) -> ndarray[dot_shape(Shape, Right)]: ...
1197
+ ) -> ndarray[dot_shape(_ShapeT_co, Right)]: ...
980
1198
  @overload
981
1199
  def dot[Right: IntTuple](
982
1200
  self,
983
1201
  b: RegularNestedList[Right, _ArrayScalar],
984
1202
  /,
985
1203
  out: None = None,
986
- ) -> ndarray[dot_shape(Shape, Right)]: ...
1204
+ ) -> ndarray[dot_shape(_ShapeT_co, Right)]: ...
987
1205
  @overload
988
1206
  def dot(
989
1207
  self, b: int | float | complex | generic, /, out: None = None
990
- ) -> ndarray[Shape]: ...
1208
+ ) -> ndarray[_ShapeT_co]: ...
991
1209
  @overload
992
1210
  def dot[Out: ndarray](self, b: ArrayLike, /, out: Out) -> Out: ...
993
1211
  # TODO(stroxler): Infer scalar dtype promotion for vector inner products.
994
1212
  @property
995
- def flat(self) -> flatiter[ndarray[Shape, DType]]: ...
1213
+ def flat(self) -> flatiter[ndarray[_ShapeT_co, _DTypeT_co]]: ...
996
1214
  @property
997
- def mT(self) -> ndarray[swapaxes_shape(Shape, -1, -2), DType]: ...
1215
+ def mT(self) -> ndarray[swapaxes_shape(_ShapeT_co, -1, -2), _DTypeT_co]: ...
998
1216
  def nonzero(
999
1217
  self,
1000
- ) -> MapIntTuples[lambda S: ndarray[S, dtype[intp]], nonzero_shapes(Shape)]: ...
1218
+ ) -> MapIntTuples[
1219
+ lambda S: ndarray[S, dtype[intp]], nonzero_shapes(_ShapeT_co)
1220
+ ]: ...
1001
1221
  @overload
1002
1222
  def repeat[Repeats: Int, Axis: Flag[int | None]](
1003
1223
  self, repeats: Repeats, /, axis: Axis = None
1004
- ) -> ndarray[repeat_shape(Shape, Repeats, Axis), DType]: ...
1224
+ ) -> ndarray[repeat_shape(_ShapeT_co, Repeats, Axis), _DTypeT_co]: ...
1005
1225
  @overload
1006
1226
  def repeat[Repeats: IntTuple, Axis: Flag[int | None]](
1007
1227
  self, repeats: Repeats | IntListLiteral[Repeats], /, axis: Axis = None
1008
- ) -> ndarray[repeat_sequence_shape(Shape, Repeats, Axis), DType]: ...
1228
+ ) -> ndarray[repeat_sequence_shape(_ShapeT_co, Repeats, Axis), _DTypeT_co]: ...
1009
1229
  @overload
1010
1230
  def repeat[Axis: Flag[int | None]](
1011
1231
  self, repeats: Sequence[int] | ndarray, /, axis: Axis = None
1012
- ) -> ndarray[repeat_shape(Shape, Int, Axis), DType]: ...
1232
+ ) -> ndarray[repeat_shape(_ShapeT_co, Int, Axis), _DTypeT_co]: ...
1013
1233
  @overload
1014
1234
  def reshape(
1015
1235
  self,
@@ -1018,7 +1238,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1018
1238
  *,
1019
1239
  order: Literal["C", "F", "A"] = "C",
1020
1240
  copy: py_bool | None = None,
1021
- ) -> ndarray[Shape, DType]: ...
1241
+ ) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
1022
1242
  @overload
1023
1243
  def reshape[Target: IntTuple](
1024
1244
  self,
@@ -1027,7 +1247,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1027
1247
  *,
1028
1248
  order: Literal["C", "F", "A"] = "C",
1029
1249
  copy: py_bool | None = None,
1030
- ) -> ndarray[reshape_shape(Shape, Target), DType]: ...
1250
+ ) -> ndarray[reshape_shape(_ShapeT_co, Target), _DTypeT_co]: ...
1031
1251
  @overload
1032
1252
  def reshape[Target: IntTuple](
1033
1253
  self,
@@ -1035,7 +1255,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1035
1255
  *shape: *Target,
1036
1256
  order: Literal["C", "F", "A"] = "C",
1037
1257
  copy: py_bool | None = None,
1038
- ) -> ndarray[reshape_varargs_shape(Shape, Target), DType]: ...
1258
+ ) -> ndarray[reshape_varargs_shape(_ShapeT_co, Target), _DTypeT_co]: ...
1039
1259
  @overload
1040
1260
  def searchsorted[N: IntVar](
1041
1261
  self: ndarray[[N]],
@@ -1062,10 +1282,10 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1062
1282
  ) -> ndarray[Values, _dtype[intp]]: ...
1063
1283
  def squeeze[Axis: Flag[_Axis]](
1064
1284
  self, axis: Axis = None
1065
- ) -> ndarray[squeeze_shape(Shape, Axis), DType]: ...
1285
+ ) -> ndarray[squeeze_shape(_ShapeT_co, Axis), _DTypeT_co]: ...
1066
1286
  def swapaxes[First: Flag[int], Second: Flag[int]](
1067
1287
  self, axis1: First, axis2: Second, /
1068
- ) -> ndarray[swapaxes_shape(Shape, First, Second), DType]: ...
1288
+ ) -> ndarray[swapaxes_shape(_ShapeT_co, First, Second), _DTypeT_co]: ...
1069
1289
  @overload
1070
1290
  def take(
1071
1291
  self,
@@ -1083,7 +1303,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1083
1303
  axis: Axis,
1084
1304
  out: None = None,
1085
1305
  mode: Literal["raise", "wrap", "clip"] = "raise",
1086
- ) -> ndarray[take_shape(Shape, IntTuple[()], Axis), DType]: ...
1306
+ ) -> ndarray[take_shape(_ShapeT_co, IntTuple[()], Axis), _DTypeT_co]: ...
1087
1307
  @overload
1088
1308
  def take[Indices: IntTuple](
1089
1309
  self,
@@ -1092,7 +1312,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1092
1312
  axis: None = None,
1093
1313
  out: None = None,
1094
1314
  mode: Literal["raise", "wrap", "clip"] = "raise",
1095
- ) -> ndarray[Indices, DType]: ...
1315
+ ) -> ndarray[Indices, _DTypeT_co]: ...
1096
1316
  @overload
1097
1317
  def take(
1098
1318
  self,
@@ -1101,7 +1321,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1101
1321
  axis: None = None,
1102
1322
  out: None = None,
1103
1323
  mode: Literal["raise", "wrap", "clip"] = "raise",
1104
- ) -> ndarray[[int], DType]: ...
1324
+ ) -> ndarray[[int], _DTypeT_co]: ...
1105
1325
  @overload
1106
1326
  def take[Axis: Flag[int]](
1107
1327
  self,
@@ -1110,7 +1330,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1110
1330
  axis: Axis,
1111
1331
  out: None = None,
1112
1332
  mode: Literal["raise", "wrap", "clip"] = "raise",
1113
- ) -> ndarray[take_shape(Shape, IntTuple[int], Axis), DType]: ...
1333
+ ) -> ndarray[take_shape(_ShapeT_co, IntTuple[int], Axis), _DTypeT_co]: ...
1114
1334
  @overload
1115
1335
  def take[Indices: IntTuple, Axis: Flag[int]](
1116
1336
  self,
@@ -1119,7 +1339,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1119
1339
  axis: Axis,
1120
1340
  out: None = None,
1121
1341
  mode: Literal["raise", "wrap", "clip"] = "raise",
1122
- ) -> ndarray[take_shape(Shape, Indices, Axis), DType]: ...
1342
+ ) -> ndarray[take_shape(_ShapeT_co, Indices, Axis), _DTypeT_co]: ...
1123
1343
  @overload
1124
1344
  def take[Out: ndarray](
1125
1345
  self,
@@ -1142,7 +1362,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1142
1362
  # TODO(stroxler): Restrict index-array dtypes to valid index types.
1143
1363
  @overload
1144
1364
  def trace[M: IntVar, N: IntVar](
1145
- self: ndarray[[M, N], DType],
1365
+ self: ndarray[[M, N], _DTypeT_co],
1146
1366
  offset: int = 0,
1147
1367
  axis1: int = 0,
1148
1368
  axis2: int = 1,
@@ -1157,7 +1377,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1157
1377
  axis2: Second = 1,
1158
1378
  dtype: Any = None,
1159
1379
  out: None = None,
1160
- ) -> ndarray[diagonal_shape(Shape, First, Second, False, 0)]: ...
1380
+ ) -> ndarray[diagonal_shape(_ShapeT_co, First, Second, False, 0)]: ...
1161
1381
  @overload
1162
1382
  def trace[Out: ndarray](
1163
1383
  self,
@@ -1172,18 +1392,18 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
1172
1392
  @overload
1173
1393
  def transpose(
1174
1394
  self, axes: None = None, /
1175
- ) -> ndarray[reverse_shape(Shape), DType]: ...
1395
+ ) -> ndarray[reverse_shape(_ShapeT_co), _DTypeT_co]: ...
1176
1396
  @overload
1177
1397
  def transpose[Axes: IntTuple](
1178
1398
  self, axes: Axes, /
1179
- ) -> ndarray[transpose_shape(Shape, Axes), DType]: ...
1399
+ ) -> ndarray[transpose_shape(_ShapeT_co, Axes), _DTypeT_co]: ...
1180
1400
  @overload
1181
1401
  def transpose[Axes: IntTuple](
1182
1402
  self, *axes: *Axes
1183
- ) -> ndarray[transpose_shape(Shape, Axes), DType]: ...
1403
+ ) -> ndarray[transpose_shape(_ShapeT_co, Axes), _DTypeT_co]: ...
1184
1404
  # TODO(stroxler): Reinterpretation can change the final dimension's size.
1185
1405
  @overload
1186
- def view(self, /) -> ndarray[Shape, DType]: ...
1406
+ def view(self, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
1187
1407
  @overload
1188
1408
  def view[ArrayT: ndarray](self, /, *, type: type[ArrayT]) -> ArrayT: ...
1189
1409
  @overload
@@ -1261,6 +1481,14 @@ class _UnaryUFunc(ufunc):
1261
1481
  def __call__[Shape: _Shape](
1262
1482
  self, x: ndarray[Shape], /, out: Any = None, **kwargs: Any
1263
1483
  ) -> ndarray[Shape]: ...
1484
+ # Scalars stay gradual so comparisons like `np.log(0.9) < 0` keep typing.
1485
+ @overload
1486
+ def __call__(self, x: _ArrayScalar, /, out: Any = None, **kwargs: Any) -> Any: ...
1487
+ # Non-scalar array-likes should not fall through to the generic Any ufunc overload.
1488
+ @overload
1489
+ def __call__(
1490
+ self, x: ArrayLike, /, out: Any = None, **kwargs: Any
1491
+ ) -> ndarray | generic: ...
1264
1492
  @overload
1265
1493
  def __call__(self, x: Any, /, out: Any = None, **kwargs: Any) -> Any: ...
1266
1494
 
@@ -1610,7 +1838,27 @@ def asarray(
1610
1838
  copy: py_bool | None = ...,
1611
1839
  like: Any,
1612
1840
  ) -> Any: ...
1613
- def round[Shape: _Shape](x: ndarray[Shape]) -> ndarray[Shape]: ...
1841
+ def round[Shape: _Shape](a: ndarray[Shape], decimals: int = 0) -> ndarray[Shape]: ...
1842
+
1843
+ # Interpolation tracks query shapes and leaves the result dtype gradual.
1844
+ @overload
1845
+ def interp[N: IntVar, Rest: _Shape = []](
1846
+ x: ndarray[[N, *Rest]] | RegularNestedList[[N, *Rest], _ArrayScalar],
1847
+ xp: ArrayLike,
1848
+ fp: ArrayLike,
1849
+ left: Any = ...,
1850
+ right: Any = ...,
1851
+ period: Any = ...,
1852
+ ) -> ndarray[[N, *Rest]]: ...
1853
+ @overload
1854
+ def interp(
1855
+ x: _ArrayScalar | ArrayLike,
1856
+ xp: ArrayLike,
1857
+ fp: ArrayLike,
1858
+ left: Any = ...,
1859
+ right: Any = ...,
1860
+ period: Any = ...,
1861
+ ) -> Any: ...
1614
1862
  @overload
1615
1863
  def clip[Shape: _Shape](
1616
1864
  a: ndarray[Shape], a_min: int | float, a_max: int | float
@@ -1640,7 +1888,25 @@ def diag[M: IntVar, N: IntVar, DType, K: Flag[int] = 0](
1640
1888
  def diag[S: _Shape, DType](
1641
1889
  v: ndarray[S, DType], k: int = 0
1642
1890
  ) -> ndarray[IntTuple, DType]: ...
1643
- def arange[N: IntVar](stop: Int[N], /) -> ndarray[[N], dtype[intp]]: ...
1891
+ @overload
1892
+ def arange[N: IntVar](
1893
+ stop: Int[N],
1894
+ /,
1895
+ *,
1896
+ dtype: None = None,
1897
+ device: Literal["cpu"] | None = None,
1898
+ like: None = None,
1899
+ ) -> ndarray[[N], dtype[intp]]: ...
1900
+ @overload
1901
+ def arange(
1902
+ start: float | integer | floating,
1903
+ stop: float | integer | floating | None = None,
1904
+ step: float | integer | floating = 1,
1905
+ dtype: DTypeLike | None = None,
1906
+ *,
1907
+ device: Literal["cpu"] | None = None,
1908
+ like: None = None,
1909
+ ) -> ndarray[[int]]: ...
1644
1910
  def expand_dims[Shape: _Shape, DType, Axis: Flag[int]](
1645
1911
  a: ndarray[Shape, DType], axis: Axis
1646
1912
  ) -> ndarray[expand_dims_shape(Shape, Axis), DType]: ...
@@ -1669,11 +1935,19 @@ def min[
1669
1935
  Axis: Flag[_Axis],
1670
1936
  KeepDims: Flag[py_bool],
1671
1937
  ](
1672
- a: ndarray[Shape, DType], axis: Axis = None, *, keepdims: KeepDims = False
1938
+ a: ndarray[Shape, DType],
1939
+ axis: Axis = None,
1940
+ *,
1941
+ keepdims: KeepDims = False,
1942
+ initial: _ArrayScalar = ...,
1673
1943
  ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), Any]: ...
1674
1944
  @overload
1675
1945
  def min(
1676
- a: Sequence[ArrayLike], axis: _Axis = None, *, keepdims: py_bool = False
1946
+ a: Sequence[ArrayLike],
1947
+ axis: _Axis = None,
1948
+ *,
1949
+ keepdims: py_bool = False,
1950
+ initial: _ArrayScalar = ...,
1677
1951
  ) -> Any: ...
1678
1952
  @overload
1679
1953
  def max[
@@ -1682,24 +1956,93 @@ def max[
1682
1956
  Axis: Flag[_Axis],
1683
1957
  KeepDims: Flag[py_bool],
1684
1958
  ](
1685
- a: ndarray[Shape, DType], axis: Axis = None, *, keepdims: KeepDims = False
1959
+ a: ndarray[Shape, DType],
1960
+ axis: Axis = None,
1961
+ *,
1962
+ keepdims: KeepDims = False,
1963
+ initial: _ArrayScalar = ...,
1686
1964
  ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), Any]: ...
1687
1965
  @overload
1688
1966
  def max(
1689
- a: Sequence[ArrayLike], axis: _Axis = None, *, keepdims: py_bool = False
1967
+ a: Sequence[ArrayLike],
1968
+ axis: _Axis = None,
1969
+ *,
1970
+ keepdims: py_bool = False,
1971
+ initial: _ArrayScalar = ...,
1690
1972
  ) -> Any: ...
1691
1973
  @overload
1974
+ def argmin[Out: ndarray, Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
1975
+ a: ArrayLike, axis: Axis, out: Out, *, keepdims: KeepDims = False
1976
+ ) -> Out: ...
1977
+ @overload
1978
+ def argmin[Out: ndarray, Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
1979
+ a: ArrayLike, axis: Axis = None, *, out: Out, keepdims: KeepDims = False
1980
+ ) -> Out: ...
1981
+ @overload
1982
+ def argmin(
1983
+ a: ArrayLike,
1984
+ axis: None = None,
1985
+ out: None = None,
1986
+ *,
1987
+ keepdims: Literal[False] = False,
1988
+ ) -> intp: ...
1989
+ @overload
1692
1990
  def argmin[
1693
1991
  Shape: _Shape,
1694
1992
  DType,
1695
1993
  Axis: Flag[_SingleAxis],
1696
1994
  KeepDims: Flag[py_bool],
1697
1995
  ](
1698
- a: ndarray[Shape, DType], axis: Axis = None, *, keepdims: KeepDims = False
1996
+ a: ndarray[Shape, DType],
1997
+ axis: Axis = None,
1998
+ out: None = None,
1999
+ *,
2000
+ keepdims: KeepDims = False,
1699
2001
  ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), dtype[intp]]: ...
1700
2002
  @overload
1701
- def argmin(
1702
- a: Sequence[ArrayLike], axis: _SingleAxis = None, *, keepdims: py_bool = False
2003
+ def argmin[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
2004
+ a: Sequence[ArrayLike] | _ArrayScalar,
2005
+ axis: Axis = None,
2006
+ out: None = None,
2007
+ *,
2008
+ keepdims: KeepDims = False,
2009
+ ) -> Any: ...
2010
+ @overload
2011
+ def argmax[Out: ndarray, Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
2012
+ a: ArrayLike, axis: Axis, out: Out, *, keepdims: KeepDims = False
2013
+ ) -> Out: ...
2014
+ @overload
2015
+ def argmax[Out: ndarray, Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
2016
+ a: ArrayLike, axis: Axis = None, *, out: Out, keepdims: KeepDims = False
2017
+ ) -> Out: ...
2018
+ @overload
2019
+ def argmax(
2020
+ a: ArrayLike,
2021
+ axis: None = None,
2022
+ out: None = None,
2023
+ *,
2024
+ keepdims: Literal[False] = False,
2025
+ ) -> intp: ...
2026
+ @overload
2027
+ def argmax[
2028
+ Shape: _Shape,
2029
+ DType,
2030
+ Axis: Flag[_SingleAxis],
2031
+ KeepDims: Flag[py_bool],
2032
+ ](
2033
+ a: ndarray[Shape, DType],
2034
+ axis: Axis = None,
2035
+ out: None = None,
2036
+ *,
2037
+ keepdims: KeepDims = False,
2038
+ ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), dtype[intp]]: ...
2039
+ @overload
2040
+ def argmax[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
2041
+ a: Sequence[ArrayLike] | _ArrayScalar,
2042
+ axis: Axis = None,
2043
+ out: None = None,
2044
+ *,
2045
+ keepdims: KeepDims = False,
1703
2046
  ) -> Any: ...
1704
2047
  @overload
1705
2048
  def zeros[N: IntVar, ScalarT: generic](
@@ -8,7 +8,7 @@ description = "NumPy type stubs with array-shape tracking, maintained by Pyrefly
8
8
  readme = "README.md"
9
9
  requires-python = ">=3.12"
10
10
  license = { file = "LICENSE" }
11
- version = "1.4.0.dev4"
11
+ version = "1.5.0.dev1"
12
12
  keywords = ["typechecker", "typechecking", "stubs", "numpy"]
13
13
  classifiers = [
14
14
  "Development Status :: 4 - Beta",
@@ -18,7 +18,7 @@ classifiers = [
18
18
  "Typing :: Stubs Only",
19
19
  ]
20
20
  dependencies = [
21
- "pyrefly-shape-extensions==1.4.0.dev4",
21
+ "pyrefly-shape-extensions==1.5.0.dev1",
22
22
  "numpy",
23
23
  ]
24
24