pyrefly-shape-extensions 1.4.0.dev4__tar.gz → 1.5.0__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.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/PKG-INFO +5 -2
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/README.md +4 -1
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/pyproject.toml +1 -1
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/__init__.py +57 -4
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/LICENSE +0 -0
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/dsl.py +0 -0
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/py.typed +0 -0
- {pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/torchscript.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyrefly-shape-extensions
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
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]`, `IntVar("B")`, and
|
|
43
|
+
typing primitives so annotations such as `Tensor[[B, T]]`, `IntVar("B")`, and
|
|
44
44
|
`assert_shape(x.shape, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
45
45
|
corresponding stubs for static shape checking.
|
|
46
46
|
|
|
@@ -57,6 +57,9 @@ integer tuples and lists. A direct, unstarred list literal such as `[2, 3]`
|
|
|
57
57
|
binds `Values` to `IntTuple[2, 3]`; an existing or starred list remains gradual,
|
|
58
58
|
while a direct literal containing a non-integer is rejected.
|
|
59
59
|
|
|
60
|
+
`@shape_transform` marks a type-level shape DSL function and is a runtime no-op.
|
|
61
|
+
`type_shape_dsl_function` remains available as a backward-compatible alias.
|
|
62
|
+
|
|
60
63
|
The package is versioned in lockstep with Pyrefly.
|
|
61
64
|
|
|
62
65
|
## Portable shape annotations
|
|
@@ -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]`, `IntVar("B")`, and
|
|
7
|
+
typing primitives so annotations such as `Tensor[[B, T]]`, `IntVar("B")`, and
|
|
8
8
|
`assert_shape(x.shape, (2, 3))` can be evaluated by Python while Pyrefly uses the
|
|
9
9
|
corresponding stubs for static shape checking.
|
|
10
10
|
|
|
@@ -21,6 +21,9 @@ integer tuples and lists. A direct, unstarred list literal such as `[2, 3]`
|
|
|
21
21
|
binds `Values` to `IntTuple[2, 3]`; an existing or starred list remains gradual,
|
|
22
22
|
while a direct literal containing a non-integer is rejected.
|
|
23
23
|
|
|
24
|
+
`@shape_transform` marks a type-level shape DSL function and is a runtime no-op.
|
|
25
|
+
`type_shape_dsl_function` remains available as a backward-compatible alias.
|
|
26
|
+
|
|
24
27
|
The package is versioned in lockstep with Pyrefly.
|
|
25
28
|
|
|
26
29
|
## Portable shape annotations
|
|
@@ -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.10"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.
|
|
11
|
+
version = "1.5.0"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "shapes", "tensor", "pyrefly"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
{pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/__init__.py
RENAMED
|
@@ -52,12 +52,14 @@ __all__ = [
|
|
|
52
52
|
"RegularNestedList",
|
|
53
53
|
"Shaped",
|
|
54
54
|
"SymbolicArithExpr",
|
|
55
|
+
"TypeVar",
|
|
55
56
|
"assert_shape",
|
|
56
57
|
"assert_raises",
|
|
57
58
|
"broadcast",
|
|
58
59
|
"defines_assert_shape",
|
|
59
60
|
"gufunc_broadcast",
|
|
60
61
|
"index_shape",
|
|
62
|
+
"shape_transform",
|
|
61
63
|
"shape_vars",
|
|
62
64
|
"static_jaxtyping",
|
|
63
65
|
"type_shape_dsl_function",
|
|
@@ -553,12 +555,18 @@ class MapIntTuples:
|
|
|
553
555
|
_F = typing.TypeVar("_F", bound=typing.Callable)
|
|
554
556
|
|
|
555
557
|
|
|
556
|
-
def
|
|
557
|
-
"""Runtime no-op for a user-defined type-level shape DSL function.
|
|
558
|
+
def shape_transform(fn: _F) -> _F:
|
|
559
|
+
"""Runtime no-op for a user-defined type-level shape DSL function.
|
|
560
|
+
|
|
561
|
+
``type_shape_dsl_function`` is a backward-compatible alias.
|
|
562
|
+
"""
|
|
558
563
|
|
|
559
564
|
return fn
|
|
560
565
|
|
|
561
566
|
|
|
567
|
+
type_shape_dsl_function = shape_transform
|
|
568
|
+
|
|
569
|
+
|
|
562
570
|
def _shape_declaration(tokens: typing.Iterable[str]) -> typing.Callable[[_F], _F]:
|
|
563
571
|
"""Build the decorator shared by `static_jaxtyping` and `shape_vars`.
|
|
564
572
|
|
|
@@ -674,20 +682,65 @@ def shape_vars(
|
|
|
674
682
|
from . import dsl as _dsl
|
|
675
683
|
|
|
676
684
|
|
|
677
|
-
@
|
|
685
|
+
@shape_transform
|
|
678
686
|
def gufunc_broadcast(spec: str, shapes: IntTuples) -> IntTuple:
|
|
679
687
|
"""Compute the output shape described by a generalized ufunc signature."""
|
|
680
688
|
|
|
681
689
|
return _dsl._gufunc_broadcast(spec, shapes)
|
|
682
690
|
|
|
683
691
|
|
|
684
|
-
@
|
|
692
|
+
@shape_transform
|
|
685
693
|
def broadcast(left: IntTuple, right: IntTuple) -> IntTuple:
|
|
686
694
|
spec = "(),()->()"
|
|
687
695
|
shapes = _dsl.IntTuples((left, right))
|
|
688
696
|
return gufunc_broadcast(spec, shapes)
|
|
689
697
|
|
|
690
698
|
|
|
699
|
+
class TypeVar:
|
|
700
|
+
"""Runtime-safe legacy type variable for variadic shape dimensions.
|
|
701
|
+
|
|
702
|
+
This accepts the same arguments as ``typing.TypeVar`` on Python 3.12 and is
|
|
703
|
+
additionally iterable, so a shape variable can be unpacked as ``*S`` when
|
|
704
|
+
an annotation is evaluated at runtime.
|
|
705
|
+
"""
|
|
706
|
+
|
|
707
|
+
__class__ = typing.TypeVar
|
|
708
|
+
|
|
709
|
+
def __init__(
|
|
710
|
+
self,
|
|
711
|
+
name: str,
|
|
712
|
+
*constraints,
|
|
713
|
+
bound=None,
|
|
714
|
+
covariant=False,
|
|
715
|
+
contravariant=False,
|
|
716
|
+
infer_variance=False,
|
|
717
|
+
):
|
|
718
|
+
self.__name__ = name
|
|
719
|
+
self.__constraints__ = constraints
|
|
720
|
+
self.__bound__ = bound
|
|
721
|
+
self.__covariant__ = covariant
|
|
722
|
+
self.__contravariant__ = contravariant
|
|
723
|
+
self.__infer_variance__ = infer_variance
|
|
724
|
+
|
|
725
|
+
def __repr__(self):
|
|
726
|
+
return self.__name__
|
|
727
|
+
|
|
728
|
+
def __hash__(self):
|
|
729
|
+
return id(self)
|
|
730
|
+
|
|
731
|
+
def __eq__(self, other):
|
|
732
|
+
return self is other
|
|
733
|
+
|
|
734
|
+
def __iter__(self):
|
|
735
|
+
yield self
|
|
736
|
+
|
|
737
|
+
def __typing_subst__(self, arg):
|
|
738
|
+
return arg
|
|
739
|
+
|
|
740
|
+
def has_default(self):
|
|
741
|
+
return False
|
|
742
|
+
|
|
743
|
+
|
|
691
744
|
class IntVar:
|
|
692
745
|
"""Symbolic variable with arithmetic support for tensor shape dimensions.
|
|
693
746
|
|
|
File without changes
|
{pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/dsl.py
RENAMED
|
File without changes
|
{pyrefly_shape_extensions-1.4.0.dev4 → pyrefly_shape_extensions-1.5.0}/shape_extensions/py.typed
RENAMED
|
File without changes
|
|
File without changes
|