mapFolding 0.9.5__tar.gz → 0.11.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.
- {mapfolding-0.9.5 → mapfolding-0.11.0}/PKG-INFO +3 -1
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/__init__.py +29 -27
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py +44 -45
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/__init__.py +17 -35
- mapfolding-0.11.0/mapFolding/someAssemblyRequired/_toolIfThis.py +53 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/_toolboxContainers.py +15 -287
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +14 -14
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +13 -13
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/toolboxNumba.py +1 -1
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/transformationTools.py +25 -195
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/PKG-INFO +3 -1
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/SOURCES.txt +1 -6
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/requires.txt +2 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/pyproject.toml +3 -1
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_theTypes.py +0 -57
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_tool_Make.py +0 -132
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_tool_Then.py +0 -152
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_toolboxAST.py +0 -57
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -404
- mapfolding-0.9.5/mapFolding/someAssemblyRequired/_toolboxPython.py +0 -188
- {mapfolding-0.9.5 → mapfolding-0.11.0}/LICENSE +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/README.md +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/basecamp.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/beDRY.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/daoOfMapFolding.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/dataBaskets.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/datatypes.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/oeis.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/py.typed +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/__init__.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/flattened.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/jaxCount.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/jobsCompleted/__init__.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/jobsCompleted/p2x19/p2x19.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/lunnonNumpy.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/lunnonWhile.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/RecipeJob.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/__init__.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/daoOfMapFolding.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/dataPacking.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/initializeCount.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/numbaCount.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/theorem2.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/theorem2Numba.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/syntheticModules/theorem2Trimmed.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/theDao.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/theSSOT.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/toolboxFilesystem.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/setup.cfg +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/__init__.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/conftest.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/test_computations.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/test_filesystem.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/test_oeis.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/test_other.py +0 -0
- {mapfolding-0.9.5 → mapfolding-0.11.0}/tests/test_tasks.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License: CC-BY-NC-4.0
|
|
@@ -31,6 +31,7 @@ Classifier: Typing :: Typed
|
|
|
31
31
|
Requires-Python: >=3.10
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
33
33
|
License-File: LICENSE
|
|
34
|
+
Requires-Dist: astToolkit
|
|
34
35
|
Requires-Dist: autoflake
|
|
35
36
|
Requires-Dist: cytoolz
|
|
36
37
|
Requires-Dist: more_itertools
|
|
@@ -41,6 +42,7 @@ Requires-Dist: platformdirs
|
|
|
41
42
|
Requires-Dist: python_minifier
|
|
42
43
|
Requires-Dist: sympy
|
|
43
44
|
Requires-Dist: tomli
|
|
45
|
+
Requires-Dist: typeshed_client
|
|
44
46
|
Requires-Dist: Z0Z_tools
|
|
45
47
|
Provides-Extra: testing
|
|
46
48
|
Requires-Dist: mypy; extra == "testing"
|
|
@@ -47,38 +47,39 @@ foundation for exploring advanced code transformation techniques.
|
|
|
47
47
|
from typing import Any, TypeAlias
|
|
48
48
|
import sys
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
yourPythonIsOld: TypeAlias = Any
|
|
51
|
+
# ruff: noqa: E402
|
|
52
|
+
|
|
53
|
+
# if sys.version_info >= (3, 12):
|
|
54
|
+
# from ast import (
|
|
55
|
+
# ParamSpec as astDOTParamSpec,
|
|
56
|
+
# type_param as astDOTtype_param,
|
|
57
|
+
# TypeAlias as astDOTTypeAlias,
|
|
58
|
+
# TypeVar as astDOTTypeVar,
|
|
59
|
+
# TypeVarTuple as astDOTTypeVarTuple,
|
|
60
|
+
# )
|
|
61
|
+
# else:
|
|
62
|
+
# astDOTParamSpec: TypeAlias = yourPythonIsOld
|
|
63
|
+
# astDOTtype_param: TypeAlias = yourPythonIsOld
|
|
64
|
+
# astDOTTypeAlias: TypeAlias = yourPythonIsOld
|
|
65
|
+
# astDOTTypeVar: TypeAlias = yourPythonIsOld
|
|
66
|
+
# astDOTTypeVarTuple: TypeAlias = yourPythonIsOld
|
|
66
67
|
|
|
67
68
|
if sys.version_info >= (3, 11):
|
|
68
|
-
from ast import TryStar as astDOTTryStar
|
|
69
|
+
# from ast import TryStar as astDOTTryStar
|
|
69
70
|
from typing import TypedDict as TypedDict
|
|
70
71
|
from typing import NotRequired as NotRequired
|
|
71
72
|
else:
|
|
72
|
-
astDOTTryStar: TypeAlias =
|
|
73
|
+
astDOTTryStar: TypeAlias = yourPythonIsOld
|
|
73
74
|
try:
|
|
74
75
|
from typing_extensions import TypedDict as TypedDict
|
|
75
76
|
from typing_extensions import NotRequired as NotRequired
|
|
76
77
|
except Exception:
|
|
77
|
-
TypedDict = dict[
|
|
78
|
+
TypedDict = dict[yourPythonIsOld, yourPythonIsOld]
|
|
78
79
|
from collections.abc import Iterable
|
|
79
80
|
NotRequired: TypeAlias = Iterable
|
|
80
81
|
|
|
81
|
-
from mapFolding.datatypes import (
|
|
82
|
+
from mapFolding.datatypes import (
|
|
82
83
|
Array1DElephino as Array1DElephino,
|
|
83
84
|
Array1DFoldsTotal as Array1DFoldsTotal,
|
|
84
85
|
Array1DLeavesTotal as Array1DLeavesTotal,
|
|
@@ -92,18 +93,18 @@ from mapFolding.datatypes import ( # noqa: E402
|
|
|
92
93
|
NumPyLeavesTotal as NumPyLeavesTotal,
|
|
93
94
|
)
|
|
94
95
|
|
|
95
|
-
from mapFolding.theSSOT import (
|
|
96
|
+
from mapFolding.theSSOT import (
|
|
96
97
|
ComputationState as ComputationState,
|
|
97
98
|
raiseIfNoneGitHubIssueNumber3 as raiseIfNoneGitHubIssueNumber3,
|
|
98
99
|
The as The,
|
|
99
100
|
)
|
|
100
101
|
|
|
101
|
-
from mapFolding.theDao import (
|
|
102
|
+
from mapFolding.theDao import (
|
|
102
103
|
countInitialize as countInitialize,
|
|
103
104
|
doTheNeedful as doTheNeedful,
|
|
104
105
|
)
|
|
105
106
|
|
|
106
|
-
from mapFolding.beDRY import (
|
|
107
|
+
from mapFolding.beDRY import (
|
|
107
108
|
getLeavesTotal as getLeavesTotal,
|
|
108
109
|
getTaskDivisions as getTaskDivisions,
|
|
109
110
|
outfitCountFolds as outfitCountFolds,
|
|
@@ -111,17 +112,18 @@ from mapFolding.beDRY import ( # noqa: E402
|
|
|
111
112
|
validateListDimensions as validateListDimensions,
|
|
112
113
|
)
|
|
113
114
|
|
|
114
|
-
from mapFolding.toolboxFilesystem import (
|
|
115
|
+
from mapFolding.toolboxFilesystem import (
|
|
115
116
|
getPathFilenameFoldsTotal as getPathFilenameFoldsTotal,
|
|
116
117
|
getPathRootJobDEFAULT as getPathRootJobDEFAULT,
|
|
117
118
|
saveFoldsTotal as saveFoldsTotal,
|
|
118
119
|
saveFoldsTotalFAILearly as saveFoldsTotalFAILearly,
|
|
119
|
-
writeStringToHere as writeStringToHere,
|
|
120
120
|
)
|
|
121
121
|
|
|
122
|
-
from
|
|
122
|
+
from Z0Z_tools import writeStringToHere as writeStringToHere
|
|
123
|
+
|
|
124
|
+
from mapFolding.basecamp import countFolds as countFolds
|
|
123
125
|
|
|
124
|
-
from mapFolding.oeis import (
|
|
126
|
+
from mapFolding.oeis import (
|
|
125
127
|
clearOEIScache as clearOEIScache,
|
|
126
128
|
getFoldsTotalKnown as getFoldsTotalKnown,
|
|
127
129
|
getOEISids as getOEISids,
|
{mapfolding-0.9.5 → mapfolding-0.11.0}/mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py
RENAMED
|
@@ -2,11 +2,11 @@ from mapFolding import raiseIfNoneGitHubIssueNumber3, The
|
|
|
2
2
|
from mapFolding.someAssemblyRequired import (
|
|
3
3
|
ast_Identifier,
|
|
4
4
|
astModuleToIngredientsFunction,
|
|
5
|
-
|
|
5
|
+
Be,
|
|
6
6
|
DOT,
|
|
7
7
|
extractFunctionDef,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Grab,
|
|
9
|
+
IfThis,
|
|
10
10
|
IngredientsFunction,
|
|
11
11
|
IngredientsModule,
|
|
12
12
|
LedgerOfImports,
|
|
@@ -26,7 +26,7 @@ from mapFolding.someAssemblyRequired.transformationTools import (
|
|
|
26
26
|
shatter_dataclassesDOTdataclass,
|
|
27
27
|
unpackDataclassCallFunctionRepackDataclass,
|
|
28
28
|
write_astModule,
|
|
29
|
-
|
|
29
|
+
)
|
|
30
30
|
from pathlib import PurePath
|
|
31
31
|
import ast
|
|
32
32
|
|
|
@@ -35,7 +35,7 @@ sourceCallableIdentifierHARDCODED = 'count'
|
|
|
35
35
|
logicalPathInfixHARDCODED: ast_Identifier = 'syntheticModules'
|
|
36
36
|
theCountingIdentifierHARDCODED: ast_Identifier = 'groupsOfFolds'
|
|
37
37
|
|
|
38
|
-
def makeInitializeGroupsOfFolds():
|
|
38
|
+
def makeInitializeGroupsOfFolds() -> None:
|
|
39
39
|
callableIdentifierHARDCODED = 'initializeGroupsOfFolds'
|
|
40
40
|
moduleIdentifierHARDCODED: ast_Identifier = 'initializeCount'
|
|
41
41
|
|
|
@@ -53,15 +53,12 @@ def makeInitializeGroupsOfFolds():
|
|
|
53
53
|
|
|
54
54
|
countInitializeIngredients.astFunctionDef.name = callableIdentifier
|
|
55
55
|
|
|
56
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
56
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countInitializeIngredients.astFunctionDef)
|
|
57
57
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
58
58
|
theCountingIdentifier = theCountingIdentifierHARDCODED
|
|
59
59
|
|
|
60
|
-
findThis =
|
|
61
|
-
doThat =
|
|
62
|
-
grab.opsAttribute(Then.replaceWith([ast.Eq()])), # type: ignore
|
|
63
|
-
grab.leftAttribute(grab.attrAttribute(Then.replaceWith(theCountingIdentifier))) # type: ignore
|
|
64
|
-
]))
|
|
60
|
+
findThis = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
61
|
+
doThat = Grab.testAttribute(Grab.andDoAllOf([ Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier))) ])) # type: ignore
|
|
65
62
|
NodeChanger(findThis, doThat).visit(countInitializeIngredients.astFunctionDef.body[0])
|
|
66
63
|
|
|
67
64
|
ingredientsModule = IngredientsModule(countInitializeIngredients)
|
|
@@ -70,7 +67,7 @@ def makeInitializeGroupsOfFolds():
|
|
|
70
67
|
|
|
71
68
|
write_astModule(ingredientsModule, pathFilename, The.packageName)
|
|
72
69
|
|
|
73
|
-
def makeDaoOfMapFolding():
|
|
70
|
+
def makeDaoOfMapFolding() -> PurePath:
|
|
74
71
|
moduleIdentifierHARDCODED: ast_Identifier = 'daoOfMapFolding'
|
|
75
72
|
|
|
76
73
|
algorithmSourceModule = algorithmSourceModuleHARDCODED
|
|
@@ -84,9 +81,9 @@ def makeDaoOfMapFolding():
|
|
|
84
81
|
daoOfMapFolding = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
|
|
85
82
|
, LedgerOfImports(astModule))
|
|
86
83
|
|
|
87
|
-
dataclassName: ast.expr | None = NodeTourist(
|
|
84
|
+
dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(daoOfMapFolding.astFunctionDef)
|
|
88
85
|
if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
|
|
89
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(
|
|
86
|
+
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
90
87
|
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
91
88
|
|
|
92
89
|
dataclassLogicalPathModule = None
|
|
@@ -98,7 +95,7 @@ def makeDaoOfMapFolding():
|
|
|
98
95
|
if dataclassLogicalPathModule:
|
|
99
96
|
break
|
|
100
97
|
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
101
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
98
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(daoOfMapFolding.astFunctionDef)
|
|
102
99
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
103
100
|
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
104
101
|
|
|
@@ -121,13 +118,14 @@ def makeDaoOfMapFolding():
|
|
|
121
118
|
doTheNeedful.imports.update(shatteredDataclass.imports)
|
|
122
119
|
targetCallableIdentifier = daoOfMapFolding.astFunctionDef.name
|
|
123
120
|
doTheNeedful = unpackDataclassCallFunctionRepackDataclass(doTheNeedful, targetCallableIdentifier, shatteredDataclass)
|
|
124
|
-
astTuple: ast.Tuple | None = NodeTourist(
|
|
121
|
+
astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(daoOfMapFolding.astFunctionDef)
|
|
125
122
|
if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
|
|
126
123
|
astTuple.ctx = ast.Store()
|
|
127
124
|
|
|
128
|
-
findThis =
|
|
129
|
-
doThat = Then.replaceWith(Make.Assign(
|
|
130
|
-
NodeChanger(findThis, doThat)
|
|
125
|
+
findThis = IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier))
|
|
126
|
+
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
|
|
127
|
+
changeAssignCallToTarget = NodeChanger(findThis, doThat)
|
|
128
|
+
changeAssignCallToTarget.visit(doTheNeedful.astFunctionDef)
|
|
131
129
|
|
|
132
130
|
ingredientsModule = IngredientsModule([daoOfMapFolding, doTheNeedful])
|
|
133
131
|
ingredientsModule.removeImportFromModule('numpy')
|
|
@@ -138,7 +136,7 @@ def makeDaoOfMapFolding():
|
|
|
138
136
|
|
|
139
137
|
return pathFilename
|
|
140
138
|
|
|
141
|
-
def makeTheorem2():
|
|
139
|
+
def makeTheorem2() -> PurePath:
|
|
142
140
|
moduleIdentifierHARDCODED: ast_Identifier = 'theorem2'
|
|
143
141
|
|
|
144
142
|
algorithmSourceModule = algorithmSourceModuleHARDCODED
|
|
@@ -152,31 +150,31 @@ def makeTheorem2():
|
|
|
152
150
|
countTheorem2 = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
|
|
153
151
|
, LedgerOfImports(astModule))
|
|
154
152
|
|
|
155
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
153
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countTheorem2.astFunctionDef)
|
|
156
154
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
157
155
|
|
|
158
|
-
findThis =
|
|
159
|
-
doThat =
|
|
156
|
+
findThis = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
157
|
+
doThat = Grab.testAttribute(Grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)]))) # type: ignore
|
|
160
158
|
NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
|
|
161
159
|
|
|
162
|
-
findThis =
|
|
160
|
+
findThis = IfThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
163
161
|
doThat = Then.extractIt(DOT.body)
|
|
164
162
|
insertLeaf = NodeTourist(findThis, doThat).captureLastMatch(countTheorem2.astFunctionDef)
|
|
165
|
-
findThis =
|
|
163
|
+
findThis = IfThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
166
164
|
doThat = Then.replaceWith(insertLeaf)
|
|
167
165
|
NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
|
|
168
166
|
|
|
169
|
-
findThis =
|
|
167
|
+
findThis = IfThis.isAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
170
168
|
doThat = Then.removeIt
|
|
171
169
|
NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
|
|
172
170
|
|
|
173
|
-
findThis =
|
|
171
|
+
findThis = IfThis.isAttributeNamespace_IdentifierLessThanOrEqual(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
174
172
|
doThat = Then.removeIt
|
|
175
173
|
NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
|
|
176
174
|
|
|
177
175
|
theCountingIdentifier = theCountingIdentifierHARDCODED
|
|
178
176
|
doubleTheCount = Make.AugAssign(Make.Attribute(ast.Name(dataclassInstanceIdentifier), theCountingIdentifier), ast.Mult(), Make.Constant(2))
|
|
179
|
-
findThis =
|
|
177
|
+
findThis = Be.Return
|
|
180
178
|
doThat = Then.insertThisAbove([doubleTheCount])
|
|
181
179
|
NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
|
|
182
180
|
|
|
@@ -188,15 +186,15 @@ def makeTheorem2():
|
|
|
188
186
|
|
|
189
187
|
return pathFilename
|
|
190
188
|
|
|
191
|
-
def trimTheorem2(pathFilenameSource: PurePath):
|
|
189
|
+
def trimTheorem2(pathFilenameSource: PurePath) -> PurePath:
|
|
192
190
|
logicalPathInfix = logicalPathInfixHARDCODED
|
|
193
191
|
sourceCallableIdentifier = sourceCallableIdentifierHARDCODED
|
|
194
192
|
ingredientsFunction = astModuleToIngredientsFunction(parsePathFilename2astModule(pathFilenameSource), sourceCallableIdentifier)
|
|
195
193
|
|
|
196
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
194
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
197
195
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
198
196
|
|
|
199
|
-
findThis =
|
|
197
|
+
findThis = IfThis.isIfUnaryNotAttributeNamespace_Identifier(dataclassInstanceIdentifier, 'dimensionsUnconstrained')
|
|
200
198
|
doThat = Then.removeIt
|
|
201
199
|
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
202
200
|
|
|
@@ -215,17 +213,17 @@ def trimTheorem2(pathFilenameSource: PurePath):
|
|
|
215
213
|
logicalPath.append(pathFilename.stem)
|
|
216
214
|
moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
|
|
217
215
|
|
|
218
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath,
|
|
216
|
+
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(ingredientsFunction.astFunctionDef.name)])
|
|
219
217
|
|
|
220
218
|
return pathFilename
|
|
221
219
|
|
|
222
|
-
def numbaOnTheorem2(pathFilenameSource: PurePath):
|
|
220
|
+
def numbaOnTheorem2(pathFilenameSource: PurePath) -> ast.ImportFrom:
|
|
223
221
|
logicalPathInfix = logicalPathInfixHARDCODED
|
|
224
222
|
sourceCallableIdentifier = sourceCallableIdentifierHARDCODED
|
|
225
223
|
countNumbaTheorem2 = astModuleToIngredientsFunction(parsePathFilename2astModule(pathFilenameSource), sourceCallableIdentifier)
|
|
226
|
-
dataclassName: ast.expr | None = NodeTourist(
|
|
224
|
+
dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
|
|
227
225
|
if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
|
|
228
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(
|
|
226
|
+
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
229
227
|
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
230
228
|
|
|
231
229
|
dataclassLogicalPathModule = None
|
|
@@ -237,7 +235,7 @@ def numbaOnTheorem2(pathFilenameSource: PurePath):
|
|
|
237
235
|
if dataclassLogicalPathModule:
|
|
238
236
|
break
|
|
239
237
|
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
240
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
238
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
|
|
241
239
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
242
240
|
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
243
241
|
|
|
@@ -263,11 +261,11 @@ def numbaOnTheorem2(pathFilenameSource: PurePath):
|
|
|
263
261
|
logicalPath.append(pathFilename.stem)
|
|
264
262
|
moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
|
|
265
263
|
|
|
266
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath,
|
|
264
|
+
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(countNumbaTheorem2.astFunctionDef.name)])
|
|
267
265
|
|
|
268
266
|
return astImportFrom
|
|
269
267
|
|
|
270
|
-
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
|
|
268
|
+
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom) -> None:
|
|
271
269
|
moduleIdentifierHARDCODED: ast_Identifier = 'dataPacking'
|
|
272
270
|
|
|
273
271
|
algorithmSourceModule = algorithmSourceModuleHARDCODED
|
|
@@ -278,9 +276,9 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
|
|
|
278
276
|
moduleIdentifier = moduleIdentifierHARDCODED
|
|
279
277
|
|
|
280
278
|
doTheNeedful: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
|
|
281
|
-
dataclassName: ast.expr | None = NodeTourist(
|
|
279
|
+
dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(doTheNeedful.astFunctionDef)
|
|
282
280
|
if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
|
|
283
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(
|
|
281
|
+
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
284
282
|
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
285
283
|
|
|
286
284
|
dataclassLogicalPathModule = None
|
|
@@ -292,7 +290,7 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
|
|
|
292
290
|
if dataclassLogicalPathModule:
|
|
293
291
|
break
|
|
294
292
|
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
295
|
-
dataclassInstanceIdentifier = NodeTourist(
|
|
293
|
+
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(doTheNeedful.astFunctionDef)
|
|
296
294
|
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
297
295
|
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
298
296
|
|
|
@@ -300,14 +298,15 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
|
|
|
300
298
|
doTheNeedful.imports.addAst(astImportFrom)
|
|
301
299
|
targetCallableIdentifier = astImportFrom.names[0].name
|
|
302
300
|
doTheNeedful = unpackDataclassCallFunctionRepackDataclass(doTheNeedful, targetCallableIdentifier, shatteredDataclass)
|
|
303
|
-
|
|
301
|
+
if astImportFrom.module is None: raise raiseIfNoneGitHubIssueNumber3
|
|
302
|
+
targetFunctionDef = extractFunctionDef(parseLogicalPath2astModule(astImportFrom.module), targetCallableIdentifier)
|
|
304
303
|
if targetFunctionDef is None: raise raiseIfNoneGitHubIssueNumber3
|
|
305
|
-
astTuple: ast.Tuple | None = NodeTourist(
|
|
304
|
+
astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)
|
|
306
305
|
if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
|
|
307
306
|
astTuple.ctx = ast.Store()
|
|
308
307
|
|
|
309
|
-
findThis =
|
|
310
|
-
doThat = Then.replaceWith(Make.Assign(
|
|
308
|
+
findThis = IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier))
|
|
309
|
+
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
|
|
311
310
|
NodeChanger(findThis, doThat).visit(doTheNeedful.astFunctionDef)
|
|
312
311
|
|
|
313
312
|
ingredientsModule = IngredientsModule(doTheNeedful)
|
|
@@ -44,54 +44,36 @@ optimizations - while maintaining the ability to verify correctness at each tran
|
|
|
44
44
|
test suite.
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
from
|
|
47
|
+
from astToolkit import (
|
|
48
48
|
ast_expr_Slice as ast_expr_Slice,
|
|
49
49
|
ast_Identifier as ast_Identifier,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
astClassHasDOTtarget as astClassHasDOTtarget,
|
|
57
|
-
astClassHasDOTtarget_expr as astClassHasDOTtarget_expr,
|
|
58
|
-
astClassHasDOTtargetAttributeNameSubscript as astClassHasDOTtargetAttributeNameSubscript,
|
|
59
|
-
astClassHasDOTvalue as astClassHasDOTvalue,
|
|
60
|
-
astClassHasDOTvalue_expr as astClassHasDOTvalue_expr,
|
|
61
|
-
astClassHasDOTvalue_exprNone as astClassHasDOTvalue_exprNone,
|
|
50
|
+
astModuleToIngredientsFunction as astModuleToIngredientsFunction,
|
|
51
|
+
Be as Be,
|
|
52
|
+
DOT as DOT,
|
|
53
|
+
extractClassDef as extractClassDef,
|
|
54
|
+
extractFunctionDef as extractFunctionDef,
|
|
55
|
+
Grab as Grab,
|
|
62
56
|
ImaCallToName as ImaCallToName,
|
|
63
|
-
intORlist_ast_type_paramORstr_orNone as intORlist_ast_type_paramORstr_orNone,
|
|
64
|
-
intORstr_orNone as intORstr_orNone,
|
|
65
|
-
list_ast_type_paramORstr_orNone as list_ast_type_paramORstr_orNone,
|
|
66
|
-
NodeORattribute as NodeORattribute,
|
|
67
|
-
str_nameDOTname as str_nameDOTname,
|
|
68
|
-
个 as 个,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
from mapFolding.someAssemblyRequired._toolboxPython import (
|
|
72
57
|
importLogicalPath2Callable as importLogicalPath2Callable,
|
|
73
58
|
importPathFilename2Callable as importPathFilename2Callable,
|
|
59
|
+
IngredientsFunction as IngredientsFunction,
|
|
60
|
+
IngredientsModule as IngredientsModule,
|
|
61
|
+
LedgerOfImports as LedgerOfImports,
|
|
62
|
+
Make as Make,
|
|
74
63
|
NodeChanger as NodeChanger,
|
|
64
|
+
NodeORattribute as NodeORattribute,
|
|
75
65
|
NodeTourist as NodeTourist,
|
|
76
66
|
parseLogicalPath2astModule as parseLogicalPath2astModule,
|
|
77
67
|
parsePathFilename2astModule as parsePathFilename2astModule,
|
|
78
|
-
|
|
68
|
+
str_nameDOTname as str_nameDOTname,
|
|
69
|
+
Then as Then,
|
|
70
|
+
个 as 个,
|
|
71
|
+
)
|
|
79
72
|
|
|
80
|
-
from mapFolding.someAssemblyRequired.
|
|
81
|
-
from mapFolding.someAssemblyRequired._tool_Make import Make as Make
|
|
82
|
-
from mapFolding.someAssemblyRequired._tool_Then import grab as grab, Then as Then
|
|
73
|
+
from mapFolding.someAssemblyRequired._toolIfThis import IfThis as IfThis
|
|
83
74
|
|
|
84
75
|
from mapFolding.someAssemblyRequired._toolboxContainers import (
|
|
85
76
|
DeReConstructField2ast as DeReConstructField2ast,
|
|
86
|
-
IngredientsFunction as IngredientsFunction,
|
|
87
|
-
IngredientsModule as IngredientsModule,
|
|
88
|
-
LedgerOfImports as LedgerOfImports,
|
|
89
77
|
RecipeSynthesizeFlow as RecipeSynthesizeFlow,
|
|
90
78
|
ShatteredDataclass as ShatteredDataclass,
|
|
91
79
|
)
|
|
92
|
-
|
|
93
|
-
from mapFolding.someAssemblyRequired._toolboxAST import (
|
|
94
|
-
astModuleToIngredientsFunction as astModuleToIngredientsFunction,
|
|
95
|
-
extractClassDef as extractClassDef,
|
|
96
|
-
extractFunctionDef as extractFunctionDef,
|
|
97
|
-
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AST Node Predicate and Access Utilities for Pattern Matching and Traversal
|
|
3
|
+
|
|
4
|
+
This module provides utilities for accessing and matching AST nodes in a consistent way. It contains three primary
|
|
5
|
+
classes:
|
|
6
|
+
|
|
7
|
+
1. DOT: Provides consistent accessor methods for AST node attributes across different node types, simplifying the access
|
|
8
|
+
to node properties.
|
|
9
|
+
|
|
10
|
+
2. be: Offers type-guard functions that verify AST node types, enabling safe type narrowing for static type checking and
|
|
11
|
+
improving code safety.
|
|
12
|
+
|
|
13
|
+
3. ifThis: Contains predicate functions for matching AST nodes based on various criteria, enabling precise targeting of
|
|
14
|
+
nodes for analysis or transformation.
|
|
15
|
+
|
|
16
|
+
These utilities form the foundation of the pattern-matching component in the AST manipulation framework, working in
|
|
17
|
+
conjunction with the NodeChanger and NodeTourist classes to enable precise and targeted code transformations. Together,
|
|
18
|
+
they implement a declarative approach to AST manipulation that separates node identification (ifThis), type verification
|
|
19
|
+
(be), and data access (DOT).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from astToolkit import IfThis as astToolkit_IfThis
|
|
23
|
+
from collections.abc import Callable
|
|
24
|
+
from mapFolding.someAssemblyRequired import ast_Identifier, Be
|
|
25
|
+
from typing import TypeGuard
|
|
26
|
+
import ast
|
|
27
|
+
|
|
28
|
+
class IfThis(astToolkit_IfThis):
|
|
29
|
+
"""
|
|
30
|
+
Provide predicate functions for matching and filtering AST nodes based on various criteria.
|
|
31
|
+
|
|
32
|
+
The ifThis class contains static methods that generate predicate functions used to test whether AST nodes match
|
|
33
|
+
specific criteria. These predicates can be used with NodeChanger and NodeTourist to identify and process specific
|
|
34
|
+
patterns in the AST.
|
|
35
|
+
|
|
36
|
+
The class provides predicates for matching various node types, attributes, identifiers, and structural patterns,
|
|
37
|
+
enabling precise targeting of AST elements for analysis or transformation.
|
|
38
|
+
"""
|
|
39
|
+
@staticmethod
|
|
40
|
+
def isAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
|
|
41
|
+
return lambda node: (Be.Compare(node)
|
|
42
|
+
and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(node.left)
|
|
43
|
+
and Be.Gt(node.ops[0])
|
|
44
|
+
and IfThis.isConstant_value(0)(node.comparators[0]))
|
|
45
|
+
@staticmethod
|
|
46
|
+
def isIfAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.If] | bool]:
|
|
47
|
+
return lambda node: (Be.If(node)
|
|
48
|
+
and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test))
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def isWhileAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
|
|
52
|
+
return lambda node: (Be.While(node)
|
|
53
|
+
and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test))
|