pyrefly-einops-stubs 1.4.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.4.0.dev1/LICENSE +21 -0
- pyrefly_einops_stubs-1.4.0.dev1/PKG-INFO +61 -0
- pyrefly_einops_stubs-1.4.0.dev1/README.md +22 -0
- pyrefly_einops_stubs-1.4.0.dev1/einops-stubs/__init__.pyi +97 -0
- pyrefly_einops_stubs-1.4.0.dev1/einops-stubs/_shapes.pyi +23 -0
- pyrefly_einops_stubs-1.4.0.dev1/einops-stubs/py.typed +1 -0
- pyrefly_einops_stubs-1.4.0.dev1/pyproject.toml +33 -0
|
@@ -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,61 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyrefly-einops-stubs
|
|
3
|
+
Version: 1.4.0.dev1
|
|
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.dev1
|
|
37
|
+
Requires-Dist: pyrefly-torch-stubs==1.4.0.dev1
|
|
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.
|
|
45
|
+
|
|
46
|
+
The precise annotations currently target PyTorch. The runtime corpus also
|
|
47
|
+
exercises NumPy and JAX to validate that the shared einops pattern semantics
|
|
48
|
+
agree across backends.
|
|
49
|
+
|
|
50
|
+
TODO: Once Pyrefly supports a `MapShape` type operator, make the annotations
|
|
51
|
+
generic over array libraries while preserving the input's nominal array type.
|
|
52
|
+
|
|
53
|
+
Patterns that need named `axes_lengths` currently return a gradual shape; the
|
|
54
|
+
core evaluator already supports those lengths, and a future call-site bridge
|
|
55
|
+
will make them available to the shape rule.
|
|
56
|
+
|
|
57
|
+
Run the static tests with:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
|
|
61
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
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.
|
|
6
|
+
|
|
7
|
+
The precise annotations currently target PyTorch. The runtime corpus also
|
|
8
|
+
exercises NumPy and JAX to validate that the shared einops pattern semantics
|
|
9
|
+
agree across backends.
|
|
10
|
+
|
|
11
|
+
TODO: Once Pyrefly supports a `MapShape` type operator, make the annotations
|
|
12
|
+
generic over array libraries while preserving the input's nominal array type.
|
|
13
|
+
|
|
14
|
+
Patterns that need named `axes_lengths` currently return a gradual shape; the
|
|
15
|
+
core evaluator already supports those lengths, and a future call-site bridge
|
|
16
|
+
will make them available to the shape rule.
|
|
17
|
+
|
|
18
|
+
Run the static tests with:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python3 tensor-shapes/pyrefly-einops-stubs/run_pyrefly.py --buck
|
|
22
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
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 Flag, IntTuple
|
|
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]](
|
|
39
|
+
tensor: Tensor[Shape], pattern: Pattern
|
|
40
|
+
) -> Tensor[rearrange_shape(Pattern, Shape)]: ...
|
|
41
|
+
@overload
|
|
42
|
+
def rearrange(
|
|
43
|
+
tensor: Tensor, pattern: str, **axes_lengths: int
|
|
44
|
+
) -> Tensor[IntTuple]: ...
|
|
45
|
+
@overload
|
|
46
|
+
def rearrange(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
47
|
+
@overload
|
|
48
|
+
def reduce[Shape: IntTuple, Pattern: Flag[str]](
|
|
49
|
+
tensor: Tensor[Shape], pattern: Pattern, reduction: Any
|
|
50
|
+
) -> Tensor[reduce_shape(Pattern, Shape)]: ...
|
|
51
|
+
@overload
|
|
52
|
+
def reduce(
|
|
53
|
+
tensor: Tensor, pattern: str, reduction: Any, **axes_lengths: int
|
|
54
|
+
) -> Tensor[IntTuple]: ...
|
|
55
|
+
@overload
|
|
56
|
+
def reduce(tensor: Any, pattern: str, reduction: Any, **axes_lengths: int) -> Any: ...
|
|
57
|
+
@overload
|
|
58
|
+
def repeat[Shape: IntTuple, Pattern: Flag[str]](
|
|
59
|
+
tensor: Tensor[Shape], pattern: Pattern
|
|
60
|
+
) -> Tensor[repeat_shape(Pattern, Shape)]: ...
|
|
61
|
+
@overload
|
|
62
|
+
def repeat(tensor: Tensor, pattern: str, **axes_lengths: int) -> Tensor[IntTuple]: ...
|
|
63
|
+
@overload
|
|
64
|
+
def repeat(tensor: Any, pattern: str, **axes_lengths: int) -> Any: ...
|
|
65
|
+
@overload
|
|
66
|
+
def einsum[S1: IntTuple, Pattern: Flag[str]](
|
|
67
|
+
tensor: Tensor[S1], pattern: Pattern, /
|
|
68
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1])]: ...
|
|
69
|
+
@overload
|
|
70
|
+
def einsum[S1: IntTuple, S2: IntTuple, Pattern: Flag[str]](
|
|
71
|
+
tensor1: Tensor[S1], tensor2: Tensor[S2], pattern: Pattern, /
|
|
72
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2])]: ...
|
|
73
|
+
@overload
|
|
74
|
+
def einsum[S1: IntTuple, S2: IntTuple, S3: IntTuple, Pattern: Flag[str]](
|
|
75
|
+
tensor1: Tensor[S1],
|
|
76
|
+
tensor2: Tensor[S2],
|
|
77
|
+
tensor3: Tensor[S3],
|
|
78
|
+
pattern: Pattern,
|
|
79
|
+
/,
|
|
80
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3])]: ...
|
|
81
|
+
@overload
|
|
82
|
+
def einsum[
|
|
83
|
+
S1: IntTuple,
|
|
84
|
+
S2: IntTuple,
|
|
85
|
+
S3: IntTuple,
|
|
86
|
+
S4: IntTuple,
|
|
87
|
+
Pattern: Flag[str],
|
|
88
|
+
](
|
|
89
|
+
tensor1: Tensor[S1],
|
|
90
|
+
tensor2: Tensor[S2],
|
|
91
|
+
tensor3: Tensor[S3],
|
|
92
|
+
tensor4: Tensor[S4],
|
|
93
|
+
pattern: Pattern,
|
|
94
|
+
/,
|
|
95
|
+
) -> Tensor[einsum_shape(Pattern, tuple[S1, S2, S3, S4])]: ...
|
|
96
|
+
@overload
|
|
97
|
+
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, type_shape_dsl_function
|
|
8
|
+
|
|
9
|
+
@type_shape_dsl_function
|
|
10
|
+
def rearrange_shape(pattern: str, shape: IntTuple) -> IntTuple:
|
|
11
|
+
return dsl.rearrange(pattern, shape)
|
|
12
|
+
|
|
13
|
+
@type_shape_dsl_function
|
|
14
|
+
def reduce_shape(pattern: str, shape: IntTuple) -> IntTuple:
|
|
15
|
+
return dsl.reduce(pattern, shape)
|
|
16
|
+
|
|
17
|
+
@type_shape_dsl_function
|
|
18
|
+
def repeat_shape(pattern: str, shape: IntTuple) -> IntTuple:
|
|
19
|
+
return dsl.repeat(pattern, shape)
|
|
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 @@
|
|
|
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.dev1"
|
|
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.dev1",
|
|
22
|
+
"pyrefly-torch-stubs==1.4.0.dev1",
|
|
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"]
|