pyrefly-torch-stubs 1.4.0.dev2__tar.gz → 1.4.0.dev4__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.
Files changed (31) hide show
  1. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/PKG-INFO +6 -3
  2. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/README.md +3 -1
  3. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/pyproject.toml +3 -2
  4. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/__init__.pyi +147 -66
  5. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/_shapes.pyi +294 -37
  6. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/distributions/__init__.pyi +3 -3
  7. pyrefly_torch_stubs-1.4.0.dev4/torch-stubs/distributions/constraints.pyi +234 -0
  8. pyrefly_torch_stubs-1.4.0.dev4/torch-stubs/distributions/transforms.pyi +149 -0
  9. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/fft.pyi +94 -9
  10. pyrefly_torch_stubs-1.4.0.dev4/torch-stubs/linalg.pyi +490 -0
  11. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/__init__.pyi +12 -11
  12. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/attention/__init__.pyi +6 -4
  13. pyrefly_torch_stubs-1.4.0.dev4/torch-stubs/nn/attention/flex_attention.pyi +143 -0
  14. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/functional.pyi +1082 -43
  15. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/init.pyi +24 -5
  16. pyrefly_torch_stubs-1.4.0.dev4/torch-stubs/return_types.pyi +190 -0
  17. pyrefly_torch_stubs-1.4.0.dev2/torch-stubs/distributions/constraints.pyi +0 -48
  18. pyrefly_torch_stubs-1.4.0.dev2/torch-stubs/distributions/transforms.pyi +0 -46
  19. pyrefly_torch_stubs-1.4.0.dev2/torch-stubs/linalg.pyi +0 -138
  20. pyrefly_torch_stubs-1.4.0.dev2/torch-stubs/nn/attention/flex_attention.pyi +0 -78
  21. pyrefly_torch_stubs-1.4.0.dev2/torch-stubs/return_types.pyi +0 -89
  22. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/LICENSE +0 -0
  23. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/test/README.md +0 -0
  24. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/_tensor.pyi +0 -0
  25. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/distributions/beta.pyi +0 -0
  26. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/distributions/categorical.pyi +0 -0
  27. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/distributions/transformed_distribution.pyi +0 -0
  28. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/modules/__init__.pyi +0 -0
  29. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/modules/module.pyi +0 -0
  30. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/nn/parameter.pyi +0 -0
  31. {pyrefly_torch_stubs-1.4.0.dev2 → pyrefly_torch_stubs-1.4.0.dev4}/torch-stubs/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyrefly-torch-stubs
3
- Version: 1.4.0.dev2
3
+ Version: 1.4.0.dev4
4
4
  Summary: PyTorch type stubs with tensor-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,8 @@ Classifier: Programming Language :: Python
33
33
  Classifier: Programming Language :: Python :: 3
34
34
  Classifier: Typing :: Stubs Only
35
35
  Requires-Python: >=3.10
36
- Requires-Dist: pyrefly-shape-extensions==1.4.0.dev2
36
+ Requires-Dist: pyrefly-shape-extensions==1.4.0.dev4
37
+ Requires-Dist: torch
37
38
  Description-Content-Type: text/markdown
38
39
 
39
40
  # pyrefly-torch-stubs
@@ -45,7 +46,9 @@ This package is a PEP 561 stub-only distribution. It installs the
45
46
  runtime `torch` package without replacing or shadowing PyTorch itself.
46
47
 
47
48
  The package is versioned in lockstep with Pyrefly and depends on the matching
48
- `pyrefly-shape-extensions` package.
49
+ `pyrefly-shape-extensions` package. Installing it also installs `torch`, which
50
+ provides upstream modules used by these partial stubs. The `torch` dependency is
51
+ unpinned, so projects can choose their own PyTorch version.
49
52
 
50
53
  Static checks use the installed Torch package for modules that this package
51
54
  intentionally leaves unshaped:
@@ -7,7 +7,9 @@ This package is a PEP 561 stub-only distribution. It installs the
7
7
  runtime `torch` package without replacing or shadowing PyTorch itself.
8
8
 
9
9
  The package is versioned in lockstep with Pyrefly and depends on the matching
10
- `pyrefly-shape-extensions` package.
10
+ `pyrefly-shape-extensions` package. Installing it also installs `torch`, which
11
+ provides upstream modules used by these partial stubs. The `torch` dependency is
12
+ unpinned, so projects can choose their own PyTorch version.
11
13
 
