pyrefly-shape-extensions 1.2.0.dev2__tar.gz → 1.2.0.dev3__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.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/PKG-INFO +2 -2
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/README.md +1 -1
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/pyproject.toml +1 -1
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/shape_extensions/__init__.py +20 -11
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/LICENSE +0 -0
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/shape_extensions/dsl.py +0 -0
- {pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/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.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
|
|
|
@@ -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]`, `IntVar("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.dev3"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "shapes", "tensor", "pyrefly"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
|
@@ -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,13 @@ 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
|
+
class IntVar:
|
|
257
267
|
"""Symbolic variable with arithmetic support for tensor shape dimensions.
|
|
258
268
|
|
|
259
269
|
Like typing.TypeVar but arithmetic operations (N + 1, N * 2, etc.)
|
|
@@ -261,8 +271,7 @@ class SymVar:
|
|
|
261
271
|
__class__ = typing.TypeVar makes isinstance(x, typing.TypeVar)
|
|
262
272
|
return True, so Generic[N] and TypedDict + Generic[N] both work.
|
|
263
273
|
|
|
264
|
-
In pyrefly, shape_extensions.
|
|
265
|
-
typing.TypeVar.
|
|
274
|
+
In pyrefly, shape_extensions.IntVar marks symbolic integer dimensions.
|
|
266
275
|
"""
|
|
267
276
|
|
|
268
277
|
__class__ = typing.TypeVar
|
|
File without changes
|
{pyrefly_shape_extensions-1.2.0.dev2 → pyrefly_shape_extensions-1.2.0.dev3}/shape_extensions/dsl.py
RENAMED
|
File without changes
|
|
File without changes
|