pyrefly-shape-extensions 1.2.0.dev1__py3-none-any.whl → 1.2.0.dev3__py3-none-any.whl
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.dist-info → pyrefly_shape_extensions-1.2.0.dev3.dist-info}/METADATA +2 -2
- pyrefly_shape_extensions-1.2.0.dev3.dist-info/RECORD +7 -0
- {pyrefly_shape_extensions-1.2.0.dev1.dist-info → pyrefly_shape_extensions-1.2.0.dev3.dist-info}/WHEEL +1 -1
- shape_extensions/__init__.py +61 -7
- pyrefly_shape_extensions-1.2.0.dev1.dist-info/RECORD +0 -7
- {pyrefly_shape_extensions-1.2.0.dev1.dist-info → pyrefly_shape_extensions-1.2.0.dev3.dist-info}/licenses/LICENSE +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.dev3
|
|
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]`, `IntVar("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
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
shape_extensions/__init__.py,sha256=dWk2rCSIw1i1vPcRZtKvBNkoJ1SYNmuWEyYQY56WLdg,10343
|
|
2
|
+
shape_extensions/dsl.py,sha256=QEGndUSJKvROYDzxVwZN4tFtuS1VBgNupibnV2muGTQ,1775
|
|
3
|
+
shape_extensions/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
pyrefly_shape_extensions-1.2.0.dev3.dist-info/METADATA,sha256=-_lXGKcnSVcudWCJEtYLuFa1Eni47aaKkCXIiRdMf3c,2317
|
|
5
|
+
pyrefly_shape_extensions-1.2.0.dev3.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
6
|
+
pyrefly_shape_extensions-1.2.0.dev3.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
|
|
7
|
+
pyrefly_shape_extensions-1.2.0.dev3.dist-info/RECORD,,
|
shape_extensions/__init__.py
CHANGED
|
@@ -68,7 +68,49 @@ def _patch_torch_if_available() -> None:
|
|
|
68
68
|
_patch_torch_if_available()
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
class
|
|
71
|
+
class IntTuple:
|
|
72
|
+
"""Tuple-valued shape annotation surface.
|
|
73
|
+
|
|
74
|
+
In type positions, Pyrefly treats `IntTuple` as the shape carrier for
|
|
75
|
+
`tuple[int, ...]`. At runtime, calling it coerces any iterable to a plain
|
|
76
|
+
tuple.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
def __new__(cls, iterable=()):
|
|
80
|
+
return tuple(iterable)
|
|
81
|
+
|
|
82
|
+
def __class_getitem__(cls, params):
|
|
83
|
+
return cls
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Elements:
|
|
87
|
+
"""Inverse of ``tuple[Unpack[S]]``: extracts the element sequence from a IntTuple carrier.
|
|
88
|
+
|
|
89
|
+
In the Python typing spec, ``tuple[Unpack[Ts]]`` wraps a ``TypeVarTuple`` into a
|
|
90
|
+
concrete tuple type. ``Elements[S]`` is the conceptual inverse: given a ``IntTuple``
|
|
91
|
+
carrier ``S``, ``*Elements[S]`` splices its element sequence into a shape position,
|
|
92
|
+
e.g. ``Array[[*Elements[S], OUT], DType]``.
|
|
93
|
+
|
|
94
|
+
This fills a gap in the current typing spec — there is no standard mechanism to
|
|
95
|
+
decompose a variadic carrier without a ``TypeVarTuple``. Pyrefly uses the ``.pyi``
|
|
96
|
+
stub for type inference; this class exists so annotations evaluate without crashing
|
|
97
|
+
at runtime.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
def __init__(self, carrier):
|
|
101
|
+
self.carrier = carrier
|
|
102
|
+
|
|
103
|
+
def __class_getitem__(cls, carrier):
|
|
104
|
+
return cls(carrier)
|
|
105
|
+
|
|
106
|
+
def __iter__(self):
|
|
107
|
+
yield self
|
|
108
|
+
|
|
109
|
+
def __repr__(self):
|
|
110
|
+
return f"Elements[{self.carrier!r}]"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class Int[T]:
|
|
72
114
|
"""Symbolic integer type for dimension values.
|
|
73
115
|
|
|
74
116
|
At runtime this is a no-op generic class. The type checker uses the
|
|
@@ -78,6 +120,12 @@ class Dim[T]:
|
|
|
78
120
|
pass
|
|
79
121
|
|
|
80
122
|
|
|
123
|
+
class ProxyMethod[T]:
|
|
124
|
+
"""Type-checker marker for method forwarding annotations."""
|
|
125
|
+
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
|
|
81
129
|
def enable_torchscript_runtime_compat() -> None:
|
|
82
130
|
"""Erase shape-only runtime annotations to types TorchScript understands.
|
|
83
131
|
|
|
@@ -85,7 +133,7 @@ def enable_torchscript_runtime_compat() -> None:
|
|
|
85
133
|
paths. It intentionally has no disable API for production callers.
|
|
86
134
|
"""
|
|
87
135
|
|
|
88
|
-
|
|
136
|
+
Int.__class_getitem__ = classmethod(_return_int)
|
|
89
137
|
|
|
90
138
|
|
|
91
139
|
@dataclass(frozen=True)
|
|
@@ -209,23 +257,29 @@ def shaped_array(*, shape: str) -> typing.Callable[[type], type]:
|
|
|
209
257
|
return decorator
|
|
210
258
|
|
|
211
259
|
|
|
212
|
-
|
|
213
|
-
"""
|
|
260
|
+
def broadcast(*_args):
|
|
261
|
+
"""Runtime placeholder for Pyrefly's native type-level broadcast intrinsic."""
|
|
262
|
+
|
|
263
|
+
return IntTuple()
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class IntVar:
|
|
267
|
+
"""Symbolic variable with arithmetic support for tensor shape dimensions.
|
|
214
268
|
|
|
215
269
|
Like typing.TypeVar but arithmetic operations (N + 1, N * 2, etc.)
|
|
216
270
|
return self instead of raising TypeError. Setting
|
|
217
271
|
__class__ = typing.TypeVar makes isinstance(x, typing.TypeVar)
|
|
218
272
|
return True, so Generic[N] and TypedDict + Generic[N] both work.
|
|
219
273
|
|
|
220
|
-
In pyrefly, shape_extensions.
|
|
221
|
-
typing.TypeVar.
|
|
274
|
+
In pyrefly, shape_extensions.IntVar marks symbolic integer dimensions.
|
|
222
275
|
"""
|
|
223
276
|
|
|
224
277
|
__class__ = typing.TypeVar
|
|
225
278
|
|
|
226
|
-
def __init__(self, name: str):
|
|
279
|
+
def __init__(self, name: str, *, bound=None):
|
|
227
280
|
self.__name__ = name
|
|
228
281
|
self.name = name
|
|
282
|
+
self.__bound__ = bound
|
|
229
283
|
|
|
230
284
|
def __repr__(self):
|
|
231
285
|
return self.name
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
shape_extensions/__init__.py,sha256=53XQgm-jGu1CJojwxmuIIfTcQ9csvfntAOQOE1oVq-Y,8748
|
|
2
|
-
shape_extensions/dsl.py,sha256=QEGndUSJKvROYDzxVwZN4tFtuS1VBgNupibnV2muGTQ,1775
|
|
3
|
-
shape_extensions/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
-
pyrefly_shape_extensions-1.2.0.dev1.dist-info/METADATA,sha256=KMhttdi73x9kvDXvg5wtimeYiQneboqCsp4-Pn5jZTE,2318
|
|
5
|
-
pyrefly_shape_extensions-1.2.0.dev1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
6
|
-
pyrefly_shape_extensions-1.2.0.dev1.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
|
|
7
|
-
pyrefly_shape_extensions-1.2.0.dev1.dist-info/RECORD,,
|
|
File without changes
|