pyrefly-einops-stubs 1.5.0.dev1__tar.gz → 1.6.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.
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/PKG-INFO +34 -11
- pyrefly_einops_stubs-1.6.0.dev1/README.md +41 -0
- pyrefly_einops_stubs-1.6.0.dev1/einops-stubs/__init__.pyi +211 -0
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/pyproject.toml +10 -3
- pyrefly_einops_stubs-1.5.0.dev1/README.md +0 -23
- pyrefly_einops_stubs-1.5.0.dev1/einops-stubs/__init__.pyi +0 -90
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/LICENSE +0 -0
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/_shapes.pyi +0 -0
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/layers/__init__.pyi +0 -0
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/layers/torch.pyi +0 -0
- {pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyrefly-einops-stubs
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.0.dev1
|
|
4
4
|
Summary: Einops 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,23 +33,45 @@ 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.
|
|
37
|
-
|
|
36
|
+
Requires-Dist: pyrefly-shape-extensions==1.6.0.dev1
|
|
37
|
+
Provides-Extra: jax
|
|
38
|
+
Requires-Dist: jax-pyrefly-stubs==1.6.0.dev1; extra == 'jax'
|
|
39
|
+
Provides-Extra: numpy
|
|
40
|
+
Requires-Dist: pyrefly-numpy-stubs==1.6.0.dev1; extra == 'numpy'
|
|
41
|
+
Provides-Extra: torch
|
|
42
|
+
Requires-Dist: pyrefly-torch-stubs==1.6.0.dev1; extra == 'torch'
|
|
38
43
|
Description-Content-Type: text/markdown
|
|
39
44
|
|
|
40
45
|
# Pyrefly einops shape stubs
|
|
41
46
|
|
|
42
|
-
This package
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
This package installs `einops-shape-stubs`, a Pyrefly-specific stub package for
|
|
48
|
+
runtime `einops`. Pyrefly discovers it by default; set
|
|
49
|
+
`use-shape-comments-and-stubs = false` to opt out. Other type checkers ignore these
|
|
50
|
+
stubs and continue using einops's ordinary types.
|
|
51
|
+
|
|
52
|
+
It provides shape-aware annotations for `rearrange`, `reduce`, `repeat`, and
|
|
53
|
+
`einsum` using Pyrefly's type-level shape DSL. The `einops.layers.torch` `Rearrange` and `Reduce`
|
|
45
54
|
modules preserve the constructor pattern and axis lengths across calls.
|
|
46
55
|
|
|
47
|
-
The precise annotations
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
The precise annotations target PyTorch, NumPy, and JAX. Shape computations are
|
|
57
|
+
shared; backend overloads describe their different result types. NumPy `rearrange`
|
|
58
|
+
and `repeat` preserve `ndarray` and its dtype. NumPy reductions and `einsum` may
|
|
59
|
+
return array scalars, so their result protocol preserves shape and array conversion
|
|
60
|
+
without promising `ndarray` or a dtype that reductions may promote. The precise
|
|
61
|
+
NumPy reduction and `einsum` overloads cover numeric and boolean dtypes; object-dtype
|
|
62
|
+
operations can return arbitrary Python objects and use the gradual fallback.
|
|
63
|
+
|
|
64
|
+
Backend shape stubs are optional dependencies: install the `torch`, `numpy`, or
|
|
65
|
+
`jax` extra, or combine them as `[torch,numpy,jax]`. The base package does not
|
|
66
|
+
install an array library. Install matching shape stubs for each of these backends
|
|
67
|
+
present in your environment. Existing Torch users upgrading from the base package
|
|
68
|
+
must add `[torch]` to retain Torch shape stubs.
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
Shape precision with optional backends requires Pyrefly's missing-import overload
|
|
71
|
+
preference. It favors resolved input contracts without adding call warnings,
|
|
72
|
+
while preserving return-only recovery and ordinary ambiguity for gradual arguments.
|
|
73
|
+
Do not configure `replace-imports-with-any` or `ignore-missing-imports` for absent
|
|
74
|
+
backends: those settings erase the provenance of unavailable annotations.
|
|
53
75
|
|
|
54
76
|
Literal `axes_lengths` keyword arguments are carried into the shape rules, so named
|
|
55
77
|
input splits and repeated output axes remain tracked. Dynamically unpacked mappings
|
|
@@ -59,4 +81,5 @@ Run the static tests with:
|
|
|
59
81
|
|
|
60
82
|
```bash
|
|
61
83
|
python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
|
|
84
|
+
python3 tensor-shapes/pyrefly-einops-stubs/run_optional_backends.py --pyrefly /path/to/pyrefly
|
|
62
85
|
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Pyrefly einops shape stubs
|
|
2
|
+
|
|
3
|
+
This package installs `einops-shape-stubs`, a Pyrefly-specific stub package for
|
|
4
|
+
runtime `einops`. Pyrefly discovers it by default; set
|
|
5
|
+
`use-shape-comments-and-stubs = false` to opt out. Other type checkers ignore these
|
|
6
|
+
stubs and continue using einops's ordinary types.
|
|
7
|
+
|
|
8
|
+
It provides shape-aware annotations for `rearrange`, `reduce`, `repeat`, and
|
|
9
|
+
`einsum` using Pyrefly's type-level shape DSL. The `einops.layers.torch` `Rearrange` and `Reduce`
|
|
10
|
+
modules preserve the constructor pattern and axis lengths across calls.
|
|
11
|
+
|
|
12
|
+
The precise annotations target PyTorch, NumPy, and JAX. Shape computations are
|
|
13
|
+
shared; backend overloads describe their different result types. NumPy `rearrange`
|
|
14
|
+
and `repeat` preserve `ndarray` and its dtype. NumPy reductions and `einsum` may
|
|
15
|
+
return array scalars, so their result protocol preserves shape and array conversion
|
|
16
|
+
without promising `ndarray` or a dtype that reductions may promote. The precise
|
|
17
|
+
NumPy reduction and `einsum` overloads cover numeric and boolean dtypes; object-dtype
|
|
18
|
+
operations can return arbitrary Python objects and use the gradual fallback.
|
|
19
|
+
|
|
20
|
+
Backend shape stubs are optional dependencies: install the `torch`, `numpy`, or
|
|
21
|
+
`jax` extra, or combine them as `[torch,numpy,jax]`. The base package does not
|
|
22
|
+
install an array library. Install matching shape stubs for each of these backends
|
|
23
|
+
present in your environment. Existing Torch users upgrading from the base package
|
|
24
|
+
must add `[torch]` to retain Torch shape stubs.
|
|
25
|
+
|
|
26
|
+
Shape precision with optional backends requires Pyrefly's missing-import overload
|
|
27
|
+
preference. It favors resolved input contracts without adding call warnings,
|
|
28
|
+
while preserving return-only recovery and ordinary ambiguity for gradual arguments.
|
|
29
|
+
Do not configure `replace-imports-with-any` or `ignore-missing-imports` for absent
|
|
30
|
+
backends: those settings erase the provenance of unavailable annotations.
|
|
31
|
+
|
|
32
|
+
Literal `axes_lengths` keyword arguments are carried into the shape rules, so named
|
|
33
|
+
input splits and repeated output axes remain tracked. Dynamically unpacked mappings
|
|
34
|
+
preserve the known rank but use gradual dimensions for unknown axis lengths.
|
|
35
|
+
|
|
36
|
+
Run the static tests with:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
|
|
40
|
+
python3 tensor-shapes/pyrefly-einops-stubs/run_optional_backends.py --pyrefly /path/to/pyrefly
|
|
41
|
+
```
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
from typing import Any, overload, Protocol
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from jax import Array as JaxArray
|
|
11
|
+
from shape_extensions import CaptureNamedInts, Flag, IntTuple, NamedInts
|
|
12
|
+
from torch import Tensor
|
|
13
|
+
|
|
14
|
+
from ._shapes import einsum_shape, rearrange_shape, reduce_shape, repeat_shape
|
|
15
|
+
|
|
16
|
+
__version__: str
|
|
17
|
+
|
|
18
|
+
class _Array[Shape: IntTuple = IntTuple](Protocol):
|
|
19
|
+
@property
|
|
20
|
+
def shape(self) -> Shape: ...
|
|
21
|
+
|
|
22
|
+
class _NumpyResult[Shape: IntTuple = IntTuple](_Array[Shape], Protocol):
|
|
23
|
+
# NumPy reductions and einsum may return either arrays or array scalars.
|
|
24
|
+
@property
|
|
25
|
+
def dtype(self) -> np.dtype[Any]: ...
|
|
26
|
+
def __array__(self) -> np.ndarray[Shape, Any]: ...
|
|
27
|
+
|
|
28
|
+
class EinopsError(RuntimeError): ...
|
|
29
|
+
|
|
30
|
+
def asnumpy[Shape: IntTuple](tensor: _Array[Shape]) -> _Array[Shape]: ...
|
|
31
|
+
def parse_shape(tensor: Tensor, pattern: str) -> dict[str, int]: ...
|
|
32
|
+
|
|
33
|
+
# TODO: Add shape primitives for the `*` packing pattern so these return precise shapes.
|
|
34
|
+
def pack(
|
|
35
|
+
tensors: Sequence[Tensor], pattern: str
|
|
36
|
+
) -> tuple[Tensor[IntTuple], list[tuple[int, ...]]]: ...
|
|
37
|
+
def unpack(
|
|
38
|
+
tensor: Tensor,
|
|
39
|
+
packed_shapes: Sequence[Sequence[int]],
|
|
40
|
+
pattern: str,
|
|
41
|
+
) -> list[Tensor[IntTuple]]: ...
|
|
42
|
+
@overload
|
|
43
|
+
def rearrange[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
44
|
+
tensor: Tensor[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
45
|
+
) -> Tensor[rearrange_shape(Pattern, Shape, Axes)]: ...
|
|
46
|
+
@overload
|
|
47
|
+
def rearrange[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
48
|
+
tensor: JaxArray[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
49
|
+
) -> JaxArray[rearrange_shape(Pattern, Shape, Axes)]: ...
|
|
50
|
+
@overload
|
|
51
|
+
def rearrange[Shape: IntTuple, DType, Pattern: Flag[str], Axes: NamedInts](
|
|
52
|
+
tensor: np.ndarray[Shape, DType],
|
|
53
|
+
pattern: Pattern,
|
|
54
|
+
**axes_lengths: CaptureNamedInts[Axes],
|
|
55
|
+
) -> np.ndarray[rearrange_shape(Pattern, Shape, Axes), DType]: ...
|
|
56
|
+
@overload
|
|
57
|
+
def rearrange(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
58
|
+
@overload
|
|
59
|
+
def reduce[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
60
|
+
tensor: Tensor[Shape],
|
|
61
|
+
pattern: Pattern,
|
|
62
|
+
reduction: Any,
|
|
63
|
+
**axes_lengths: CaptureNamedInts[Axes],
|
|
64
|
+
) -> Tensor[reduce_shape(Pattern, Shape, Axes)]: ...
|
|
65
|
+
@overload
|
|
66
|
+
def reduce[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
67
|
+
tensor: JaxArray[Shape],
|
|
68
|
+
pattern: Pattern,
|
|
69
|
+
reduction: Any,
|
|
70
|
+
**axes_lengths: CaptureNamedInts[Axes],
|
|
71
|
+
) -> JaxArray[reduce_shape(Pattern, Shape, Axes)]: ...
|
|
72
|
+
@overload
|
|
73
|
+
def reduce[
|
|
74
|
+
Shape: IntTuple,
|
|
75
|
+
Scalar: np.number | np.bool_,
|
|
76
|
+
Pattern: Flag[str],
|
|
77
|
+
Axes: NamedInts,
|
|
78
|
+
](
|
|
79
|
+
tensor: np.ndarray[Shape, np.dtype[Scalar]],
|
|
80
|
+
pattern: Pattern,
|
|
81
|
+
reduction: Any,
|
|
82
|
+
**axes_lengths: CaptureNamedInts[Axes],
|
|
83
|
+
) -> _NumpyResult[reduce_shape(Pattern, Shape, Axes)]: ...
|
|
84
|
+
@overload
|
|
85
|
+
def reduce(tensor: Any, pattern: str, reduction: Any, **axes_lengths: int) -> Any: ...
|
|
86
|
+
@overload
|
|
87
|
+
def repeat[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
88
|
+
tensor: Tensor[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
89
|
+
) -> Tensor[repeat_shape(Pattern, Shape, Axes)]: ...
|
|
90
|
+
@overload
|
|
91
|
+
def repeat[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
92
|
+
tensor: JaxArray[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
93
|
+
) -> JaxArray[repeat_shape(Pattern, Shape, Axes)]: ...
|
|
94
|
+
@overload
|
|
95
|
+
def repeat[Shape: IntTuple, DType, Pattern: Flag[str], Axes: NamedInts](
|
|
96
|
+
tensor: np.ndarray[Shape, DType],
|
|
97
|
+
pattern: Pattern,
|
|
98
|
+
**axes_lengths: CaptureNamedInts[Axes],
|
|
99
|
+
) -> np.ndarray[repeat_shape(Pattern, Shape, Axes), DType]: ...
|
|
100
|
+
@overload
|
|
101
|
+
def repeat(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
102
|
+
@overload
|
|
103
|
+
def einsum[S1: IntTuple, Pattern: Flag[str]](
|
|
104
|
+
tensor: Tensor[S1], pattern: Pattern, /
|
|
105
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1])]: ...
|
|
106
|
+
@overload
|
|
107
|
+
def einsum[S1: IntTuple, S2: IntTuple, Pattern: Flag[str]](
|
|
108
|
+
tensor1: Tensor[S1], tensor2: Tensor[S2], pattern: Pattern, /
|
|
109
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2])]: ...
|
|
110
|
+
@overload
|
|
111
|
+
def einsum[S1: IntTuple, S2: IntTuple, S3: IntTuple, Pattern: Flag[str]](
|
|
112
|
+
tensor1: Tensor[S1],
|
|
113
|
+
tensor2: Tensor[S2],
|
|
114
|
+
tensor3: Tensor[S3],
|
|
115
|
+
pattern: Pattern,
|
|
116
|
+
/,
|
|
117
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3])]: ...
|
|
118
|
+
@overload
|
|
119
|
+
def einsum[
|
|
120
|
+
S1: IntTuple,
|
|
121
|
+
S2: IntTuple,
|
|
122
|
+
S3: IntTuple,
|
|
123
|
+
S4: IntTuple,
|
|
124
|
+
Pattern: Flag[str],
|
|
125
|
+
](
|
|
126
|
+
tensor1: Tensor[S1],
|
|
127
|
+
tensor2: Tensor[S2],
|
|
128
|
+
tensor3: Tensor[S3],
|
|
129
|
+
tensor4: Tensor[S4],
|
|
130
|
+
pattern: Pattern,
|
|
131
|
+
/,
|
|
132
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3, S4])]: ...
|
|
133
|
+
@overload
|
|
134
|
+
def einsum[S1: IntTuple, Pattern: Flag[str]](
|
|
135
|
+
tensor: JaxArray[S1], pattern: Pattern, /
|
|
136
|
+
) -> JaxArray[einsum_shape(Pattern, tuple[S1])]: ...
|
|
137
|
+
@overload
|
|
138
|
+
def einsum[S1: IntTuple, S2: IntTuple, Pattern: Flag[str]](
|
|
139
|
+
tensor1: JaxArray[S1], tensor2: JaxArray[S2], pattern: Pattern, /
|
|
140
|
+
) -> JaxArray[einsum_shape(Pattern, tuple[S1, S2])]: ...
|
|
141
|
+
@overload
|
|
142
|
+
def einsum[S1: IntTuple, S2: IntTuple, S3: IntTuple, Pattern: Flag[str]](
|
|
143
|
+
tensor1: JaxArray[S1],
|
|
144
|
+
tensor2: JaxArray[S2],
|
|
145
|
+
tensor3: JaxArray[S3],
|
|
146
|
+
pattern: Pattern,
|
|
147
|
+
/,
|
|
148
|
+
) -> JaxArray[einsum_shape(Pattern, tuple[S1, S2, S3])]: ...
|
|
149
|
+
@overload
|
|
150
|
+
def einsum[
|
|
151
|
+
S1: IntTuple,
|
|
152
|
+
S2: IntTuple,
|
|
153
|
+
S3: IntTuple,
|
|
154
|
+
S4: IntTuple,
|
|
155
|
+
Pattern: Flag[str],
|
|
156
|
+
](
|
|
157
|
+
tensor1: JaxArray[S1],
|
|
158
|
+
tensor2: JaxArray[S2],
|
|
159
|
+
tensor3: JaxArray[S3],
|
|
160
|
+
tensor4: JaxArray[S4],
|
|
161
|
+
pattern: Pattern,
|
|
162
|
+
/,
|
|
163
|
+
) -> JaxArray[einsum_shape(Pattern, tuple[S1, S2, S3, S4])]: ...
|
|
164
|
+
@overload
|
|
165
|
+
def einsum[S1: IntTuple, Scalar: np.number | np.bool_, Pattern: Flag[str]](
|
|
166
|
+
tensor: np.ndarray[S1, np.dtype[Scalar]], pattern: Pattern, /
|
|
167
|
+
) -> _NumpyResult[einsum_shape(Pattern, tuple[S1])]: ...
|
|
168
|
+
@overload
|
|
169
|
+
def einsum[
|
|
170
|
+
S1: IntTuple,
|
|
171
|
+
S2: IntTuple,
|
|
172
|
+
Scalar: np.number | np.bool_,
|
|
173
|
+
Pattern: Flag[str],
|
|
174
|
+
](
|
|
175
|
+
tensor1: np.ndarray[S1, np.dtype[Scalar]],
|
|
176
|
+
tensor2: np.ndarray[S2, np.dtype[Scalar]],
|
|
177
|
+
pattern: Pattern,
|
|
178
|
+
/,
|
|
179
|
+
) -> _NumpyResult[einsum_shape(Pattern, tuple[S1, S2])]: ...
|
|
180
|
+
@overload
|
|
181
|
+
def einsum[
|
|
182
|
+
S1: IntTuple,
|
|
183
|
+
S2: IntTuple,
|
|
184
|
+
S3: IntTuple,
|
|
185
|
+
Scalar: np.number | np.bool_,
|
|
186
|
+
Pattern: Flag[str],
|
|
187
|
+
](
|
|
188
|
+
tensor1: np.ndarray[S1, np.dtype[Scalar]],
|
|
189
|
+
tensor2: np.ndarray[S2, np.dtype[Scalar]],
|
|
190
|
+
tensor3: np.ndarray[S3, np.dtype[Scalar]],
|
|
191
|
+
pattern: Pattern,
|
|
192
|
+
/,
|
|
193
|
+
) -> _NumpyResult[einsum_shape(Pattern, tuple[S1, S2, S3])]: ...
|
|
194
|
+
@overload
|
|
195
|
+
def einsum[
|
|
196
|
+
S1: IntTuple,
|
|
197
|
+
S2: IntTuple,
|
|
198
|
+
S3: IntTuple,
|
|
199
|
+
S4: IntTuple,
|
|
200
|
+
Scalar: np.number | np.bool_,
|
|
201
|
+
Pattern: Flag[str],
|
|
202
|
+
](
|
|
203
|
+
tensor1: np.ndarray[S1, np.dtype[Scalar]],
|
|
204
|
+
tensor2: np.ndarray[S2, np.dtype[Scalar]],
|
|
205
|
+
tensor3: np.ndarray[S3, np.dtype[Scalar]],
|
|
206
|
+
tensor4: np.ndarray[S4, np.dtype[Scalar]],
|
|
207
|
+
pattern: Pattern,
|
|
208
|
+
/,
|
|
209
|
+
) -> _NumpyResult[einsum_shape(Pattern, tuple[S1, S2, S3, S4])]: ...
|
|
210
|
+
@overload
|
|
211
|
+
def einsum(*tensors_and_pattern: Any) -> Any: ...
|
|
@@ -8,7 +8,7 @@ description = "Einops type stubs with tensor-shape tracking, maintained by Pyref
|
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.
|
|
11
|
+
version = "1.6.0.dev1"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "stubs", "einops"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
|
@@ -18,10 +18,14 @@ classifiers = [
|
|
|
18
18
|
"Typing :: Stubs Only",
|
|
19
19
|
]
|
|
20
20
|
dependencies = [
|
|
21
|
-
"pyrefly-shape-extensions==1.
|
|
22
|
-
"pyrefly-torch-stubs==1.5.0.dev1",
|
|
21
|
+
"pyrefly-shape-extensions==1.6.0.dev1",
|
|
23
22
|
]
|
|
24
23
|
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
torch = ["pyrefly-torch-stubs==1.6.0.dev1"]
|
|
26
|
+
jax = ["jax-pyrefly-stubs==1.6.0.dev1"]
|
|
27
|
+
numpy = ["pyrefly-numpy-stubs==1.6.0.dev1"]
|
|
28
|
+
|
|
25
29
|
[project.urls]
|
|
26
30
|
homepage = "https://pyrefly.org"
|
|
27
31
|
documentation = "https://pyrefly.org/en/docs/"
|
|
@@ -29,5 +33,8 @@ documentation = "https://pyrefly.org/en/docs/"
|
|
|
29
33
|
[tool.hatch.build.targets.wheel]
|
|
30
34
|
only-include = ["einops-stubs"]
|
|
31
35
|
|
|
36
|
+
[tool.hatch.build.targets.wheel.sources]
|
|
37
|
+
"einops-stubs" = "einops-shape-stubs"
|
|
38
|
+
|
|
32
39
|
[tool.hatch.build.targets.sdist]
|
|
33
40
|
include = ["einops-stubs/", "README.md", "LICENSE"]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Pyrefly einops shape stubs
|
|
2
|
-
|
|
3
|
-
This package is a PEP 561 stub-only distribution for `einops`. It provides
|
|
4
|
-
shape-aware annotations for `rearrange`, `reduce`, `repeat`, and `einsum` using
|
|
5
|
-
Pyrefly's type-level shape DSL. The `einops.layers.torch` `Rearrange` and `Reduce`
|
|
6
|
-
modules preserve the constructor pattern and axis lengths across calls.
|
|
7
|
-
|
|
8
|
-
The precise annotations currently target PyTorch. The runtime corpus also
|
|
9
|
-
exercises NumPy and JAX to validate that the shared einops pattern semantics
|
|
10
|
-
agree across backends.
|
|
11
|
-
|
|
12
|
-
TODO: Once Pyrefly supports a `MapShape` type operator, make the annotations
|
|
13
|
-
generic over array libraries while preserving the input's nominal array type.
|
|
14
|
-
|
|
15
|
-
Literal `axes_lengths` keyword arguments are carried into the shape rules, so named
|
|
16
|
-
input splits and repeated output axes remain tracked. Dynamically unpacked mappings
|
|
17
|
-
preserve the known rank but use gradual dimensions for unknown axis lengths.
|
|
18
|
-
|
|
19
|
-
Run the static tests with:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
|
|
23
|
-
```
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
#
|
|
3
|
-
# This source code is licensed under the MIT license found in the
|
|
4
|
-
# LICENSE file in the root directory of this source tree.
|
|
5
|
-
|
|
6
|
-
from collections.abc import Sequence
|
|
7
|
-
from typing import Any, overload, Protocol
|
|
8
|
-
|
|
9
|
-
from shape_extensions import CaptureNamedInts, Flag, IntTuple, NamedInts
|
|
10
|
-
from torch import Tensor
|
|
11
|
-
|
|
12
|
-
from ._shapes import einsum_shape, rearrange_shape, reduce_shape, repeat_shape
|
|
13
|
-
|
|
14
|
-
__version__: str
|
|
15
|
-
|
|
16
|
-
class _Array[Shape: IntTuple = IntTuple](Protocol):
|
|
17
|
-
@property
|
|
18
|
-
def shape(self) -> Shape: ...
|
|
19
|
-
|
|
20
|
-
class EinopsError(RuntimeError): ...
|
|
21
|
-
|
|
22
|
-
def asnumpy[Shape: IntTuple](tensor: _Array[Shape]) -> _Array[Shape]: ...
|
|
23
|
-
def parse_shape(tensor: Tensor, pattern: str) -> dict[str, int]: ...
|
|
24
|
-
|
|
25
|
-
# TODO: Add shape primitives for the `*` packing pattern so these return precise shapes.
|
|
26
|
-
def pack(
|
|
27
|
-
tensors: Sequence[Tensor], pattern: str
|
|
28
|
-
) -> tuple[Tensor[IntTuple], list[tuple[int, ...]]]: ...
|
|
29
|
-
def unpack(
|
|
30
|
-
tensor: Tensor,
|
|
31
|
-
packed_shapes: Sequence[Sequence[int]],
|
|
32
|
-
pattern: str,
|
|
33
|
-
) -> list[Tensor[IntTuple]]: ...
|
|
34
|
-
|
|
35
|
-
# TODO: Replace these Torch-specific overloads with library-agnostic `MapShape`
|
|
36
|
-
# signatures that preserve each input array's nominal type.
|
|
37
|
-
@overload
|
|
38
|
-
def rearrange[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
39
|
-
tensor: Tensor[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
40
|
-
) -> Tensor[rearrange_shape(Pattern, Shape, Axes)]: ...
|
|
41
|
-
@overload
|
|
42
|
-
def rearrange(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
43
|
-
@overload
|
|
44
|
-
def reduce[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
45
|
-
tensor: Tensor[Shape],
|
|
46
|
-
pattern: Pattern,
|
|
47
|
-
reduction: Any,
|
|
48
|
-
**axes_lengths: CaptureNamedInts[Axes],
|
|
49
|
-
) -> Tensor[reduce_shape(Pattern, Shape, Axes)]: ...
|
|
50
|
-
@overload
|
|
51
|
-
def reduce(tensor: Any, pattern: str, reduction: Any, **axes_lengths: int) -> Any: ...
|
|
52
|
-
@overload
|
|
53
|
-
def repeat[Shape: IntTuple, Pattern: Flag[str], Axes: NamedInts](
|
|
54
|
-
tensor: Tensor[Shape], pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
|
|
55
|
-
) -> Tensor[repeat_shape(Pattern, Shape, Axes)]: ...
|
|
56
|
-
@overload
|
|
57
|
-
def repeat(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
58
|
-
@overload
|
|
59
|
-
def einsum[S1: IntTuple, Pattern: Flag[str]](
|
|
60
|
-
tensor: Tensor[S1], pattern: Pattern, /
|
|
61
|
-
) -> Tensor[einsum_shape(Pattern, tuple[S1])]: ...
|
|
62
|
-
@overload
|
|
63
|
-
def einsum[S1: IntTuple, S2: IntTuple, Pattern: Flag[str]](
|
|
64
|
-
tensor1: Tensor[S1], tensor2: Tensor[S2], pattern: Pattern, /
|
|
65
|
-
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2])]: ...
|
|
66
|
-
@overload
|
|
67
|
-
def einsum[S1: IntTuple, S2: IntTuple, S3: IntTuple, Pattern: Flag[str]](
|
|
68
|
-
tensor1: Tensor[S1],
|
|
69
|
-
tensor2: Tensor[S2],
|
|
70
|
-
tensor3: Tensor[S3],
|
|
71
|
-
pattern: Pattern,
|
|
72
|
-
/,
|
|
73
|
-
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3])]: ...
|
|
74
|
-
@overload
|
|
75
|
-
def einsum[
|
|
76
|
-
S1: IntTuple,
|
|
77
|
-
S2: IntTuple,
|
|
78
|
-
S3: IntTuple,
|
|
79
|
-
S4: IntTuple,
|
|
80
|
-
Pattern: Flag[str],
|
|
81
|
-
](
|
|
82
|
-
tensor1: Tensor[S1],
|
|
83
|
-
tensor2: Tensor[S2],
|
|
84
|
-
tensor3: Tensor[S3],
|
|
85
|
-
tensor4: Tensor[S4],
|
|
86
|
-
pattern: Pattern,
|
|
87
|
-
/,
|
|
88
|
-
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3, S4])]: ...
|
|
89
|
-
@overload
|
|
90
|
-
def einsum(*tensors_and_pattern: Any) -> Any: ...
|
|
File without changes
|
{pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/_shapes.pyi
RENAMED
|
File without changes
|
{pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/layers/__init__.pyi
RENAMED
|
File without changes
|
{pyrefly_einops_stubs-1.5.0.dev1 → pyrefly_einops_stubs-1.6.0.dev1}/einops-stubs/layers/torch.pyi
RENAMED
|
File without changes
|
|
File without changes
|