pyrefly-torch-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.
Files changed (26) hide show
  1. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/PKG-INFO +2 -2
  2. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/pyproject.toml +2 -2
  3. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/__init__.pyi +79 -22
  4. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/LICENSE +0 -0
  5. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/README.md +0 -0
  6. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/test/README.md +0 -0
  7. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/_shapes.pyi +0 -0
  8. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/_tensor.pyi +0 -0
  9. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/__init__.pyi +0 -0
  10. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/beta.pyi +0 -0
  11. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/categorical.pyi +0 -0
  12. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/constraints.pyi +0 -0
  13. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/transformed_distribution.pyi +0 -0
  14. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/distributions/transforms.pyi +0 -0
  15. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/fft.pyi +0 -0
  16. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/linalg.pyi +0 -0
  17. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/__init__.pyi +0 -0
  18. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/attention/__init__.pyi +0 -0
  19. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/attention/flex_attention.pyi +0 -0
  20. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/functional.pyi +0 -0
  21. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/init.pyi +0 -0
  22. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/modules/__init__.pyi +0 -0
  23. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/modules/module.pyi +0 -0
  24. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/nn/parameter.pyi +0 -0
  25. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/py.typed +0 -0
  26. {pyrefly_torch_stubs-1.4.0.dev4 → pyrefly_torch_stubs-1.5.0.dev1}/torch-stubs/return_types.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyrefly-torch-stubs
3
- Version: 1.4.0.dev4
3
+ Version: 1.5.0.dev1
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,7 @@ 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.dev4
36
+ Requires-Dist: pyrefly-shape-extensions==1.5.0.dev1
37
37
  Requires-Dist: torch
38
38
  Description-Content-Type: text/markdown
39
39
 
@@ -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.dev4"
11
+ version = "1.5.0.dev1"
12
12
  keywords = ["typechecker", "typechecking", "stubs", "torch", "pytorch"]
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
  "torch",
23
23
  ]
24
24
 
@@ -16,6 +16,9 @@ from math import e as e, nan as nan
16
16
  from types import EllipsisType
17
17
  from typing import Any, Callable, Literal, overload, Self, TYPE_CHECKING, Unpack
18
18
 
19
+ # Torch does not require NumPy, so this import is intentionally not a package
20
+ # dependency.
21
+ import numpy as np
19
22
  from shape_extensions import (
20
23
  broadcast,
21
24
  Flag,
@@ -643,7 +646,10 @@ from torch._shapes import (
643
646
  )
644
647
  from torch._tensor_str import set_printoptions as set_printoptions
645
648
  from torch.amp import autocast as autocast, GradScaler as GradScaler
646
- from torch.autograd import enable_grad as enable_grad
649
+ from torch.autograd import (
650
+ enable_grad as enable_grad,
651
+ set_grad_enabled as set_grad_enabled,
652
+ )
647
653
  from torch.func import vmap as vmap
648
654
  from torch.functional import (
649
655
  align_tensors as align_tensors,
@@ -688,6 +694,7 @@ type _LegacyTensorScalar = builtins.bool | builtins.int | builtins.float
688
694
  qint8: Any
689
695
  quint8: Any
690
696
  float16: Any
697
+ half: Any
691
698
  float32: Any
692
699
  float64: Any
693
700
  int8: Any
@@ -698,6 +705,7 @@ uint8: Any
698
705
  int: Any
699
706
  bool: Any
700
707
  channels_last: memory_format
708
+ strided: layout
701
709
  ops: Any
702
710
 
703
711
  # ============================================================================
@@ -820,7 +828,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
820
828
  | Tensor,
821
829
  ...,
822
830
  ],
823
- value: Tensor | builtins.int | builtins.float,
831
+ value: Tensor | _Scalar,
824
832
  ) -> None:
825
833
  """Set values in tensor via indexing. Mutates tensor in-place."""
826
834
  ...
