pyrefly-shape-extensions 1.2.0.dev1__tar.gz → 1.2.0.dev2__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_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/PKG-INFO +2 -2
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/README.md +1 -1
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/pyproject.toml +1 -1
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/shape_extensions/__init__.py +49 -4
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/LICENSE +0 -0
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/shape_extensions/dsl.py +0 -0
- {pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/shape_extensions/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyrefly-shape-extensions
|
|
3
|
-
Version: 1.2.0.
|
|
3
|
+
Version: 1.2.0.dev2
|
|
4
4
|
Summary: Shape typing primitives and DSL for Pyrefly tensor shape tracking
|
|
5
5
|
Project-URL: homepage, https://pyrefly.org
|
|
6
6
|
Project-URL: documentation, https://pyrefly.org/en/docs/
|
|
@@ -40,7 +40,7 @@ Runtime helpers for Pyrefly tensor shape annotations.
|
|
|
40
40
|
|
|
41
41
|
This package provides the lightweight `shape_extensions` module used by
|
|
42
42
|
Pyrefly's tensor shape stubs. It defines runtime no-op versions of the shape
|
|
43
|
-
typing primitives so annotations such as `Tensor[B, T]`, `
|
|
43
|
+
typing primitives so annotations such as `Tensor[B, T]`, `SymVar("B")`, and
|
|
44
44
|
`assert_shape(x, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
45
45
|
corresponding stubs for static shape checking.
|
|
46
46
|
|
|
@@ -4,7 +4,7 @@ Runtime helpers for Pyrefly tensor shape annotations.
|
|
|
4
4
|
|
|
5
5
|
This package provides the lightweight `shape_extensions` module used by
|
|
6
6
|
Pyrefly's tensor shape stubs. It defines runtime no-op versions of the shape
|
|
7
|
-
typing primitives so annotations such as `Tensor[B, T]`, `
|
|
7
|
+
typing primitives so annotations such as `Tensor[B, T]`, `SymVar("B")`, and
|
|
8
8
|
`assert_shape(x, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
9
9
|
corresponding stubs for static shape checking.
|
|
10
10
|
|
|
@@ -8,7 +8,7 @@ description = "Shape typing primitives and DSL for Pyrefly tensor shape tracking
|
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.2.0.
|
|
11
|
+
version = "1.2.0.dev2"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "shapes", "tensor", "pyrefly"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
|
@@ -68,6 +68,44 @@ def _patch_torch_if_available() -> None:
|
|
|
68
68
|
_patch_torch_if_available()
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
class SizeTuple:
|
|
72
|
+
"""Integer tuple carrier for shape-like type parameters.
|
|
73
|
+
|
|
74
|
+
At runtime this is a no-op marker class. Pyrefly treats `SizeTuple` in type
|
|
75
|
+
positions as the shape carrier corresponding to `tuple[int, ...]`.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
def __class_getitem__(cls, params):
|
|
79
|
+
return cls
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class Elements:
|
|
83
|
+
"""Inverse of ``tuple[Unpack[S]]``: extracts the element sequence from a SizeTuple carrier.
|
|
84
|
+
|
|
85
|
+
In the Python typing spec, ``tuple[Unpack[Ts]]`` wraps a ``TypeVarTuple`` into a
|
|
86
|
+
concrete tuple type. ``Elements[S]`` is the conceptual inverse: given a ``SizeTuple``
|
|
87
|
+
carrier ``S``, ``*Elements[S]`` splices its element sequence into a shape position,
|
|
88
|
+
e.g. ``Array[[*Elements[S], OUT], DType]``.
|
|
89
|
+
|
|
90
|
+
This fills a gap in the current typing spec — there is no standard mechanism to
|
|
91
|
+
decompose a variadic carrier without a ``TypeVarTuple``. Pyrefly uses the ``.pyi``
|
|
92
|
+
stub for type inference; this class exists so annotations evaluate without crashing
|
|
93
|
+
at runtime.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
def __init__(self, carrier):
|
|
97
|
+
self.carrier = carrier
|
|
98
|
+
|
|
99
|
+
def __class_getitem__(cls, carrier):
|
|
100
|
+
return cls(carrier)
|
|
101
|
+
|
|
102
|
+
def __iter__(self):
|
|
103
|
+
yield self
|
|
104
|
+
|
|
105
|
+
def __repr__(self):
|
|
106
|
+
return f"Elements[{self.carrier!r}]"
|
|
107
|
+
|
|
108
|
+
|
|
71
109
|
class Dim[T]:
|
|
72
110
|
"""Symbolic integer type for dimension values.
|
|
73
111
|
|
|
@@ -78,6 +116,12 @@ class Dim[T]:
|
|
|
78
116
|
pass
|
|
79
117
|
|
|
80
118
|
|
|
119
|
+
class ProxyMethod[T]:
|
|
120
|
+
"""Type-checker marker for method forwarding annotations."""
|
|
121
|
+
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
|
|
81
125
|
def enable_torchscript_runtime_compat() -> None:
|
|
82
126
|
"""Erase shape-only runtime annotations to types TorchScript understands.
|
|
83
127
|
|
|
@@ -209,23 +253,24 @@ def shaped_array(*, shape: str) -> typing.Callable[[type], type]:
|
|
|
209
253
|
return decorator
|
|
210
254
|
|
|
211
255
|
|
|
212
|
-
class
|
|
213
|
-
"""
|
|
256
|
+
class SymVar:
|
|
257
|
+
"""Symbolic variable with arithmetic support for tensor shape dimensions.
|
|
214
258
|
|
|
215
259
|
Like typing.TypeVar but arithmetic operations (N + 1, N * 2, etc.)
|
|
216
260
|
return self instead of raising TypeError. Setting
|
|
217
261
|
__class__ = typing.TypeVar makes isinstance(x, typing.TypeVar)
|
|
218
262
|
return True, so Generic[N] and TypedDict + Generic[N] both work.
|
|
219
263
|
|
|
220
|
-
In pyrefly, shape_extensions.
|
|
264
|
+
In pyrefly, shape_extensions.SymVar is treated identically to
|
|
221
265
|
typing.TypeVar.
|
|
222
266
|
"""
|
|
223
267
|
|
|
224
268
|
__class__ = typing.TypeVar
|
|
225
269
|
|
|
226
|
-
def __init__(self, name: str):
|
|
270
|
+
def __init__(self, name: str, *, bound=None):
|
|
227
271
|
self.__name__ = name
|
|
228
272
|
self.name = name
|
|
273
|
+
self.__bound__ = bound
|
|
229
274
|
|
|
230
275
|
def __repr__(self):
|
|
231
276
|
return self.name
|
|
File without changes
|
{pyrefly_shape_extensions-1.2.0.dev1 → pyrefly_shape_extensions-1.2.0.dev2}/shape_extensions/dsl.py
RENAMED
|
File without changes
|
|
File without changes
|