12
14
  Static checks use the installed Torch package for modules that this package
13
15
  intentionally leaves unshaped:
@@ -8,7 +8,7 @@ description = "PyTorch type stubs with tensor-shape tracking, maintained by Pyre
8
8
  readme = "README.md"
9
9
  requires-python = ">=3.10"
10
10
  license = { file = "LICENSE" }
11
- version = "1.4.0.dev2"
11
+ version = "1.4.0.dev4"
12
12
  keywords = ["typechecker", "typechecking", "stubs", "torch", "pytorch"]
13
13
  classifiers = [
14
14
  "Development Status :: 4 - Beta",
@@ -18,7 +18,8 @@ classifiers = [
18
18
  "Typing :: Stubs Only",
19
19
  ]
20
20
  dependencies = [
21
- "pyrefly-shape-extensions==1.4.0.dev2",
21
+ "pyrefly-shape-extensions==1.4.0.dev4",
22
+ "torch",
22
23
  ]
23
24
 
24
25
  [project.urls]
@@ -18,7 +18,6 @@ from typing import Any, Callable, Literal, overload, Self, TYPE_CHECKING, Unpack
18
18
 
19
19
  from shape_extensions import (
20
20
  broadcast,
21
- Elements,
22
21
  Flag,
23
22
  Index,
24
23
  index_shape,
@@ -622,6 +621,7 @@ from torch._shapes import (
622
621
  repeat_shape,
623
622
  replace_axis_extent,
624
623
  reshape_shape,
624
+ reverse_shape,
625
625
  scatter_shape,
626
626
  select_shape,
627
627
  size_dim_shape,
@@ -666,6 +666,7 @@ from torch.random import (
666
666
  thread_safe_generator as thread_safe_generator,
667
667
  )
668
668
  from torch.storage import TypedStorage as TypedStorage, UntypedStorage as UntypedStorage
669
+ from typing_extensions import TypeIs
669
670
 
670
671
  if TYPE_CHECKING:
671
672
  from shape_extensions import Int as _Int
@@ -683,7 +684,7 @@ type _BasicIndex = builtins.int | slice | list[builtins.int] | None | EllipsisTy
683
684
  type _TensorScalar = builtins.bool | builtins.int | builtins.float | builtins.complex
684
685
  type _LegacyTensorScalar = builtins.bool | builtins.int | builtins.float
685
686
 
686
- # Dtype constants
687
+ # Dtype and memory-format constants
687
688
  qint8: Any
688
689
  quint8: Any
689
690
  float16: Any
@@ -693,8 +694,10 @@ int8: Any
693
694
  int16: Any
694
695
  int32: Any
695
696
  int64: Any
697
+ uint8: Any
696
698
  int: Any
697
699
  bool: Any
700
+ channels_last: memory_format
698
701
  ops: Any
699
702
 
700
703
  # ============================================================================
@@ -755,7 +758,8 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
755
758
  device: Any # Device where tensor is stored (cpu, cuda, etc.)
756
759
  dtype: Any # Data type of tensor elements (float32, int64, etc.)
757
760
  ndim: builtins.int # Number of dimensions
758
- T: Self # Transpose property (for 2D tensors). Use .t() method for shape inference.
761
+ @property
762
+ def T(self: Tensor[Shape]) -> Tensor[reverse_shape(Shape)]: ...
759
763
  real: Self # Real part of complex tensor (shape-preserving)
760
764
  imag: Self # Imaginary part of complex tensor (shape-preserving)
761
765
 
@@ -893,18 +897,12 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
893
897
 
894
898
  # ==== Comparison Operations ====
895
899
 
896
- @overload
897
- def __eq__[OtherShape: _Shape](
898
- self, other: Tensor[OtherShape]
900
+ def __eq__[OtherShape: _Shape = []](
901
+ self, other: _TensorLike[OtherShape]
899
902
  ) -> Tensor[broadcast(Shape, OtherShape)]: ... # type: ignore[override]
900
- @overload
901
- def __eq__(self, other: builtins.float | builtins.int) -> Self: ... # type: ignore[override]
902
- @overload
903
- def __ne__[OtherShape: _Shape](
904
- self, other: Tensor[OtherShape]
903
+ def __ne__[OtherShape: _Shape = []](
904
+ self, other: _TensorLike[OtherShape]
905
905
  ) -> Tensor[broadcast(Shape, OtherShape)]: ... # type: ignore[override]
906
- @overload
907
- def __ne__(self, other: builtins.float | builtins.int) -> Self: ... # type: ignore[override]
908
906
  # Ordering results are gradual because they are tensors elementwise, but
909
907
  # scalar tensors are also valid in truth-valued comparison protocols.
910
908
  def __lt__(self, other: Tensor | builtins.float | builtins.int) -> Any: ...
@@ -917,24 +915,15 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
917
915
  # comparison operators do. Combining masks with `&` and `|` is the common
918
916
  # case, and those masks come from the comparisons above.
919
917
 
920
- @overload
921
- def __and__[OtherShape: _Shape](
922
- self, other: Tensor[OtherShape]
918
+ def __and__[OtherShape: _Shape = []](
919
+ self, other: _IntegerTensorLike[OtherShape]
923
920
  ) -> Tensor[broadcast(Shape, OtherShape)]: ...
924
- @overload
925
- def __and__(self, other: bool | int) -> Self: ...
926
- @overload
927
- def __or__[OtherShape: _Shape](
928
- self, other: Tensor[OtherShape]
921
+ def __or__[OtherShape: _Shape = []](
922
+ self, other: _IntegerTensorLike[OtherShape]
929
923
  ) -> Tensor[broadcast(Shape, OtherShape)]: ...
930
- @overload
931
- def __or__(self, other: bool | int) -> Self: ...
932
- @overload
933
- def __xor__[OtherShape: _Shape](
934
- self, other: Tensor[OtherShape]
924
+ def __xor__[OtherShape: _Shape = []](
925
+ self, other: _IntegerTensorLike[OtherShape]
935
926
  ) -> Tensor[broadcast(Shape, OtherShape)]: ...
936
- @overload
937
- def __xor__(self, other: bool | int) -> Self: ...
938
927
  def __rand__(self, other: bool | int) -> Self: ...
939
928
  def __ror__(self, other: bool | int) -> Self: ...
940
929
  def __rxor__(self, other: bool | int) -> Self: ...
@@ -1676,22 +1665,26 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1676
1665
  """Compute distance to another tensor. Returns scalar tensor."""
1677
1666
  ...
1678
1667
 
1679
- def cumsum[Shape: IntTuple](self: Tensor[Shape], dim: int) -> Tensor[Shape]:
1668
+ def cumsum[Shape: IntTuple](
1669
+ self: Tensor[Shape], dim: builtins.int
1670
+ ) -> Tensor[Shape]:
1680
1671
  """Cumulative sum along dimension. Shape-preserving operation."""
1681
1672
  ...
1682
1673
 
1683
- def cumprod[Shape: IntTuple](self: Tensor[Shape], dim: int) -> Tensor[Shape]:
1674
+ def cumprod[Shape: IntTuple](
1675
+ self: Tensor[Shape], dim: builtins.int
1676
+ ) -> Tensor[Shape]:
1684
1677
  """Cumulative product along dimension. Shape-preserving operation."""
1685
1678
  ...
1686
1679
 
1687
1680
  def cummax[Shape: IntTuple](
1688
- self: Tensor[Shape], dim: int
1681
+ self: Tensor[Shape], dim: builtins.int
1689
1682
  ) -> return_types.cummax[Shape]:
1690
1683
  """Cumulative maximum along dimension. Returns (values, indices). Shape-preserving operation."""
1691
1684
  ...
1692
1685
 
1693
1686
  def cummin[Shape: IntTuple](
1694
- self: Tensor[Shape], dim: int
1687
+ self: Tensor[Shape], dim: builtins.int
1695
1688
  ) -> return_types.cummin[Shape]:
1696
1689
  """Cumulative minimum along dimension. Returns (values, indices). Shape-preserving operation."""
1697
1690
  ...
@@ -1708,17 +1701,17 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1708
1701
  self: Tensor[Shape],
1709
1702
  k: K,
1710
1703
  dim: Dim = -1,
1711
- largest: bool = True,
1712
- sorted: bool = True,
1704
+ largest: builtins.bool = True,
1705
+ sorted: builtins.bool = True,
1713
1706
  ) -> return_types.topk[topk_shape(Shape, Dim, K)]:
1714
1707
  """Top k elements. Returns (values, indices). Shape inference via meta-shape: torch.Tensor.topk"""
1715
1708
  ...
1716
1709
 
1717
1710
  def sort[Shape: IntTuple](
1718
1711
  self: Tensor[Shape],
1719
- dim: int = -1,
1720
- descending: bool = False,
1721
- stable: bool = False,
1712
+ dim: builtins.int = -1,
1713
+ descending: builtins.bool = False,
1714
+ stable: builtins.bool = False,
1722
1715
  ) -> return_types.sort[Shape]:
1723
1716
  """Sort tensor. Returns (values, indices). Shape-preserving operation."""
1724
1717
  ...
@@ -1728,7 +1721,10 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1728
1721
  Dim: Flag[builtins.int],
1729
1722
  Keepdim: Flag[builtins.bool],
1730
1723
  ](
1731
- self: Tensor[Shape], k: int, dim: Dim = -1, keepdim: Keepdim = False
1724
+ self: Tensor[Shape],
1725
+ k: builtins.int,
1726
+ dim: Dim = -1,
1727
+ keepdim: Keepdim = False,
1732
1728
  ) -> return_types.kthvalue[reduce_shape(Shape, Dim, Keepdim)]:
1733
1729
  """Kth smallest value. Returns (values, indices). Shape inference via meta-shape: torch.Tensor.kthvalue"""
1734
1730
  ...
@@ -1746,11 +1742,11 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1746
1742
  """Create diagonal tensor. Shape inference via meta-shape: torch.Tensor.diag_embed"""
1747
1743
  ...
1748
1744
 
1749
- def tril(self, diagonal: int = 0) -> Self:
1745
+ def tril(self, diagonal: builtins.int = 0) -> Self:
1750
1746
  """Lower triangular part. Shape inference via generic fixture signature."""
1751
1747
  ...
1752
1748
 
1753
- def triu(self, diagonal: int = 0) -> Self:
1749
+ def triu(self, diagonal: builtins.int = 0) -> Self:
1754
1750
  """Upper triangular part. Shape inference via generic fixture signature."""
1755
1751
  ...
1756
1752
 
@@ -2090,7 +2086,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2090
2086
  """Digamma function. Shape inference via generic fixture signature."""
2091
2087
  ...
2092
2088
 
2093
- def polygamma(self, n: int) -> Self:
2089
+ def polygamma(self, n: builtins.int) -> Self:
2094
2090
  """Polygamma function. Shape inference via generic fixture signature."""
2095
2091
  ...
2096
2092
 
@@ -2217,7 +2213,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2217
2213
 
2218
2214
  # ==== Phase 4: Advanced Linear Algebra Methods ====
2219
2215
 
2220
- def cholesky(self, upper: bool = False) -> Self:
2216
+ def cholesky(self, upper: builtins.bool = False) -> Self:
2221
2217
  """Cholesky decomposition. Shape inference via generic fixture signature."""
2222
2218
  ...
2223
2219
 
@@ -2226,26 +2222,26 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2226
2222
  ...
2227
2223
 
2228
2224
  def det[Batch: IntTuple, M: IntVar, N: IntVar](
2229
- self: Tensor[[*Elements[Batch], M, N]],
2225
+ self: Tensor[[*Batch, M, N]],
2230
2226
  ) -> Tensor[Batch]:
2231
2227
  """Determinant. Returns batch dimensions only (drops last 2 dims)."""
2232
2228
  ...
2233
2229
 
2234
2230
  def logdet[Batch: IntTuple, M: IntVar, N: IntVar](
2235
- self: Tensor[[*Elements[Batch], M, N]],
2231
+ self: Tensor[[*Batch, M, N]],
2236
2232
  ) -> Tensor[Batch]:
2237
2233
  """Log determinant. Returns batch dimensions only (drops last 2 dims)."""
2238
2234
  ...
2239
2235
 
2240
2236
  @overload
2241
2237
  def slogdet[Batch: IntTuple, M: IntVar, N: IntVar](
2242
- self: Tensor[[*Elements[Batch], M, N]],
2238
+ self: Tensor[[*Batch, M, N]],
2243
2239
  ) -> return_types.slogdet[Batch]: ...
2244
2240
  @overload
2245
2241
  def slogdet[Shape: IntTuple](
2246
2242
  self: Tensor[Shape],
2247
2243
  ) -> return_types.slogdet[slogdet_shape(Shape)]: ...
2248
- def matrix_power(self, n: int) -> Self:
2244
+ def matrix_power(self, n: builtins.int) -> Self:
2249
2245
  """Matrix power. Shape inference via generic fixture signature."""
2250
2246
  ...
2251
2247
 
@@ -2337,7 +2333,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2337
2333
  self,
2338
2334
  indices: tuple[Tensor, ...],
2339
2335
  values: Tensor,
2340
- accumulate: bool = False,
2336
+ accumulate: builtins.bool = False,
2341
2337
  ) -> Self:
2342
2338
  """Put values at indices. Shape inference via generic fixture signature."""
2343
2339
  ...
@@ -2346,7 +2342,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2346
2342
  self,
2347
2343
  indices: tuple[Tensor, ...],
2348
2344
  values: Tensor,
2349
- accumulate: bool = False,
2345
+ accumulate: builtins.bool = False,
2350
2346
  ) -> Self:
2351
2347
  """Put values at indices in-place. Shape inference via generic fixture signature."""
2352
2348
  ...
@@ -2380,7 +2376,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2380
2376
  self: Tensor[Shape],
2381
2377
  index: Tensor[IndexShape],
2382
2378
  source: Tensor[SourceShape],
2383
- accumulate: bool = False,
2379
+ accumulate: builtins.bool = False,
2384
2380
  ) -> Tensor[put_shape(Shape, IndexShape, SourceShape)]:
2385
2381
  """Put values at indices. Shape inference via generic fixture signature."""
2386
2382
  ...
@@ -2389,7 +2385,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2389
2385
  self: Tensor[Shape],
2390
2386
  index: Tensor[IndexShape],
2391
2387
  source: Tensor[SourceShape],
2392
- accumulate: bool = False,
2388
+ accumulate: builtins.bool = False,
2393
2389
  ) -> Tensor[put_shape(Shape, IndexShape, SourceShape)]:
2394
2390
  """Put values at indices in-place. Shape inference via generic fixture signature."""
2395
2391
  ...
@@ -2439,8 +2435,8 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2439
2435
 
2440
2436
  def random_(
2441
2437
  self,
2442
- low: int = 0,
2443
- high: int | None = None,
2438
+ low: builtins.int = 0,
2439
+ high: builtins.int | None = None,
2444
2440
  *,
2445
2441
  generator: Generator | None = None,
2446
2442
  ) -> Self:
@@ -2469,6 +2465,8 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2469
2465
  """Return the number of elements."""
2470
2466
  ...
2471
2467
 
2468
+ FloatTensor = Tensor
2469
+
2472
2470
  # ============================================================================
2473
2471
  # Module-level Functions
2474
2472
  # ============================================================================
@@ -2479,6 +2477,78 @@ def matmul[Left: IntTuple, Right: IntTuple](
2479
2477
  """Matrix multiplication function. Shape inference via meta-shape: torch.matmul"""
2480
2478
  ...
2481
2479
 
2480
+ @overload
2481
+ def unique(
2482
+ input: Tensor,
2483
+ sorted: builtins.bool = True,
2484
+ return_inverse: Literal[False] = False,
2485
+ return_counts: Literal[False] = False,
2486
+ dim: None = None,
2487
+ ) -> Tensor[[Any]]: ...
2488
+ @overload
2489
+ def unique(
2490
+ input: Tensor,
2491
+ sorted: builtins.bool = True,
2492
+ return_inverse: Literal[False] = False,
2493
+ return_counts: Literal[False] = False,
2494
+ dim: builtins.int = 0,
2495
+ ) -> Tensor: ...
2496
+ @overload
2497
+ def unique[Shape: IntTuple](
2498
+ input: Tensor[Shape],
2499
+ sorted: builtins.bool = True,
2500
+ return_inverse: Literal[True] = True,
2501
+ return_counts: Literal[False] = False,
2502
+ dim: None = None,
2503
+ ) -> tuple[Tensor[[Any]], Tensor[Shape]]: ...
2504
+ @overload
2505
+ def unique(
2506
+ input: Tensor,
2507
+ sorted: builtins.bool = True,
2508
+ return_inverse: Literal[True] = True,
2509
+ return_counts: Literal[False] = False,
2510
+ dim: builtins.int = 0,
2511
+ ) -> tuple[Tensor, Tensor[[Any]]]: ...
2512
+ @overload
2513
+ def unique(
2514
+ input: Tensor,
2515
+ sorted: builtins.bool = True,
2516
+ return_inverse: Literal[False] = False,
2517
+ return_counts: Literal[True] = True,
2518
+ dim: None = None,
2519
+ ) -> tuple[Tensor[[Any]], Tensor[[Any]]]: ...
2520
+ @overload
2521
+ def unique(
2522
+ input: Tensor,
2523
+ sorted: builtins.bool = True,
2524
+ return_inverse: Literal[False] = False,
2525
+ return_counts: Literal[True] = True,
2526
+ dim: builtins.int = 0,
2527
+ ) -> tuple[Tensor, Tensor[[Any]]]: ...
2528
+ @overload
2529
+ def unique[Shape: IntTuple](
2530
+ input: Tensor[Shape],
2531
+ sorted: builtins.bool = True,
2532
+ return_inverse: Literal[True] = True,
2533
+ return_counts: Literal[True] = True,
2534
+ dim: None = None,
2535
+ ) -> tuple[Tensor[[Any]], Tensor[Shape], Tensor[[Any]]]: ...
2536
+ @overload
2537
+ def unique(
2538
+ input: Tensor,
2539
+ sorted: builtins.bool = True,
2540
+ return_inverse: Literal[True] = True,
2541
+ return_counts: Literal[True] = True,
2542
+ dim: builtins.int = 0,
2543
+ ) -> tuple[Tensor, Tensor[[Any]], Tensor[[Any]]]: ...
2544
+ @overload
2545
+ def unique(
2546
+ input: Tensor,
2547
+ sorted: builtins.bool = True,
2548
+ return_inverse: builtins.bool = False,
2549
+ return_counts: builtins.bool = False,
2550
+ dim: builtins.int | None = None,
2551
+ ) -> Tensor | tuple[Tensor, Tensor] | tuple[Tensor, Tensor, Tensor]: ...
2482
2552
  def cat[Shapes: IntTuples, Dim: Flag[builtins.int]](
2483
2553
  tensors: MapIntTuples[lambda S: Tensor[S], Shapes], dim: Dim = 0
2484
2554
  ) -> Tensor[cat_shape(Shapes, Dim)]:
@@ -3831,16 +3901,16 @@ def einsum[Spec: Flag[str], Shapes: IntTuples](
3831
3901
  # Eigenvalue decomposition
3832
3902
  @overload
3833
3903
  def eig[Batch: IntTuple, M: IntVar, N: IntVar](
3834
- self: Tensor[[*Elements[Batch], M, N]], eigenvectors: bool = False
3835
- ) -> tuple[Tensor[[*Elements[Batch], M]], Tensor[[*Elements[Batch], M, N]]]: ...
3904
+ self: Tensor[[*Batch, M, N]], eigenvectors: bool = False
3905
+ ) -> tuple[Tensor[[*Batch, M]], Tensor[[*Batch, M, N]]]: ...
3836
3906
  @overload
3837
3907
  def eig[Shape: IntTuple](
3838
3908
  self: Tensor[Shape], eigenvectors: bool = False
3839
3909
  ) -> tuple[Tensor[eig_shape(Shape)], Tensor[Shape]]: ...
3840
3910
  @overload
3841
3911
  def eigh[Batch: IntTuple, M: IntVar, N: IntVar](
3842
- self: Tensor[[*Elements[Batch], M, N]], UPLO: str = "L"
3843
- ) -> tuple[Tensor[[*Elements[Batch], M]], Tensor[[*Elements[Batch], M, N]]]: ...
3912
+ self: Tensor[[*Batch, M, N]], UPLO: str = "L"
3913
+ ) -> tuple[Tensor[[*Batch, M]], Tensor[[*Batch, M, N]]]: ...
3844
3914
  @overload
3845
3915
  def eigh[Shape: IntTuple](
3846
3916
  self: Tensor[Shape], UPLO: str = "L"
@@ -3876,20 +3946,20 @@ def inverse[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]:
3876
3946
 
3877
3947
  # Determinant
3878
3948
  def det[Batch: IntTuple, M: IntVar, N: IntVar](
3879
- input: Tensor[[*Elements[Batch], M, N]],
3949
+ input: Tensor[[*Batch, M, N]],
3880
3950
  ) -> Tensor[Batch]:
3881
3951
  """Determinant. Returns batch dimensions only (drops last 2 dims)."""
3882
3952
  ...
3883
3953
 
3884
3954
  def logdet[Batch: IntTuple, M: IntVar, N: IntVar](
3885
- input: Tensor[[*Elements[Batch], M, N]],
3955
+ input: Tensor[[*Batch, M, N]],
3886
3956
  ) -> Tensor[Batch]:
3887
3957
  """Log determinant. Returns batch dimensions only (drops last 2 dims)."""
3888
3958
  ...
3889
3959
 
3890
3960
  @overload
3891
3961
  def slogdet[Batch: IntTuple, M: IntVar, N: IntVar](
3892
- self: Tensor[[*Elements[Batch], M, N]],
3962
+ self: Tensor[[*Batch, M, N]],
3893
3963
  ) -> return_types.slogdet[Batch]: ...
3894
3964
  @overload
3895
3965
  def slogdet[Shape: IntTuple](
@@ -3912,7 +3982,7 @@ def trace[M: IntVar, N: IntVar](input: Tensor[[M, N]]) -> Tensor[[]]:
3912
3982
 
3913
3983
  # Matrix rank
3914
3984
  def matrix_rank[Batch: IntTuple, M: IntVar, N: IntVar](
3915
- input: Tensor[[*Elements[Batch], M, N]],
3985
+ input: Tensor[[*Batch, M, N]],
3916
3986
  tol: builtins.float | None = None,
3917
3987
  symmetric: bool = False,
3918
3988
  ) -> Tensor[Batch]:
@@ -4108,7 +4178,7 @@ def poisson[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]:
4108
4178
  ...
4109
4179
 
4110
4180
  # Tensor property functions
4111
- def is_tensor(obj: object, /) -> builtins.bool:
4181
+ def is_tensor(obj: object, /) -> TypeIs[Tensor]:
4112
4182
  """Return whether an object is a PyTorch tensor."""
4113
4183
  ...
4114
4184
 
@@ -4186,6 +4256,17 @@ def from_numpy(ndarray: Any) -> Tensor:
4186
4256
  """Create a CPU tensor that shares memory with a numpy array."""
4187
4257
  ...
4188
4258
 
4259
+ @overload
4260
+ def randint[Shape: IntTuple](
4261
+ high: int,
4262
+ size: Shape,
4263
+ *,
4264
+ generator: Any = None,
4265
+ dtype: Any = None,
4266
+ device: Any = None,
4267
+ requires_grad: bool = False,
4268
+ ) -> Tensor[Shape]: ...
4269
+ @overload
4189
4270
  def randint[Shape: IntTuple](
4190
4271
  low: int,
4191
4272
  high: int,
@@ -4233,11 +4314,11 @@ def polar[Shape: IntTuple](abs: Tensor[Shape], angle: Tensor[Shape]) -> Tensor[S
4233
4314
  """Construct complex tensor from polar coordinates. Shape-preserving operation."""
4234
4315
  ...
4235
4316
 
4236
- def view_as_complex[S: IntTuple](input: Tensor[[*Elements[S], 2]]) -> Tensor[S]:
4317
+ def view_as_complex[S: IntTuple](input: Tensor[[*S, 2]]) -> Tensor[S]:
4237
4318
  """View a real tensor as complex. Last dim of size 2 is consumed."""
4238
4319
  ...
4239
4320
 
4240
- def view_as_real[S: IntTuple](input: Tensor[S]) -> Tensor[[*Elements[S], 2]]:
4321
+ def view_as_real[S: IntTuple](input: Tensor[S]) -> Tensor[[*S, 2]]:
4241
4322
  """View a complex tensor as real. Appends trailing dim of size 2."""
4242
4323
  ...
4243
4324
 
@@ -4284,10 +4365,10 @@ def addmm[N: IntVar, K: IntVar, M: IntVar](
4284
4365
  ...
4285
4366
 
4286
4367
  def cross[B: IntTuple](
4287
- input: Tensor[[*Elements[B], 3]],
4288
- other: Tensor[[*Elements[B], 3]],
4368
+ input: Tensor[[*B, 3]],
4369
+ other: Tensor[[*B, 3]],
4289
4370
  dim: int = -1,
4290
- ) -> Tensor[[*Elements[B], 3]]:
4371
+ ) -> Tensor[[*B, 3]]:
4291
4372
  """Cross product of two tensors along a dimension of size 3."""
4292
4373
  ...
4293
4374