pyrefly-torch-stubs 1.3.0.dev3__tar.gz → 1.3.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.
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/PKG-INFO +2 -2
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/pyproject.toml +2 -2
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/__init__.pyi +176 -100
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/_shapes.pyi +562 -367
- pyrefly_torch_stubs-1.3.0.dev4/torch-stubs/fft.pyi +94 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/nn/__init__.pyi +191 -114
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/nn/functional.pyi +244 -121
- pyrefly_torch_stubs-1.3.0.dev3/torch-stubs/fft.pyi +0 -142
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/LICENSE +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/README.md +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/__init__.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/beta.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/categorical.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/constraints.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/transformed_distribution.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/distributions/transforms.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/linalg.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/nn/attention/__init__.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/nn/attention/flex_attention.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/nn/init.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/optim/__init__.pyi +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/py.typed +0 -0
- {pyrefly_torch_stubs-1.3.0.dev3 → pyrefly_torch_stubs-1.3.0.dev4}/torch-stubs/quantization/__init__.pyi +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyrefly-torch-stubs
|
|
3
|
-
Version: 1.3.0.
|
|
3
|
+
Version: 1.3.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,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.3.0.
|
|
36
|
+
Requires-Dist: pyrefly-shape-extensions==1.3.0.dev4
|
|
37
37
|
Description-Content-Type: text/markdown
|
|
38
38
|
|
|
39
39
|
# pyrefly-torch-stubs
|
|
@@ -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.12"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.3.0.
|
|
11
|
+
version = "1.3.0.dev4"
|
|
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.3.0.
|
|
21
|
+
"pyrefly-shape-extensions==1.3.0.dev4",
|
|
22
22
|
]
|
|
23
23
|
|
|
24
24
|
[project.urls]
|
|
@@ -6,18 +6,27 @@
|
|
|
6
6
|
"""
|
|
7
7
|
Comprehensive type stubs for PyTorch with shape inference.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
`torch/_shapes.pyi
|
|
11
|
-
the older `@uses_shape_dsl(...)` decorator while the stub library is migrated; new rules should not
|
|
12
|
-
extend that legacy path.
|
|
9
|
+
Shape inference is expressed through type-level functions in annotations. Library-specific
|
|
10
|
+
functions are defined in `torch/_shapes.pyi`.
|
|
13
11
|
"""
|
|
14
12
|
|
|
15
13
|
import builtins
|
|
16
14
|
from collections.abc import Sequence
|
|
17
|
-
from
|
|
15
|
+
from types import EllipsisType
|
|
16
|
+
from typing import Any, overload, Self, TYPE_CHECKING, Unpack
|
|
18
17
|
|
|
19
18
|
import shape_extensions
|
|
20
|
-
from shape_extensions import
|
|
19
|
+
from shape_extensions import (
|
|
20
|
+
broadcast,
|
|
21
|
+
Elements,
|
|
22
|
+
Flag,
|
|
23
|
+
Index,
|
|
24
|
+
index_shape,
|
|
25
|
+
IntTuple,
|
|
26
|
+
IntTuples,
|
|
27
|
+
IntVar,
|
|
28
|
+
MapIntTuples,
|
|
29
|
+
)
|
|
21
30
|
|
|
22
31
|
# `Generator` is not defined anywhere in this package, and resolving it relies
|
|
23
32
|
# on how a partial stub package is looked up. The `py.typed` file here contains
|
|
@@ -34,20 +43,18 @@ from torch._C import Generator
|
|
|
34
43
|
from torch._shapes import (
|
|
35
44
|
arange_extent,
|
|
36
45
|
arange_step_extent,
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
cat_shape,
|
|
47
|
+
chunk_shapes,
|
|
39
48
|
diag_embed_shape,
|
|
40
49
|
dim_shape,
|
|
41
50
|
eig_shape,
|
|
42
|
-
|
|
51
|
+
einsum_shape,
|
|
43
52
|
expand_shape,
|
|
44
53
|
flatten_shape,
|
|
45
54
|
index_select_shape,
|
|
46
|
-
item_ir,
|
|
47
55
|
matmul_shape,
|
|
48
|
-
movedim_input_ir,
|
|
49
|
-
movedim_ir,
|
|
50
56
|
movedim_scalar_shape,
|
|
57
|
+
movedim_tuple_shape,
|
|
51
58
|
multinomial_shape,
|
|
52
59
|
numel_shape,
|
|
53
60
|
permute_shape,
|
|
@@ -62,9 +69,10 @@ from torch._shapes import (
|
|
|
62
69
|
select_shape,
|
|
63
70
|
size_dim_shape,
|
|
64
71
|
slogdet_shape,
|
|
65
|
-
|
|
72
|
+
split_sections_shapes,
|
|
73
|
+
split_size_shapes,
|
|
66
74
|
squeeze_shape,
|
|
67
|
-
|
|
75
|
+
stack_shape,
|
|
68
76
|
tensordot_shape,
|
|
69
77
|
tile_shape,
|
|
70
78
|
topk_shape,
|
|
@@ -81,6 +89,7 @@ __all__ = ["Tensor"]
|
|
|
81
89
|
|
|
82
90
|
type _Shape = IntTuple
|
|
83
91
|
type _AnyShape = tuple[Any, ...]
|
|
92
|
+
type _BasicIndex = builtins.int | slice | list[builtins.int] | None | EllipsisType
|
|
84
93
|
|
|
85
94
|
# ============================================================================
|
|
86
95
|
# Device Type
|
|
@@ -111,7 +120,7 @@ ops: Any
|
|
|
111
120
|
# Tensor Class
|
|
112
121
|
# ============================================================================
|
|
113
122
|
|
|
114
|
-
@shape_extensions.shaped_array(shape="Shape")
|
|
123
|
+
@shape_extensions.shaped_array(shape="Shape", builtin_indexing=False)
|
|
115
124
|
class Tensor[Shape: _Shape = _AnyShape]:
|
|
116
125
|
"""
|
|
117
126
|
PyTorch Tensor with shape type parameter.
|
|
@@ -134,24 +143,38 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
134
143
|
imag: Self # Imaginary part of complex tensor (shape-preserving)
|
|
135
144
|
# Note: Use .dim() method for rank (ndim removed in favor of dim())
|
|
136
145
|
# ==== Indexing ====
|
|
146
|
+
@overload
|
|
147
|
+
def __getitem__[I: Index](
|
|
148
|
+
self: Tensor[Shape], index: I
|
|
149
|
+
) -> Tensor[index_shape(Shape, I)]: ...
|
|
150
|
+
@overload
|
|
137
151
|
def __getitem__(
|
|
138
152
|
self: Tensor,
|
|
139
|
-
index:
|
|
140
|
-
|
|
|
141
|
-
|
|
|
153
|
+
index: _BasicIndex
|
|
154
|
+
| Sequence[builtins.int]
|
|
155
|
+
| Sequence[Sequence[builtins.int]]
|
|
142
156
|
| Tensor
|
|
143
|
-
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
| tuple[
|
|
158
|
+
_BasicIndex
|
|
159
|
+
| Sequence[builtins.int]
|
|
160
|
+
| Sequence[Sequence[builtins.int]]
|
|
161
|
+
| Tensor,
|
|
162
|
+
...,
|
|
163
|
+
],
|
|
164
|
+
) -> Tensor[IntTuple]: ...
|
|
148
165
|
def __setitem__(
|
|
149
166
|
self: Tensor,
|
|
150
|
-
index:
|
|
151
|
-
|
|
|
152
|
-
|
|
|
167
|
+
index: _BasicIndex
|
|
168
|
+
| Sequence[builtins.int]
|
|
169
|
+
| Sequence[Sequence[builtins.int]]
|
|
153
170
|
| Tensor
|
|
154
|
-
|
|
|
171
|
+
| tuple[
|
|
172
|
+
_BasicIndex
|
|
173
|
+
| Sequence[builtins.int]
|
|
174
|
+
| Sequence[Sequence[builtins.int]]
|
|
175
|
+
| Tensor,
|
|
176
|
+
...,
|
|
177
|
+
],
|
|
155
178
|
value: Tensor | int | float,
|
|
156
179
|
) -> None:
|
|
157
180
|
"""Set values in tensor via indexing. Mutates tensor in-place."""
|
|
@@ -403,36 +426,36 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
403
426
|
@overload
|
|
404
427
|
def repeat_interleave[
|
|
405
428
|
Shape: IntTuple,
|
|
406
|
-
Repeats:
|
|
407
|
-
OutputSize:
|
|
429
|
+
Repeats: _Int,
|
|
430
|
+
OutputSize: _Int,
|
|
408
431
|
Dim: Flag[builtins.int | None],
|
|
409
432
|
](
|
|
410
433
|
self: Tensor[Shape],
|
|
411
|
-
repeats:
|
|
434
|
+
repeats: Repeats,
|
|
412
435
|
dim: Dim = None,
|
|
413
436
|
*,
|
|
414
|
-
output_size:
|
|
437
|
+
output_size: OutputSize,
|
|
415
438
|
) -> Tensor[repeat_interleave_checked_shape(Shape, Repeats, OutputSize, Dim)]: ...
|
|
416
439
|
@overload
|
|
417
440
|
def repeat_interleave[
|
|
418
441
|
Shape: IntTuple,
|
|
419
|
-
OutputSize:
|
|
442
|
+
OutputSize: _Int,
|
|
420
443
|
Dim: Flag[builtins.int | None],
|
|
421
444
|
](
|
|
422
445
|
self: Tensor[Shape],
|
|
423
446
|
repeats: Tensor,
|
|
424
447
|
dim: Dim = None,
|
|
425
448
|
*,
|
|
426
|
-
output_size:
|
|
449
|
+
output_size: OutputSize,
|
|
427
450
|
) -> Tensor[repeat_interleave_output_shape(Shape, OutputSize, Dim)]: ...
|
|
428
451
|
@overload
|
|
429
452
|
def repeat_interleave[
|
|
430
453
|
Shape: IntTuple,
|
|
431
|
-
Repeats:
|
|
454
|
+
Repeats: _Int,
|
|
432
455
|
Dim: Flag[builtins.int | None],
|
|
433
456
|
](
|
|
434
457
|
self: Tensor[Shape],
|
|
435
|
-
repeats:
|
|
458
|
+
repeats: Repeats,
|
|
436
459
|
dim: Dim = None,
|
|
437
460
|
*,
|
|
438
461
|
output_size: None = None,
|
|
@@ -570,9 +593,8 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
570
593
|
"""Enable/disable gradient tracking in-place. Shape-preserving."""
|
|
571
594
|
...
|
|
572
595
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
"""Returns Python scalar from 0-dimensional tensor. Shape inference via meta-shape: torch.Tensor.item"""
|
|
596
|
+
def item(self: Tensor[[]]) -> builtins.float | builtins.int:
|
|
597
|
+
"""Return a Python scalar from a rank-zero tensor."""
|
|
576
598
|
...
|
|
577
599
|
|
|
578
600
|
def tolist(self: Tensor) -> Any:
|
|
@@ -594,31 +616,54 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
594
616
|
def narrow[
|
|
595
617
|
Shape: IntTuple,
|
|
596
618
|
Dim: Flag[builtins.int],
|
|
597
|
-
Length:
|
|
619
|
+
Length: _Int,
|
|
598
620
|
](
|
|
599
|
-
self: Tensor[Shape], dim: Dim, start: int, length:
|
|
621
|
+
self: Tensor[Shape], dim: Dim, start: int, length: Length
|
|
600
622
|
) -> Tensor[replace_axis_extent(Shape, Dim, Length)]:
|
|
601
623
|
"""Narrow tensor along dimension. Shape inference via meta-shape: torch.Tensor.narrow"""
|
|
602
624
|
...
|
|
603
625
|
|
|
604
|
-
@uses_shape_dsl(split_ir)
|
|
605
626
|
@overload
|
|
606
|
-
def split
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
627
|
+
def split[
|
|
628
|
+
Shape: IntTuple,
|
|
629
|
+
SplitSize: _Int,
|
|
630
|
+
Dim: Flag[builtins.int],
|
|
631
|
+
](
|
|
632
|
+
self: Tensor[Shape], split_size_or_sections: SplitSize, dim: Dim = 0
|
|
633
|
+
) -> MapIntTuples[lambda S: Tensor[S], split_size_shapes(Shape, SplitSize, Dim)]:
|
|
634
|
+
"""Split tensor into chunks. Shape inference via the type-level DSL."""
|
|
610
635
|
...
|
|
611
636
|
|
|
637
|
+
@overload
|
|
638
|
+
def split[
|
|
639
|
+
Shape: IntTuple,
|
|
640
|
+
Sections: IntTuple,
|
|
641
|
+
Dim: Flag[builtins.int],
|
|
642
|
+
](
|
|
643
|
+
self: Tensor[Shape], split_size_or_sections: Sections, dim: Dim = 0
|
|
644
|
+
) -> MapIntTuples[lambda S: Tensor[S], split_sections_shapes(Shape, Sections, Dim)]:
|
|
645
|
+
"""Split tensor into variable-sized chunks. Shape inference via the type-level DSL."""
|
|
646
|
+
...
|
|
647
|
+
|
|
648
|
+
# A list is mutable, so V2 cannot preserve its element values; this trailing
|
|
649
|
+
# overload keeps the documented list spelling checking without shape inference.
|
|
650
|
+
# TODO(stroxler): Route lists through `split_sections_shapes` once list values
|
|
651
|
+
# survive to the type level.
|
|
612
652
|
@overload
|
|
613
653
|
def split(
|
|
614
654
|
self: Tensor, split_size_or_sections: list[int], dim: int = 0
|
|
615
655
|
) -> tuple[Tensor, ...]:
|
|
616
|
-
"""Split tensor into variable-sized chunks. Shape inference
|
|
656
|
+
"""Split tensor into variable-sized chunks. Shape inference unavailable for lists."""
|
|
617
657
|
...
|
|
618
658
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
659
|
+
def chunk[
|
|
660
|
+
Shape: IntTuple,
|
|
661
|
+
Chunks: _Int,
|
|
662
|
+
Dim: Flag[builtins.int],
|
|
663
|
+
](
|
|
664
|
+
self: Tensor[Shape], chunks: Chunks, dim: Dim = 0
|
|
665
|
+
) -> MapIntTuples[lambda S: Tensor[S], chunk_shapes(Shape, Chunks, Dim)]:
|
|
666
|
+
"""Split tensor into chunks. Shape inference via the type-level DSL."""
|
|
622
667
|
...
|
|
623
668
|
|
|
624
669
|
def index_select[
|
|
@@ -666,11 +711,10 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
666
711
|
"""Move a single dimension to a new position."""
|
|
667
712
|
...
|
|
668
713
|
|
|
669
|
-
@uses_shape_dsl(movedim_ir)
|
|
670
714
|
@overload
|
|
671
|
-
def movedim(
|
|
672
|
-
self: Tensor, source:
|
|
673
|
-
) -> Tensor:
|
|
715
|
+
def movedim[Shape: IntTuple, Source: IntTuple, Destination: IntTuple](
|
|
716
|
+
self: Tensor[Shape], source: Source, destination: Destination
|
|
717
|
+
) -> Tensor[movedim_tuple_shape(Shape, Source, Destination)]:
|
|
674
718
|
"""Move multiple dimensions to new positions. Shape inference via meta-shape: torch.Tensor.movedim"""
|
|
675
719
|
...
|
|
676
720
|
|
|
@@ -685,11 +729,10 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
685
729
|
"""Alias for movedim with a single source and destination."""
|
|
686
730
|
...
|
|
687
731
|
|
|
688
|
-
@uses_shape_dsl(movedim_ir)
|
|
689
732
|
@overload
|
|
690
|
-
def moveaxis(
|
|
691
|
-
self: Tensor, source:
|
|
692
|
-
) -> Tensor:
|
|
733
|
+
def moveaxis[Shape: IntTuple, Source: IntTuple, Destination: IntTuple](
|
|
734
|
+
self: Tensor[Shape], source: Source, destination: Destination
|
|
735
|
+
) -> Tensor[movedim_tuple_shape(Shape, Source, Destination)]:
|
|
693
736
|
"""Alias for movedim. Shape inference via meta-shape: torch.Tensor.moveaxis"""
|
|
694
737
|
...
|
|
695
738
|
|
|
@@ -911,9 +954,9 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
911
954
|
"""Mode along dimension. Returns (values, indices). Shape inference via meta-shape: torch.Tensor.mode"""
|
|
912
955
|
...
|
|
913
956
|
|
|
914
|
-
def topk[Shape: IntTuple, K:
|
|
957
|
+
def topk[Shape: IntTuple, K: _Int, Dim: Flag[builtins.int]](
|
|
915
958
|
self: Tensor[Shape],
|
|
916
|
-
k:
|
|
959
|
+
k: K,
|
|
917
960
|
dim: Dim = -1,
|
|
918
961
|
largest: bool = True,
|
|
919
962
|
sorted: bool = True,
|
|
@@ -1471,9 +1514,9 @@ class Tensor[Shape: _Shape = _AnyShape]:
|
|
|
1471
1514
|
"""Sample from Bernoulli distribution in-place. Shape inference via generic fixture signature."""
|
|
1472
1515
|
...
|
|
1473
1516
|
|
|
1474
|
-
def multinomial[Shape: IntTuple, NumSamples:
|
|
1517
|
+
def multinomial[Shape: IntTuple, NumSamples: _Int](
|
|
1475
1518
|
self: Tensor[Shape],
|
|
1476
|
-
num_samples:
|
|
1519
|
+
num_samples: NumSamples,
|
|
1477
1520
|
replacement: bool = False,
|
|
1478
1521
|
) -> Tensor[multinomial_shape(Shape, NumSamples)]:
|
|
1479
1522
|
"""Sample from multinomial distribution. Shape inference via meta-shape: torch.Tensor.multinomial"""
|
|
@@ -1513,18 +1556,21 @@ def matmul[Left: IntTuple, Right: IntTuple](
|
|
|
1513
1556
|
"""Matrix multiplication function. Shape inference via meta-shape: torch.matmul"""
|
|
1514
1557
|
...
|
|
1515
1558
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1559
|
+
def cat[Shapes: IntTuples, Dim: Flag[builtins.int]](
|
|
1560
|
+
tensors: MapIntTuples[lambda S: Tensor[S], Shapes], dim: Dim = 0
|
|
1561
|
+
) -> Tensor[cat_shape(Shapes, Dim)]:
|
|
1518
1562
|
"""Concatenate tensors. Shape inference via meta-shape: torch.cat"""
|
|
1519
1563
|
...
|
|
1520
1564
|
|
|
1521
|
-
|
|
1522
|
-
|
|
1565
|
+
def concat[Shapes: IntTuples, Dim: Flag[builtins.int]](
|
|
1566
|
+
tensors: MapIntTuples[lambda S: Tensor[S], Shapes], dim: Dim = 0
|
|
1567
|
+
) -> Tensor[cat_shape(Shapes, Dim)]:
|
|
1523
1568
|
"""Alias for concatenate/cat. Shape inference via meta-shape: torch.cat"""
|
|
1524
1569
|
...
|
|
1525
1570
|
|
|
1526
|
-
|
|
1527
|
-
|
|
1571
|
+
def stack[Shapes: IntTuples, Dim: Flag[builtins.int]](
|
|
1572
|
+
tensors: MapIntTuples[lambda S: Tensor[S], Shapes], dim: Dim = 0
|
|
1573
|
+
) -> Tensor[stack_shape(Shapes, Dim)]:
|
|
1528
1574
|
"""Stack tensors (adds new dimension)."""
|
|
1529
1575
|
...
|
|
1530
1576
|
|
|
@@ -1568,32 +1614,32 @@ def unsqueeze[Shape: IntTuple, Dim: Flag[builtins.int]](
|
|
|
1568
1614
|
@overload
|
|
1569
1615
|
def repeat_interleave[
|
|
1570
1616
|
Shape: IntTuple,
|
|
1571
|
-
Repeats:
|
|
1572
|
-
OutputSize:
|
|
1617
|
+
Repeats: _Int,
|
|
1618
|
+
OutputSize: _Int,
|
|
1573
1619
|
Dim: Flag[builtins.int | None],
|
|
1574
1620
|
](
|
|
1575
1621
|
input: Tensor[Shape],
|
|
1576
|
-
repeats:
|
|
1622
|
+
repeats: Repeats,
|
|
1577
1623
|
dim: Dim = None,
|
|
1578
1624
|
*,
|
|
1579
|
-
output_size:
|
|
1625
|
+
output_size: OutputSize,
|
|
1580
1626
|
) -> Tensor[repeat_interleave_checked_shape(Shape, Repeats, OutputSize, Dim)]: ...
|
|
1581
1627
|
@overload
|
|
1582
1628
|
def repeat_interleave[
|
|
1583
1629
|
Shape: IntTuple,
|
|
1584
|
-
OutputSize:
|
|
1630
|
+
OutputSize: _Int,
|
|
1585
1631
|
Dim: Flag[builtins.int | None],
|
|
1586
1632
|
](
|
|
1587
1633
|
input: Tensor[Shape],
|
|
1588
1634
|
repeats: Tensor,
|
|
1589
1635
|
dim: Dim = None,
|
|
1590
1636
|
*,
|
|
1591
|
-
output_size:
|
|
1637
|
+
output_size: OutputSize,
|
|
1592
1638
|
) -> Tensor[repeat_interleave_output_shape(Shape, OutputSize, Dim)]: ...
|
|
1593
1639
|
@overload
|
|
1594
|
-
def repeat_interleave[Shape: IntTuple, Repeats:
|
|
1640
|
+
def repeat_interleave[Shape: IntTuple, Repeats: _Int, Dim: Flag[builtins.int | None]](
|
|
1595
1641
|
input: Tensor[Shape],
|
|
1596
|
-
repeats:
|
|
1642
|
+
repeats: Repeats,
|
|
1597
1643
|
dim: Dim = None,
|
|
1598
1644
|
*,
|
|
1599
1645
|
output_size: None = None,
|
|
@@ -1831,7 +1877,7 @@ def full[Shape: IntTuple](size: Shape, fill_value: float) -> Tensor[Shape]:
|
|
|
1831
1877
|
@overload
|
|
1832
1878
|
def arange[End: IntVar](
|
|
1833
1879
|
end: _Int[End], *, dtype: int | None = None, device: Any = None
|
|
1834
|
-
) -> Tensor[[arange_extent(End)]]:
|
|
1880
|
+
) -> Tensor[[arange_extent(_Int[End])]]:
|
|
1835
1881
|
"""Create 1D tensor with range [0, end). Shape inference via meta-shape: torch.arange"""
|
|
1836
1882
|
...
|
|
1837
1883
|
|
|
@@ -1843,7 +1889,7 @@ def arange[Start: IntVar, End: IntVar, Step: Flag[builtins.int]](
|
|
|
1843
1889
|
*,
|
|
1844
1890
|
dtype: int | None = None,
|
|
1845
1891
|
device: Any = None,
|
|
1846
|
-
) -> Tensor[[arange_step_extent(Start, End, Step)]]:
|
|
1892
|
+
) -> Tensor[[arange_step_extent(_Int[Start], _Int[End], Step)]]:
|
|
1847
1893
|
"""Create 1D tensor with range [start, end) with step. Shape inference via meta-shape: torch.arange"""
|
|
1848
1894
|
...
|
|
1849
1895
|
|
|
@@ -1897,22 +1943,53 @@ def select[Shape: IntTuple, Dim: Flag[builtins.int]](
|
|
|
1897
1943
|
"""Select along dimension. Shape inference via meta-shape: torch.select"""
|
|
1898
1944
|
...
|
|
1899
1945
|
|
|
1900
|
-
def narrow[Shape: IntTuple, Dim: Flag[builtins.int], Length:
|
|
1901
|
-
self: Tensor[Shape], dim: Dim, start: int, length:
|
|
1946
|
+
def narrow[Shape: IntTuple, Dim: Flag[builtins.int], Length: _Int](
|
|
1947
|
+
self: Tensor[Shape], dim: Dim, start: int, length: Length
|
|
1902
1948
|
) -> Tensor[replace_axis_extent(Shape, Dim, Length)]:
|
|
1903
1949
|
"""Narrow tensor along dimension. Shape inference via meta-shape: torch.narrow"""
|
|
1904
1950
|
...
|
|
1905
1951
|
|
|
1906
|
-
@
|
|
1952
|
+
@overload
|
|
1953
|
+
def split[
|
|
1954
|
+
Shape: IntTuple,
|
|
1955
|
+
SplitSize: _Int,
|
|
1956
|
+
Dim: Flag[builtins.int],
|
|
1957
|
+
](
|
|
1958
|
+
self: Tensor[Shape], split_size_or_sections: SplitSize, dim: Dim = 0
|
|
1959
|
+
) -> MapIntTuples[lambda S: Tensor[S], split_size_shapes(Shape, SplitSize, Dim)]:
|
|
1960
|
+
"""Split tensor into chunks. Shape inference via the type-level DSL."""
|
|
1961
|
+
...
|
|
1962
|
+
|
|
1963
|
+
@overload
|
|
1964
|
+
def split[
|
|
1965
|
+
Shape: IntTuple,
|
|
1966
|
+
Sections: IntTuple,
|
|
1967
|
+
Dim: Flag[builtins.int],
|
|
1968
|
+
](
|
|
1969
|
+
self: Tensor[Shape], split_size_or_sections: Sections, dim: Dim = 0
|
|
1970
|
+
) -> MapIntTuples[lambda S: Tensor[S], split_sections_shapes(Shape, Sections, Dim)]:
|
|
1971
|
+
"""Split tensor into variable-sized chunks. Shape inference via the type-level DSL."""
|
|
1972
|
+
...
|
|
1973
|
+
|
|
1974
|
+
# A list is mutable, so V2 cannot preserve its element values; this trailing
|
|
1975
|
+
# overload keeps the documented list spelling checking without shape inference.
|
|
1976
|
+
# TODO(stroxler): Route lists through `split_sections_shapes` once list values
|
|
1977
|
+
# survive to the type level.
|
|
1978
|
+
@overload
|
|
1907
1979
|
def split(
|
|
1908
|
-
self: Tensor, split_size_or_sections: int, dim: int = 0
|
|
1980
|
+
self: Tensor, split_size_or_sections: list[int], dim: int = 0
|
|
1909
1981
|
) -> tuple[Tensor, ...]:
|
|
1910
|
-
"""Split tensor into chunks. Shape inference
|
|
1982
|
+
"""Split tensor into variable-sized chunks. Shape inference unavailable for lists."""
|
|
1911
1983
|
...
|
|
1912
1984
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1985
|
+
def chunk[
|
|
1986
|
+
Shape: IntTuple,
|
|
1987
|
+
Chunks: _Int,
|
|
1988
|
+
Dim: Flag[builtins.int],
|
|
1989
|
+
](
|
|
1990
|
+
self: Tensor[Shape], chunks: Chunks, dim: Dim = 0
|
|
1991
|
+
) -> MapIntTuples[lambda S: Tensor[S], chunk_shapes(Shape, Chunks, Dim)]:
|
|
1992
|
+
"""Split tensor into chunks. Shape inference via the type-level DSL."""
|
|
1916
1993
|
...
|
|
1917
1994
|
|
|
1918
1995
|
def index_select[
|
|
@@ -1960,11 +2037,10 @@ def movedim[
|
|
|
1960
2037
|
"""Move a single dimension to a new position."""
|
|
1961
2038
|
...
|
|
1962
2039
|
|
|
1963
|
-
@uses_shape_dsl(movedim_input_ir)
|
|
1964
2040
|
@overload
|
|
1965
|
-
def movedim(
|
|
1966
|
-
input: Tensor, source:
|
|
1967
|
-
) -> Tensor:
|
|
2041
|
+
def movedim[Shape: IntTuple, Source: IntTuple, Destination: IntTuple](
|
|
2042
|
+
input: Tensor[Shape], source: Source, destination: Destination
|
|
2043
|
+
) -> Tensor[movedim_tuple_shape(Shape, Source, Destination)]:
|
|
1968
2044
|
"""Move multiple dimensions to new positions. Shape inference via meta-shape: torch.movedim"""
|
|
1969
2045
|
...
|
|
1970
2046
|
|
|
@@ -1979,11 +2055,10 @@ def moveaxis[
|
|
|
1979
2055
|
"""Alias for movedim with a single source and destination."""
|
|
1980
2056
|
...
|
|
1981
2057
|
|
|
1982
|
-
@uses_shape_dsl(movedim_input_ir)
|
|
1983
2058
|
@overload
|
|
1984
|
-
def moveaxis(
|
|
1985
|
-
input: Tensor, source:
|
|
1986
|
-
) -> Tensor:
|
|
2059
|
+
def moveaxis[Shape: IntTuple, Source: IntTuple, Destination: IntTuple](
|
|
2060
|
+
input: Tensor[Shape], source: Source, destination: Destination
|
|
2061
|
+
) -> Tensor[movedim_tuple_shape(Shape, Source, Destination)]:
|
|
1987
2062
|
"""Alias for movedim. Shape inference via meta-shape: torch.moveaxis"""
|
|
1988
2063
|
...
|
|
1989
2064
|
|
|
@@ -2114,9 +2189,9 @@ def mode[Shape: IntTuple, Dim: Flag[builtins.int], Keepdim: Flag[builtins.bool]]
|
|
|
2114
2189
|
"""Mode along dimension. Returns (values, indices). Shape inference via meta-shape: torch.mode"""
|
|
2115
2190
|
...
|
|
2116
2191
|
|
|
2117
|
-
def topk[Shape: IntTuple, K:
|
|
2192
|
+
def topk[Shape: IntTuple, K: _Int, Dim: Flag[builtins.int]](
|
|
2118
2193
|
self: Tensor[Shape],
|
|
2119
|
-
k:
|
|
2194
|
+
k: K,
|
|
2120
2195
|
dim: Dim = -1,
|
|
2121
2196
|
largest: bool = True,
|
|
2122
2197
|
sorted: bool = True,
|
|
@@ -2590,9 +2665,10 @@ def tensordot(self: Tensor, other: Tensor, dims: tuple[list[int], list[int]]) ->
|
|
|
2590
2665
|
"""
|
|
2591
2666
|
...
|
|
2592
2667
|
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2668
|
+
def einsum[Spec: Flag[str], Shapes: IntTuples](
|
|
2669
|
+
spec: Spec, *operands: Unpack[MapIntTuples[lambda S: Tensor[S], Shapes]]
|
|
2670
|
+
) -> Tensor[einsum_shape(Spec, Shapes)]:
|
|
2671
|
+
"""Einstein summation convention. Shape inference via type-level DSL."""
|
|
2596
2672
|
...
|
|
2597
2673
|
|
|
2598
2674
|
# Eigenvalue decomposition
|
|
@@ -2759,9 +2835,9 @@ def bernoulli[Shape: IntTuple](input: Tensor[Shape], p: float = 0.5) -> Tensor[S
|
|
|
2759
2835
|
"""Sample from Bernoulli distribution. Shape inference via generic fixture signature."""
|
|
2760
2836
|
...
|
|
2761
2837
|
|
|
2762
|
-
def multinomial[Shape: IntTuple, NumSamples:
|
|
2838
|
+
def multinomial[Shape: IntTuple, NumSamples: _Int](
|
|
2763
2839
|
input: Tensor[Shape],
|
|
2764
|
-
num_samples:
|
|
2840
|
+
num_samples: NumSamples,
|
|
2765
2841
|
replacement: bool = False,
|
|
2766
2842
|
) -> Tensor[multinomial_shape(Shape, NumSamples)]:
|
|
2767
2843
|
"""Sample from multinomial distribution. Shape inference via meta-shape: torch.multinomial"""
|