@@ -877,11 +885,11 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
877
885
  ) -> Tensor[inplace_broadcast_shape(Shape, OtherShape)]: ...
878
886
 
879
887
  # Reverse operations for scalars
880
- def __radd__(self, other: builtins.float | builtins.int) -> Self: ...
881
- def __rsub__(self, other: builtins.float | builtins.int) -> Self: ...
882
- def __rmul__(self, other: builtins.float | builtins.int) -> Self: ...
883
- def __rtruediv__(self, other: builtins.float | builtins.int) -> Self: ...
884
- def __rpow__(self, other: builtins.float | builtins.int) -> Self: ...
888
+ def __radd__(self, other: _Scalar) -> Self: ...
889
+ def __rsub__(self, other: _Scalar) -> Self: ...
890
+ def __rmul__(self, other: _Scalar) -> Self: ...
891
+ def __rtruediv__(self, other: _Scalar) -> Self: ...
892
+ def __rpow__(self, other: _Scalar) -> Self: ...
885
893
 
886
894
  # Power operations
887
895
  def __pow__[OtherShape: _Shape = []](
@@ -1190,7 +1198,7 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1190
1198
  def new_full(
1191
1199
  self,
1192
1200
  size: tuple[builtins.int, ...],
1193
- fill_value: builtins.float | builtins.int,
1201
+ fill_value: _Scalar,
1194
1202
  dtype: Any = None,
1195
1203
  device: Any = None,
1196
1204
  requires_grad: builtins.bool = False,
@@ -1283,8 +1291,14 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
1283
1291
  """Returns tensor as a nested Python list."""
1284
1292
  ...
1285
1293
 
1286
- def numpy(self: Tensor) -> Any:
1287
- """Returns tensor as a NumPy array."""
1294
+ def numpy[Shape: IntTuple](self: Tensor[Shape]) -> np.ndarray[Shape]:
1295
+ """Return a NumPy array with the same shape.
1296
+
1297
+ NumPy is an optional dependency of this stub package. Installing
1298
+ `pyrefly-numpy-stubs` adds shape inference for values created through
1299
+ NumPy APIs; otherwise only shape information already present in NumPy's
1300
+ own annotations is preserved.
1301
+ """
1288
1302
  ...
1289
1303
 
1290
1304
  # TODO: Restrict this to statically single-element tensors once the type
@@ -2036,6 +2050,14 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2036
2050
  """Element-wise hypotenuse. Shape inference via generic fixture signature."""
2037
2051
  ...
2038
2052
 
2053
+ @overload
2054
+ def lerp[OtherShape: _Shape, WeightShape: _Shape](
2055
+ self, end: Tensor[OtherShape], weight: Tensor[WeightShape]
2056
+ ) -> Tensor[broadcast(Shape, broadcast(OtherShape, WeightShape))]:
2057
+ """Linear interpolation. Shape inference via generic fixture signature."""
2058
+ ...
2059
+
2060
+ @overload
2039
2061
  def lerp[OtherShape: _Shape](
2040
2062
  self, end: Tensor[OtherShape], weight: builtins.float
2041
2063
  ) -> Tensor[broadcast(Shape, OtherShape)]:
@@ -2188,25 +2210,25 @@ class Tensor[Shape: _Shape = _Shape](_TensorBase):
2188
2210
  ...
2189
2211
 
2190
2212
  def maximum[OtherShape: _Shape = []](
2191
- self, other: _TensorLike[OtherShape]
2213
+ self, other: Tensor[OtherShape]
2192
2214
  ) -> Tensor[broadcast(Shape, OtherShape)]:
2193
2215
  """Element-wise maximum. Shape inference via generic fixture signature."""
2194
2216
  ...
2195
2217
 
2196
2218
  def minimum[OtherShape: _Shape = []](
2197
- self, other: _TensorLike[OtherShape]
2219
+ self, other: Tensor[OtherShape]
2198
2220
  ) -> Tensor[broadcast(Shape, OtherShape)]:
2199
2221
  """Element-wise minimum. Shape inference via generic fixture signature."""
2200
2222
  ...
2201
2223
 
2202
2224
  def fmax[OtherShape: _Shape = []](
2203
- self, other: _TensorLike[OtherShape]
2225
+ self, other: Tensor[OtherShape]
2204
2226
  ) -> Tensor[broadcast(Shape, OtherShape)]:
2205
2227
  """Element-wise maximum (NaN handling). Shape inference via generic fixture signature."""
2206
2228
  ...
2207
2229
 
2208
2230
  def fmin[OtherShape: _Shape = []](
2209
- self, other: _TensorLike[OtherShape]
2231
+ self, other: Tensor[OtherShape]
2210
2232
  ) -> Tensor[broadcast(Shape, OtherShape)]:
2211
2233
  """Element-wise minimum (NaN handling). Shape inference via generic fixture signature."""
2212
2234
  ...
@@ -2954,14 +2976,21 @@ def ones(
2954
2976
  ) -> Tensor: ...
2955
2977
  @overload
2956
2978
  def empty[Shape: IntTuple](
2957
- *size: *Shape, dtype: Any = None, device: Any = None
2979
+ *size: *Shape,
2980
+ dtype: Any = None,
2981
+ device: Any = None,
2982
+ requires_grad: builtins.bool = False,
2958
2983
  ) -> Tensor[Shape]:
2959
2984
  """Create uninitialized tensor. Shape is inferred from `size`."""
2960
2985
  ...
2961
2986
 
2962
2987
  @overload
2963
2988
  def empty[Shape: IntTuple](
2964
- size: Shape, dtype: Any = None, device: Any = None
2989
+ size: Shape,
2990
+ *,
2991
+ dtype: Any = None,
2992
+ device: Any = None,
2993
+ requires_grad: builtins.bool = False,
2965
2994
  ) -> Tensor[Shape]:
2966
2995
  """Create uninitialized tensor. Shape is inferred from `size`."""
2967
2996
  ...
@@ -3672,6 +3701,14 @@ def atan[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]:
3672
3701
  """Element-wise arctangent. Shape inference via generic fixture signature."""
3673
3702
  ...
3674
3703
 
3704
+ @overload
3705
+ def lerp[Shape: IntTuple, OtherShape: IntTuple, WeightShape: IntTuple](
3706
+ input: Tensor[Shape], end: Tensor[OtherShape], weight: Tensor[WeightShape]
3707
+ ) -> Tensor[broadcast(Shape, broadcast(OtherShape, WeightShape))]:
3708
+ """Linear interpolation. Shape inference via generic fixture signature."""
3709
+ ...
3710
+
3711
+ @overload
3675
3712
  def lerp[Shape: IntTuple, OtherShape: IntTuple](
3676
3713
  input: Tensor[Shape], end: Tensor[OtherShape], weight: builtins.float
3677
3714
  ) -> Tensor[broadcast(Shape, OtherShape)]:
@@ -3846,13 +3883,13 @@ def allclose(
3846
3883
  equal_nan: builtins.bool = False,
3847
3884
  ) -> builtins.bool: ...
3848
3885
  def maximum[Shape: IntTuple, OtherShape: IntTuple = []](
3849
- input: Tensor[Shape], other: _TensorLike[OtherShape]
3886
+ input: Tensor[Shape], other: Tensor[OtherShape]
3850
3887
  ) -> Tensor[broadcast(Shape, OtherShape)]:
3851
3888
  """Element-wise maximum. Shape inference via generic fixture signature."""
3852
3889
  ...
3853
3890
 
3854
3891
  def minimum[Shape: IntTuple, OtherShape: IntTuple = []](
3855
- input: Tensor[Shape], other: _TensorLike[OtherShape]
3892
+ input: Tensor[Shape], other: Tensor[OtherShape]
3856
3893
  ) -> Tensor[broadcast(Shape, OtherShape)]:
3857
3894
  """Element-wise minimum. Shape inference via generic fixture signature."""
3858
3895
  ...
@@ -3861,13 +3898,13 @@ def expm1[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]: ...
3861
3898
  def log10[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]: ...
3862
3899
  def sign[Shape: IntTuple](input: Tensor[Shape]) -> Tensor[Shape]: ...
3863
3900
  def fmax[Shape: IntTuple, OtherShape: IntTuple = []](
3864
- input: Tensor[Shape], other: _TensorLike[OtherShape]
3901
+ input: Tensor[Shape], other: Tensor[OtherShape]
3865
3902
  ) -> Tensor[broadcast(Shape, OtherShape)]:
3866
3903
  """Element-wise maximum (NaN handling). Shape inference via generic fixture signature."""
3867
3904
  ...
3868
3905
 
3869
3906
  def fmin[Shape: IntTuple, OtherShape: IntTuple = []](
3870
- input: Tensor[Shape], other: _TensorLike[OtherShape]
3907
+ input: Tensor[Shape], other: Tensor[OtherShape]
3871
3908
  ) -> Tensor[broadcast(Shape, OtherShape)]:
3872
3909
  """Element-wise minimum (NaN handling). Shape inference via generic fixture signature."""
3873
3910
  ...
@@ -4209,6 +4246,8 @@ class dtype:
4209
4246
  ...
4210
4247
 
4211
4248
  float: dtype = ...
4249
+ complex64: dtype = ...
4250
+ complex128: dtype = ...
4212
4251
 
4213
4252
  # ==============================================================================
4214
4253
  # Tensor Creation with dtype support
@@ -4252,8 +4291,14 @@ def as_tensor(
4252
4291
  """Create tensor from data, sharing memory with the input when possible."""
4253
4292
  ...
4254
4293
 
4255
- def from_numpy(ndarray: Any) -> Tensor:
4256
- """Create a CPU tensor that shares memory with a numpy array."""
4294
+ def from_numpy[Shape: IntTuple](ndarray: np.ndarray[Shape]) -> Tensor[Shape]:
4295
+ """Create a shape-preserving CPU tensor that shares memory with a NumPy array.
4296
+
4297
+ NumPy is an optional dependency of this stub package. Installing
4298
+ `pyrefly-numpy-stubs` adds shape inference for values created through NumPy
4299
+ APIs; otherwise only shape information already present in NumPy's own
4300
+ annotations is preserved.
4301
+ """
4257
4302
  ...
4258
4303
 
4259
4304
  @overload
@@ -4373,6 +4418,14 @@ def cross[B: IntTuple](
4373
4418
  ...
4374
4419
 
4375
4420
  # Context managers
4421
+ # Define the top-level API directly because older Torch versions lack torch.compiler.
4422
+ @overload
4423
+ def compile[F: Callable[..., Any]](model: F, **kwargs: Any) -> F: ...
4424
+ @overload
4425
+ def compile[**P, R](
4426
+ model: None = None, **kwargs: Any
4427
+ ) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
4428
+
4376
4429
  class no_grad:
4377
4430
  """Context manager and decorator that disables gradient tracking.
4378
4431
 
@@ -4427,6 +4480,10 @@ def meshgrid(
4427
4480
  # The functions below carry no shape information. They are declared because this
4428
4481
  # module shadows torch's own `__init__`, as described at the `torch._C` import
4429
4482
  # above, so omitting them removes them from `torch` for every dependent target.
4483
+ def set_default_dtype(d: dtype, /) -> None: ...
4484
+ def get_num_threads() -> builtins.int: ...
4485
+ def get_float32_matmul_precision() -> str: ...
4486
+ def are_deterministic_algorithms_enabled() -> builtins.bool: ...
4430
4487
  def manual_seed(seed: int) -> Generator:
4431
4488
  """Set the seed for generating random numbers on all devices."""
4432
4489
  ...