pyrefly-numpy-stubs 1.4.0.dev1__py3-none-any.whl → 1.4.0.dev3__py3-none-any.whl

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.
numpy-stubs/__init__.pyi CHANGED
@@ -183,6 +183,7 @@ from numpy._core.shape_base import (
183
183
  from numpy._pytesttester import PytestTester
184
184
  from numpy._shapes import (
185
185
  diag_extent,
186
+ expand_dims_shape,
186
187
  matmul_shape,
187
188
  matvec_shape,
188
189
  reduce_shape,
@@ -376,7 +377,6 @@ from numpy.matrixlib import (
376
377
  )
377
378
  from shape_extensions import (
378
379
  broadcast as _broadcast_shape,
379
- Elements,
380
380
  Flag,
381
381
  Index,
382
382
  index_shape,
@@ -410,9 +410,12 @@ from . import (
410
410
 
411
411
  type _Shape = IntTuple
412
412
  type _Axis = int | tuple[int, ...] | None
413
+ type _SingleAxis = int | None
413
414
  type _BasicIndex = int | slice | list[int] | None | EllipsisType
414
415
 
415
- class generic: ...
416
+ class generic:
417
+ def astype(self, dtype: Any, **kwargs: Any) -> Any: ...
418
+
416
419
  class bool_(generic): ...
417
420
  class float32(generic): ...
418
421
  class float64(generic): ...
@@ -456,6 +459,7 @@ _dtype = dtype
456
459
 
457
460
  class _Flags:
458
461
  f_contiguous: py_bool
462
+ def __getitem__(self, key: str) -> py_bool: ...
459
463
 
460
464
  class ndarray[Shape: _Shape = _Shape, DType = Any]:
461
465
  shape: Shape
@@ -490,10 +494,9 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
490
494
  def real(self) -> ndarray[Shape]: ...
491
495
  @real.setter
492
496
  def real(self, value: Any) -> None: ...
493
- @overload
494
- def __len__[N: IntVar](self: ndarray[[N]]) -> Int[N]: ...
495
- @overload
496
- def __len__[N: IntVar, M: IntVar](self: ndarray[[N, M]]) -> Int[N]: ...
497
+ def __len__[N: IntVar, Rest: _Shape = []](
498
+ self: ndarray[[N, *Rest]],
499
+ ) -> Int[N]: ...
497
500
  @overload
498
501
  def __getitem__[
499
502
  N: IntVar,
@@ -522,12 +525,12 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
522
525
  # Assignment preserves the receiver's shape; value broadcasting is gradual.
523
526
  def __setitem__(self, key: _ArrayIndex, value: ArrayLike, /) -> None: ...
524
527
  @overload
525
- def __iter__[N: IntVar, M: IntVar](
526
- self: ndarray[[N, M], DType], /
527
- ) -> Iterator[ndarray[[M], DType]]: ...
528
- # Scalar dtypes and iteration over other ranks remain gradual.
528
+ def __iter__[N: IntVar, M: IntVar, Rest: _Shape = []](
529
+ self: ndarray[[N, M, *Rest], DType], /
530
+ ) -> Iterator[ndarray[[M, *Rest], DType]]: ...
531
+ # Iteration over one-dimensional arrays yields NumPy scalars.
529
532
  @overload
530
- def __iter__(self, /) -> Iterator[Any]: ...
533
+ def __iter__[N: IntVar](self: ndarray[[N], DType], /) -> Iterator[Any]: ...
531
534
  def __int__(self: ndarray[[]], /) -> int: ...
532
535
  def __float__(self: ndarray[[]], /) -> float: ...
533
536
  def __complex__(self: ndarray[[]], /) -> complex: ...
@@ -538,48 +541,48 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
538
541
  ) -> ndarray[[P, N], DType]: ...
539
542
  # Unpacking preserves gradual array shapes instead of using the scalar default.
540
543
  def __add__[OtherShape: _Shape = []](
541
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
544
+ self, other: ndarray[[*OtherShape]] | int | float
542
545
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
543
546
  def __radd__[OtherShape: _Shape = []](
544
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
547
+ self, other: ndarray[[*OtherShape]] | int | float
545
548
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
546
549
  def __sub__[OtherShape: _Shape = []](
547
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
550
+ self, other: ndarray[[*OtherShape]] | int | float
548
551
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
549
552
  def __rsub__[OtherShape: _Shape = []](
550
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
553
+ self, other: ndarray[[*OtherShape]] | int | float
551
554
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
552
555
  def __truediv__[OtherShape: _Shape = []](
553
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
556
+ self, other: ndarray[[*OtherShape]] | int | float
554
557
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
555
558
  def __rtruediv__[OtherShape: _Shape = []](
556
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
559
+ self, other: ndarray[[*OtherShape]] | int | float
557
560
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
558
561
  def __mul__[OtherShape: _Shape = []](
559
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
562
+ self, other: ndarray[[*OtherShape]] | int | float
560
563
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
561
564
  def __rmul__[OtherShape: _Shape = []](
562
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
565
+ self, other: ndarray[[*OtherShape]] | int | float
563
566
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
564
567
  def __floordiv__[OtherShape: _Shape = []](
565
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
568
+ self, other: ndarray[[*OtherShape]] | int | float
566
569
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
567
570
  def __rfloordiv__[OtherShape: _Shape = []](
568
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
571
+ self, other: ndarray[[*OtherShape]] | int | float
569
572
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
570
573
  def __mod__[OtherShape: _Shape = []](
571
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
574
+ self, other: ndarray[[*OtherShape]] | int | float
572
575
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
573
576
  def __rmod__[OtherShape: _Shape = []](
574
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
577
+ self, other: ndarray[[*OtherShape]] | int | float
575
578
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
576
579
  def __neg__(self) -> ndarray[Shape, DType]: ...
577
580
  def __pos__(self) -> ndarray[Shape, DType]: ...
578
581
  def __pow__[OtherShape: _Shape = []](
579
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
582
+ self, other: ndarray[[*OtherShape]] | int | float
580
583
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
581
584
  def __rpow__[OtherShape: _Shape = []](
582
- self, other: ndarray[[*Elements[OtherShape]]] | int | float
585
+ self, other: ndarray[[*OtherShape]] | int | float
583
586
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), DType]: ...
584
587
  # Scalar results also satisfy Python's truth-valued comparison protocols.
585
588
  @overload
@@ -587,13 +590,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
587
590
  @overload
588
591
  def __lt__[OtherShape: _Shape = []](
589
592
  self,
590
- other: ndarray[[*Elements[OtherShape]]]
591
- | int
592
- | float
593
- | complex
594
- | str
595
- | bytes
596
- | generic,
593
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
597
594
  /,
598
595
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
599
596
  @overload
@@ -603,13 +600,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
603
600
  @overload
604
601
  def __le__[OtherShape: _Shape = []](
605
602
  self,
606
- other: ndarray[[*Elements[OtherShape]]]
607
- | int
608
- | float
609
- | complex
610
- | str
611
- | bytes
612
- | generic,
603
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
613
604
  /,
614
605
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
615
606
  @overload
@@ -619,13 +610,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
619
610
  @overload
620
611
  def __gt__[OtherShape: _Shape = []](
621
612
  self,
622
- other: ndarray[[*Elements[OtherShape]]]
623
- | int
624
- | float
625
- | complex
626
- | str
627
- | bytes
628
- | generic,
613
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
629
614
  /,
630
615
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
631
616
  @overload
@@ -635,13 +620,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
635
620
  @overload
636
621
  def __ge__[OtherShape: _Shape = []](
637
622
  self,
638
- other: ndarray[[*Elements[OtherShape]]]
639
- | int
640
- | float
641
- | complex
642
- | str
643
- | bytes
644
- | generic,
623
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
645
624
  /,
646
625
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
647
626
  @overload
@@ -651,13 +630,7 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
651
630
  @overload
652
631
  def __eq__[OtherShape: _Shape = []](
653
632
  self,
654
- other: ndarray[[*Elements[OtherShape]]]
655
- | int
656
- | float
657
- | complex
658
- | str
659
- | bytes
660
- | generic,
633
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
661
634
  /,
662
635
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
663
636
  @overload
@@ -667,35 +640,29 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
667
640
  @overload
668
641
  def __ne__[OtherShape: _Shape = []](
669
642
  self,
670
- other: ndarray[[*Elements[OtherShape]]]
671
- | int
672
- | float
673
- | complex
674
- | str
675
- | bytes
676
- | generic,
643
+ other: ndarray[[*OtherShape]] | int | float | complex | str | bytes | generic,
677
644
  /,
678
645
  ) -> ndarray[_broadcast_shape(Shape, OtherShape), _dtype[bool_]]: ...
679
646
  @overload
680
647
  def __ne__(self, other: ArrayLike, /) -> ndarray[IntTuple, _dtype[bool_]]: ...
681
648
  def __invert__(self) -> ndarray[Shape, DType]: ...
682
649
  def __and__[OtherShape: _Shape = []](
683
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
650
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
684
651
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
685
652
  def __or__[OtherShape: _Shape = []](
686
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
653
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
687
654
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
688
655
  def __xor__[OtherShape: _Shape = []](
689
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
656
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
690
657
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
691
658
  def __rand__[OtherShape: _Shape = []](
692
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
659
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
693
660
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
694
661
  def __ror__[OtherShape: _Shape = []](
695
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
662
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
696
663
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
697
664
  def __rxor__[OtherShape: _Shape = []](
698
- self, other: ndarray[[*Elements[OtherShape]]] | _IndexScalar, /
665
+ self, other: ndarray[[*OtherShape]] | _IndexScalar, /
699
666
  ) -> ndarray[_broadcast_shape(Shape, OtherShape)]: ...
700
667
  def __matmul__[OtherShape: _Shape](
701
668
  self, other: ndarray[OtherShape]
@@ -740,14 +707,14 @@ class ndarray[Shape: _Shape = _Shape, DType = Any]:
740
707
  *,
741
708
  where: Any = True,
742
709
  ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[bool_]]: ...
743
- def argmax[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
710
+ def argmax[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
744
711
  self,
745
712
  axis: Axis = None,
746
713
  out: Any = None,
747
714
  *,
748
715
  keepdims: KeepDims = False,
749
716
  ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), _dtype[intp]]: ...
750
- def argmin[Axis: Flag[_Axis], KeepDims: Flag[py_bool]](
717
+ def argmin[Axis: Flag[_SingleAxis], KeepDims: Flag[py_bool]](
751
718
  self,
752
719
  axis: Axis = None,
753
720
  out: Any = None,
@@ -1373,21 +1340,9 @@ def diag[S: _Shape, DType](
1373
1340
  v: ndarray[S, DType], k: int = 0
1374
1341
  ) -> ndarray[IntTuple, DType]: ...
1375
1342
  def arange[N: IntVar](stop: Int[N], /) -> ndarray[[N], dtype[intp]]: ...
1376
- @overload
1377
- def expand_dims[N: IntVar, M: IntVar, DType](
1378
- a: ndarray[[N, M], DType],
1379
- axis: Literal[0, -3],
1380
- ) -> ndarray[[1, N, M], DType]: ...
1381
- @overload
1382
- def expand_dims[N: IntVar, M: IntVar, DType](
1383
- a: ndarray[[N, M], DType],
1384
- axis: Literal[1, -2],
1385
- ) -> ndarray[[N, 1, M], DType]: ...
1386
- @overload
1387
- def expand_dims[N: IntVar, M: IntVar, DType](
1388
- a: ndarray[[N, M], DType],
1389
- axis: Literal[2, -1],
1390
- ) -> ndarray[[N, M, 1], DType]: ...
1343
+ def expand_dims[Shape: _Shape, DType, Axis: Flag[int]](
1344
+ a: ndarray[Shape, DType], axis: Axis
1345
+ ) -> ndarray[expand_dims_shape(Shape, Axis), DType]: ...
1391
1346
 
1392
1347
  # These stubs track reduction shapes but leave reduction dtype gradual.
1393
1348
  def sum[
@@ -1433,115 +1388,78 @@ def max(
1433
1388
  a: Sequence[ArrayLike], axis: _Axis = None, *, keepdims: py_bool = False
1434
1389
  ) -> Any: ...
1435
1390
  @overload
1436
- def argmin[N: IntVar, M: IntVar](
1437
- a: ndarray[[N, M]],
1438
- axis: Literal[0, -2],
1439
- *,
1440
- keepdims: Literal[False] = False,
1441
- ) -> ndarray[[M], dtype[intp]]: ...
1391
+ def argmin[
1392
+ Shape: _Shape,
1393
+ DType,
1394
+ Axis: Flag[_SingleAxis],
1395
+ KeepDims: Flag[py_bool],
1396
+ ](
1397
+ a: ndarray[Shape, DType], axis: Axis = None, *, keepdims: KeepDims = False
1398
+ ) -> ndarray[reduce_shape(Shape, Axis, KeepDims), dtype[intp]]: ...
1442
1399
  @overload
1443
- def argmin[N: IntVar, M: IntVar](
1444
- a: ndarray[[N, M]],
1445
- axis: Literal[1, -1],
1446
- *,
1447
- keepdims: Literal[False] = False,
1448
- ) -> ndarray[[N], dtype[intp]]: ...
1449
-
1450
- # TODO(stroxler): Replace these finite tuple-shape constructor overloads with a
1451
- # generic `Shape: tuple[int, ...]` overload once whole-shape parameters flow
1452
- # through downstream array operations without degrading to unknown.
1400
+ def argmin(
1401
+ a: Sequence[ArrayLike], axis: _SingleAxis = None, *, keepdims: py_bool = False
1402
+ ) -> Any: ...
1453
1403
  @overload
1454
1404
  def zeros[N: IntVar, ScalarT: generic](
1455
1405
  shape: Int[N], dtype: type[ScalarT], order: str = ...
1456
1406
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1457
1407
  @overload
1458
- def zeros[N: IntVar, ScalarT: generic](
1459
- shape: IntTuple[N], dtype: type[ScalarT], order: str = ...
1460
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1461
- @overload
1462
- def zeros[N: IntVar, M: IntVar, ScalarT: generic](
1463
- shape: IntTuple[N, M], dtype: type[ScalarT], order: str = ...
1464
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1408
+ def zeros[Shape: IntTuple, ScalarT: generic](
1409
+ shape: Shape, dtype: type[ScalarT], order: str = ...
1410
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1465
1411
  @overload
1466
1412
  def zeros[N: IntVar, ScalarT: generic](
1467
1413
  shape: Int[N], dtype: dtype[ScalarT], order: str = ...
1468
1414
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1469
1415
  @overload
1470
- def zeros[N: IntVar, ScalarT: generic](
1471
- shape: IntTuple[N], dtype: dtype[ScalarT], order: str = ...
1472
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1473
- @overload
1474
- def zeros[N: IntVar, M: IntVar, ScalarT: generic](
1475
- shape: IntTuple[N, M], dtype: dtype[ScalarT], order: str = ...
1476
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1416
+ def zeros[Shape: IntTuple, ScalarT: generic](
1417
+ shape: Shape, dtype: dtype[ScalarT], order: str = ...
1418
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1477
1419
  @overload
1478
1420
  def zeros[N: IntVar](
1479
1421
  shape: Int[N], dtype: None = ..., order: str = ...
1480
1422
  ) -> ndarray[[N], dtype[float64]]: ...
1481
1423
  @overload
1482
- def zeros[N: IntVar](
1483
- shape: IntTuple[N], dtype: None = ..., order: str = ...
1484
- ) -> ndarray[[N], dtype[float64]]: ...
1485
- @overload
1486
- def zeros[N: IntVar, M: IntVar](
1487
- shape: IntTuple[N, M], dtype: None = ..., order: str = ...
1488
- ) -> ndarray[[N, M], dtype[float64]]: ...
1424
+ def zeros[Shape: IntTuple](
1425
+ shape: Shape, dtype: None = ..., order: str = ...
1426
+ ) -> ndarray[Shape, dtype[float64]]: ...
1489
1427
  @overload
1490
1428
  def zeros[N: IntVar](shape: Int[N], dtype: Any, order: str = ...) -> ndarray[[N]]: ...
1491
1429
  @overload
1492
- def zeros[N: IntVar](
1493
- shape: IntTuple[N], dtype: Any, order: str = ...
1494
- ) -> ndarray[[N]]: ...
1495
- @overload
1496
- def zeros[N: IntVar, M: IntVar](
1497
- shape: IntTuple[N, M], dtype: Any, order: str = ...
1498
- ) -> ndarray[[N, M]]: ...
1430
+ def zeros[Shape: IntTuple](
1431
+ shape: Shape, dtype: Any, order: str = ...
1432
+ ) -> ndarray[Shape]: ...
1499
1433
  @overload
1500
1434
  def ones[N: IntVar, ScalarT: generic](
1501
1435
  shape: Int[N], dtype: type[ScalarT], order: str = ...
1502
1436
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1503
1437
  @overload
1504
- def ones[N: IntVar, ScalarT: generic](
1505
- shape: IntTuple[N], dtype: type[ScalarT], order: str = ...
1506
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1507
- @overload
1508
- def ones[N: IntVar, M: IntVar, ScalarT: generic](
1509
- shape: IntTuple[N, M], dtype: type[ScalarT], order: str = ...
1510
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1438
+ def ones[Shape: IntTuple, ScalarT: generic](
1439
+ shape: Shape, dtype: type[ScalarT], order: str = ...
1440
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1511
1441
  @overload
1512
1442
  def ones[N: IntVar, ScalarT: generic](
1513
1443
  shape: Int[N], dtype: dtype[ScalarT], order: str = ...
1514
1444
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1515
1445
  @overload
1516
- def ones[N: IntVar, ScalarT: generic](
1517
- shape: IntTuple[N], dtype: dtype[ScalarT], order: str = ...
1518
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1519
- @overload
1520
- def ones[N: IntVar, M: IntVar, ScalarT: generic](
1521
- shape: IntTuple[N, M], dtype: dtype[ScalarT], order: str = ...
1522
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1446
+ def ones[Shape: IntTuple, ScalarT: generic](
1447
+ shape: Shape, dtype: dtype[ScalarT], order: str = ...
1448
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1523
1449
  @overload
1524
1450
  def ones[N: IntVar](
1525
1451
  shape: Int[N], dtype: None = ..., order: str = ...
1526
1452
  ) -> ndarray[[N], dtype[float64]]: ...
1527
1453
  @overload
1528
- def ones[N: IntVar](
1529
- shape: IntTuple[N], dtype: None = ..., order: str = ...
1530
- ) -> ndarray[[N], dtype[float64]]: ...
1531
- @overload
1532
- def ones[N: IntVar, M: IntVar](
1533
- shape: IntTuple[N, M], dtype: None = ..., order: str = ...
1534
- ) -> ndarray[[N, M], dtype[float64]]: ...
1454
+ def ones[Shape: IntTuple](
1455
+ shape: Shape, dtype: None = ..., order: str = ...
1456
+ ) -> ndarray[Shape, dtype[float64]]: ...
1535
1457
  @overload
1536
1458
  def ones[N: IntVar](shape: Int[N], dtype: Any, order: str = ...) -> ndarray[[N]]: ...
1537
1459
  @overload
1538
- def ones[N: IntVar](
1539
- shape: IntTuple[N], dtype: Any, order: str = ...
1540
- ) -> ndarray[[N]]: ...
1541
- @overload
1542
- def ones[N: IntVar, M: IntVar](
1543
- shape: IntTuple[N, M], dtype: Any, order: str = ...
1544
- ) -> ndarray[[N, M]]: ...
1460
+ def ones[Shape: IntTuple](
1461
+ shape: Shape, dtype: Any, order: str = ...
1462
+ ) -> ndarray[Shape]: ...
1545
1463
  @overload
1546
1464
  def full[N: IntVar, ScalarT: generic](
1547
1465
  shape: Int[N],
@@ -1550,19 +1468,12 @@ def full[N: IntVar, ScalarT: generic](
1550
1468
  order: str = ...,
1551
1469
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1552
1470
  @overload
1553
- def full[N: IntVar, ScalarT: generic](
1554
- shape: IntTuple[N],
1555
- fill_value: Any,
1556
- dtype: type[ScalarT],
1557
- order: str = ...,
1558
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1559
- @overload
1560
- def full[N: IntVar, M: IntVar, ScalarT: generic](
1561
- shape: IntTuple[N, M],
1471
+ def full[Shape: IntTuple, ScalarT: generic](
1472
+ shape: Shape,
1562
1473
  fill_value: Any,
1563
1474
  dtype: type[ScalarT],
1564
1475
  order: str = ...,
1565
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1476
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1566
1477
  @overload
1567
1478
  def full[N: IntVar, ScalarT: generic](
1568
1479
  shape: Int[N],
@@ -1571,80 +1482,50 @@ def full[N: IntVar, ScalarT: generic](
1571
1482
  order: str = ...,
1572
1483
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1573
1484
  @overload
1574
- def full[N: IntVar, ScalarT: generic](
1575
- shape: IntTuple[N],
1485
+ def full[Shape: IntTuple, ScalarT: generic](
1486
+ shape: Shape,
1576
1487
  fill_value: Any,
1577
1488
  dtype: dtype[ScalarT],
1578
1489
  order: str = ...,
1579
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1580
- @overload
1581
- def full[N: IntVar, M: IntVar, ScalarT: generic](
1582
- shape: IntTuple[N, M],
1583
- fill_value: Any,
1584
- dtype: dtype[ScalarT],
1585
- order: str = ...,
1586
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1490
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1587
1491
  @overload
1588
1492
  def full[N: IntVar](
1589
1493
  shape: Int[N], fill_value: Any, dtype: Any = ..., order: str = ...
1590
1494
  ) -> ndarray[[N]]: ...
1591
1495
  @overload
1592
- def full[N: IntVar](
1593
- shape: IntTuple[N], fill_value: Any, dtype: Any = ..., order: str = ...
1594
- ) -> ndarray[[N]]: ...
1595
- @overload
1596
- def full[N: IntVar, M: IntVar](
1597
- shape: IntTuple[N, M],
1598
- fill_value: Any,
1599
- dtype: Any = ...,
1600
- order: str = ...,
1601
- ) -> ndarray[[N, M]]: ...
1496
+ def full[Shape: IntTuple](
1497
+ shape: Shape, fill_value: Any, dtype: Any = ..., order: str = ...
1498
+ ) -> ndarray[Shape]: ...
1602
1499
  @overload
1603
1500
  def empty[N: IntVar, ScalarT: generic](
1604
1501
  shape: Int[N], dtype: type[ScalarT], order: str = ...
1605
1502
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1606
1503
  @overload
1607
- def empty[N: IntVar, ScalarT: generic](
1608
- shape: IntTuple[N], dtype: type[ScalarT], order: str = ...
1609
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1610
- @overload
1611
- def empty[N: IntVar, M: IntVar, ScalarT: generic](
1612
- shape: IntTuple[N, M], dtype: type[ScalarT], order: str = ...
1613
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1504
+ def empty[Shape: IntTuple, ScalarT: generic](
1505
+ shape: Shape, dtype: type[ScalarT], order: str = ...
1506
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1614
1507
  @overload
1615
1508
  def empty[N: IntVar, ScalarT: generic](
1616
1509
  shape: Int[N], dtype: dtype[ScalarT], order: str = ...
1617
1510
  ) -> ndarray[[N], dtype[ScalarT]]: ...
1618
1511
  @overload
1619
- def empty[N: IntVar, ScalarT: generic](
1620
- shape: IntTuple[N], dtype: dtype[ScalarT], order: str = ...
1621
- ) -> ndarray[[N], dtype[ScalarT]]: ...
1622
- @overload
1623
- def empty[N: IntVar, M: IntVar, ScalarT: generic](
1624
- shape: IntTuple[N, M], dtype: dtype[ScalarT], order: str = ...
1625
- ) -> ndarray[[N, M], dtype[ScalarT]]: ...
1512
+ def empty[Shape: IntTuple, ScalarT: generic](
1513
+ shape: Shape, dtype: dtype[ScalarT], order: str = ...
1514
+ ) -> ndarray[Shape, dtype[ScalarT]]: ...
1626
1515
  @overload
1627
1516
  def empty[N: IntVar](
1628
1517
  shape: Int[N], dtype: None = ..., order: str = ...
1629
1518
  ) -> ndarray[[N], dtype[float64]]: ...
1630
1519
  @overload
1631
- def empty[N: IntVar](
1632
- shape: IntTuple[N], dtype: None = ..., order: str = ...
1633
- ) -> ndarray[[N], dtype[float64]]: ...
1634
- @overload
1635
- def empty[N: IntVar, M: IntVar](
1636
- shape: IntTuple[N, M], dtype: None = ..., order: str = ...
1637
- ) -> ndarray[[N, M], dtype[float64]]: ...
1520
+ def empty[Shape: IntTuple](
1521
+ shape: Shape, dtype: None = ..., order: str = ...
1522
+ ) -> ndarray[Shape, dtype[float64]]: ...
1638
1523
  @overload
1639
1524
  def empty[N: IntVar](shape: Int[N], dtype: Any, order: str = ...) -> ndarray[[N]]: ...
1640
1525
  @overload
1641
- def empty[N: IntVar](
1642
- shape: IntTuple[N], dtype: Any, order: str = ...
1643
- ) -> ndarray[[N]]: ...
1644
- @overload
1645
- def empty[N: IntVar, M: IntVar](
1646
- shape: IntTuple[N, M], dtype: Any, order: str = ...
1647
- ) -> ndarray[[N, M]]: ...
1526
+ def empty[Shape: IntTuple](
1527
+ shape: Shape, dtype: Any, order: str = ...
1528
+ ) -> ndarray[Shape]: ...
1648
1529
  @overload
1649
1530
  def eye[N: IntVar, ScalarT: generic](
1650
1531
  N: Int[N], M: None = ..., k: int = ..., *, dtype: type[ScalarT], order: str = ...
@@ -1691,7 +1572,12 @@ def identity[N: IntVar](
1691
1572
  n: Int[N], dtype: Any, *, like: Any = ...
1692
1573
  ) -> ndarray[[N, N]]: ...
1693
1574
 
1694
- # TODO(stroxler): Replace these placeholders with NumPy's scalar type hierarchy.
1575
+ # TODO(stroxler): Replace the remaining placeholders with NumPy's scalar hierarchy.
1576
+ class number(generic): ...
1577
+ class inexact(number): ...
1578
+ class floating(inexact): ...
1579
+ class integer(number): ...
1580
+
1695
1581
  bool: Any
1696
1582
  broadcast: Any
1697
1583
  byte: Any
@@ -1707,18 +1593,14 @@ datetime64: Any
1707
1593
  double: Any
1708
1594
  flexible: Any
1709
1595
  float16: Any
1710
- floating: Any
1711
1596
  half: Any
1712
- inexact: Any
1713
1597
  int16: Any
1714
1598
  int8: Any
1715
1599
  int_: Any
1716
1600
  intc: Any
1717
- integer: Any
1718
1601
  long: Any
1719
1602
  longdouble: Any
1720
1603
  longlong: Any
1721
- number: Any
1722
1604
  object_: Any
1723
1605
  short: Any
1724
1606
  signedinteger: Any
numpy-stubs/_shapes.pyi CHANGED
@@ -123,3 +123,22 @@ def stack_shape(shapes: IntTuples, axis: int) -> IntTuple:
123
123
  for index in range(output_rank)
124
124
  )
125
125
  )
126
+
127
+ @type_shape_dsl_function
128
+ def expand_dims_shape(shape: IntTuple, axis: int) -> IntTuple:
129
+ output_rank = len(shape) + 1
130
+ # Unary minus is not supported by the type-level DSL.
131
+ if axis < 0 - output_rank or axis >= output_rank:
132
+ return dsl.Invalid("expand_dims axis out of bounds")
133
+ if axis < 0:
134
+ norm_axis = axis + output_rank
135
+ else:
136
+ norm_axis = axis + 0
137
+ return dsl.IntTuple(
138
+ (
139
+ 1
140
+ if index == norm_axis
141
+ else shape[index if index < norm_axis else index - 1]
142
+ for index in range(output_rank)
143
+ )
144
+ )
@@ -79,13 +79,11 @@ from numpy.random.mtrand import (
79
79
  weibull as weibull,
80
80
  zipf as zipf,
81
81
  )
82
- from shape_extensions import Int, IntVar
82
+ from shape_extensions import IntTuple
83
83
 
84
84
  from .. import dtype, float64, ndarray
85
85
 
86
86
  @overload
87
- def randn[N: IntVar](d0: Int[N], /) -> ndarray[[N], dtype[float64]]: ...
87
+ def randn() -> float: ...
88
88
  @overload
89
- def randn[N: IntVar, M: IntVar](
90
- d0: Int[N], d1: Int[M], /
91
- ) -> ndarray[[N, M], dtype[float64]]: ...
89
+ def randn[Shape: IntTuple](*dims: *Shape) -> ndarray[Shape, dtype[float64]]: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyrefly-numpy-stubs
3
- Version: 1.4.0.dev1
3
+ Version: 1.4.0.dev3
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/
@@ -33,7 +33,7 @@ Classifier: Programming Language :: Python
33
33
  Classifier: Programming Language :: Python :: 3
34
34
  Classifier: Typing :: Stubs Only
35
35
  Requires-Python: >=3.12
36
- Requires-Dist: pyrefly-shape-extensions==1.4.0.dev1
36
+ Requires-Dist: pyrefly-shape-extensions==1.4.0.dev3
37
37
  Description-Content-Type: text/markdown
38
38
 
39
39
  # pyrefly-numpy-stubs
@@ -0,0 +1,9 @@
1
+ numpy-stubs/__init__.pyi,sha256=oqLstLya9CVOV64Xbrxnk4NFKGF_PAtKcnmrBfUIiVY,48009
2
+ numpy-stubs/_shapes.pyi,sha256=kvbytJygme4DluXr_v2iO_kAnWrZaRTUCb0MNgi-6Oo,4802
3
+ numpy-stubs/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
4
+ numpy-stubs/linalg/__init__.pyi,sha256=HqAg4mSr0csSnsIRougqxHP7dzUww7wa6USyN51PPAQ,2734
5
+ numpy-stubs/random/__init__.pyi,sha256=rZT47dwZw1ev6xXQsngIZQL8SnkI2vEUBbK2p-vSi7w,2404
6
+ pyrefly_numpy_stubs-1.4.0.dev3.dist-info/METADATA,sha256=aIsXl5CWsurKc73ZyNHSbwzebFWd5R2tzl9-VuZvNnE,2662
7
+ pyrefly_numpy_stubs-1.4.0.dev3.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
8
+ pyrefly_numpy_stubs-1.4.0.dev3.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
9
+ pyrefly_numpy_stubs-1.4.0.dev3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.3
2
+ Generator: hatchling 1.32.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,9 +0,0 @@
1
- numpy-stubs/__init__.pyi,sha256=t57N4li3sxqfy87EI3QN5BLw2zdc1Z0qOROl0H-gUlE,51183
2
- numpy-stubs/_shapes.pyi,sha256=6SWZvOMJ3L2GzcglV5b1Df4hut3XabWziTnfZZV-O0Q,4203
3
- numpy-stubs/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
4
- numpy-stubs/linalg/__init__.pyi,sha256=HqAg4mSr0csSnsIRougqxHP7dzUww7wa6USyN51PPAQ,2734
5
- numpy-stubs/random/__init__.pyi,sha256=vRqvYq0cOhRWx86DXEgGZ1fxPO4kTCl_CCx92Ud-Z14,2478
6
- pyrefly_numpy_stubs-1.4.0.dev1.dist-info/METADATA,sha256=90ytQrkkZ3OlOX63AhGU4xhjc3jZOA5MLkLcJvZo5KE,2662
7
- pyrefly_numpy_stubs-1.4.0.dev1.dist-info/WHEEL,sha256=THafob7ofN-NsuMN7Mg4qZyHaQI7KkD-QlcQatYhXPo,87
8
- pyrefly_numpy_stubs-1.4.0.dev1.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
9
- pyrefly_numpy_stubs-1.4.0.dev1.dist-info/RECORD,,