@@ -2845,6 +2845,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2845
2845
# operand. An exception to this rule are unsigned integers though, which
2846
2846
# also accepts a signed integer for the right operand as long it is a 0D
2847
2847
# object and its value is >= 0
2848
+ # NOTE: Due to a mypy bug, overloading on e.g. `self: NDArray[SCT_floating]` won't
2849
+ # work, as this will lead to `false negatives` when using these inplace ops.
2848
2850
@overload
2849
2851
def __iadd__ (self : NDArray [_UnknownType ], other : _ArrayLikeUnknown , / ) -> NDArray [Any ]: ...
2850
2852
@overload
@@ -2858,6 +2860,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2858
2860
@overload
2859
2861
def __iadd__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2860
2862
@overload
2863
+ def __iadd__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2864
+ @overload
2861
2865
def __iadd__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2862
2866
@overload
2863
2867
def __iadd__ (self : NDArray [timedelta64 ], other : _ArrayLikeTD64_co , / ) -> NDArray [timedelta64 ]: ...
@@ -2877,6 +2881,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2877
2881
@overload
2878
2882
def __isub__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2879
2883
@overload
2884
+ def __isub__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2885
+ @overload
2880
2886
def __isub__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2881
2887
@overload
2882
2888
def __isub__ (self : NDArray [timedelta64 ], other : _ArrayLikeTD64_co , / ) -> NDArray [timedelta64 ]: ...
@@ -2898,6 +2904,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2898
2904
@overload
2899
2905
def __imul__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2900
2906
@overload
2907
+ def __imul__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2908
+ @overload
2901
2909
def __imul__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2902
2910
@overload
2903
2911
def __imul__ (self : NDArray [timedelta64 ], other : _ArrayLikeFloat_co , / ) -> NDArray [timedelta64 ]: ...
@@ -2911,6 +2919,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2911
2919
@overload
2912
2920
def __itruediv__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2913
2921
@overload
2922
+ def __itruediv__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2923
+ @overload
2914
2924
def __itruediv__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2915
2925
@overload
2916
2926
def __itruediv__ (self : NDArray [timedelta64 ], other : _ArrayLikeBool_co , / ) -> NoReturn : ...
@@ -2930,6 +2940,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2930
2940
@overload
2931
2941
def __ifloordiv__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2932
2942
@overload
2943
+ def __ifloordiv__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2944
+ @overload
2933
2945
def __ifloordiv__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2934
2946
@overload
2935
2947
def __ifloordiv__ (self : NDArray [timedelta64 ], other : _ArrayLikeBool_co , / ) -> NoReturn : ...
@@ -2949,6 +2961,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2949
2961
@overload
2950
2962
def __ipow__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
2951
2963
@overload
2964
+ def __ipow__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
2965
+ @overload
2952
2966
def __ipow__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
2953
2967
@overload
2954
2968
def __ipow__ (self : NDArray [object_ ], other : Any , / ) -> NDArray [object_ ]: ...
@@ -3032,6 +3046,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
3032
3046
@overload
3033
3047
def __imatmul__ (self : NDArray [floating [_NBit1 ]], other : _ArrayLikeFloat_co , / ) -> NDArray [floating [_NBit1 ]]: ...
3034
3048
@overload
3049
+ def __imatmul__ (self : NDArray [complex128 ], other : _ArrayLikeComplex_co , / ) -> NDArray [complex128 ]: ...
3050
+ @overload
3035
3051
def __imatmul__ (self : NDArray [complexfloating [_NBit1 , _NBit1 ]], other : _ArrayLikeComplex_co , / ) -> NDArray [complexfloating [_NBit1 , _NBit1 ]]: ...
3036
3052
@overload
3037
3053
def __imatmul__ (self : NDArray [object_ ], other : Any , / ) -> NDArray [object_ ]: ...
@@ -3534,8 +3550,7 @@ uint: TypeAlias = uintp
3534
3550
ulong : TypeAlias = unsignedinteger [_NBitLong ]
3535
3551
ulonglong : TypeAlias = unsignedinteger [_NBitLongLong ]
3536
3552
3537
- class inexact (number [_NBit1 ]): # type: ignore
3538
- def __getnewargs__ (self : inexact [_64Bit ]) -> tuple [float , ...]: ...
3553
+ class inexact (number [_NBit1 ]): ... # type: ignore[misc]
3539
3554
3540
3555
_IntType = TypeVar ("_IntType" , bound = integer [Any ])
3541
3556
@@ -3571,6 +3586,7 @@ float32: TypeAlias = floating[_32Bit]
3571
3586
3572
3587
# NOTE: `_64Bit` is equivalent to `_64Bit | _32Bit | _16Bit | _8Bit`
3573
3588
_Float64_co : TypeAlias = float | floating [_64Bit ] | integer [_64Bit ] | np .bool
3589
+ _Complex128_co : TypeAlias = complex | complexfloating [_64Bit , _64Bit ] | _Float64_co
3574
3590
3575
3591
# either a C `double`, `float`, or `longdouble`
3576
3592
class float64 (floating [_64Bit ], float ): # type: ignore[misc]
@@ -3588,77 +3604,101 @@ class float64(floating[_64Bit], float): # type: ignore[misc]
3588
3604
@overload
3589
3605
def __add__ (self , other : _Float64_co , / ) -> float64 : ...
3590
3606
@overload
3607
+ def __add__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3608
+ @overload
3591
3609
def __add__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3592
3610
@overload
3593
3611
def __add__ (self , other : complex , / ) -> float64 | complex128 : ...
3594
3612
@overload
3595
3613
def __radd__ (self , other : _Float64_co , / ) -> float64 : ...
3596
3614
@overload
3615
+ def __radd__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3616
+ @overload
3597
3617
def __radd__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3598
3618
@overload
3599
3619
def __radd__ (self , other : complex , / ) -> float64 | complex128 : ...
3600
3620
3601
3621
@overload
3602
3622
def __sub__ (self , other : _Float64_co , / ) -> float64 : ...
3603
3623
@overload
3624
+ def __sub__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3625
+ @overload
3604
3626
def __sub__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3605
3627
@overload
3606
3628
def __sub__ (self , other : complex , / ) -> float64 | complex128 : ...
3607
3629
@overload
3608
3630
def __rsub__ (self , other : _Float64_co , / ) -> float64 : ...
3609
3631
@overload
3632
+ def __rsub__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3633
+ @overload
3610
3634
def __rsub__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3611
3635
@overload
3612
3636
def __rsub__ (self , other : complex , / ) -> float64 | complex128 : ...
3613
3637
3614
3638
@overload
3615
3639
def __mul__ (self , other : _Float64_co , / ) -> float64 : ...
3616
3640
@overload
3641
+ def __mul__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3642
+ @overload
3617
3643
def __mul__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3618
3644
@overload
3619
3645
def __mul__ (self , other : complex , / ) -> float64 | complex128 : ...
3620
3646
@overload
3621
3647
def __rmul__ (self , other : _Float64_co , / ) -> float64 : ...
3622
3648
@overload
3649
+ def __rmul__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3650
+ @overload
3623
3651
def __rmul__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3624
3652
@overload
3625
3653
def __rmul__ (self , other : complex , / ) -> float64 | complex128 : ...
3626
3654
3627
3655
@overload
3628
3656
def __truediv__ (self , other : _Float64_co , / ) -> float64 : ...
3629
3657
@overload
3658
+ def __truediv__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3659
+ @overload
3630
3660
def __truediv__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3631
3661
@overload
3632
3662
def __truediv__ (self , other : complex , / ) -> float64 | complex128 : ...
3633
3663
@overload
3634
3664
def __rtruediv__ (self , other : _Float64_co , / ) -> float64 : ...
3635
3665
@overload
3666
+ def __rtruediv__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3667
+ @overload
3636
3668
def __rtruediv__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3637
3669
@overload
3638
3670
def __rtruediv__ (self , other : complex , / ) -> float64 | complex128 : ...
3639
3671
3640
3672
@overload
3641
3673
def __floordiv__ (self , other : _Float64_co , / ) -> float64 : ...
3642
3674
@overload
3675
+ def __floordiv__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3676
+ @overload
3643
3677
def __floordiv__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3644
3678
@overload
3645
3679
def __floordiv__ (self , other : complex , / ) -> float64 | complex128 : ...
3646
3680
@overload
3647
3681
def __rfloordiv__ (self , other : _Float64_co , / ) -> float64 : ...
3648
3682
@overload
3683
+ def __rfloordiv__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3684
+ @overload
3649
3685
def __rfloordiv__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3650
3686
@overload
3651
3687
def __rfloordiv__ (self , other : complex , / ) -> float64 | complex128 : ...
3652
3688
3653
3689
@overload
3654
3690
def __pow__ (self , other : _Float64_co , / ) -> float64 : ...
3655
3691
@overload
3692
+ def __pow__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3693
+ @overload
3656
3694
def __pow__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3657
3695
@overload
3658
3696
def __pow__ (self , other : complex , / ) -> float64 | complex128 : ...
3659
3697
@overload
3660
3698
def __rpow__ (self , other : _Float64_co , / ) -> float64 : ...
3661
3699
@overload
3700
+ def __rpow__ (self , other : complexfloating [_64Bit , _64Bit ], / ) -> complex128 : ...
3701
+ @overload
3662
3702
def __rpow__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3663
3703
@overload
3664
3704
def __rpow__ (self , other : complex , / ) -> float64 | complex128 : ...
@@ -3681,16 +3721,13 @@ longdouble: TypeAlias = floating[_NBitLongDouble]
3681
3721
3682
3722
class complexfloating (inexact [_NBit1 ], Generic [_NBit1 , _NBit2 ]):
3683
3723
def __init__ (self , value : _ComplexValue = ..., / ) -> None : ...
3684
- def item (
3685
- self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ,
3686
- ) -> complex : ...
3724
+ def item (self , args : L [0 ] | tuple [()] | tuple [L [0 ]] = ..., / ) -> complex : ...
3687
3725
def tolist (self ) -> complex : ...
3688
3726
@property
3689
3727
def real (self ) -> floating [_NBit1 ]: ... # type: ignore[override]
3690
3728
@property
3691
3729
def imag (self ) -> floating [_NBit2 ]: ... # type: ignore[override]
3692
3730
def __abs__ (self ) -> floating [_NBit1 ]: ... # type: ignore[override]
3693
- def __getnewargs__ (self : complex128 ) -> tuple [float , float ]: ...
3694
3731
# NOTE: Deprecated
3695
3732
# def __round__(self, ndigits=...): ...
3696
3733
__add__ : _ComplexOp [_NBit1 ]
@@ -3705,7 +3742,49 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
3705
3742
__rpow__ : _ComplexOp [_NBit1 ]
3706
3743
3707
3744
complex64 : TypeAlias = complexfloating [_32Bit , _32Bit ]
3708
- complex128 : TypeAlias = complexfloating [_64Bit , _64Bit ]
3745
+
3746
+ class complex128 (complexfloating [_64Bit , _64Bit ], complex ):
3747
+ def __getnewargs__ (self , / ) -> tuple [float , float ]: ...
3748
+
3749
+ # overrides for `floating` and `builtins.float` compatibility
3750
+ @property
3751
+ def real (self ) -> float64 : ...
3752
+ @property
3753
+ def imag (self ) -> float64 : ...
3754
+ def __abs__ (self ) -> float64 : ...
3755
+ def conjugate (self ) -> Self : ...
3756
+
3757
+ # complex128-specific operator overrides
3758
+ @overload
3759
+ def __add__ (self , other : _Complex128_co , / ) -> complex128 : ...
3760
+ @overload
3761
+ def __add__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3762
+ def __radd__ (self , other : _Complex128_co , / ) -> complex128 : ...
3763
+
3764
+ @overload
3765
+ def __sub__ (self , other : _Complex128_co , / ) -> complex128 : ...
3766
+ @overload
3767
+ def __sub__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3768
+ def __rsub__ (self , other : _Complex128_co , / ) -> complex128 : ...
3769
+
3770
+ @overload
3771
+ def __mul__ (self , other : _Complex128_co , / ) -> complex128 : ...
3772
+ @overload
3773
+ def __mul__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3774
+ def __rmul__ (self , other : _Complex128_co , / ) -> complex128 : ...
3775
+
3776
+ @overload
3777
+ def __truediv__ (self , other : _Complex128_co , / ) -> complex128 : ...
3778
+ @overload
3779
+ def __truediv__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3780
+ def __rtruediv__ (self , other : _Complex128_co , / ) -> complex128 : ...
3781
+
3782
+ @overload
3783
+ def __pow__ (self , other : _Complex128_co , / ) -> complex128 : ...
3784
+ @overload
3785
+ def __pow__ (self , other : complexfloating [_NBit1 , _NBit2 ], / ) -> complexfloating [_NBit1 | _64Bit , _NBit2 | _64Bit ]: ...
3786
+ def __rpow__ (self , other : _Complex128_co , / ) -> complex128 : ...
3787
+
3709
3788
3710
3789
csingle : TypeAlias = complexfloating [_NBitSingle , _NBitSingle ]
3711
3790
cdouble : TypeAlias = complexfloating [_NBitDouble , _NBitDouble ]
0 commit comments