mapFolding 0.16.1__py3-none-any.whl → 0.16.4__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.
- easyRun/A000682.py +1 -1
- easyRun/A005316.py +2 -3
- easyRun/NOTcountingFolds.py +6 -5
- easyRun/countFolds.py +1 -1
- easyRun/generateAllModules.py +14 -0
- easyRun/meanders.py +16 -18
- mapFolding/__init__.py +1 -0
- mapFolding/_theSSOT.py +3 -2
- mapFolding/_theTypes.py +3 -0
- mapFolding/algorithms/A086345.py +75 -0
- mapFolding/algorithms/matrixMeanders.py +15 -28
- mapFolding/algorithms/matrixMeandersBeDry.py +34 -116
- mapFolding/algorithms/matrixMeandersNumPy.py +117 -70
- mapFolding/algorithms/matrixMeandersPandas.py +113 -130
- mapFolding/algorithms/oeisIDbyFormula.py +25 -14
- mapFolding/algorithms/symmetricFolds.py +36 -0
- mapFolding/algorithms/zCuzDocStoopidoeisIDbyFormula.py +26 -12
- mapFolding/basecamp.py +152 -323
- mapFolding/dataBaskets.py +136 -34
- mapFolding/filesystemToolkit.py +4 -32
- mapFolding/oeis.py +5 -12
- mapFolding/reference/A000682facts.py +785 -1264
- mapFolding/reference/A005316facts.py +958 -923
- mapFolding/reference/A086345Wu.py +25 -0
- mapFolding/reference/matrixMeandersAnalysis/signatures.py +2033 -0
- mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +9 -44
- mapFolding/someAssemblyRequired/A007822/_asynchronousAnnex.py +51 -0
- mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +39 -136
- mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +44 -45
- mapFolding/someAssemblyRequired/RecipeJob.py +78 -18
- mapFolding/someAssemblyRequired/__init__.py +3 -8
- mapFolding/someAssemblyRequired/_toolkitContainers.py +32 -3
- mapFolding/someAssemblyRequired/infoBooth.py +40 -23
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +75 -154
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +56 -88
- mapFolding/someAssemblyRequired/makingModules_count.py +91 -85
- mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +7 -65
- mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/makeMapFoldingModules.py +25 -31
- mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +14 -13
- mapFolding/someAssemblyRequired/toolkitMakeModules.py +10 -10
- mapFolding/someAssemblyRequired/toolkitNumba.py +1 -1
- mapFolding/someAssemblyRequired/transformationTools.py +17 -19
- mapFolding/syntheticModules/A007822/algorithm.py +46 -50
- mapFolding/syntheticModules/A007822/asynchronous.py +93 -34
- mapFolding/syntheticModules/A007822/initializeState.py +15 -21
- mapFolding/syntheticModules/A007822/theorem2.py +21 -21
- mapFolding/syntheticModules/A007822/theorem2Numba.py +42 -23
- mapFolding/syntheticModules/A007822/theorem2Trimmed.py +21 -21
- mapFolding/syntheticModules/countParallelNumba.py +3 -7
- mapFolding/syntheticModules/daoOfMapFoldingNumba.py +3 -6
- mapFolding/syntheticModules/meanders/bigInt.py +15 -25
- mapFolding/syntheticModules/theorem2.py +6 -0
- mapFolding/syntheticModules/theorem2Numba.py +26 -2
- mapFolding/syntheticModules/theorem2Trimmed.py +6 -0
- mapFolding/tests/test_computations.py +1 -1
- mapFolding/zCuzDocStoopid/makeDocstrings.py +2 -0
- {mapfolding-0.16.1.dist-info → mapfolding-0.16.4.dist-info}/METADATA +4 -1
- mapfolding-0.16.4.dist-info/RECORD +106 -0
- mapFolding/_dataPacking.py +0 -68
- mapFolding/reference/meandersDumpingGround/A005316intOptimized.py +0 -122
- mapFolding/reference/meandersDumpingGround/A005316optimized128bit.py +0 -79
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaseline.py +0 -65
- mapFolding/reference/meandersDumpingGround/matrixMeandersBaselineAnnex.py +0 -84
- mapFolding/reference/meandersDumpingGround/matrixMeandersSimpleQueue.py +0 -90
- mapFolding/syntheticModules/A007822/algorithmNumba.py +0 -94
- mapFolding/syntheticModules/A007822/asynchronousAnnex.py +0 -66
- mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +0 -85
- mapFolding/syntheticModules/A007822/asynchronousNumba.py +0 -52
- mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +0 -53
- mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +0 -47
- mapFolding/syntheticModules/dataPacking.py +0 -28
- mapFolding/syntheticModules/dataPackingA007822.py +0 -92
- mapfolding-0.16.1.dist-info/RECORD +0 -114
- /mapFolding/someAssemblyRequired/{mapFolding → mapFoldingModules}/__init__.py +0 -0
- {mapfolding-0.16.1.dist-info → mapfolding-0.16.4.dist-info}/WHEEL +0 -0
- {mapfolding-0.16.1.dist-info → mapfolding-0.16.4.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.16.1.dist-info → mapfolding-0.16.4.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.16.1.dist-info → mapfolding-0.16.4.dist-info}/top_level.txt +0 -0
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"""Make functions that are complementary to the `count` function and are often called by `doTheNeedful`."""
|
|
2
2
|
from astToolkit import (
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Be, DOT, Grab, identifierDotAttribute, IngredientsFunction, IngredientsModule, LedgerOfImports, NodeChanger,
|
|
4
|
+
NodeTourist, Then)
|
|
5
5
|
from astToolkit.transformationTools import inlineFunctionDef, write_astModule
|
|
6
6
|
from hunterMakesPy import raiseIfNone
|
|
7
7
|
from mapFolding import packageSettings
|
|
8
|
-
from mapFolding.someAssemblyRequired import
|
|
9
|
-
|
|
10
|
-
identifierModuleDataPackingDEFAULT, identifierModuleSourceAlgorithmDEFAULT, IfThis, logicalPathInfixAlgorithmDEFAULT,
|
|
11
|
-
logicalPathInfixDEFAULT, ShatteredDataclass)
|
|
12
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import findDataclass, getPathFilename
|
|
13
|
-
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
14
|
-
shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
15
|
-
from os import PathLike
|
|
8
|
+
from mapFolding.someAssemblyRequired import default, IfThis
|
|
9
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getPathFilename
|
|
16
10
|
from pathlib import PurePath
|
|
17
|
-
from typing import cast
|
|
18
11
|
import ast
|
|
19
12
|
|
|
20
|
-
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix:
|
|
13
|
+
def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
21
14
|
"""Generate initialization module for counting variable setup.
|
|
22
15
|
|
|
23
16
|
(AI generated docstring)
|
|
@@ -49,12 +42,12 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
49
42
|
Filesystem path where the initialization module was written.
|
|
50
43
|
|
|
51
44
|
"""
|
|
52
|
-
sourceCallableIdentifier: identifierDotAttribute =
|
|
45
|
+
sourceCallableIdentifier: identifierDotAttribute = default['function']['counting']
|
|
53
46
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
54
47
|
ingredientsFunction.astFunctionDef.name = callableIdentifier or sourceCallableIdentifier
|
|
55
48
|
|
|
56
49
|
dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
57
|
-
theCountingIdentifier: identifierDotAttribute =
|
|
50
|
+
theCountingIdentifier: identifierDotAttribute = default['variable']['counting']
|
|
58
51
|
|
|
59
52
|
findThis = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
|
|
60
53
|
doThat = Grab.testAttribute(Grab.andDoAllOf([Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier)))]))
|
|
@@ -64,54 +57,3 @@ def makeInitializeState(astModule: ast.Module, moduleIdentifier: str, callableId
|
|
|
64
57
|
write_astModule(IngredientsModule(ingredientsFunction), pathFilename, packageSettings.identifierPackage)
|
|
65
58
|
|
|
66
59
|
return pathFilename
|
|
67
|
-
|
|
68
|
-
def makeUnRePackDataclass(astImportFrom: ast.ImportFrom, moduleIdentifier: str = identifierModuleDataPackingDEFAULT) -> None:
|
|
69
|
-
"""Generate interface module for dataclass unpacking and repacking operations.
|
|
70
|
-
|
|
71
|
-
Parameters
|
|
72
|
-
----------
|
|
73
|
-
astImportFrom : ast.ImportFrom
|
|
74
|
-
Import statement specifying the target optimized function to call.
|
|
75
|
-
|
|
76
|
-
Returns
|
|
77
|
-
-------
|
|
78
|
-
None
|
|
79
|
-
The generated module is written directly to the filesystem.
|
|
80
|
-
|
|
81
|
-
"""
|
|
82
|
-
callableIdentifierHARDCODED: str = 'sequential'
|
|
83
|
-
|
|
84
|
-
algorithmSourceModule: identifierDotAttribute = identifierModuleSourceAlgorithmDEFAULT
|
|
85
|
-
callableIdentifier: identifierDotAttribute = callableIdentifierHARDCODED
|
|
86
|
-
logicalPathInfix: identifierDotAttribute = logicalPathInfixDEFAULT
|
|
87
|
-
logicalPathInfixAlgorithm: identifierDotAttribute = logicalPathInfixAlgorithmDEFAULT
|
|
88
|
-
sourceCallableIdentifier: identifierDotAttribute = identifierCallableSourceDispatcherDEFAULT
|
|
89
|
-
|
|
90
|
-
logicalPathSourceModule: identifierDotAttribute = '.'.join([packageSettings.identifierPackage, logicalPathInfixAlgorithm, algorithmSourceModule]) # noqa: FLY002
|
|
91
|
-
|
|
92
|
-
ingredientsFunction: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
|
|
93
|
-
ingredientsFunction.astFunctionDef.name = callableIdentifier
|
|
94
|
-
|
|
95
|
-
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(*findDataclass(ingredientsFunction))
|
|
96
|
-
|
|
97
|
-
ingredientsFunction.imports.update(shatteredDataclass.imports)
|
|
98
|
-
ingredientsFunction.imports.addAst(astImportFrom)
|
|
99
|
-
targetCallableIdentifier: str = astImportFrom.names[0].name
|
|
100
|
-
ingredientsFunction = raiseIfNone(unpackDataclassCallFunctionRepackDataclass(ingredientsFunction, targetCallableIdentifier, shatteredDataclass))
|
|
101
|
-
targetFunctionDef: ast.FunctionDef = raiseIfNone(extractFunctionDef(parseLogicalPath2astModule(raiseIfNone(astImportFrom.module)), targetCallableIdentifier))
|
|
102
|
-
astTuple: ast.Tuple = cast('ast.Tuple', raiseIfNone(NodeTourist(Be.Return.valueIs(Be.Tuple)
|
|
103
|
-
, doThat=Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)))
|
|
104
|
-
astTuple.ctx = Make.Store()
|
|
105
|
-
|
|
106
|
-
changeAssignCallToTarget = NodeChanger(
|
|
107
|
-
findThis = Be.Assign.valueIs(IfThis.isCallIdentifier(targetCallableIdentifier))
|
|
108
|
-
, doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts))))
|
|
109
|
-
changeAssignCallToTarget.visit(ingredientsFunction.astFunctionDef)
|
|
110
|
-
|
|
111
|
-
ingredientsModule = IngredientsModule(ingredientsFunction)
|
|
112
|
-
ingredientsModule.removeImportFromModule('numpy')
|
|
113
|
-
|
|
114
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, moduleIdentifier)
|
|
115
|
-
|
|
116
|
-
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
117
|
-
|
|
@@ -6,17 +6,14 @@ from astToolkit import (
|
|
|
6
6
|
from astToolkit.transformationTools import inlineFunctionDef, removeUnusedParameters, write_astModule
|
|
7
7
|
from hunterMakesPy import importLogicalPath2Identifier, raiseIfNone
|
|
8
8
|
from mapFolding import packageSettings
|
|
9
|
-
from mapFolding.someAssemblyRequired import
|
|
10
|
-
DeReConstructField2ast, identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis,
|
|
11
|
-
logicalPathInfixDEFAULT, ShatteredDataclass)
|
|
9
|
+
from mapFolding.someAssemblyRequired import default, DeReConstructField2ast, IfThis, ShatteredDataclass
|
|
12
10
|
from mapFolding.someAssemblyRequired.makingModules_count import (
|
|
13
|
-
|
|
14
|
-
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState
|
|
15
|
-
from mapFolding.someAssemblyRequired.toolkitMakeModules import
|
|
11
|
+
makeMapFoldingNumba, makeTheorem2, numbaOnTheorem2, trimTheorem2)
|
|
12
|
+
from mapFolding.someAssemblyRequired.makingModules_doTheNeedful import makeInitializeState
|
|
13
|
+
from mapFolding.someAssemblyRequired.toolkitMakeModules import getModule, getPathFilename
|
|
16
14
|
from mapFolding.someAssemblyRequired.toolkitNumba import decorateCallableWithNumba, parametersNumbaLight
|
|
17
15
|
from mapFolding.someAssemblyRequired.transformationTools import (
|
|
18
16
|
removeDataclassFromFunction, shatter_dataclassesDOTdataclass, unpackDataclassCallFunctionRepackDataclass)
|
|
19
|
-
from os import PathLike
|
|
20
17
|
from pathlib import PurePath
|
|
21
18
|
from typing import Any, TYPE_CHECKING
|
|
22
19
|
import ast
|
|
@@ -25,7 +22,7 @@ import dataclasses
|
|
|
25
22
|
if TYPE_CHECKING:
|
|
26
23
|
from collections.abc import Sequence
|
|
27
24
|
|
|
28
|
-
def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module,
|
|
25
|
+
def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, identifierModule: str, identifierCallable: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath: # noqa: ARG001
|
|
29
26
|
"""Generate parallel implementation with concurrent execution and task division.
|
|
30
27
|
|
|
31
28
|
Parameters
|
|
@@ -47,11 +44,11 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
47
44
|
Filesystem path where the parallel module was written.
|
|
48
45
|
|
|
49
46
|
"""
|
|
50
|
-
sourceCallableIdentifier =
|
|
51
|
-
if
|
|
52
|
-
|
|
47
|
+
sourceCallableIdentifier = default['function']['counting']
|
|
48
|
+
if identifierCallable is None:
|
|
49
|
+
identifierCallable = sourceCallableIdentifier
|
|
53
50
|
ingredientsFunction = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule), LedgerOfImports(astModule))
|
|
54
|
-
ingredientsFunction.astFunctionDef.name =
|
|
51
|
+
ingredientsFunction.astFunctionDef.name = identifierCallable
|
|
55
52
|
|
|
56
53
|
dataclassName: ast.expr = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
57
54
|
dataclassIdentifier: str = raiseIfNone(NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName))
|
|
@@ -69,10 +66,10 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
69
66
|
dataclassInstanceIdentifier: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
70
67
|
shatteredDataclass: ShatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclassIdentifier, dataclassInstanceIdentifier)
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
dataclassBaseFields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifier))
|
|
69
|
+
# START add the parallel state fields to the count function ------------------------------------------------
|
|
70
|
+
dataclassBaseFields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifier))
|
|
74
71
|
dataclassIdentifierParallel: identifierDotAttribute = 'Parallel' + dataclassIdentifier
|
|
75
|
-
dataclassFieldsParallel: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifierParallel))
|
|
72
|
+
dataclassFieldsParallel: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(importLogicalPath2Identifier(dataclassLogicalPathModule, dataclassIdentifierParallel))
|
|
76
73
|
onlyParallelFields: list[dataclasses.Field[Any]] = [field for field in dataclassFieldsParallel if field.name not in [fieldBase.name for fieldBase in dataclassBaseFields]]
|
|
77
74
|
|
|
78
75
|
Official_fieldOrder: list[str] = []
|
|
@@ -108,12 +105,12 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
108
105
|
shatteredDataclassParallel.imports.update(shatteredDataclass.imports)
|
|
109
106
|
shatteredDataclassParallel.imports.removeImportFrom(dataclassLogicalPathModule, dataclassIdentifier)
|
|
110
107
|
|
|
111
|
-
|
|
108
|
+
# END add the parallel state fields to the count function ------------------------------------------------
|
|
112
109
|
|
|
113
110
|
ingredientsFunction.imports.update(shatteredDataclassParallel.imports)
|
|
114
111
|
ingredientsFunction: IngredientsFunction = removeDataclassFromFunction(ingredientsFunction, shatteredDataclassParallel)
|
|
115
112
|
|
|
116
|
-
|
|
113
|
+
# START add the parallel logic to the count function ------------------------------------------------
|
|
117
114
|
|
|
118
115
|
findThis = Be.While.testIs(Be.Compare.leftIs(IfThis.isNameIdentifier('leafConnectee')))
|
|
119
116
|
captureCountGapsCodeBlock: NodeTourist[ast.While, Sequence[ast.stmt]] = NodeTourist(findThis, doThat = Then.extractIt(DOT.body))
|
|
@@ -127,20 +124,20 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
127
124
|
countGapsCodeBlockNew: list[ast.stmt] = [thisIsMyTaskIndexCodeBlock, countGapsCodeBlock[-1]]
|
|
128
125
|
NodeChanger[ast.While, hasDOTbody](findThis, doThat = Grab.bodyAttribute(Then.replaceWith(countGapsCodeBlockNew))).visit(ingredientsFunction.astFunctionDef)
|
|
129
126
|
|
|
130
|
-
|
|
127
|
+
# END add the parallel logic to the count function ------------------------------------------------
|
|
131
128
|
|
|
132
129
|
ingredientsFunction = removeUnusedParameters(ingredientsFunction)
|
|
133
130
|
|
|
134
131
|
ingredientsFunction = decorateCallableWithNumba(ingredientsFunction, parametersNumbaLight)
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
sourceCallableIdentifier =
|
|
133
|
+
# START unpack/repack the dataclass function ------------------------------------------------
|
|
134
|
+
sourceCallableIdentifier = default['function']['dispatcher']
|
|
138
135
|
|
|
139
136
|
unRepackDataclass: IngredientsFunction = astModuleToIngredientsFunction(astModule, sourceCallableIdentifier)
|
|
140
137
|
unRepackDataclass.astFunctionDef.name = 'unRepack' + dataclassIdentifierParallel
|
|
141
138
|
unRepackDataclass.imports.update(shatteredDataclassParallel.imports)
|
|
142
139
|
NodeChanger(
|
|
143
|
-
findThis = Be.arg.annotationIs(Be.Name.idIs(lambda thisAttribute: thisAttribute == dataclassIdentifier))
|
|
140
|
+
findThis = Be.arg.annotationIs(Be.Name.idIs(lambda thisAttribute: thisAttribute == dataclassIdentifier))
|
|
144
141
|
, doThat = Grab.annotationAttribute(Grab.idAttribute(Then.replaceWith(dataclassIdentifierParallel)))
|
|
145
142
|
).visit(unRepackDataclass.astFunctionDef)
|
|
146
143
|
unRepackDataclass.astFunctionDef.returns = Make.Name(dataclassIdentifierParallel)
|
|
@@ -187,7 +184,7 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
187
184
|
)
|
|
188
185
|
ingredientsModule.removeImportFromModule('numpy')
|
|
189
186
|
|
|
190
|
-
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix,
|
|
187
|
+
pathFilename: PurePath = getPathFilename(packageSettings.pathPackage, logicalPathInfix, identifierModule)
|
|
191
188
|
|
|
192
189
|
write_astModule(ingredientsModule, pathFilename, packageSettings.identifierPackage)
|
|
193
190
|
|
|
@@ -196,25 +193,22 @@ def makeDaoOfMapFoldingParallelNumba(astModule: ast.Module, moduleIdentifier: st
|
|
|
196
193
|
def makeMapFoldingModules() -> None:
|
|
197
194
|
"""Make multidimensional map folding modules."""
|
|
198
195
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
199
|
-
pathFilename: PurePath =
|
|
196
|
+
pathFilename: PurePath = makeMapFoldingNumba(astModule, 'daoOfMapFoldingNumba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
200
197
|
|
|
201
198
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
202
|
-
pathFilename = makeDaoOfMapFoldingParallelNumba(astModule, 'countParallelNumba', None,
|
|
199
|
+
pathFilename = makeDaoOfMapFoldingParallelNumba(astModule, 'countParallelNumba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
203
200
|
|
|
204
201
|
astModule: ast.Module = getModule(logicalPathInfix='algorithms')
|
|
205
|
-
makeInitializeState(astModule, 'initializeState', '
|
|
202
|
+
makeInitializeState(astModule, default['module']['initializeState'], default['function']['initializeState'], default['logicalPath']['synthetic'])
|
|
206
203
|
|
|
207
204
|
astModule = getModule(logicalPathInfix='algorithms')
|
|
208
|
-
pathFilename = makeTheorem2(astModule, 'theorem2', None,
|
|
205
|
+
pathFilename = makeTheorem2(astModule, 'theorem2', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
209
206
|
|
|
210
207
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
211
|
-
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None,
|
|
208
|
+
pathFilename = trimTheorem2(astModule, 'theorem2Trimmed', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
212
209
|
|
|
213
210
|
astModule = parsePathFilename2astModule(pathFilename)
|
|
214
|
-
pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None,
|
|
215
|
-
|
|
216
|
-
astImportFrom: ast.ImportFrom = Make.ImportFrom(getLogicalPath(packageSettings.identifierPackage, logicalPathInfixDEFAULT, 'theorem2Numba'), list_alias=[Make.alias(identifierCallableSourceDEFAULT)])
|
|
217
|
-
makeUnRePackDataclass(astImportFrom)
|
|
211
|
+
pathFilename = numbaOnTheorem2(astModule, 'theorem2Numba', None, default['logicalPath']['synthetic'], default['function']['dispatcher'])
|
|
218
212
|
|
|
219
213
|
if __name__ == '__main__':
|
|
220
214
|
makeMapFoldingModules()
|
|
@@ -3,24 +3,22 @@ from astToolkit import (
|
|
|
3
3
|
astModuleToIngredientsFunction, Be, Grab, identifierDotAttribute, Make, NodeChanger, NodeTourist, Then)
|
|
4
4
|
from hunterMakesPy import raiseIfNone
|
|
5
5
|
from mapFolding import packageSettings
|
|
6
|
-
from mapFolding.someAssemblyRequired import
|
|
7
|
-
identifierCallableSourceDEFAULT, identifierCallableSourceDispatcherDEFAULT, IfThis, logicalPathInfixDEFAULT)
|
|
6
|
+
from mapFolding.someAssemblyRequired import default, IfThis
|
|
8
7
|
from mapFolding.someAssemblyRequired.toolkitMakeModules import (
|
|
9
8
|
findDataclass, getModule, getPathFilename, write_astModule)
|
|
10
|
-
from os import PathLike
|
|
11
9
|
from pathlib import PurePath
|
|
12
10
|
import ast
|
|
13
11
|
|
|
14
12
|
identifierDataclassNumPyHARDCODED = 'MatrixMeandersNumPyState'
|
|
15
13
|
|
|
16
|
-
logicalPathInfixMeanders: str =
|
|
14
|
+
logicalPathInfixMeanders: str = default['logicalPath']['synthetic'] + '.meanders'
|
|
17
15
|
|
|
18
|
-
def makeCountBigInt(astModule: ast.Module,
|
|
16
|
+
def makeCountBigInt(astModule: ast.Module, identifierModule: str, callableIdentifier: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, sourceCallableDispatcher: str | None = None) -> PurePath:
|
|
19
17
|
"""Make `countBigInt` module for meanders using `MatrixMeandersNumPyState` dataclass."""
|
|
20
18
|
identifierDataclassNumPy: str = identifierDataclassNumPyHARDCODED
|
|
21
19
|
_logicalPathDataclass, identifierDataclassOld, identifierDataclassInstance = findDataclass(astModuleToIngredientsFunction(astModule, raiseIfNone(sourceCallableDispatcher)))
|
|
22
20
|
|
|
23
|
-
NodeChanger(findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(
|
|
21
|
+
NodeChanger(findThis=Be.FunctionDef.nameIs(IfThis.isIdentifier(default['function']['counting']))
|
|
24
22
|
, doThat=Grab.nameAttribute(Then.replaceWith(raiseIfNone(callableIdentifier)))
|
|
25
23
|
).visit(astModule)
|
|
26
24
|
|
|
@@ -36,29 +34,32 @@ def makeCountBigInt(astModule: ast.Module, moduleIdentifier: str, callableIdenti
|
|
|
36
34
|
, Grab.nameAttribute(Then.replaceWith(identifierDataclassNumPy))
|
|
37
35
|
).visit(astModule)
|
|
38
36
|
|
|
39
|
-
# while (state.
|
|
37
|
+
# while (state.boundary > 0 and areIntegersWide(state)): # noqa: ERA001
|
|
40
38
|
Call_areIntegersWide: ast.Call = Make.Call(Make.Name('areIntegersWide'), listParameters=[Make.Name('state')])
|
|
41
39
|
astCompare: ast.Compare = raiseIfNone(NodeTourist(
|
|
42
|
-
findThis=IfThis.isAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, '
|
|
40
|
+
findThis=IfThis.isAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, 'boundary')
|
|
43
41
|
, doThat=Then.extractIt
|
|
44
42
|
).captureLastMatch(astModule))
|
|
45
43
|
newTest: ast.expr = Make.And.join([astCompare, Call_areIntegersWide])
|
|
46
44
|
|
|
47
|
-
NodeChanger(IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, '
|
|
45
|
+
NodeChanger(IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0(identifierDataclassInstance, 'boundary')
|
|
48
46
|
, Grab.testAttribute(Then.replaceWith(newTest))
|
|
49
47
|
).visit(astModule)
|
|
50
48
|
|
|
51
49
|
# from mapFolding.algorithms.matrixMeandersBeDry import areIntegersWide # noqa: ERA001
|
|
52
50
|
astModule.body.insert(0, Make.ImportFrom('mapFolding.algorithms.matrixMeandersBeDry', list_alias=[Make.alias('areIntegersWide')]))
|
|
53
51
|
|
|
54
|
-
pathFilename = getPathFilename(logicalPathInfix=logicalPathInfix,
|
|
52
|
+
pathFilename: PurePath = getPathFilename(logicalPathInfix=logicalPathInfix, identifierModule=identifierModule)
|
|
55
53
|
|
|
56
54
|
write_astModule(astModule, pathFilename, packageSettings.identifierPackage)
|
|
57
55
|
|
|
58
56
|
return pathFilename
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
def makeMeandersModules() -> None:
|
|
59
|
+
"""Make meanders modules."""
|
|
60
|
+
astModule: ast.Module = getModule(logicalPathInfix='algorithms', identifierModule='matrixMeanders')
|
|
61
|
+
pathFilename: PurePath = makeCountBigInt(astModule, 'bigInt', 'countBigInt', logicalPathInfixMeanders, default['function']['dispatcher'])
|
|
63
62
|
|
|
63
|
+
if __name__ == '__main__':
|
|
64
|
+
makeMeandersModules()
|
|
64
65
|
|
|
@@ -36,7 +36,7 @@ from astToolkit import (
|
|
|
36
36
|
from autoflake import fix_code as autoflake_fix_code
|
|
37
37
|
from hunterMakesPy import raiseIfNone, writeStringToHere
|
|
38
38
|
from mapFolding import packageSettings
|
|
39
|
-
from mapFolding.someAssemblyRequired import
|
|
39
|
+
from mapFolding.someAssemblyRequired import default
|
|
40
40
|
from os import PathLike
|
|
41
41
|
from pathlib import PurePath
|
|
42
42
|
from typing import Any
|
|
@@ -85,32 +85,32 @@ def findDataclass(ingredientsFunction: IngredientsFunction) -> tuple[identifierD
|
|
|
85
85
|
identifierDataclassInstance: identifierDotAttribute = raiseIfNone(NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef))
|
|
86
86
|
return raiseIfNone(logicalPathDataclass), identifierDataclass, identifierDataclassInstance
|
|
87
87
|
|
|
88
|
-
def getLogicalPath(identifierPackage: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, *
|
|
88
|
+
def getLogicalPath(identifierPackage: str | None = None, logicalPathInfix: identifierDotAttribute | None = None, *identifierModule: str | None) -> identifierDotAttribute:
|
|
89
89
|
"""Get logical path from components."""
|
|
90
90
|
listLogicalPathParts: list[str] = []
|
|
91
91
|
if identifierPackage:
|
|
92
92
|
listLogicalPathParts.append(identifierPackage)
|
|
93
93
|
if logicalPathInfix:
|
|
94
94
|
listLogicalPathParts.append(logicalPathInfix)
|
|
95
|
-
if
|
|
96
|
-
listLogicalPathParts.extend([module for module in
|
|
95
|
+
if identifierModule:
|
|
96
|
+
listLogicalPathParts.extend([module for module in identifierModule if module is not None])
|
|
97
97
|
return '.'.join(listLogicalPathParts)
|
|
98
98
|
|
|
99
|
-
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix: identifierDotAttribute | None =
|
|
99
|
+
def getModule(identifierPackage: str | None = packageSettings.identifierPackage, logicalPathInfix: identifierDotAttribute | None = default['logicalPath']['synthetic'], identifierModule: str | None = default['module']['algorithm']) -> ast.Module:
|
|
100
100
|
"""Get Module."""
|
|
101
|
-
logicalPathSourceModule: identifierDotAttribute = getLogicalPath(identifierPackage, logicalPathInfix,
|
|
101
|
+
logicalPathSourceModule: identifierDotAttribute = getLogicalPath(identifierPackage, logicalPathInfix, identifierModule)
|
|
102
102
|
astModule: ast.Module = parseLogicalPath2astModule(logicalPathSourceModule)
|
|
103
103
|
return astModule
|
|
104
104
|
|
|
105
|
-
def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix:
|
|
105
|
+
def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.pathPackage, logicalPathInfix: identifierDotAttribute | None = None, identifierModule: str = '', fileExtension: str = packageSettings.fileExtension) -> PurePath:
|
|
106
106
|
"""Construct filesystem path from logical path.
|
|
107
107
|
|
|
108
108
|
Parameters
|
|
109
109
|
----------
|
|
110
110
|
pathRoot : PathLike[str] | PurePath | None = packageSettings.pathPackage
|
|
111
111
|
Base directory for the package structure.
|
|
112
|
-
logicalPathInfix :
|
|
113
|
-
|
|
112
|
+
logicalPathInfix : identifierDotAttribute | None = None
|
|
113
|
+
Logical path in dot notation.
|
|
114
114
|
moduleIdentifier : str = ''
|
|
115
115
|
Name of the specific module file.
|
|
116
116
|
fileExtension : str = packageSettings.fileExtension
|
|
@@ -122,7 +122,7 @@ def getPathFilename(pathRoot: PathLike[str] | PurePath | None = packageSettings.
|
|
|
122
122
|
Complete filesystem path for the generated module file.
|
|
123
123
|
|
|
124
124
|
"""
|
|
125
|
-
pathFilename = PurePath(
|
|
125
|
+
pathFilename = PurePath(identifierModule + fileExtension)
|
|
126
126
|
if logicalPathInfix:
|
|
127
127
|
pathFilename = PurePath(*(str(logicalPathInfix).split('.')), pathFilename)
|
|
128
128
|
if pathRoot:
|
|
@@ -281,7 +281,7 @@ def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, paramete
|
|
|
281
281
|
return ingredientsFunction
|
|
282
282
|
|
|
283
283
|
@dataclasses.dataclass
|
|
284
|
-
class SpicesJobNumba:
|
|
284
|
+
class SpicesJobNumba: # slots?
|
|
285
285
|
"""Configuration container for Numba-specific job processing options.
|
|
286
286
|
|
|
287
287
|
(AI generated docstring)
|
|
@@ -34,7 +34,7 @@ from mapFolding.someAssemblyRequired import DeReConstructField2ast, IfThis, Shat
|
|
|
34
34
|
import ast
|
|
35
35
|
import dataclasses
|
|
36
36
|
|
|
37
|
-
def shatter_dataclassesDOTdataclass(
|
|
37
|
+
def shatter_dataclassesDOTdataclass(logicalPathDataclass: identifierDotAttribute, identifierDataclass: str, identifierDataclassInstance: str) -> ShatteredDataclass:
|
|
38
38
|
"""Decompose a dataclass definition into AST components for manipulation and code generation.
|
|
39
39
|
|
|
40
40
|
(AI generated docstring)
|
|
@@ -77,19 +77,19 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: identifierDotAttribute, d
|
|
|
77
77
|
Official_fieldOrder: list[str] = []
|
|
78
78
|
dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
|
|
79
79
|
|
|
80
|
-
dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(
|
|
80
|
+
dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(logicalPathDataclass), identifierDataclass)
|
|
81
81
|
if not dataclassClassDef:
|
|
82
|
-
message = f"I could not find `{
|
|
82
|
+
message: str = f"I could not find `{identifierDataclass = }` in `{logicalPathDataclass = }`."
|
|
83
83
|
raise ValueError(message)
|
|
84
84
|
|
|
85
|
-
countingVariable = None
|
|
86
|
-
for aField in dataclasses.fields(importLogicalPath2Identifier(
|
|
85
|
+
countingVariable: str | None = None
|
|
86
|
+
for aField in dataclasses.fields(importLogicalPath2Identifier(logicalPathDataclass, identifierDataclass)): # pyright: ignore [reportArgumentType]
|
|
87
87
|
Official_fieldOrder.append(aField.name)
|
|
88
|
-
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(
|
|
88
|
+
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(logicalPathDataclass, dataclassClassDef, identifierDataclassInstance, aField)
|
|
89
89
|
if aField.metadata.get('theCountingIdentifier', False):
|
|
90
90
|
countingVariable = dictionaryDeReConstruction[aField.name].name
|
|
91
91
|
if countingVariable is None:
|
|
92
|
-
message = f"I could not find the counting variable in `{
|
|
92
|
+
message = f"I could not find the counting variable in `{identifierDataclass = }` in `{logicalPathDataclass = }`."
|
|
93
93
|
raise ValueError(message)
|
|
94
94
|
|
|
95
95
|
shatteredDataclass = ShatteredDataclass(
|
|
@@ -99,17 +99,18 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: identifierDotAttribute, d
|
|
|
99
99
|
Z0Z_field2AnnAssign={dictionaryDeReConstruction[field].name: dictionaryDeReConstruction[field].Z0Z_hack for field in Official_fieldOrder},
|
|
100
100
|
list_argAnnotated4ArgumentsSpecification=[dictionaryDeReConstruction[field].ast_argAnnotated for field in Official_fieldOrder],
|
|
101
101
|
list_keyword_field__field4init=[dictionaryDeReConstruction[field].ast_keyword_field__field for field in Official_fieldOrder if dictionaryDeReConstruction[field].init],
|
|
102
|
+
listIdentifiersStaticScalars=[dictionaryDeReConstruction[field].name for field in Official_fieldOrder if (dictionaryDeReConstruction[field].Z0Z_hack[1] == 'scalar' and not dictionaryDeReConstruction[field].init)],
|
|
102
103
|
listAnnotations=[dictionaryDeReConstruction[field].astAnnotation for field in Official_fieldOrder],
|
|
103
104
|
listName4Parameters=[dictionaryDeReConstruction[field].astName for field in Official_fieldOrder],
|
|
104
105
|
listUnpack=[Make.AnnAssign(dictionaryDeReConstruction[field].astName, dictionaryDeReConstruction[field].astAnnotation, dictionaryDeReConstruction[field].ast_nameDOTname) for field in Official_fieldOrder],
|
|
105
106
|
map_stateDOTfield2Name={dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder},
|
|
106
107
|
)
|
|
107
108
|
shatteredDataclass.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclass.listName4Parameters, ast.Store())
|
|
108
|
-
shatteredDataclass.repack = Make.Assign([Make.Name(
|
|
109
|
+
shatteredDataclass.repack = Make.Assign([Make.Name(identifierDataclassInstance)], value=Make.Call(Make.Name(identifierDataclass), list_keyword=shatteredDataclass.list_keyword_field__field4init))
|
|
109
110
|
shatteredDataclass.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclass.listAnnotations))
|
|
110
111
|
|
|
111
112
|
shatteredDataclass.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
|
|
112
|
-
shatteredDataclass.imports.addImportFrom_asStr(
|
|
113
|
+
shatteredDataclass.imports.addImportFrom_asStr(logicalPathDataclass, identifierDataclass)
|
|
113
114
|
|
|
114
115
|
return shatteredDataclass
|
|
115
116
|
|
|
@@ -145,12 +146,11 @@ def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shattere
|
|
|
145
146
|
"""
|
|
146
147
|
ingredientsTarget.astFunctionDef.args = Make.arguments(list_arg=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
147
148
|
ingredientsTarget.astFunctionDef.returns = shatteredDataclass.signatureReturnAnnotation
|
|
148
|
-
|
|
149
|
-
changeReturnCallable.visit(ingredientsTarget.astFunctionDef)
|
|
149
|
+
NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.fragments4AssignmentOrParameters))).visit(ingredientsTarget.astFunctionDef)
|
|
150
150
|
ingredientsTarget.astFunctionDef = unparseFindReplace(ingredientsTarget.astFunctionDef, shatteredDataclass.map_stateDOTfield2Name)
|
|
151
151
|
return ingredientsTarget
|
|
152
152
|
|
|
153
|
-
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction,
|
|
153
|
+
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, identifierCallee: str, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
154
154
|
"""Transform a caller function to interface with a dataclass-free target function.
|
|
155
155
|
|
|
156
156
|
(AI generated docstring)
|
|
@@ -184,12 +184,10 @@ def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFun
|
|
|
184
184
|
The modified caller function with appropriate unpacking and repacking around the target call.
|
|
185
185
|
|
|
186
186
|
"""
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
replaceAssignTargetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
192
|
-
unpack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
193
|
-
repack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
187
|
+
AssignAndCall: ast.Assign = Make.Assign([shatteredDataclass.fragments4AssignmentOrParameters], value=Make.Call(Make.Name(identifierCallee), shatteredDataclass.listName4Parameters))
|
|
188
|
+
NodeChanger(Be.Assign.valueIs(IfThis.isCallIdentifier(identifierCallee)), Then.replaceWith(AssignAndCall)).visit(ingredientsCaller.astFunctionDef)
|
|
189
|
+
NodeChanger(Be.Assign.valueIs(IfThis.isCallIdentifier(identifierCallee)), Then.insertThisAbove(shatteredDataclass.listUnpack)).visit(ingredientsCaller.astFunctionDef)
|
|
190
|
+
NodeChanger(Be.Assign.valueIs(IfThis.isCallIdentifier(identifierCallee)), Then.insertThisBelow([shatteredDataclass.repack])).visit(ingredientsCaller.astFunctionDef)
|
|
194
191
|
return ingredientsCaller
|
|
195
192
|
|
|
193
|
+
|