mapFolding 0.11.3__py3-none-any.whl → 0.12.0__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.
- mapFolding/oeis.py +9 -5
- mapFolding/someAssemblyRequired/RecipeJob.py +14 -14
- mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +188 -247
- mapFolding/someAssemblyRequired/__init__.py +7 -2
- mapFolding/someAssemblyRequired/_toolIfThis.py +7 -7
- mapFolding/someAssemblyRequired/_toolkitContainers.py +12 -12
- mapFolding/someAssemblyRequired/infoBooth.py +14 -67
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +11 -12
- mapFolding/someAssemblyRequired/toolkitNumba.py +4 -4
- mapFolding/someAssemblyRequired/transformationTools.py +4 -15
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/METADATA +2 -4
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/RECORD +16 -16
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/WHEEL +1 -1
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.11.3.dist-info → mapfolding-0.12.0.dist-info}/top_level.txt +0 -0
mapFolding/oeis.py
CHANGED
|
@@ -23,13 +23,13 @@ from functools import cache
|
|
|
23
23
|
from mapFolding import countFolds, packageSettings, TypedDict
|
|
24
24
|
from pathlib import Path
|
|
25
25
|
from typing import Any, Final
|
|
26
|
+
from urllib.parse import urlparse
|
|
26
27
|
from Z0Z_tools import writeStringToHere
|
|
27
28
|
import argparse
|
|
28
29
|
import random
|
|
29
30
|
import sys
|
|
30
31
|
import time
|
|
31
32
|
import urllib.request
|
|
32
|
-
import urllib.response
|
|
33
33
|
import warnings
|
|
34
34
|
|
|
35
35
|
cacheDays = 30
|
|
@@ -186,10 +186,14 @@ def getOEISofficial(pathFilenameCache: Path, url: str) -> None | str:
|
|
|
186
186
|
tryCache = False
|
|
187
187
|
|
|
188
188
|
if not tryCache:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
parsedUrl = urlparse(url)
|
|
190
|
+
if parsedUrl.scheme not in ("http", "https"):
|
|
191
|
+
warnings.warn(f"I received the URL '{url}', but only 'http' and 'https' schemes are permitted.")
|
|
192
|
+
else:
|
|
193
|
+
httpResponse = urllib.request.urlopen(url)
|
|
194
|
+
oeisInformationRaw = httpResponse.read().decode('utf-8')
|
|
195
|
+
oeisInformation = str(oeisInformationRaw)
|
|
196
|
+
writeStringToHere(oeisInformation, pathFilenameCache)
|
|
193
197
|
|
|
194
198
|
if not oeisInformation:
|
|
195
199
|
warnings.warn(f"Failed to retrieve OEIS sequence information for {pathFilenameCache.stem}.")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from astToolkit import
|
|
2
|
-
from mapFolding import getPathFilenameFoldsTotal, getPathRootJobDEFAULT, MapFoldingState
|
|
1
|
+
from astToolkit import parseLogicalPath2astModule, str_nameDOTname
|
|
2
|
+
from mapFolding import getPathFilenameFoldsTotal, getPathRootJobDEFAULT, MapFoldingState, packageSettings
|
|
3
3
|
from mapFolding import DatatypeElephino as TheDatatypeElephino, DatatypeFoldsTotal as TheDatatypeFoldsTotal, DatatypeLeavesTotal as TheDatatypeLeavesTotal
|
|
4
|
-
from mapFolding.someAssemblyRequired import
|
|
4
|
+
from mapFolding.someAssemblyRequired import dataclassInstanceIdentifierDEFAULT, ShatteredDataclass
|
|
5
5
|
from mapFolding.someAssemblyRequired.transformationTools import shatter_dataclassesDOTdataclass
|
|
6
6
|
from pathlib import Path, PurePosixPath
|
|
7
7
|
from typing import TypeAlias
|
|
@@ -17,32 +17,32 @@ class RecipeJobTheorem2Numba:
|
|
|
17
17
|
# ========================================
|
|
18
18
|
# Source
|
|
19
19
|
source_astModule = parseLogicalPath2astModule('mapFolding.syntheticModules.theorem2Numba')
|
|
20
|
-
sourceCountCallable:
|
|
20
|
+
sourceCountCallable: str = 'count'
|
|
21
21
|
|
|
22
22
|
sourceLogicalPathModuleDataclass: str_nameDOTname = 'mapFolding.dataBaskets'
|
|
23
|
-
sourceDataclassIdentifier:
|
|
24
|
-
sourceDataclassInstance:
|
|
23
|
+
sourceDataclassIdentifier: str = 'MapFoldingState'
|
|
24
|
+
sourceDataclassInstance: str = dataclassInstanceIdentifierDEFAULT
|
|
25
25
|
|
|
26
|
-
sourcePathPackage: PurePosixPath | None = PurePosixPath(
|
|
27
|
-
sourcePackageIdentifier:
|
|
26
|
+
sourcePathPackage: PurePosixPath | None = PurePosixPath(packageSettings.pathPackage)
|
|
27
|
+
sourcePackageIdentifier: str | None = packageSettings.packageName
|
|
28
28
|
|
|
29
29
|
# ========================================
|
|
30
30
|
# Filesystem (names of physical objects)
|
|
31
31
|
pathPackage: PurePosixPath | None = None
|
|
32
32
|
pathModule: PurePosixPath | None = PurePosixPath(getPathRootJobDEFAULT())
|
|
33
33
|
""" `pathModule` will override `pathPackage` and `logicalPathRoot`."""
|
|
34
|
-
fileExtension: str =
|
|
34
|
+
fileExtension: str = packageSettings.fileExtension
|
|
35
35
|
pathFilenameFoldsTotal: PurePosixPath = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
36
36
|
|
|
37
37
|
# ========================================
|
|
38
38
|
# Logical identifiers (as opposed to physical identifiers)
|
|
39
|
-
packageIdentifier:
|
|
39
|
+
packageIdentifier: str | None = None
|
|
40
40
|
logicalPathRoot: str_nameDOTname | None = None
|
|
41
41
|
""" `logicalPathRoot` likely corresponds to a physical filesystem directory."""
|
|
42
|
-
moduleIdentifier:
|
|
43
|
-
countCallable:
|
|
44
|
-
dataclassIdentifier:
|
|
45
|
-
dataclassInstance:
|
|
42
|
+
moduleIdentifier: str = dataclasses.field(default=None, init=True) # pyright: ignore[reportAssignmentType]
|
|
43
|
+
countCallable: str = sourceCountCallable
|
|
44
|
+
dataclassIdentifier: str | None = sourceDataclassIdentifier
|
|
45
|
+
dataclassInstance: str | None = sourceDataclassInstance
|
|
46
46
|
logicalPathModuleDataclass: str_nameDOTname | None = sourceLogicalPathModuleDataclass
|
|
47
47
|
|
|
48
48
|
# ========================================
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
from collections.abc import Sequence
|
|
2
1
|
from astToolkit import (
|
|
3
|
-
ast_Identifier,
|
|
4
2
|
astModuleToIngredientsFunction,
|
|
5
3
|
Be,
|
|
6
4
|
ClassIsAndAttribute,
|
|
@@ -20,149 +18,139 @@ from astToolkit import (
|
|
|
20
18
|
Then,
|
|
21
19
|
)
|
|
22
20
|
from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
|
|
21
|
+
from collections.abc import Sequence
|
|
22
|
+
from mapFolding import packageSettings
|
|
23
23
|
from mapFolding.someAssemblyRequired import (
|
|
24
24
|
DeReConstructField2ast,
|
|
25
25
|
IfThis,
|
|
26
|
-
|
|
27
|
-
raiseIfNoneGitHubIssueNumber3,
|
|
26
|
+
raiseIfNone,
|
|
28
27
|
ShatteredDataclass,
|
|
28
|
+
sourceCallableDispatcherDEFAULT,
|
|
29
29
|
)
|
|
30
|
+
from mapFolding.someAssemblyRequired.infoBooth import algorithmSourceModuleDEFAULT, dataPackingModuleIdentifierDEFAULT, logicalPathInfixDEFAULT, sourceCallableIdentifierDEFAULT, theCountingIdentifierDEFAULT
|
|
30
31
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
31
32
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
32
33
|
removeDataclassFromFunction,
|
|
33
34
|
shatter_dataclassesDOTdataclass,
|
|
34
35
|
unpackDataclassCallFunctionRepackDataclass,
|
|
35
36
|
)
|
|
37
|
+
from os import PathLike
|
|
36
38
|
from pathlib import PurePath
|
|
39
|
+
from typing import cast
|
|
37
40
|
from Z0Z_tools import importLogicalPath2Callable
|
|
38
41
|
import ast
|
|
39
42
|
import dataclasses
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
callableIdentifier = callableIdentifierHARDCODED
|
|
56
|
-
logicalPathInfix = logicalPathInfixHARDCODED
|
|
57
|
-
moduleIdentifier = moduleIdentifierHARDCODED
|
|
44
|
+
def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[str, str, str]:
|
|
45
|
+
dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
46
|
+
dataclass_Identifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
|
|
47
|
+
dataclassLogicalPathModule = None
|
|
48
|
+
for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports.dictionaryImportFrom.items():
|
|
49
|
+
for nameTuple in listNameTuples:
|
|
50
|
+
if nameTuple[0] == dataclass_Identifier:
|
|
51
|
+
dataclassLogicalPathModule = moduleWithLogicalPath
|
|
52
|
+
break
|
|
53
|
+
if dataclassLogicalPathModule:
|
|
54
|
+
break
|
|
55
|
+
dataclassInstanceIdentifier = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
56
|
+
return raiseIfNone(dataclassLogicalPathModule), dataclass_Identifier, dataclassInstanceIdentifier
|
|
58
57
|
|
|
58
|
+
def _getLogicalPath(packageName: str | None = None, logicalPathInfix: str | None = None, moduleIdentifier: str | None = None, *modules: str) -> str_nameDOTname:
|
|
59
|
+
listLogicalPathParts: list[str] = []
|
|
60
|
+
if packageName:
|
|
61
|
+
listLogicalPathParts.append(packageName)
|
|
62
|
+
if logicalPathInfix:
|
|
63
|
+
listLogicalPathParts.append(logicalPathInfix)
|
|
64
|
+
if moduleIdentifier:
|
|
65
|
+
listLogicalPathParts.append(moduleIdentifier)
|
|
66
|
+
if modules:
|
|
67
|
+
listLogicalPathParts.extend(modules)
|
|
68
|
+
logicalPath = '.'.join(listLogicalPathParts)
|
|
69
|
+
return logicalPath
|
|
70
|
+
|
|
71
|
+
def getModule(packageName: str | None = packageSettings.packageName, logicalPathInfix: str | None = logicalPathInfixDEFAULT, moduleIdentifier: str | None = algorithmSourceModuleDEFAULT) -> ast.Module:
|
|
72
|
+
logicalPathSourceModule = _getLogicalPath(packageName, logicalPathInfix, moduleIdentifier)
|
|
59
73
|
astModule = parseLogicalPath2astModule(logicalPathSourceModule)
|
|
60
|
-
|
|
61
|
-
, LedgerOfImports(astModule))
|
|
62
|
-
|
|
63
|
-
countInitializeIngredients.astFunctionDef.name = callableIdentifier
|
|
64
|
-
|
|
65
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countInitializeIngredients.astFunctionDef)
|
|
66
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
67
|
-
theCountingIdentifier = theCountingIdentifierHARDCODED
|
|
68
|
-
|
|
69
|
-
findThis = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
70
|
-
doThat = Grab.testAttribute(Grab.andDoAllOf([ Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier))) ])) # type: ignore
|
|
71
|
-
NodeChanger(findThis, doThat).visit(countInitializeIngredients.astFunctionDef.body[0])
|
|
72
|
-
|
|
73
|
-
ingredientsModule = IngredientsModule(countInitializeIngredients)
|
|
74
|
+
return astModule
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
def _getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix: PathLike[str] | PurePath | str | None = None, moduleIdentifier: str = '', fileExtension: str = packageSettings.fileExtension) -> PurePath:
|
|
77
|
+
pathFilename = PurePath(moduleIdentifier + fileExtension)
|
|
78
|
+
if logicalPathInfix:
|
|
79
|
+
pathFilename = PurePath(logicalPathInfix, pathFilename)
|
|
80
|
+
if pathRoot:
|
|
81
|
+
pathFilename = PurePath(pathRoot, pathFilename)
|
|
82
|
+
return pathFilename
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
def makeInitializeGroupsOfFolds(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
85
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
86
|
+
if callableIdentifier is None:
|
|
87
|
+
callableIdentifier = sourceCallableIdentifier
|
|
88
|
+
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
89
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
78
90
|
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
dataclassInstanceIdentifier = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
92
|
+
theCountingIdentifier = theCountingIdentifierDEFAULT
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
95
|
+
doThat = Grab.testAttribute(Grab.andDoAllOf([Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier)))])) # pyright: ignore[reportArgumentType]
|
|
96
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef.body[0])
|
|
85
97
|
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
99
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
100
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
daoOfMapFolding = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
|
|
91
|
-
, LedgerOfImports(astModule))
|
|
102
|
+
return pathFilename
|
|
92
103
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
104
|
+
def makeDaoOfMapFolding(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
105
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
106
|
+
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if nameTuple[0] == dataclass_Identifier:
|
|
102
|
-
dataclassLogicalPathModule = moduleWithLogicalPath
|
|
103
|
-
break
|
|
104
|
-
if dataclassLogicalPathModule:
|
|
105
|
-
break
|
|
106
|
-
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
107
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(daoOfMapFolding.astFunctionDef)
|
|
108
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
109
|
-
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
108
|
+
if callableIdentifier is None:
|
|
109
|
+
callableIdentifier = sourceCallableIdentifier
|
|
110
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
# doubleTheCount = Make.AugAssign(Make.Attribute(ast.Name(dataclassInstanceIdentifier), theCountingIdentifier), ast.Mult(), Make.Constant(2))
|
|
113
|
-
# findThis = be.Return
|
|
114
|
-
# doThat = Then.insertThisAbove([doubleTheCount])
|
|
115
|
-
# NodeChanger(findThis, doThat).visit(daoOfMapFolding.astFunctionDef)
|
|
112
|
+
shatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
115
|
+
ingredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
|
|
116
|
+
ingredientsFunction = removeUnusedParameters(ingredientsFunction)
|
|
117
|
+
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
119
118
|
|
|
120
|
-
|
|
119
|
+
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
if sourceCallableDispatcher is not None:
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
ingredientsFunctionDispatcher: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableDispatcher)
|
|
124
|
+
ingredientsFunctionDispatcher.imports.update(shatteredDataclass.imports)
|
|
125
|
+
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
126
|
+
ingredientsFunctionDispatcher = unpackDataclassCallFunctionRepackDataclass(ingredientsFunctionDispatcher, targetCallableIdentifier, shatteredDataclass)
|
|
127
|
+
astTuple = raiseIfNone(NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
128
|
+
cast(ast.Tuple, astTuple).ctx = ast.Store()
|
|
125
129
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(daoOfMapFolding.astFunctionDef) # type: ignore
|
|
131
|
-
if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
|
|
132
|
-
astTuple.ctx = ast.Store()
|
|
133
|
-
ast.Return()
|
|
130
|
+
findThis = ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCall_Identifier(targetCallableIdentifier))
|
|
131
|
+
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), cast(ast.Tuple, astTuple).elts)))
|
|
132
|
+
changeAssignCallToTarget = NodeChanger(findThis, doThat)
|
|
133
|
+
changeAssignCallToTarget.visit(ingredientsFunctionDispatcher.astFunctionDef)
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
|
|
137
|
-
changeAssignCallToTarget = NodeChanger(findThis, doThat)
|
|
138
|
-
changeAssignCallToTarget.visit(doTheNeedful.astFunctionDef)
|
|
135
|
+
ingredientsModule.appendIngredientsFunction(ingredientsFunctionDispatcher)
|
|
139
136
|
|
|
140
|
-
ingredientsModule = IngredientsModule([daoOfMapFolding, doTheNeedful])
|
|
141
137
|
ingredientsModule.removeImportFromModule('numpy')
|
|
142
138
|
|
|
143
|
-
pathFilename =
|
|
139
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
144
140
|
|
|
145
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
141
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
146
142
|
|
|
147
143
|
return pathFilename
|
|
148
144
|
|
|
149
|
-
def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
sourceCallableIdentifier = sourceCallableIdentifierHARDCODED
|
|
154
|
-
logicalPathSourceModule = '.'.join([packageInformation.packageName, algorithmSourceModule])
|
|
155
|
-
|
|
156
|
-
logicalPathInfix = logicalPathInfixHARDCODED
|
|
157
|
-
moduleIdentifier = moduleIdentifierHARDCODED
|
|
158
|
-
|
|
159
|
-
astModule = parseLogicalPath2astModule(logicalPathSourceModule)
|
|
145
|
+
def makeDaoOfMapFoldingParallel(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
146
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
147
|
+
if callableIdentifier is None:
|
|
148
|
+
callableIdentifier = sourceCallableIdentifier
|
|
160
149
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
150
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
161
151
|
|
|
162
|
-
dataclassName: ast.expr
|
|
163
|
-
|
|
164
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
165
|
-
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
152
|
+
dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
153
|
+
dataclass_Identifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
|
|
166
154
|
|
|
167
155
|
dataclassLogicalPathModule = None
|
|
168
156
|
for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports.dictionaryImportFrom.items():
|
|
@@ -172,9 +160,8 @@ def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
|
172
160
|
break
|
|
173
161
|
if dataclassLogicalPathModule:
|
|
174
162
|
break
|
|
175
|
-
if dataclassLogicalPathModule is None: raise
|
|
176
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
177
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
163
|
+
if dataclassLogicalPathModule is None: raise Exception
|
|
164
|
+
dataclassInstanceIdentifier = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
178
165
|
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
179
166
|
|
|
180
167
|
# Start add the parallel state fields to the count function ================================================
|
|
@@ -183,8 +170,8 @@ def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
|
183
170
|
dataclassFieldsParallel = dataclasses.fields(importLogicalPath2Callable(dataclassLogicalPathModule, dataclass_IdentifierParallel)) # pyright: ignore [reportArgumentType]
|
|
184
171
|
onlyParallelFields = [field for field in dataclassFieldsParallel if field.name not in [fieldBase.name for fieldBase in dataclassBaseFields]]
|
|
185
172
|
|
|
186
|
-
Official_fieldOrder: list[
|
|
187
|
-
dictionaryDeReConstruction: dict[
|
|
173
|
+
Official_fieldOrder: list[str] = []
|
|
174
|
+
dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
|
|
188
175
|
|
|
189
176
|
dataclassClassDef = extractClassDef(parseLogicalPath2astModule(dataclassLogicalPathModule), dataclass_IdentifierParallel)
|
|
190
177
|
if not isinstance(dataclassClassDef, ast.ClassDef): raise ValueError(f"I could not find `{dataclass_IdentifierParallel = }` in `{dataclassLogicalPathModule = }`.")
|
|
@@ -224,8 +211,7 @@ def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
|
224
211
|
findThis = ClassIsAndAttribute.testIs(ast.While, ClassIsAndAttribute.leftIs(ast.Compare, IfThis.isName_Identifier('leafConnectee')))
|
|
225
212
|
doThat = Then.extractIt(DOT.body)
|
|
226
213
|
captureCountGapsCodeBlock: NodeTourist[ast.While, Sequence[ast.stmt]] = NodeTourist(findThis, doThat)
|
|
227
|
-
countGapsCodeBlock = captureCountGapsCodeBlock.captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
228
|
-
if countGapsCodeBlock is None: raise raiseIfNoneGitHubIssueNumber3
|
|
214
|
+
countGapsCodeBlock = raiseIfNone(captureCountGapsCodeBlock.captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
229
215
|
|
|
230
216
|
thisIsMyTaskIndexCodeBlock = ast.If(ast.BoolOp(ast.Or()
|
|
231
217
|
, values=[ast.Compare(ast.Name('leaf1ndex'), ops=[ast.NotEq()], comparators=[ast.Name('taskDivisions')])
|
|
@@ -244,23 +230,22 @@ def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
|
244
230
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
245
231
|
|
|
246
232
|
# Start unpack/repack the dataclass function ================================================
|
|
247
|
-
sourceCallableIdentifier =
|
|
233
|
+
sourceCallableIdentifier = sourceCallableDispatcherDEFAULT
|
|
248
234
|
|
|
249
235
|
unRepackDataclass: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableIdentifier)
|
|
250
236
|
unRepackDataclass.astFunctionDef.name = 'unRepack' + dataclass_IdentifierParallel
|
|
251
237
|
unRepackDataclass.imports.update(shatteredDataclassParallel.imports)
|
|
252
|
-
findThis = ClassIsAndAttribute.annotationIs(ast.arg, IfThis.isName_Identifier(dataclass_Identifier)) #
|
|
253
|
-
doThat = Grab.annotationAttribute(Grab.idAttribute(Then.replaceWith(dataclass_IdentifierParallel))) #
|
|
254
|
-
NodeChanger(findThis, doThat).visit(unRepackDataclass.astFunctionDef) #
|
|
238
|
+
findThis = ClassIsAndAttribute.annotationIs(ast.arg, IfThis.isName_Identifier(dataclass_Identifier)) # pyright: ignore[reportArgumentType, reportUnknownVariableType, reportCallIssue]
|
|
239
|
+
doThat = Grab.annotationAttribute(Grab.idAttribute(Then.replaceWith(dataclass_IdentifierParallel))) # pyright: ignore[reportArgumentType]
|
|
240
|
+
NodeChanger(findThis, doThat).visit(unRepackDataclass.astFunctionDef) # pyright: ignore[reportUnknownArgumentType]
|
|
255
241
|
unRepackDataclass.astFunctionDef.returns = Make.Name(dataclass_IdentifierParallel)
|
|
256
242
|
targetCallableIdentifier = ingredientsFunction.astFunctionDef.name
|
|
257
243
|
unRepackDataclass = unpackDataclassCallFunctionRepackDataclass(unRepackDataclass, targetCallableIdentifier, shatteredDataclassParallel)
|
|
258
244
|
|
|
259
|
-
astTuple
|
|
260
|
-
|
|
261
|
-
astTuple.ctx = ast.Store()
|
|
245
|
+
astTuple = raiseIfNone(NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
246
|
+
cast(ast.Tuple, astTuple).ctx = ast.Store()
|
|
262
247
|
findThis = ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCall_Identifier(targetCallableIdentifier))
|
|
263
|
-
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
|
|
248
|
+
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), cast(ast.Tuple, astTuple).elts)))
|
|
264
249
|
changeAssignCallToTarget = NodeChanger(findThis, doThat)
|
|
265
250
|
changeAssignCallToTarget.visit(unRepackDataclass.astFunctionDef)
|
|
266
251
|
|
|
@@ -295,68 +280,64 @@ def makeDaoOfMapFoldingParallel() -> PurePath:
|
|
|
295
280
|
)
|
|
296
281
|
ingredientsModule.removeImportFromModule('numpy')
|
|
297
282
|
|
|
298
|
-
pathFilename =
|
|
283
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
299
284
|
|
|
300
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
285
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
301
286
|
return pathFilename
|
|
302
287
|
|
|
303
|
-
def makeTheorem2() -> PurePath:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
logicalPathInfix = logicalPathInfixHARDCODED
|
|
311
|
-
moduleIdentifier = moduleIdentifierHARDCODED
|
|
312
|
-
|
|
313
|
-
astModule = parseLogicalPath2astModule(logicalPathSourceModule)
|
|
314
|
-
countTheorem2 = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
|
|
315
|
-
, LedgerOfImports(astModule))
|
|
288
|
+
def makeTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
289
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
290
|
+
if callableIdentifier is None:
|
|
291
|
+
callableIdentifier = sourceCallableIdentifier
|
|
292
|
+
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
293
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
316
294
|
|
|
317
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(
|
|
318
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
295
|
+
dataclassInstanceIdentifier = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
319
296
|
|
|
320
|
-
findThis = IfThis.
|
|
321
|
-
doThat = Grab.testAttribute(Grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)]))) #
|
|
322
|
-
NodeChanger(findThis, doThat).visit(
|
|
297
|
+
findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
298
|
+
doThat = Grab.testAttribute(Grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)]))) # pyright: ignore[reportArgumentType]
|
|
299
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
323
300
|
|
|
324
|
-
findThis = IfThis.
|
|
301
|
+
findThis = IfThis.isIfAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
325
302
|
doThat = Then.extractIt(DOT.body)
|
|
326
|
-
insertLeaf = NodeTourist(findThis, doThat).captureLastMatch(
|
|
327
|
-
findThis = IfThis.
|
|
303
|
+
insertLeaf = NodeTourist(findThis, doThat).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
304
|
+
findThis = IfThis.isIfAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
328
305
|
doThat = Then.replaceWith(insertLeaf)
|
|
329
|
-
NodeChanger(findThis, doThat).visit(
|
|
306
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
330
307
|
|
|
331
|
-
findThis = IfThis.
|
|
308
|
+
findThis = IfThis.isAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
332
309
|
doThat = Then.removeIt
|
|
333
|
-
NodeChanger(findThis, doThat).visit(
|
|
310
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
334
311
|
|
|
335
|
-
findThis = IfThis.
|
|
312
|
+
findThis = IfThis.isAttributeNamespaceIdentifierLessThanOrEqual0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
336
313
|
doThat = Then.removeIt
|
|
337
|
-
NodeChanger(findThis, doThat).visit(
|
|
314
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
338
315
|
|
|
339
|
-
theCountingIdentifier =
|
|
316
|
+
theCountingIdentifier = theCountingIdentifierDEFAULT
|
|
340
317
|
doubleTheCount = Make.AugAssign(Make.Attribute(ast.Name(dataclassInstanceIdentifier), theCountingIdentifier), ast.Mult(), Make.Constant(2))
|
|
341
318
|
findThis = Be.Return
|
|
342
319
|
doThat = Then.insertThisAbove([doubleTheCount])
|
|
343
|
-
NodeChanger(findThis, doThat).visit(
|
|
320
|
+
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
321
|
+
|
|
322
|
+
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
344
323
|
|
|
345
|
-
|
|
324
|
+
if sourceCallableDispatcher is not None:
|
|
325
|
+
raise NotImplementedError('sourceCallableDispatcher is not implemented yet')
|
|
346
326
|
|
|
347
|
-
pathFilename =
|
|
327
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
348
328
|
|
|
349
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
329
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
350
330
|
|
|
351
331
|
return pathFilename
|
|
352
332
|
|
|
353
|
-
def trimTheorem2(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
333
|
+
def trimTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
334
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
335
|
+
if callableIdentifier is None:
|
|
336
|
+
callableIdentifier = sourceCallableIdentifier
|
|
337
|
+
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
338
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
357
339
|
|
|
358
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
359
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
340
|
+
dataclassInstanceIdentifier = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
360
341
|
|
|
361
342
|
findThis = IfThis.isIfUnaryNotAttributeNamespace_Identifier(dataclassInstanceIdentifier, 'dimensionsUnconstrained')
|
|
362
343
|
doThat = Then.removeIt
|
|
@@ -365,128 +346,88 @@ def trimTheorem2(pathFilenameSource: PurePath) -> PurePath:
|
|
|
365
346
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
366
347
|
ingredientsModule.removeImportFromModule('numpy')
|
|
367
348
|
|
|
368
|
-
pathFilename =
|
|
349
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
369
350
|
|
|
370
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
371
|
-
|
|
372
|
-
logicalPath: list[str] = []
|
|
373
|
-
if packageInformation.packageName:
|
|
374
|
-
logicalPath.append(packageInformation.packageName)
|
|
375
|
-
if logicalPathInfix:
|
|
376
|
-
logicalPath.append(logicalPathInfix)
|
|
377
|
-
logicalPath.append(pathFilename.stem)
|
|
378
|
-
moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
|
|
379
|
-
|
|
380
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(ingredientsFunction.astFunctionDef.name)])
|
|
351
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
381
352
|
|
|
382
353
|
return pathFilename
|
|
383
354
|
|
|
384
|
-
def numbaOnTheorem2(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
391
|
-
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
392
|
-
|
|
393
|
-
dataclassLogicalPathModule = None
|
|
394
|
-
for moduleWithLogicalPath, listNameTuples in countNumbaTheorem2.imports.dictionaryImportFrom.items():
|
|
395
|
-
for nameTuple in listNameTuples:
|
|
396
|
-
if nameTuple[0] == dataclass_Identifier:
|
|
397
|
-
dataclassLogicalPathModule = moduleWithLogicalPath
|
|
398
|
-
break
|
|
399
|
-
if dataclassLogicalPathModule:
|
|
400
|
-
break
|
|
401
|
-
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
402
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
|
|
403
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
404
|
-
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
405
|
-
|
|
406
|
-
countNumbaTheorem2.imports.update(shatteredDataclass.imports)
|
|
407
|
-
countNumbaTheorem2 = removeDataclassFromFunction(countNumbaTheorem2, shatteredDataclass)
|
|
355
|
+
def numbaOnTheorem2(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: PathLike[str] | PurePath | str | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
356
|
+
sourceCallableIdentifier = sourceCallableIdentifierDEFAULT
|
|
357
|
+
if callableIdentifier is None:
|
|
358
|
+
callableIdentifier = sourceCallableIdentifier
|
|
359
|
+
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
360
|
+
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
408
361
|
|
|
409
|
-
|
|
362
|
+
shatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
410
363
|
|
|
411
|
-
|
|
364
|
+
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
365
|
+
ingredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclass)
|
|
366
|
+
ingredientsFunction = removeUnusedParameters(ingredientsFunction)
|
|
367
|
+
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
412
368
|
|
|
413
|
-
ingredientsModule = IngredientsModule(
|
|
369
|
+
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
414
370
|
ingredientsModule.removeImportFromModule('numpy')
|
|
415
371
|
|
|
416
|
-
pathFilename =
|
|
372
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
417
373
|
|
|
418
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
374
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
419
375
|
|
|
420
|
-
|
|
421
|
-
if packageInformation.packageName:
|
|
422
|
-
logicalPath.append(packageInformation.packageName)
|
|
423
|
-
if logicalPathInfix:
|
|
424
|
-
logicalPath.append(logicalPathInfix)
|
|
425
|
-
logicalPath.append(pathFilename.stem)
|
|
426
|
-
moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
|
|
427
|
-
|
|
428
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(countNumbaTheorem2.astFunctionDef.name)])
|
|
429
|
-
|
|
430
|
-
return astImportFrom
|
|
376
|
+
return pathFilename
|
|
431
377
|
|
|
432
378
|
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom) -> None:
|
|
433
|
-
callableIdentifierHARDCODED:
|
|
379
|
+
callableIdentifierHARDCODED: str = 'sequential'
|
|
434
380
|
|
|
435
|
-
algorithmSourceModule =
|
|
436
|
-
sourceCallableIdentifier =
|
|
437
|
-
logicalPathSourceModule = '.'.join([
|
|
381
|
+
algorithmSourceModule = algorithmSourceModuleDEFAULT
|
|
382
|
+
sourceCallableIdentifier = sourceCallableDispatcherDEFAULT
|
|
383
|
+
logicalPathSourceModule = '.'.join([packageSettings.packageName, algorithmSourceModule])
|
|
438
384
|
|
|
439
|
-
logicalPathInfix =
|
|
440
|
-
moduleIdentifier =
|
|
385
|
+
logicalPathInfix = logicalPathInfixDEFAULT
|
|
386
|
+
moduleIdentifier = dataPackingModuleIdentifierDEFAULT
|
|
441
387
|
callableIdentifier = callableIdentifierHARDCODED
|
|
442
388
|
|
|
443
389
|
ingredientsFunction: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
|
|
444
390
|
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
445
|
-
dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
446
|
-
if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
|
|
447
|
-
dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
|
|
448
|
-
if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
449
391
|
|
|
450
|
-
|
|
451
|
-
for moduleWithLogicalPath, listNameTuples in ingredientsFunction.imports.dictionaryImportFrom.items():
|
|
452
|
-
for nameTuple in listNameTuples:
|
|
453
|
-
if nameTuple[0] == dataclass_Identifier:
|
|
454
|
-
dataclassLogicalPathModule = moduleWithLogicalPath
|
|
455
|
-
break
|
|
456
|
-
if dataclassLogicalPathModule:
|
|
457
|
-
break
|
|
458
|
-
if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
|
|
459
|
-
dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
|
|
460
|
-
if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
|
|
461
|
-
shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
|
|
392
|
+
shatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
462
393
|
|
|
463
394
|
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
464
395
|
ingredientsFunction.imports.addAst(astImportFrom)
|
|
465
396
|
targetCallableIdentifier = astImportFrom.names[0].name
|
|
466
|
-
ingredientsFunction = unpackDataclassCallFunctionRepackDataclass(ingredientsFunction, targetCallableIdentifier, shatteredDataclass)
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef) # type: ignore
|
|
471
|
-
if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
|
|
472
|
-
astTuple.ctx = ast.Store()
|
|
397
|
+
ingredientsFunction = raiseIfNone(unpackDataclassCallFunctionRepackDataclass(ingredientsFunction, targetCallableIdentifier, shatteredDataclass))
|
|
398
|
+
targetFunctionDef = raiseIfNone(extractFunctionDef(parseLogicalPath2astModule(raiseIfNone(astImportFrom.module)), targetCallableIdentifier))
|
|
399
|
+
astTuple = raiseIfNone(NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef))
|
|
400
|
+
cast(ast.Tuple, astTuple).ctx = ast.Store()
|
|
473
401
|
|
|
474
402
|
findThis = ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCall_Identifier(targetCallableIdentifier))
|
|
475
|
-
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
|
|
403
|
+
doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), cast(ast.Tuple, astTuple).elts)))
|
|
476
404
|
NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
|
|
477
405
|
|
|
478
406
|
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
479
407
|
ingredientsModule.removeImportFromModule('numpy')
|
|
480
408
|
|
|
481
|
-
pathFilename =
|
|
409
|
+
pathFilename = _getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
482
410
|
|
|
483
|
-
write_astModule(ingredientsModule, pathFilename,
|
|
411
|
+
write_astModule(ingredientsModule, pathFilename, packageSettings.packageName)
|
|
484
412
|
|
|
485
413
|
if __name__ == '__main__':
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
414
|
+
astModule = getModule(logicalPathInfix=None)
|
|
415
|
+
makeInitializeGroupsOfFolds(astModule, 'initializeCount', 'initializeGroupsOfFolds', logicalPathInfixDEFAULT)
|
|
416
|
+
|
|
417
|
+
astModule = getModule(logicalPathInfix=None)
|
|
418
|
+
pathFilename = makeDaoOfMapFolding(astModule, 'daoOfMapFolding', None, logicalPathInfixDEFAULT, sourceCallableDispatcherDEFAULT)
|
|
419
|
+
|
|
420
|
+
astModule = getModule(logicalPathInfix=None)
|
|
421
|
+
pathFilename = makeDaoOfMapFoldingParallel(astModule, 'countParallel', None, logicalPathInfixDEFAULT, sourceCallableDispatcherDEFAULT)
|
|
422
|
+
|
|
423
|
+
astModule = getModule(logicalPathInfix=None)
|
|
424
|
+
pathFilename = makeTheorem2(astModule, 'theorem2', None, logicalPathInfixDEFAULT, None)
|
|
425
|
+
|
|
426
|
+
astModule = parsePathFilename2astModule(pathFilename)
|
|
427
|
+
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None, logicalPathInfixDEFAULT, None)
|
|
428
|
+
|
|
429
|
+
astModule = parsePathFilename2astModule(pathFilename)
|
|
430
|
+
pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None, logicalPathInfixDEFAULT, None)
|
|
431
|
+
|
|
432
|
+
astImportFrom = Make.ImportFrom(_getLogicalPath(packageSettings.packageName, logicalPathInfixDEFAULT, 'theorem2Numba'), list_alias=[Make.alias(sourceCallableIdentifierDEFAULT)])
|
|
490
433
|
makeUnRePackDataclass(astImportFrom)
|
|
491
|
-
pathFilename = makeDaoOfMapFolding()
|
|
492
|
-
makeDaoOfMapFoldingParallel()
|
|
@@ -45,9 +45,9 @@ test suite.
|
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
47
|
from mapFolding.someAssemblyRequired.infoBooth import (
|
|
48
|
-
|
|
48
|
+
dataclassInstanceIdentifierDEFAULT as dataclassInstanceIdentifierDEFAULT,
|
|
49
49
|
raiseIfNoneGitHubIssueNumber3 as raiseIfNoneGitHubIssueNumber3,
|
|
50
|
-
|
|
50
|
+
sourceCallableDispatcherDEFAULT as sourceCallableDispatcherDEFAULT,
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
from mapFolding.someAssemblyRequired._toolIfThis import IfThis as IfThis
|
|
@@ -56,3 +56,8 @@ from mapFolding.someAssemblyRequired._toolkitContainers import (
|
|
|
56
56
|
DeReConstructField2ast as DeReConstructField2ast,
|
|
57
57
|
ShatteredDataclass as ShatteredDataclass,
|
|
58
58
|
)
|
|
59
|
+
|
|
60
|
+
def raiseIfNone[TypeSansNone](returnTarget: TypeSansNone | None) -> TypeSansNone:
|
|
61
|
+
if returnTarget is None:
|
|
62
|
+
raise ValueError('Return is None.')
|
|
63
|
+
return returnTarget
|
|
@@ -19,7 +19,7 @@ they implement a declarative approach to AST manipulation that separates node id
|
|
|
19
19
|
(be), and data access (DOT).
|
|
20
20
|
"""
|
|
21
21
|
|
|
22
|
-
from astToolkit import
|
|
22
|
+
from astToolkit import Be, DOT, IfThis as astToolkit_IfThis
|
|
23
23
|
from collections.abc import Callable
|
|
24
24
|
from typing import TypeGuard
|
|
25
25
|
import ast
|
|
@@ -36,23 +36,23 @@ class IfThis(astToolkit_IfThis):
|
|
|
36
36
|
enabling precise targeting of AST elements for analysis or transformation.
|
|
37
37
|
"""
|
|
38
38
|
@staticmethod
|
|
39
|
-
def
|
|
39
|
+
def isAttributeNamespaceIdentifierGreaterThan0(namespace: str, identifier: str) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
|
|
40
40
|
return lambda node: (Be.Compare(node)
|
|
41
41
|
and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(DOT.left(node))
|
|
42
42
|
and Be.Gt(node.ops[0])
|
|
43
43
|
and IfThis.isConstant_value(0)(node.comparators[0]))
|
|
44
44
|
@staticmethod
|
|
45
|
-
def
|
|
45
|
+
def isIfAttributeNamespaceIdentifierGreaterThan0(namespace: str, identifier: str) -> Callable[[ast.AST], TypeGuard[ast.If] | bool]:
|
|
46
46
|
return lambda node: (Be.If(node)
|
|
47
|
-
and IfThis.
|
|
47
|
+
and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
|
|
48
48
|
|
|
49
49
|
@staticmethod
|
|
50
|
-
def
|
|
50
|
+
def isWhileAttributeNamespaceIdentifierGreaterThan0(namespace: str, identifier: str) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
|
|
51
51
|
return lambda node: (Be.While(node)
|
|
52
|
-
and IfThis.
|
|
52
|
+
and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
|
|
53
53
|
|
|
54
54
|
@staticmethod
|
|
55
|
-
def
|
|
55
|
+
def isAttributeNamespaceIdentifierLessThanOrEqual0(namespace: str, identifier: str) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
|
|
56
56
|
return lambda node: (Be.Compare(node)
|
|
57
57
|
and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(DOT.left(node))
|
|
58
58
|
and Be.LtE(node.ops[0]))
|
|
@@ -18,7 +18,7 @@ The containers work in conjunction with transformation tools that manipulate the
|
|
|
18
18
|
specific optimizations and transformations.
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
from astToolkit import
|
|
21
|
+
from astToolkit import ClassIsAndAttribute, DOT, LedgerOfImports, Make, NodeTourist, str_nameDOTname, Then
|
|
22
22
|
from collections.abc import Callable
|
|
23
23
|
from copy import deepcopy
|
|
24
24
|
from mapFolding.someAssemblyRequired import IfThis, raiseIfNoneGitHubIssueNumber3
|
|
@@ -38,10 +38,10 @@ class ShatteredDataclass:
|
|
|
38
38
|
countingVariableName: ast.Name
|
|
39
39
|
"""AST name node representing the counting variable identifier."""
|
|
40
40
|
|
|
41
|
-
field2AnnAssign: dict[
|
|
41
|
+
field2AnnAssign: dict[str, ast.AnnAssign | ast.Assign] = dataclasses.field(default_factory=lambda: dict[str, ast.AnnAssign | ast.Assign]())
|
|
42
42
|
"""Maps field names to their corresponding AST call expressions."""
|
|
43
43
|
|
|
44
|
-
Z0Z_field2AnnAssign: dict[
|
|
44
|
+
Z0Z_field2AnnAssign: dict[str, tuple[ast.AnnAssign | ast.Assign, str]] = dataclasses.field(default_factory=lambda: dict[str, tuple[ast.AnnAssign | ast.Assign, str]]())
|
|
45
45
|
|
|
46
46
|
fragments4AssignmentOrParameters: ast.Tuple = dummyTuple
|
|
47
47
|
"""AST tuple used as target for assignment to capture returned fragments."""
|
|
@@ -93,12 +93,12 @@ class DeReConstructField2ast:
|
|
|
93
93
|
"""
|
|
94
94
|
dataclassesDOTdataclassLogicalPathModule: dataclasses.InitVar[str_nameDOTname]
|
|
95
95
|
dataclassClassDef: dataclasses.InitVar[ast.ClassDef]
|
|
96
|
-
dataclassesDOTdataclassInstance_Identifier: dataclasses.InitVar[
|
|
96
|
+
dataclassesDOTdataclassInstance_Identifier: dataclasses.InitVar[str]
|
|
97
97
|
field: dataclasses.InitVar[dataclasses.Field[Any]]
|
|
98
98
|
|
|
99
99
|
ledger: LedgerOfImports = dataclasses.field(default_factory=LedgerOfImports)
|
|
100
100
|
|
|
101
|
-
name:
|
|
101
|
+
name: str = dataclasses.field(init=False)
|
|
102
102
|
typeBuffalo: type[Any] | str | Any = dataclasses.field(init=False)
|
|
103
103
|
default: Any | None = dataclasses.field(init=False)
|
|
104
104
|
default_factory: Callable[..., Any] | None = dataclasses.field(init=False)
|
|
@@ -117,7 +117,7 @@ class DeReConstructField2ast:
|
|
|
117
117
|
astAnnAssignConstructor: ast.AnnAssign|ast.Assign = dataclasses.field(init=False)
|
|
118
118
|
Z0Z_hack: tuple[ast.AnnAssign|ast.Assign, str] = dataclasses.field(init=False)
|
|
119
119
|
|
|
120
|
-
def __post_init__(self, dataclassesDOTdataclassLogicalPathModule: str_nameDOTname, dataclassClassDef: ast.ClassDef, dataclassesDOTdataclassInstance_Identifier:
|
|
120
|
+
def __post_init__(self, dataclassesDOTdataclassLogicalPathModule: str_nameDOTname, dataclassClassDef: ast.ClassDef, dataclassesDOTdataclassInstance_Identifier: str, field: dataclasses.Field[Any]) -> None:
|
|
121
121
|
self.compare = field.compare
|
|
122
122
|
self.default = field.default if field.default is not dataclasses.MISSING else None
|
|
123
123
|
self.default_factory = field.default_factory if field.default_factory is not dataclasses.MISSING else None
|
|
@@ -133,15 +133,15 @@ class DeReConstructField2ast:
|
|
|
133
133
|
self.ast_keyword_field__field = Make.keyword(self.name, self.astName)
|
|
134
134
|
self.ast_nameDOTname = Make.Attribute(Make.Name(dataclassesDOTdataclassInstance_Identifier), self.name)
|
|
135
135
|
|
|
136
|
-
sherpa
|
|
136
|
+
sherpa = NodeTourist( # pyright: ignore[reportUnknownVariableType]
|
|
137
137
|
findThis=ClassIsAndAttribute.targetIs(ast.AnnAssign, IfThis.isName_Identifier(self.name))
|
|
138
|
-
, doThat=Then.extractIt(DOT.annotation) #
|
|
138
|
+
, doThat=Then.extractIt(DOT.annotation) # pyright: ignore[reportArgumentType]
|
|
139
139
|
).captureLastMatch(dataclassClassDef)
|
|
140
140
|
|
|
141
|
-
if sherpa is None: raise raiseIfNoneGitHubIssueNumber3
|
|
141
|
+
if sherpa is None: raise raiseIfNoneGitHubIssueNumber3
|
|
142
142
|
else: self.astAnnotation = sherpa
|
|
143
143
|
|
|
144
|
-
self.ast_argAnnotated = Make.arg(self.name, self.astAnnotation)
|
|
144
|
+
self.ast_argAnnotated = Make.arg(self.name, self.astAnnotation) # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType]
|
|
145
145
|
|
|
146
146
|
dtype = self.metadata.get('dtype', None)
|
|
147
147
|
if dtype:
|
|
@@ -156,7 +156,7 @@ class DeReConstructField2ast:
|
|
|
156
156
|
ast_expr = Make.Subscript(Make.Name(annotationType), Make.Tuple([axesSubscript, Make.Subscript(Make.Name('dtype'), dtype_asnameName)]))
|
|
157
157
|
constructor = 'array'
|
|
158
158
|
self.ledger.addImportFrom_asStr(moduleWithLogicalPath, constructor)
|
|
159
|
-
dtypeIdentifier:
|
|
159
|
+
dtypeIdentifier: str = dtype.__name__
|
|
160
160
|
self.ledger.addImportFrom_asStr(moduleWithLogicalPath, dtypeIdentifier, dtype_asnameName.id)
|
|
161
161
|
self.astAnnAssignConstructor = Make.AnnAssign(self.astName, ast_expr, Make.Call(Make.Name(constructor), list_keyword=[Make.keyword('dtype', dtype_asnameName)]))
|
|
162
162
|
self.astAnnAssignConstructor = Make.Assign([self.astName], Make.Call(Make.Name(constructor), list_keyword=[Make.keyword('dtype', dtype_asnameName)]))
|
|
@@ -165,7 +165,7 @@ class DeReConstructField2ast:
|
|
|
165
165
|
self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, Make.Call(self.astAnnotation, [Make.Constant(-1)]))
|
|
166
166
|
self.Z0Z_hack = (self.astAnnAssignConstructor, 'scalar')
|
|
167
167
|
elif isinstance(self.astAnnotation, ast.Subscript):
|
|
168
|
-
elementConstructor:
|
|
168
|
+
elementConstructor: str = self.metadata['elementConstructor']
|
|
169
169
|
self.ledger.addImportFrom_asStr(dataclassesDOTdataclassLogicalPathModule, elementConstructor)
|
|
170
170
|
takeTheTuple = deepcopy(self.astAnnotation.slice)
|
|
171
171
|
self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, takeTheTuple)
|
|
@@ -1,70 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# "Evaluate When Packaging" and "Evaluate When Installing"
|
|
10
|
-
# https://github.com/hunterhogan/mapFolding/issues/18
|
|
11
|
-
dataclassIdentifier: str = dataclasses.field(default='ComputationState', metadata={'evaluateWhen': 'packaging'})
|
|
12
|
-
"""Name of the dataclass used to track computation state."""
|
|
13
|
-
|
|
14
|
-
dataclassInstance: str = dataclasses.field(default='state', metadata={'evaluateWhen': 'packaging'})
|
|
15
|
-
"""Default variable name for instances of the computation state dataclass."""
|
|
16
|
-
|
|
17
|
-
dataclassInstanceTaskDistributionSuffix: str = dataclasses.field(default='Parallel', metadata={'evaluateWhen': 'packaging'})
|
|
18
|
-
"""Suffix added to dataclassInstance for parallel task distribution."""
|
|
19
|
-
|
|
20
|
-
dataclassModule: str = dataclasses.field(default='beDRY', metadata={'evaluateWhen': 'packaging'})
|
|
21
|
-
"""Module containing the computation state dataclass definition."""
|
|
22
|
-
|
|
23
|
-
datatypePackage: str = dataclasses.field(default='numpy', metadata={'evaluateWhen': 'packaging'})
|
|
24
|
-
"""Package providing the numeric data types used in computation."""
|
|
25
|
-
|
|
26
|
-
sourceAlgorithm: str = dataclasses.field(default='theDao', metadata={'evaluateWhen': 'packaging'})
|
|
27
|
-
"""Module containing the reference implementation of the algorithm."""
|
|
28
|
-
|
|
29
|
-
sourceCallableDispatcher: str = dataclasses.field(default='doTheNeedful', metadata={'evaluateWhen': 'packaging'})
|
|
30
|
-
"""Name of the function that dispatches computation in the source algorithm."""
|
|
31
|
-
|
|
32
|
-
sourceCallableInitialize: str = dataclasses.field(default='countInitialize', metadata={'evaluateWhen': 'packaging'})
|
|
33
|
-
"""Name of the function that initializes computation in the source algorithm."""
|
|
34
|
-
|
|
35
|
-
sourceCallableParallel: str = dataclasses.field(default='countParallel', metadata={'evaluateWhen': 'packaging'})
|
|
36
|
-
"""Name of the function that performs parallel computation in the source algorithm."""
|
|
37
|
-
|
|
38
|
-
sourceCallableSequential: str = dataclasses.field(default='countSequential', metadata={'evaluateWhen': 'packaging'})
|
|
39
|
-
"""Name of the function that performs sequential computation in the source algorithm."""
|
|
40
|
-
|
|
41
|
-
sourceConcurrencyManagerIdentifier: str = dataclasses.field(default='submit', metadata={'evaluateWhen': 'packaging'})
|
|
42
|
-
"""Method name used to submit tasks to the concurrency manager."""
|
|
43
|
-
|
|
44
|
-
sourceConcurrencyManagerNamespace: str = dataclasses.field(default='concurrencyManager', metadata={'evaluateWhen': 'packaging'})
|
|
45
|
-
"""Variable name used for the concurrency manager instance."""
|
|
46
|
-
|
|
47
|
-
sourceConcurrencyPackage: str = dataclasses.field(default='multiprocessing', metadata={'evaluateWhen': 'packaging'})
|
|
48
|
-
"""Default package used for concurrency in the source algorithm."""
|
|
49
|
-
|
|
50
|
-
dataclassInstanceTaskDistribution: str = dataclasses.field(default=None, metadata={'evaluateWhen': 'packaging'}) # pyright: ignore[reportAssignmentType]
|
|
51
|
-
"""Variable name for the parallel distribution instance of the computation state."""
|
|
52
|
-
|
|
53
|
-
logicalPathModuleDataclass: str = dataclasses.field(default=None, metadata={'evaluateWhen': 'packaging'}) # pyright: ignore[reportAssignmentType]
|
|
54
|
-
"""Fully qualified import path to the module containing the computation state dataclass."""
|
|
55
|
-
|
|
56
|
-
logicalPathModuleSourceAlgorithm: str = dataclasses.field(default=None, metadata={'evaluateWhen': 'packaging'}) # pyright: ignore[reportAssignmentType]
|
|
57
|
-
"""Fully qualified import path to the module containing the source algorithm."""
|
|
58
|
-
|
|
59
|
-
def __post_init__(self) -> None:
|
|
60
|
-
if self.dataclassInstanceTaskDistribution is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
61
|
-
self.dataclassInstanceTaskDistribution = self.dataclassInstance + self.dataclassInstanceTaskDistributionSuffix
|
|
62
|
-
|
|
63
|
-
if self.logicalPathModuleDataclass is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
64
|
-
self.logicalPathModuleDataclass = '.'.join([self.packageName, self.dataclassModule])
|
|
65
|
-
if self.logicalPathModuleSourceAlgorithm is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
66
|
-
self.logicalPathModuleSourceAlgorithm = '.'.join([self.packageName, self.sourceAlgorithm])
|
|
1
|
+
algorithmSourceModuleDEFAULT: str = 'daoOfMapFolding'
|
|
2
|
+
dataclassInstanceIdentifierDEFAULT: str = 'state'
|
|
3
|
+
dataPackingModuleIdentifierDEFAULT: str = 'dataPacking'
|
|
4
|
+
logicalPathInfixDEFAULT: str = 'syntheticModules'
|
|
5
|
+
sourceCallableDispatcherDEFAULT: str = 'doTheNeedful'
|
|
6
|
+
sourceCallableIdentifierDEFAULT: str = 'count'
|
|
7
|
+
theCountingIdentifierDEFAULT: str = 'groupsOfFolds'
|
|
67
8
|
|
|
68
9
|
class raiseIfNoneGitHubIssueNumber3(Exception): pass
|
|
69
10
|
|
|
70
|
-
|
|
11
|
+
dictionaryEstimates: dict[tuple[int, ...], int] = {
|
|
12
|
+
(2,2,2,2,2,2,2,2): 798148657152000,
|
|
13
|
+
(2,21): 776374224866624,
|
|
14
|
+
(3,15): 824761667826225,
|
|
15
|
+
(3,3,3,3): 85109616000000000000000000000000,
|
|
16
|
+
(8,8): 791274195985524900,
|
|
17
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
from mapFolding import getPathFilenameFoldsTotal, MapFoldingState
|
|
2
|
-
from mapFolding.someAssemblyRequired import IfThis,
|
|
1
|
+
from mapFolding import getPathFilenameFoldsTotal, MapFoldingState, packageSettings
|
|
2
|
+
from mapFolding.someAssemblyRequired import IfThis, raiseIfNoneGitHubIssueNumber3
|
|
3
3
|
from astToolkit import (
|
|
4
|
-
ast_Identifier,
|
|
5
4
|
Be,
|
|
6
5
|
ClassIsAndAttribute,
|
|
7
6
|
extractFunctionDef,
|
|
@@ -69,8 +68,8 @@ if __name__ == '__main__':
|
|
|
69
68
|
writeStream.write(str(foldsTotal))
|
|
70
69
|
writeStream.close()
|
|
71
70
|
"""
|
|
72
|
-
numba_progressPythonClass:
|
|
73
|
-
numba_progressNumbaType:
|
|
71
|
+
numba_progressPythonClass: str = 'ProgressBar'
|
|
72
|
+
numba_progressNumbaType: str = 'ProgressBarType'
|
|
74
73
|
ingredientsModule.imports.addImportFrom_asStr('numba_progress', numba_progressPythonClass)
|
|
75
74
|
ingredientsModule.imports.addImportFrom_asStr('numba_progress', numba_progressNumbaType)
|
|
76
75
|
|
|
@@ -117,11 +116,11 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
|
|
|
117
116
|
ingredientsFunction.imports.update(job.shatteredDataclass.imports)
|
|
118
117
|
|
|
119
118
|
list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
|
|
120
|
-
list_arg_arg: list[
|
|
119
|
+
list_arg_arg: list[str] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
|
|
121
120
|
listName: list[ast.Name] = []
|
|
122
121
|
NodeTourist(Be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
|
|
123
|
-
list_Identifiers: list[
|
|
124
|
-
list_IdentifiersNotUsed: list[
|
|
122
|
+
list_Identifiers: list[str] = [astName.id for astName in listName]
|
|
123
|
+
list_IdentifiersNotUsed: list[str] = list(set(list_arg_arg) - set(list_Identifiers))
|
|
125
124
|
|
|
126
125
|
for ast_arg in list_argCuzMyBrainRefusesToThink:
|
|
127
126
|
if ast_arg.arg in job.shatteredDataclass.field2AnnAssign:
|
|
@@ -202,9 +201,9 @@ if __name__ == '__main__':
|
|
|
202
201
|
|
|
203
202
|
class DatatypeConfig(NamedTuple):
|
|
204
203
|
Z0Z_module: str_nameDOTname
|
|
205
|
-
fml:
|
|
206
|
-
Z0Z_type_name:
|
|
207
|
-
Z0Z_asname:
|
|
204
|
+
fml: str
|
|
205
|
+
Z0Z_type_name: str
|
|
206
|
+
Z0Z_asname: str | None = None
|
|
208
207
|
|
|
209
208
|
listDatatypeConfigs = [
|
|
210
209
|
DatatypeConfig(fml='DatatypeLeavesTotal', Z0Z_module='numba', Z0Z_type_name='uint8'),
|
|
@@ -267,7 +266,7 @@ if __name__ == '__main__':
|
|
|
267
266
|
# foldsTotalEstimated = getFoldsTotalKnown(state.mapShape) // state.leavesTotal
|
|
268
267
|
# foldsTotalEstimated = dictionaryEstimates[state.mapShape] // state.leavesTotal
|
|
269
268
|
foldsTotalEstimated = 0
|
|
270
|
-
pathModule = PurePosixPath(
|
|
269
|
+
pathModule = PurePosixPath(packageSettings.pathPackage, 'jobs')
|
|
271
270
|
pathFilenameFoldsTotal = PurePosixPath(getPathFilenameFoldsTotal(state.mapShape, pathModule))
|
|
272
271
|
aJob = RecipeJobTheorem2Numba(state, foldsTotalEstimated, pathModule=pathModule, pathFilenameFoldsTotal=pathFilenameFoldsTotal)
|
|
273
272
|
spices = SpicesJobNumba(useNumbaProgressBar=False, parametersNumba=parametersNumbaLight)
|
|
@@ -17,7 +17,7 @@ performance improvements while preserving code semantics and correctness.
|
|
|
17
17
|
|
|
18
18
|
from collections.abc import Callable, Sequence
|
|
19
19
|
from mapFolding import NotRequired, TypedDict
|
|
20
|
-
from astToolkit import
|
|
20
|
+
from astToolkit import IngredientsFunction, Make, str_nameDOTname
|
|
21
21
|
from astToolkit.transformationTools import write_astModule
|
|
22
22
|
from numba.core.compiler import CompilerBase as numbaCompilerBase
|
|
23
23
|
from typing import Any, cast, Final
|
|
@@ -53,7 +53,7 @@ parametersNumbaDefault: Final[ParametersNumba] = { '_nrt': True, 'boundscheck':
|
|
|
53
53
|
parametersNumbaLight: Final[ParametersNumba] = {'cache': True, 'error_model': 'numpy', 'fastmath': True, 'forceinline': True}
|
|
54
54
|
|
|
55
55
|
Z0Z_numbaDataTypeModule: str_nameDOTname = 'numba'
|
|
56
|
-
Z0Z_decoratorCallable:
|
|
56
|
+
Z0Z_decoratorCallable: str = 'jit'
|
|
57
57
|
|
|
58
58
|
def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, parametersNumba: ParametersNumba | None = None) -> IngredientsFunction:
|
|
59
59
|
def Z0Z_UnhandledDecorators(astCallable: ast.FunctionDef) -> ast.FunctionDef:
|
|
@@ -128,5 +128,5 @@ def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, paramete
|
|
|
128
128
|
@dataclasses.dataclass
|
|
129
129
|
class SpicesJobNumba:
|
|
130
130
|
useNumbaProgressBar: bool = True
|
|
131
|
-
numbaProgressBarIdentifier:
|
|
132
|
-
parametersNumba: ParametersNumba = dataclasses.field(default_factory=ParametersNumba)
|
|
131
|
+
numbaProgressBarIdentifier: str = 'ProgressBarGroupsOfFolds'
|
|
132
|
+
parametersNumba: ParametersNumba = dataclasses.field(default_factory=ParametersNumba) # pyright: ignore[reportArgumentType, reportCallIssue, reportUnknownVariableType]
|
|
@@ -25,7 +25,6 @@ from mapFolding.someAssemblyRequired import (
|
|
|
25
25
|
ShatteredDataclass,
|
|
26
26
|
)
|
|
27
27
|
from astToolkit import(
|
|
28
|
-
ast_Identifier,
|
|
29
28
|
Be,
|
|
30
29
|
extractClassDef,
|
|
31
30
|
IngredientsFunction,
|
|
@@ -40,7 +39,7 @@ from Z0Z_tools import importLogicalPath2Callable
|
|
|
40
39
|
import ast
|
|
41
40
|
import dataclasses
|
|
42
41
|
|
|
43
|
-
def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclass_Identifier:
|
|
42
|
+
def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclass_Identifier: str, instance_Identifier: str) -> ShatteredDataclass:
|
|
44
43
|
"""
|
|
45
44
|
Decompose a dataclass definition into AST components for manipulation and code generation.
|
|
46
45
|
|
|
@@ -70,8 +69,8 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
70
69
|
Raises:
|
|
71
70
|
ValueError: If the dataclass cannot be found in the specified module or if no counting variable is identified in the dataclass.
|
|
72
71
|
"""
|
|
73
|
-
Official_fieldOrder: list[
|
|
74
|
-
dictionaryDeReConstruction: dict[
|
|
72
|
+
Official_fieldOrder: list[str] = []
|
|
73
|
+
dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
|
|
75
74
|
|
|
76
75
|
dataclassClassDef = extractClassDef(parseLogicalPath2astModule(logicalPathModule), dataclass_Identifier)
|
|
77
76
|
if not isinstance(dataclassClassDef, ast.ClassDef): raise ValueError(f"I could not find `{dataclass_Identifier = }` in `{logicalPathModule = }`.")
|
|
@@ -109,8 +108,6 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
109
108
|
|
|
110
109
|
return shatteredDataclass
|
|
111
110
|
|
|
112
|
-
# END of acceptable classes and functions ======================================================
|
|
113
|
-
|
|
114
111
|
def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
115
112
|
ingredientsTarget.astFunctionDef.args = Make.arguments(args=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
116
113
|
ingredientsTarget.astFunctionDef.returns = shatteredDataclass.signatureReturnAnnotation
|
|
@@ -119,7 +116,7 @@ def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shattere
|
|
|
119
116
|
ingredientsTarget.astFunctionDef = unparseFindReplace(ingredientsTarget.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
120
117
|
return ingredientsTarget
|
|
121
118
|
|
|
122
|
-
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, targetCallableIdentifier:
|
|
119
|
+
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, targetCallableIdentifier: str, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
123
120
|
astCallTargetCallable = Make.Call(Make.Name(targetCallableIdentifier), shatteredDataclass.listName4Parameters)
|
|
124
121
|
replaceAssignTargetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCall_Identifier(targetCallableIdentifier)), Then.replaceWith(Make.Assign([shatteredDataclass.fragments4AssignmentOrParameters], value=astCallTargetCallable)))
|
|
125
122
|
unpack4targetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCall_Identifier(targetCallableIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
@@ -128,11 +125,3 @@ def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFun
|
|
|
128
125
|
unpack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
129
126
|
repack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
130
127
|
return ingredientsCaller
|
|
131
|
-
|
|
132
|
-
dictionaryEstimates: dict[tuple[int, ...], int] = {
|
|
133
|
-
(2,2,2,2,2,2,2,2): 798148657152000,
|
|
134
|
-
(2,21): 776374224866624,
|
|
135
|
-
(3,15): 824761667826225,
|
|
136
|
-
(3,3,3,3): 85109616000000000000000000000000,
|
|
137
|
-
(8,8): 791274195985524900,
|
|
138
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.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
|
|
@@ -18,8 +18,6 @@ Classifier: Natural Language :: English
|
|
|
18
18
|
Classifier: Operating System :: OS Independent
|
|
19
19
|
Classifier: Programming Language :: Python
|
|
20
20
|
Classifier: Programming Language :: Python :: 3
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
23
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
22
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
23
|
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
@@ -28,7 +26,7 @@ Classifier: Topic :: Software Development :: Code Generators
|
|
|
28
26
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
27
|
Classifier: Topic :: Software Development :: Compilers
|
|
30
28
|
Classifier: Typing :: Typed
|
|
31
|
-
Requires-Python: >=3.
|
|
29
|
+
Requires-Python: >=3.12
|
|
32
30
|
Description-Content-Type: text/markdown
|
|
33
31
|
License-File: LICENSE
|
|
34
32
|
Requires-Dist: astToolkit
|
|
@@ -5,7 +5,7 @@ mapFolding/daoOfMapFolding.py,sha256=ncTIiBfTsM8SNVx9qefZ0bBcBtviWLSk4iPv3Z9nGiE
|
|
|
5
5
|
mapFolding/dataBaskets.py,sha256=crfmmYJGeJ7QLCzuYi4rtVOtzCDRoOiTNfPfHbc6Foo,5620
|
|
6
6
|
mapFolding/datatypes.py,sha256=dqOAa2RbiGcsRl9X4qo4tdMamgOoZVnewrMjY4mHXS4,773
|
|
7
7
|
mapFolding/filesystemToolkit.py,sha256=O9VQ0tSXlrGUhU3qN7uWxOTAZfuQb3fcRkTrfRZrGXo,9854
|
|
8
|
-
mapFolding/oeis.py,sha256=
|
|
8
|
+
mapFolding/oeis.py,sha256=ENTFLTQ2gfet16AA0CHy55mq5Qc0FBiix3IEpdymaV8,17115
|
|
9
9
|
mapFolding/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
mapFolding/theSSOT.py,sha256=7CyB3FnDWyNovTuUPRvSIfF7GxQc3aZoIsIwF1-4OyE,1456
|
|
11
11
|
mapFolding/reference/__init__.py,sha256=GKcSgYE49NcTISx-JZbELXyq-eRkMeTL5g4DXInWFw0,2206
|
|
@@ -20,16 +20,16 @@ mapFolding/reference/total_countPlus1vsPlusN.py,sha256=yJZAVLVdoXqHag2_N6_6CT-Q6
|
|
|
20
20
|
mapFolding/reference/jobsCompleted/__init__.py,sha256=TU93ZGUW1xEkT6d9mQFn_rp5DvRy0ZslEB2Q6MF5ZDc,2596
|
|
21
21
|
mapFolding/reference/jobsCompleted/[2x19]/p2x19.py,sha256=_tvYtfzMWVo2VtUbIAieoscb4N8FFflgTdW4-ljBUuA,19626
|
|
22
22
|
mapFolding/reference/jobsCompleted/p2x19/p2x19.py,sha256=eZEw4Me4ocTt6VXoK2-Sbd5SowZtxRIbN9dZmc7OCVg,6395
|
|
23
|
-
mapFolding/someAssemblyRequired/RecipeJob.py,sha256=
|
|
24
|
-
mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py,sha256=
|
|
25
|
-
mapFolding/someAssemblyRequired/__init__.py,sha256=
|
|
26
|
-
mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=
|
|
27
|
-
mapFolding/someAssemblyRequired/_toolkitContainers.py,sha256=
|
|
23
|
+
mapFolding/someAssemblyRequired/RecipeJob.py,sha256=oDOg5FVGTlnZQFW1K0OVucoHbApjsLTpPXy9GtMbjp4,4339
|
|
24
|
+
mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py,sha256=MmwL95QGFKwuJFk2l2PCo2f4FMuVAtLsqiLFofX0Lns,28872
|
|
25
|
+
mapFolding/someAssemblyRequired/__init__.py,sha256=ndEXbwc6SSGnAyYkgL2I4nvDGQa8EbJu_f9l9NJwTsw,2931
|
|
26
|
+
mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=h1ueRlUU6Rb4vZCa3KtxFjUSrULRl-GkPp8NrosWdzM,3012
|
|
27
|
+
mapFolding/someAssemblyRequired/_toolkitContainers.py,sha256=OBEqbzY137YVht5sWjJhfBSeE1qnx_xHRzjx4QFZ6P0,9767
|
|
28
28
|
mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=9RPU6vK_eUg64GtVFI_nZnvUryXw8gfHJs9NyDYHIvg,2745
|
|
29
|
-
mapFolding/someAssemblyRequired/infoBooth.py,sha256=
|
|
30
|
-
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=
|
|
31
|
-
mapFolding/someAssemblyRequired/toolkitNumba.py,sha256=
|
|
32
|
-
mapFolding/someAssemblyRequired/transformationTools.py,sha256=
|
|
29
|
+
mapFolding/someAssemblyRequired/infoBooth.py,sha256=RbYswVvjE0mfORepk4tUzScMCb7WYf0GFMs0u-MUmn0,635
|
|
30
|
+
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=csxagvDr89U5fBOSxD6KB6JJh5UVWF8IFGzogIMh1qY,13928
|
|
31
|
+
mapFolding/someAssemblyRequired/toolkitNumba.py,sha256=F4DriKPj9TeEJ1qB9H74ekJfMfw2vJvW1zeJXHtxE0E,6680
|
|
32
|
+
mapFolding/someAssemblyRequired/transformationTools.py,sha256=kL3pDENALrayrDRa7gv64IPG-o7tBw8MYnqM0_xJvIQ,7868
|
|
33
33
|
mapFolding/syntheticModules/__init__.py,sha256=evVFqhCGa-WZKDiLcnQWjs-Bj34eRnfSLqz_d7dFYZY,83
|
|
34
34
|
mapFolding/syntheticModules/countParallel.py,sha256=OK_IB9w4yy9MMAiGvkei5ezPm_00v2nYjPrQZ_IlELg,7733
|
|
35
35
|
mapFolding/syntheticModules/daoOfMapFolding.py,sha256=cfWPABtXyCxJ0BwPI7rhfLh_2UYV_XKAL8lJ4GLNXaQ,5896
|
|
@@ -38,7 +38,7 @@ mapFolding/syntheticModules/initializeCount.py,sha256=nWSlJMMfIM3DvZxMn6ISQusUJq
|
|
|
38
38
|
mapFolding/syntheticModules/theorem2.py,sha256=9jrbZNNX4BWYZW1S0JjvRY2k7RU7I1RNUMV7JdCt1ZY,3017
|
|
39
39
|
mapFolding/syntheticModules/theorem2Numba.py,sha256=-cKjNyxgUMFhEyFVs0VJ7hw4LfrV0WSNK5tPYbQ1oNU,3369
|
|
40
40
|
mapFolding/syntheticModules/theorem2Trimmed.py,sha256=DHW3NxBdtABQYBKm2WRvfQ5kzc2_UwGI2h4ePuYEJoM,2685
|
|
41
|
-
mapfolding-0.
|
|
41
|
+
mapfolding-0.12.0.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
|
42
42
|
tests/__init__.py,sha256=5VhHf0JJ2_DSh58zJ0rR5UkpoCon-0IkdljspTCzZ04,1950
|
|
43
43
|
tests/conftest.py,sha256=eumQRoDuWVrhsjDxWXGhW0N7lH0ZZ9XD-5q81bWFqOs,10874
|
|
44
44
|
tests/test_computations.py,sha256=HNpfs9Yz3rdfJInD15Jwd6DYsSR5TCwnR5EW0n7KbeI,5682
|
|
@@ -46,8 +46,8 @@ tests/test_filesystem.py,sha256=imlcetleJc4G9pDZTgS1j8UAs7ADbRxXVuNPecJAvqc,2964
|
|
|
46
46
|
tests/test_oeis.py,sha256=uxvwmgbnylSDdsVJfuAT0LuYLbIVFwSgdLxHm-xUGBM,5043
|
|
47
47
|
tests/test_other.py,sha256=DT7YE82YCHrSjdxhpY4UJnXmZvDm1b4e1QpZV3LyzcM,3747
|
|
48
48
|
tests/test_tasks.py,sha256=pEDukf2SVTOMEsn82JpAWKQzn1ZCTlkhLzQ5hYLg2yY,2780
|
|
49
|
-
mapfolding-0.
|
|
50
|
-
mapfolding-0.
|
|
51
|
-
mapfolding-0.
|
|
52
|
-
mapfolding-0.
|
|
53
|
-
mapfolding-0.
|
|
49
|
+
mapfolding-0.12.0.dist-info/METADATA,sha256=omaT9GvKUuLWj6JcQjB61-7_ygQQhVtAs00fmbcIguk,7610
|
|
50
|
+
mapfolding-0.12.0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
51
|
+
mapfolding-0.12.0.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
52
|
+
mapfolding-0.12.0.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
|
|
53
|
+
mapfolding-0.12.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|