pyrefly-einops-stubs 1.4.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyrefly-einops-stubs
3
+ Version: 1.4.0
4
+ Summary: Einops type stubs with tensor-shape tracking, maintained by Pyrefly
5
+ Project-URL: homepage, https://pyrefly.org
6
+ Project-URL: documentation, https://pyrefly.org/en/docs/
7
+ License: MIT License
8
+
9
+ Copyright (c) Meta Platforms, Inc. and affiliates.
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Keywords: einops,stubs,typechecker,typechecking
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Typing :: Stubs Only
35
+ Requires-Python: >=3.12
36
+ Requires-Dist: pyrefly-shape-extensions==1.4.0
37
+ Requires-Dist: pyrefly-torch-stubs==1.4.0
38
+ Description-Content-Type: text/markdown
39
+
40
+ # Pyrefly einops shape stubs
41
+
42
+ This package is a PEP 561 stub-only distribution for `einops`. It provides
43
+ shape-aware annotations for `rearrange`, `reduce`, `repeat`, and `einsum` using
44
+ Pyrefly's type-level shape DSL. The `einops.layers.torch` `Rearrange` and `Reduce`
45
+ modules preserve the constructor pattern and axis lengths across calls.
46
+
47
+ The precise annotations currently target PyTorch. The runtime corpus also
48
+ exercises NumPy and JAX to validate that the shared einops pattern semantics
49
+ agree across backends.
50
+
51
+ TODO: Once Pyrefly supports a `MapShape` type operator, make the annotations
52
+ generic over array libraries while preserving the input's nominal array type.
53
+
54
+ Literal `axes_lengths` keyword arguments are carried into the shape rules, so named
55
+ input splits and repeated output axes remain tracked. Dynamically unpacked mappings
56
+ preserve the known rank but use gradual dimensions for unknown axis lengths.
57
+
58
+ Run the static tests with:
59
+
60
+ ```bash
61
+ python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
62
+ ```
@@ -0,0 +1,23 @@
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
+ ```
@@ -0,0 +1,90 @@
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: ...
@@ -0,0 +1,23 @@
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
+ import shape_extensions.dsl as dsl
7
+ from shape_extensions import IntTuple, IntTuples, NamedInts, type_shape_dsl_function
8
+
9
+ @type_shape_dsl_function
10
+ def rearrange_shape(pattern: str, shape: IntTuple, axes: NamedInts) -> IntTuple:
11
+ return dsl.rearrange(pattern, shape, axes)
12
+
13
+ @type_shape_dsl_function
14
+ def reduce_shape(pattern: str, shape: IntTuple, axes: NamedInts) -> IntTuple:
15
+ return dsl.reduce(pattern, shape, axes)
16
+
17
+ @type_shape_dsl_function
18
+ def repeat_shape(pattern: str, shape: IntTuple, axes: NamedInts) -> IntTuple:
19
+ return dsl.repeat(pattern, shape, axes)
20
+
21
+ @type_shape_dsl_function
22
+ def einsum_shape(pattern: str, shapes: IntTuples) -> IntTuple:
23
+ return dsl.einops_einsum(pattern, shapes)
@@ -0,0 +1,39 @@
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 shape_extensions import CaptureNamedInts, Flag, IntTuple, NamedInts
7
+ from torch import Tensor
8
+ from torch.nn import Module
9
+
10
+ from .._shapes import rearrange_shape, reduce_shape
11
+
12
+ class Rearrange[Pattern: Flag[str], Axes: NamedInts](Module):
13
+ def __init__(
14
+ self, pattern: Pattern, **axes_lengths: CaptureNamedInts[Axes]
15
+ ) -> None: ...
16
+ def forward[Shape: IntTuple](
17
+ self, input: Tensor[Shape]
18
+ ) -> Tensor[rearrange_shape(Pattern, Shape, Axes)]: ...
19
+
20
+ class Reduce[Pattern: Flag[str], Axes: NamedInts](Module):
21
+ def __init__(
22
+ self,
23
+ pattern: Pattern,
24
+ reduction: str,
25
+ **axes_lengths: CaptureNamedInts[Axes],
26
+ ) -> None: ...
27
+ def forward[Shape: IntTuple](
28
+ self, input: Tensor[Shape]
29
+ ) -> Tensor[reduce_shape(Pattern, Shape, Axes)]: ...
30
+
31
+ class EinMix(Module):
32
+ def __init__(
33
+ self,
34
+ pattern: str,
35
+ weight_shape: str,
36
+ bias_shape: str | None = None,
37
+ **axes_lengths: int,
38
+ ) -> None: ...
39
+ def forward(self, input: Tensor[IntTuple]) -> Tensor[IntTuple]: ...
@@ -0,0 +1 @@
1
+ partial
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pyrefly-einops-stubs"
7
+ description = "Einops type stubs with tensor-shape tracking, maintained by Pyrefly"
8
+ readme = "README.md"
9
+ requires-python = ">=3.12"
10
+ license = { file = "LICENSE" }
11
+ version = "1.4.0"
12
+ keywords = ["typechecker", "typechecking", "stubs", "einops"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3",
18
+ "Typing :: Stubs Only",
19
+ ]
20
+ dependencies = [
21
+ "pyrefly-shape-extensions==1.4.0",
22
+ "pyrefly-torch-stubs==1.4.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ homepage = "https://pyrefly.org"
27
+ documentation = "https://pyrefly.org/en/docs/"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ only-include = ["einops-stubs"]
31
+
32
+ [tool.hatch.build.targets.sdist]
33
+ include = ["einops-stubs/", "README.md", "LICENSE"]