egglog 0.4.0__cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
Potentially problematic release.
This version of egglog might be problematic. Click here for more details.
- egglog/__init__.py +5 -0
- egglog/bindings.cpython-312-x86_64-linux-gnu.so +0 -0
- egglog/bindings.pyi +415 -0
- egglog/builtins.py +345 -0
- egglog/config.py +8 -0
- egglog/declarations.py +934 -0
- egglog/egraph.py +1041 -0
- egglog/examples/README.rst +5 -0
- egglog/examples/__init__.py +0 -0
- egglog/examples/eqsat_basic.py +43 -0
- egglog/examples/fib.py +28 -0
- egglog/examples/lambda.py +310 -0
- egglog/examples/matrix.py +184 -0
- egglog/examples/ndarrays.py +159 -0
- egglog/examples/resolution.py +84 -0
- egglog/examples/schedule_demo.py +33 -0
- egglog/ipython_magic.py +40 -0
- egglog/monkeypatch.py +33 -0
- egglog/py.typed +0 -0
- egglog/runtime.py +304 -0
- egglog/type_constraint_solver.py +79 -0
- egglog-0.4.0.dist-info/METADATA +53 -0
- egglog-0.4.0.dist-info/RECORD +25 -0
- egglog-0.4.0.dist-info/WHEEL +4 -0
- egglog-0.4.0.dist-info/license_files/LICENSE +21 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from itertools import chain, repeat
|
|
5
|
+
from typing import Collection, Optional
|
|
6
|
+
|
|
7
|
+
from .declarations import *
|
|
8
|
+
|
|
9
|
+
__all__ = ["TypeConstraintSolver", "TypeConstraintError"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TypeConstraintError(RuntimeError):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class TypeConstraintSolver:
|
|
18
|
+
"""
|
|
19
|
+
Given some typevars and types, solves the constraints to resolve the typevars.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# Mapping of class typevar index to their types
|
|
23
|
+
_cls_typevar_index_to_type: dict[int, JustTypeRef] = field(default_factory=dict)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def from_type_parameters(cls, tps: Collection[JustTypeRef]) -> TypeConstraintSolver:
|
|
27
|
+
"""
|
|
28
|
+
Create a TypeInference from a parameterized class, given as a bound typevar.
|
|
29
|
+
|
|
30
|
+
Used for a situation like Map[int, str].create()
|
|
31
|
+
"""
|
|
32
|
+
cs = cls()
|
|
33
|
+
# For each param in the class, use this as the ith bound class typevar
|
|
34
|
+
for i, tp in enumerate(tps):
|
|
35
|
+
cs._cls_typevar_index_to_type[i] = tp
|
|
36
|
+
return cs
|
|
37
|
+
|
|
38
|
+
def infer_return_type(
|
|
39
|
+
self,
|
|
40
|
+
fn_args: Collection[TypeOrVarRef],
|
|
41
|
+
fn_return: TypeOrVarRef,
|
|
42
|
+
fn_var_args: Optional[TypeOrVarRef],
|
|
43
|
+
args: Collection[JustTypeRef],
|
|
44
|
+
) -> JustTypeRef:
|
|
45
|
+
# Infer the type of each type variable based on the actual types of the arguments
|
|
46
|
+
self._infer_typevars_zip(fn_args, fn_var_args, args)
|
|
47
|
+
# Substitute the type variables with their inferred types
|
|
48
|
+
return self._subtitute_typevars(fn_return)
|
|
49
|
+
|
|
50
|
+
def _infer_typevars_zip(
|
|
51
|
+
self, fn_args: Collection[TypeOrVarRef], fn_var_args: Optional[TypeOrVarRef], args: Collection[JustTypeRef]
|
|
52
|
+
) -> None:
|
|
53
|
+
if len(fn_args) != len(args) if fn_var_args is None else len(fn_args) > len(args):
|
|
54
|
+
raise TypeConstraintError(f"Expected {len(fn_args)} args, got {len(args)}")
|
|
55
|
+
all_fn_args = fn_args if fn_var_args is None else chain(fn_args, repeat(fn_var_args))
|
|
56
|
+
for fn_arg, arg in zip(all_fn_args, args):
|
|
57
|
+
self._infer_typevars(fn_arg, arg)
|
|
58
|
+
|
|
59
|
+
def _infer_typevars(self, fn_arg: TypeOrVarRef, arg: JustTypeRef) -> None:
|
|
60
|
+
if isinstance(fn_arg, TypeRefWithVars):
|
|
61
|
+
if fn_arg.name != arg.name:
|
|
62
|
+
raise TypeConstraintError(f"Expected {fn_arg.name}, got {arg.name}")
|
|
63
|
+
self._infer_typevars_zip(fn_arg.args, None, arg.args)
|
|
64
|
+
elif fn_arg.index not in self._cls_typevar_index_to_type:
|
|
65
|
+
self._cls_typevar_index_to_type[fn_arg.index] = arg
|
|
66
|
+
elif self._cls_typevar_index_to_type[fn_arg.index] != arg:
|
|
67
|
+
raise TypeConstraintError(f"Expected {fn_arg}, got {arg}")
|
|
68
|
+
|
|
69
|
+
def _subtitute_typevars(self, tp: TypeOrVarRef) -> JustTypeRef:
|
|
70
|
+
if isinstance(tp, ClassTypeVarRef):
|
|
71
|
+
try:
|
|
72
|
+
return self._cls_typevar_index_to_type[tp.index]
|
|
73
|
+
except KeyError:
|
|
74
|
+
raise TypeConstraintError(f"Not enough bound typevars for {tp}")
|
|
75
|
+
elif isinstance(tp, TypeRefWithVars):
|
|
76
|
+
return JustTypeRef(
|
|
77
|
+
tp.name,
|
|
78
|
+
tuple(self._subtitute_typevars(arg) for arg in tp.args),
|
|
79
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: egglog
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Classifier: Environment :: MacOS X
|
|
5
|
+
Classifier: Environment :: Win32 (MS Windows)
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Natural Language :: English
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Rust
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Dist: typing-extensions
|
|
21
|
+
Requires-Dist: black
|
|
22
|
+
Requires-Dist: graphviz
|
|
23
|
+
Requires-Dist: pytest; extra == 'test'
|
|
24
|
+
Requires-Dist: mypy; extra == 'test'
|
|
25
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
|
|
26
|
+
Requires-Dist: myst-nb; extra == 'docs'
|
|
27
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
|
|
28
|
+
Requires-Dist: sphinx-gallery; extra == 'docs'
|
|
29
|
+
Requires-Dist: matplotlib; extra == 'docs'
|
|
30
|
+
Requires-Dist: nbconvert; extra == 'docs'
|
|
31
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
32
|
+
Requires-Dist: black; extra == 'dev'
|
|
33
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
34
|
+
Requires-Dist: flake8; extra == 'dev'
|
|
35
|
+
Requires-Dist: isort; extra == 'dev'
|
|
36
|
+
Provides-Extra: test
|
|
37
|
+
Provides-Extra: docs
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Summary: e-graphs in Python built around the the egglog rust library
|
|
41
|
+
License: MIT
|
|
42
|
+
Requires-Python: >=3.7
|
|
43
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
44
|
+
|
|
45
|
+
# `egglog` Python wrapper
|
|
46
|
+
|
|
47
|
+
[](https://egg-smol-python.readthedocs.io/en/latest/?badge=latest) [](https://github.com/metadsl/egglog-python/actions/workflows/CI.yml) [](https://pypi.org/project/egglog/) [](https://pypi.org/project/egglog/) [](https://pypi.org/project/egglog/) [](https://github.com/pre-commit/pre-commit)
|
|
48
|
+
|
|
49
|
+
`egglog` is a Python package that provides bindings to the Rust library [`egglog`](https://github.com/egraphs-good/egglog/),
|
|
50
|
+
allowing you to use e-graphs in Python for optimization, symbolic computation, and analysis.
|
|
51
|
+
|
|
52
|
+
Please see the [documentation](https://egg-smol-python.readthedocs.io/en/latest/?badge=latest) for more information.
|
|
53
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
egglog-0.4.0.dist-info/METADATA,sha256=YaRlVy3sIsMgI8zUkrlQYtLkkuXkWgtVKNi4RTGZ5Qg,2840
|
|
2
|
+
egglog-0.4.0.dist-info/WHEEL,sha256=cMZaAELfCq-Wny4Kd-Zb88nk1QVHKOQ56uOMKlU1ooA,130
|
|
3
|
+
egglog-0.4.0.dist-info/license_files/LICENSE,sha256=9cYb25jNLLm6mgX6Io4aYZ2UaiWcSCl_ROMIev2vX-Y,1064
|
|
4
|
+
egglog/__init__.py,sha256=y9IIN--blzi8SjA7MUuN8WiVW8Mpl-dRffbh2to8oHA,143
|
|
5
|
+
egglog/bindings.pyi,sha256=kS4m5XQ7kR9-2U5jGX66G2FsifTGEtVXGSr_Tx8Y1GU,8188
|
|
6
|
+
egglog/examples/resolution.py,sha256=l_YkhZUenncGhp8JkQQ6upLgAaTlcIrmr3crrn22Sog,2100
|
|
7
|
+
egglog/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
egglog/examples/lambda.py,sha256=pA1vGapQ--80AlUUr4r9gT_wW1pQh5h8Kz7wiCFzjM0,8643
|
|
9
|
+
egglog/examples/README.rst,sha256=ztTvpofR0eotSqGoCy_C1fPLDPCncjvcqDanXtLHNNU,232
|
|
10
|
+
egglog/examples/eqsat_basic.py,sha256=ezv6PlJRAySfW5KBl90B_ZdqGXxzeO-aFLD6wTfxPfM,990
|
|
11
|
+
egglog/examples/matrix.py,sha256=XYsAO1oXYIVl-h4KxHkVsLs4sdIIEKAdI6h3kg_gMow,5281
|
|
12
|
+
egglog/examples/ndarrays.py,sha256=zvLaWmqP-85PbVFx3XDcGMJ_04DKHpqe3mgqxki6EFE,4230
|
|
13
|
+
egglog/examples/schedule_demo.py,sha256=C4w9cevqmQbiJT_Ms2RV1vXtsvckur4J-mMAooMJG2Y,723
|
|
14
|
+
egglog/examples/fib.py,sha256=IR67Ehd0tMn9efE9UTLFvuGe2h6D0Ip2X2RxT1xk6is,505
|
|
15
|
+
egglog/type_constraint_solver.py,sha256=o0KOmJQhXNkuXcxmi8cTfCNsYQ0ZE5rHQK5rsXlq-R4,3153
|
|
16
|
+
egglog/runtime.py,sha256=FN-hXLdOflh-tkTUOgkeX3NxznKxEpS2qRRV8rFyfl4,11975
|
|
17
|
+
egglog/egraph.py,sha256=xbfvcz8nwa2xfST0G-1yJY5QHWOefS28K9CETh37MuE,36861
|
|
18
|
+
egglog/declarations.py,sha256=L3hqbirdUSdfDK3rqS1fsHDeUl8D4hlKcA7kgoilkEI,32042
|
|
19
|
+
egglog/builtins.py,sha256=A28JPrH5Q3iL1-hyE96zbEWI4QpYZzndKisopN9yJWU,9347
|
|
20
|
+
egglog/config.py,sha256=yM3FIcVCKnhWZmHD0pxkzx7ah7t5PxZx3WUqKtA9tjU,168
|
|
21
|
+
egglog/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
egglog/ipython_magic.py,sha256=7VEOYg90X0xRkQdqXGSJZoGYv59Re-Z4Ss3l0OI1t3A,1168
|
|
23
|
+
egglog/monkeypatch.py,sha256=HKabvIfRoVQoIXLR4smtU0R9Fyc4GGuWF3al5xeh65w,1140
|
|
24
|
+
egglog/bindings.cpython-312-x86_64-linux-gnu.so,sha256=rE1Ln6PtZMZcHcEOENK5xXqqxKWyuieA-E8VlYedKBw,9310512
|
|
25
|
+
egglog-0.4.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 metadsl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|