pyrefly-shape-extensions 1.2.0.dev2__py3-none-any.whl → 1.3.0.dev1__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.dev2.dist-info → pyrefly_shape_extensions-1.3.0.dev1.dist-info}/METADATA +2 -2
- pyrefly_shape_extensions-1.3.0.dev1.dist-info/RECORD +7 -0
- shape_extensions/__init__.py +26 -11
- pyrefly_shape_extensions-1.2.0.dev2.dist-info/RECORD +0 -7
- {pyrefly_shape_extensions-1.2.0.dev2.dist-info → pyrefly_shape_extensions-1.3.0.dev1.dist-info}/WHEEL +0 -0
- {pyrefly_shape_extensions-1.2.0.dev2.dist-info → pyrefly_shape_extensions-1.3.0.dev1.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.
|
|
3
|
+
Version: 1.3.0.dev1
|
|
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=gi8ElHrsI7dcvJTxSOGzSktIkQfi9V8yky4paWRhY3g,10495
|
|
2
|
+
shape_extensions/dsl.py,sha256=QEGndUSJKvROYDzxVwZN4tFtuS1VBgNupibnV2muGTQ,1775
|
|
3
|
+
shape_extensions/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
pyrefly_shape_extensions-1.3.0.dev1.dist-info/METADATA,sha256=KNMwKuLV2TDvCZGgBPTPKNaPsSU6Xhb_mPhrkC9Rw-U,2317
|
|
5
|
+
pyrefly_shape_extensions-1.3.0.dev1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
6
|
+
pyrefly_shape_extensions-1.3.0.dev1.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
|
|
7
|
+
pyrefly_shape_extensions-1.3.0.dev1.dist-info/RECORD,,
|
shape_extensions/__init__.py
CHANGED
|
@@ -68,22 +68,26 @@ def _patch_torch_if_available() -> None:
|
|
|
68
68
|
_patch_torch_if_available()
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
class
|
|
72
|
-
"""
|
|
71
|
+
class IntTuple:
|
|
72
|
+
"""Tuple-valued shape annotation surface.
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
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.
|
|
76
77
|
"""
|
|
77
78
|
|
|
79
|
+
def __new__(cls, iterable=()):
|
|
80
|
+
return tuple(iterable)
|
|
81
|
+
|
|
78
82
|
def __class_getitem__(cls, params):
|
|
79
83
|
return cls
|
|
80
84
|
|
|
81
85
|
|
|
82
86
|
class Elements:
|
|
83
|
-
"""Inverse of ``tuple[Unpack[S]]``: extracts the element sequence from a
|
|
87
|
+
"""Inverse of ``tuple[Unpack[S]]``: extracts the element sequence from a IntTuple carrier.
|
|
84
88
|
|
|
85
89
|
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 ``
|
|
90
|
+
concrete tuple type. ``Elements[S]`` is the conceptual inverse: given a ``IntTuple``
|
|
87
91
|
carrier ``S``, ``*Elements[S]`` splices its element sequence into a shape position,
|
|
88
92
|
e.g. ``Array[[*Elements[S], OUT], DType]``.
|
|
89
93
|
|
|
@@ -106,7 +110,7 @@ class Elements:
|
|
|
106
110
|
return f"Elements[{self.carrier!r}]"
|
|
107
111
|
|
|
108
112
|
|
|
109
|
-
class
|
|
113
|
+
class Int[T]:
|
|
110
114
|
"""Symbolic integer type for dimension values.
|
|
111
115
|
|
|
112
116
|
At runtime this is a no-op generic class. The type checker uses the
|
|
@@ -129,7 +133,7 @@ def enable_torchscript_runtime_compat() -> None:
|
|
|
129
133
|
paths. It intentionally has no disable API for production callers.
|
|
130
134
|
"""
|
|
131
135
|
|
|
132
|
-
|
|
136
|
+
Int.__class_getitem__ = classmethod(_return_int)
|
|
133
137
|
|
|
134
138
|
|
|
135
139
|
@dataclass(frozen=True)
|
|
@@ -253,7 +257,19 @@ def shaped_array(*, shape: str) -> typing.Callable[[type], type]:
|
|
|
253
257
|
return decorator
|
|
254
258
|
|
|
255
259
|
|
|
256
|
-
|
|
260
|
+
def broadcast(*_args):
|
|
261
|
+
"""Runtime placeholder for Pyrefly's native type-level broadcast intrinsic."""
|
|
262
|
+
|
|
263
|
+
return IntTuple()
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def type_shape_dsl_function[F: typing.Callable](fn: F) -> F:
|
|
267
|
+
"""Runtime no-op for a user-defined type-level shape DSL function."""
|
|
268
|
+
|
|
269
|
+
return fn
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class IntVar:
|
|
257
273
|
"""Symbolic variable with arithmetic support for tensor shape dimensions.
|
|
258
274
|
|
|
259
275
|
Like typing.TypeVar but arithmetic operations (N + 1, N * 2, etc.)
|
|
@@ -261,8 +277,7 @@ class SymVar:
|
|
|
261
277
|
__class__ = typing.TypeVar makes isinstance(x, typing.TypeVar)
|
|
262
278
|
return True, so Generic[N] and TypedDict + Generic[N] both work.
|
|
263
279
|
|
|
264
|
-
In pyrefly, shape_extensions.
|
|
265
|
-
typing.TypeVar.
|
|
280
|
+
In pyrefly, shape_extensions.IntVar marks symbolic integer dimensions.
|
|
266
281
|
"""
|
|
267
282
|
|
|
268
283
|
__class__ = typing.TypeVar
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
shape_extensions/__init__.py,sha256=ulJRDn1aXvsrqsMSBAgaWOYWfk_ImJjRKkjTlUADUi0,10162
|
|
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.dev2.dist-info/METADATA,sha256=4misAtwrNE8ZGBuoCpGT_ovOtYlCQFeBo9a4vMr-wZ8,2317
|
|
5
|
-
pyrefly_shape_extensions-1.2.0.dev2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
6
|
-
pyrefly_shape_extensions-1.2.0.dev2.dist-info/licenses/LICENSE,sha256=2m03A-0Ry-Qr0hLHJZV8mNojy_8ZmMBfpLPZdtGljpM,1088
|
|
7
|
-
pyrefly_shape_extensions-1.2.0.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|