mapFolding 0.7.1__py3-none-any.whl → 0.8.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/beDRY.py +77 -81
- mapFolding/noHomeYet.py +2 -2
- mapFolding/oeis.py +2 -2
- mapFolding/someAssemblyRequired/Z0Z_workbench.py +347 -30
- mapFolding/someAssemblyRequired/__init__.py +4 -3
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -1
- mapFolding/someAssemblyRequired/ingredientsNumba.py +87 -2
- mapFolding/someAssemblyRequired/synthesizeDataConverters.py +34 -52
- mapFolding/someAssemblyRequired/{synthesizeNumbaJob.py → synthesizeNumbaJobVESTIGIAL.py} +18 -21
- mapFolding/someAssemblyRequired/transformationTools.py +546 -208
- mapFolding/syntheticModules/numbaCount_doTheNeedful.py +197 -12
- mapFolding/theDao.py +23 -16
- mapFolding/theSSOT.py +28 -43
- {mapfolding-0.7.1.dist-info → mapfolding-0.8.0.dist-info}/METADATA +6 -7
- mapfolding-0.8.0.dist-info/RECORD +41 -0
- {mapfolding-0.7.1.dist-info → mapfolding-0.8.0.dist-info}/WHEEL +1 -1
- tests/conftest.py +2 -3
- tests/test_filesystem.py +0 -2
- tests/test_other.py +2 -3
- tests/test_tasks.py +0 -4
- mapFolding/someAssemblyRequired/synthesizeCountingFunctions.py +0 -7
- mapFolding/someAssemblyRequired/synthesizeNumba.py +0 -91
- mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +0 -91
- mapFolding/someAssemblyRequired/whatWillBe.py +0 -357
- mapFolding/syntheticModules/__init__.py +0 -0
- mapFolding/syntheticModules/dataNamespaceFlattened.py +0 -30
- mapFolding/syntheticModules/multiprocessingCount_doTheNeedful.py +0 -216
- mapFolding/syntheticModules/numbaCount.py +0 -90
- mapFolding/syntheticModules/numbaCountSequential.py +0 -111
- mapFolding/syntheticModules/numba_doTheNeedful.py +0 -12
- mapfolding-0.7.1.dist-info/RECORD +0 -51
- /mapFolding/syntheticModules/{numbaCountExample.py → numbaCountHistoricalExample.py} +0 -0
- /mapFolding/syntheticModules/{numba_doTheNeedfulExample.py → numba_doTheNeedfulHistoricalExample.py} +0 -0
- {mapfolding-0.7.1.dist-info → mapfolding-0.8.0.dist-info}/LICENSE +0 -0
- {mapfolding-0.7.1.dist-info → mapfolding-0.8.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.7.1.dist-info → mapfolding-0.8.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
from collections.abc import Callable
|
|
1
|
+
from collections.abc import Callable, Sequence
|
|
2
|
+
from mapFolding.someAssemblyRequired import ifThis, IngredientsFunction, Make
|
|
2
3
|
from numba.core.compiler import CompilerBase as numbaCompilerBase
|
|
3
|
-
from typing import Any, TYPE_CHECKING, Final
|
|
4
|
+
from typing import Any, TYPE_CHECKING, Final, cast
|
|
5
|
+
import ast
|
|
4
6
|
|
|
5
7
|
try:
|
|
6
8
|
from typing import NotRequired
|
|
@@ -98,3 +100,86 @@ parametersNumbaMinimum: Final[ParametersNumba] = {
|
|
|
98
100
|
'nopython': False,
|
|
99
101
|
'forceobj': True,
|
|
100
102
|
'parallel': False, }
|
|
103
|
+
|
|
104
|
+
Z0Z_numbaDataTypeModule = 'numba'
|
|
105
|
+
Z0Z_decoratorCallable = 'jit'
|
|
106
|
+
|
|
107
|
+
def thisIsNumbaDotJit(Ima: ast.AST) -> bool:
|
|
108
|
+
return ifThis.isCallNamespace_Identifier(Z0Z_numbaDataTypeModule, Z0Z_decoratorCallable)(Ima)
|
|
109
|
+
|
|
110
|
+
def thisIsJit(Ima: ast.AST) -> bool:
|
|
111
|
+
return ifThis.isCall_Identifier(Z0Z_decoratorCallable)(Ima)
|
|
112
|
+
|
|
113
|
+
def thisIsAnyNumbaJitDecorator(Ima: ast.AST) -> bool:
|
|
114
|
+
return thisIsNumbaDotJit(Ima) or thisIsJit(Ima)
|
|
115
|
+
|
|
116
|
+
def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, parametersNumba: ParametersNumba | None = None) -> IngredientsFunction:
|
|
117
|
+
def Z0Z_UnhandledDecorators(astCallable: ast.FunctionDef) -> ast.FunctionDef:
|
|
118
|
+
# TODO: more explicit handling of decorators. I'm able to ignore this because I know `algorithmSource` doesn't have any decorators.
|
|
119
|
+
for decoratorItem in astCallable.decorator_list.copy():
|
|
120
|
+
import warnings
|
|
121
|
+
astCallable.decorator_list.remove(decoratorItem)
|
|
122
|
+
warnings.warn(f"Removed decorator {ast.unparse(decoratorItem)} from {astCallable.name}")
|
|
123
|
+
return astCallable
|
|
124
|
+
|
|
125
|
+
def makeSpecialSignatureForNumba(signatureElement: ast.arg) -> ast.Subscript | ast.Name | None:
|
|
126
|
+
if isinstance(signatureElement.annotation, ast.Subscript) and isinstance(signatureElement.annotation.slice, ast.Tuple):
|
|
127
|
+
annotationShape: ast.expr = signatureElement.annotation.slice.elts[0]
|
|
128
|
+
if isinstance(annotationShape, ast.Subscript) and isinstance(annotationShape.slice, ast.Tuple):
|
|
129
|
+
shapeAsListSlices: list[ast.Slice] = [ast.Slice() for _axis in range(len(annotationShape.slice.elts))]
|
|
130
|
+
shapeAsListSlices[-1] = ast.Slice(step=ast.Constant(value=1))
|
|
131
|
+
shapeAST: ast.Slice | ast.Tuple = ast.Tuple(elts=list(shapeAsListSlices), ctx=ast.Load())
|
|
132
|
+
else:
|
|
133
|
+
shapeAST = ast.Slice(step=ast.Constant(value=1))
|
|
134
|
+
|
|
135
|
+
annotationDtype: ast.expr = signatureElement.annotation.slice.elts[1]
|
|
136
|
+
if (isinstance(annotationDtype, ast.Subscript) and isinstance(annotationDtype.slice, ast.Attribute)):
|
|
137
|
+
datatypeAST = annotationDtype.slice.attr
|
|
138
|
+
else:
|
|
139
|
+
datatypeAST = None
|
|
140
|
+
|
|
141
|
+
ndarrayName = signatureElement.arg
|
|
142
|
+
Z0Z_hacky_dtype: str = ndarrayName
|
|
143
|
+
datatype_attr = datatypeAST or Z0Z_hacky_dtype
|
|
144
|
+
ingredientsFunction.imports.addImportFromStr(datatypeModuleDecorator, datatype_attr)
|
|
145
|
+
datatypeNumba = ast.Name(id=datatype_attr, ctx=ast.Load())
|
|
146
|
+
|
|
147
|
+
return ast.Subscript(value=datatypeNumba, slice=shapeAST, ctx=ast.Load())
|
|
148
|
+
|
|
149
|
+
elif isinstance(signatureElement.annotation, ast.Name):
|
|
150
|
+
return signatureElement.annotation
|
|
151
|
+
return None
|
|
152
|
+
|
|
153
|
+
datatypeModuleDecorator: str = Z0Z_numbaDataTypeModule
|
|
154
|
+
list_argsDecorator: Sequence[ast.expr] = []
|
|
155
|
+
|
|
156
|
+
list_arg4signature_or_function: list[ast.expr] = []
|
|
157
|
+
for parameter in ingredientsFunction.astFunctionDef.args.args:
|
|
158
|
+
# Efficient translation of Python scalar types to Numba types https://github.com/hunterhogan/mapFolding/issues/8
|
|
159
|
+
# For now, let Numba infer them.
|
|
160
|
+
continue
|
|
161
|
+
signatureElement: ast.Subscript | ast.Name | None = makeSpecialSignatureForNumba(parameter)
|
|
162
|
+
if signatureElement:
|
|
163
|
+
list_arg4signature_or_function.append(signatureElement)
|
|
164
|
+
|
|
165
|
+
if ingredientsFunction.astFunctionDef.returns and isinstance(ingredientsFunction.astFunctionDef.returns, ast.Name):
|
|
166
|
+
theReturn: ast.Name = ingredientsFunction.astFunctionDef.returns
|
|
167
|
+
list_argsDecorator = [cast(ast.expr, ast.Call(func=ast.Name(id=theReturn.id, ctx=ast.Load())
|
|
168
|
+
, args=list_arg4signature_or_function if list_arg4signature_or_function else [], keywords=[] ) )]
|
|
169
|
+
elif list_arg4signature_or_function:
|
|
170
|
+
list_argsDecorator = [cast(ast.expr, ast.Tuple(elts=list_arg4signature_or_function, ctx=ast.Load()))]
|
|
171
|
+
|
|
172
|
+
ingredientsFunction.astFunctionDef = Z0Z_UnhandledDecorators(ingredientsFunction.astFunctionDef)
|
|
173
|
+
if parametersNumba is None:
|
|
174
|
+
parametersNumba = parametersNumbaDEFAULT
|
|
175
|
+
listDecoratorKeywords: list[ast.keyword] = [Make.ast_keyword(parameterName, Make.astConstant(parameterValue)) for parameterName, parameterValue in parametersNumba.items()]
|
|
176
|
+
|
|
177
|
+
decoratorModule: str = Z0Z_numbaDataTypeModule
|
|
178
|
+
decoratorCallable: str = Z0Z_decoratorCallable
|
|
179
|
+
ingredientsFunction.imports.addImportFromStr(decoratorModule, decoratorCallable)
|
|
180
|
+
# Leave this line in so that global edits will change it.
|
|
181
|
+
astDecorator: ast.Call = Make.astCall(Make.astName(decoratorCallable), list_argsDecorator, listDecoratorKeywords)
|
|
182
|
+
astDecorator: ast.Call = Make.astCall(Make.astName(decoratorCallable), list_astKeywords=listDecoratorKeywords) # type: ignore[no-redef]
|
|
183
|
+
|
|
184
|
+
ingredientsFunction.astFunctionDef.decorator_list = [astDecorator]
|
|
185
|
+
return ingredientsFunction
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
2
|
from importlib import import_module
|
|
3
3
|
from inspect import getsource as inspect_getsource
|
|
4
|
-
from
|
|
5
|
-
from types import ModuleType
|
|
6
|
-
from typing import Any, cast, overload, Literal
|
|
7
|
-
import ast
|
|
8
|
-
import pickle
|
|
9
|
-
from mapFolding.beDRY import ComputationState, outfitCountFolds, validateListDimensions
|
|
4
|
+
from mapFolding.beDRY import outfitCountFolds, validateListDimensions
|
|
10
5
|
from mapFolding.filesystem import getPathFilenameFoldsTotal
|
|
11
6
|
from mapFolding.someAssemblyRequired import (
|
|
12
7
|
ast_Identifier,
|
|
13
|
-
executeActionUnlessDescendantMatches,
|
|
14
8
|
extractClassDef,
|
|
15
9
|
ifThis,
|
|
16
|
-
IngredientsFunction,
|
|
17
10
|
LedgerOfImports,
|
|
18
11
|
Make,
|
|
19
12
|
NodeCollector,
|
|
20
13
|
strDotStrCuzPyStoopid,
|
|
21
14
|
Then,
|
|
15
|
+
Z0Z_executeActionUnlessDescendantMatches,
|
|
22
16
|
)
|
|
23
|
-
from mapFolding.theSSOT import getSourceAlgorithm
|
|
17
|
+
from mapFolding.theSSOT import ComputationState, getSourceAlgorithm
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from types import ModuleType
|
|
20
|
+
from typing import Any, Literal, overload
|
|
21
|
+
import ast
|
|
22
|
+
import pickle
|
|
23
|
+
|
|
24
|
+
# Would `LibCST` be better than `ast` in some cases? https://github.com/hunterhogan/mapFolding/issues/7
|
|
24
25
|
|
|
25
26
|
def shatter_dataclassesDOTdataclass(logicalPathModule: strDotStrCuzPyStoopid, dataclass_Identifier: ast_Identifier, instance_Identifier: ast_Identifier
|
|
26
|
-
|
|
27
|
+
)-> tuple[ast.Name, LedgerOfImports, list[ast.AnnAssign], ast.Tuple, list[ast.Name], list[ast.arg], ast.Subscript, ast.Assign, list[ast.keyword]]:
|
|
27
28
|
"""
|
|
28
29
|
Parameters:
|
|
29
30
|
logicalPathModule: gimme string cuz python is stoopid
|
|
@@ -37,63 +38,44 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: strDotStrCuzPyStoopid, da
|
|
|
37
38
|
if not isinstance(dataclass, ast.ClassDef):
|
|
38
39
|
raise ValueError(f"I could not find {dataclass_Identifier=} in {logicalPathModule=}.")
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
ledgerDataclassANDFragments = LedgerOfImports()
|
|
42
|
+
list_ast_argAnnotated4ArgumentsSpecification: list[ast.arg] = []
|
|
43
|
+
list_keyword4DataclassInitialization: list[ast.keyword] = []
|
|
44
|
+
listAnnAssign4DataclassUnpack: list[ast.AnnAssign] = []
|
|
45
|
+
listAnnotations: list[ast.expr] = []
|
|
46
|
+
listNameDataclassFragments4Parameters: list[ast.Name] = []
|
|
44
47
|
|
|
45
48
|
addToLedgerPredicate = ifThis.isAnnAssignAndAnnotationIsName
|
|
46
|
-
addToLedgerAction = Then.Z0Z_ledger(logicalPathModule,
|
|
49
|
+
addToLedgerAction = Then.Z0Z_ledger(logicalPathModule, ledgerDataclassANDFragments)
|
|
47
50
|
addToLedger = NodeCollector(addToLedgerPredicate, [addToLedgerAction])
|
|
48
51
|
|
|
49
52
|
exclusionPredicate = ifThis.is_keyword_IdentifierEqualsConstantValue('init', False)
|
|
50
|
-
appendKeywordAction = Then.Z0Z_appendKeywordMirroredTo(
|
|
51
|
-
filteredAppendKeywordAction =
|
|
53
|
+
appendKeywordAction = Then.Z0Z_appendKeywordMirroredTo(list_keyword4DataclassInitialization)
|
|
54
|
+
filteredAppendKeywordAction = Z0Z_executeActionUnlessDescendantMatches(exclusionPredicate, appendKeywordAction) # type: ignore
|
|
52
55
|
|
|
53
56
|
collector = NodeCollector(
|
|
54
57
|
ifThis.isAnnAssignAndTargetIsName,
|
|
55
|
-
[Then.
|
|
56
|
-
, Then.append_targetTo(
|
|
58
|
+
[Then.Z0Z_appendAnnAssignOf_nameDOTnameTo(instance_Identifier, listAnnAssign4DataclassUnpack)
|
|
59
|
+
, Then.append_targetTo(listNameDataclassFragments4Parameters) # type: ignore
|
|
57
60
|
, lambda node: addToLedger.visit(node)
|
|
58
61
|
, filteredAppendKeywordAction
|
|
62
|
+
, lambda node: list_ast_argAnnotated4ArgumentsSpecification.append(Make.ast_arg(node.target.id, node.annotation)) # type: ignore
|
|
63
|
+
, lambda node: listAnnotations.append(node.annotation) # type: ignore
|
|
59
64
|
]
|
|
60
65
|
)
|
|
61
66
|
|
|
62
67
|
collector.visit(dataclass)
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
astNameDataclass = Make.astName(dataclass_Identifier)
|
|
67
|
-
astTupleForAssignTargetsToFragments: ast.Tuple = Make.astTuple(list_astNameDataclassFragments, ast.Store())
|
|
68
|
-
return astNameDataclass, ledgerDataclassAndFragments, list_astAnnAssign, list_astNameDataclassFragments, listKeywordForDataclassInitialization, astTupleForAssignTargetsToFragments
|
|
69
|
-
|
|
70
|
-
def makeDataclassConverter(dataclassIdentifier: str,
|
|
71
|
-
logicalPathModuleDataclass: str,
|
|
72
|
-
dataclassInstance: str,
|
|
73
|
-
dispatcherCallable: str,
|
|
74
|
-
logicalPathModuleDispatcher: str,
|
|
75
|
-
dataConverterCallable: str,
|
|
76
|
-
) -> IngredientsFunction:
|
|
77
|
-
|
|
78
|
-
astNameDataclass, ledgerDataclassAndFragments, list_astAnnAssign, list_astNameDataclassFragments, list_astKeywordDataclassFragments, astTupleForAssignTargetsToFragments = shatter_dataclassesDOTdataclass(logicalPathModuleDataclass, dataclassIdentifier, dataclassInstance)
|
|
79
|
-
|
|
80
|
-
ingredientsFunction = IngredientsFunction(
|
|
81
|
-
FunctionDef = Make.astFunctionDef(name=dataConverterCallable
|
|
82
|
-
, argumentsSpecification=Make.astArgumentsSpecification(args=[Make.astArg(dataclassInstance, astNameDataclass)])
|
|
83
|
-
, body = cast(list[ast.stmt], list_astAnnAssign)
|
|
84
|
-
, returns = astNameDataclass
|
|
85
|
-
)
|
|
86
|
-
, imports = ledgerDataclassAndFragments
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
callToDispatcher = Make.astAssign(listTargets=[astTupleForAssignTargetsToFragments]
|
|
90
|
-
, value=Make.astCall(Make.astName(dispatcherCallable), args=list_astNameDataclassFragments))
|
|
91
|
-
ingredientsFunction.FunctionDef.body.append(callToDispatcher)
|
|
92
|
-
ingredientsFunction.imports.addImportFromStr(logicalPathModuleDispatcher, dispatcherCallable)
|
|
69
|
+
astSubscriptPrimitiveTupleAnnotations4FunctionDef_returns = Make.astSubscript(Make.astName('tuple'), Make.astTuple(listAnnotations))
|
|
93
70
|
|
|
94
|
-
|
|
71
|
+
ledgerDataclassANDFragments.addImportFromStr(logicalPathModule, dataclass_Identifier)
|
|
95
72
|
|
|
96
|
-
|
|
73
|
+
astName_dataclassesDOTdataclass = Make.astName(dataclass_Identifier)
|
|
74
|
+
astTuple4AssignTargetsToFragments: ast.Tuple = Make.astTuple(listNameDataclassFragments4Parameters, ast.Store())
|
|
75
|
+
astAssignDataclassRepack = Make.astAssign(listTargets=[Make.astName(instance_Identifier)], value=Make.astCall(astName_dataclassesDOTdataclass, list_astKeywords=list_keyword4DataclassInitialization))
|
|
76
|
+
return (astName_dataclassesDOTdataclass, ledgerDataclassANDFragments, listAnnAssign4DataclassUnpack,
|
|
77
|
+
astTuple4AssignTargetsToFragments, listNameDataclassFragments4Parameters, list_ast_argAnnotated4ArgumentsSpecification,
|
|
78
|
+
astSubscriptPrimitiveTupleAnnotations4FunctionDef_returns, astAssignDataclassRepack, list_keyword4DataclassInitialization)
|
|
97
79
|
|
|
98
80
|
@overload
|
|
99
81
|
def makeStateJob(listDimensions: Sequence[int], *, writeJob: Literal[True], **keywordArguments: Any) -> Path: ...
|
|
@@ -116,11 +98,11 @@ def makeStateJob(listDimensions: Sequence[int], *, writeJob: bool = True, **keyw
|
|
|
116
98
|
the path to the saved state file if writeJob is True.
|
|
117
99
|
"""
|
|
118
100
|
mapShape = validateListDimensions(listDimensions)
|
|
119
|
-
stateUniversal = outfitCountFolds(mapShape, **keywordArguments)
|
|
101
|
+
stateUniversal: ComputationState = outfitCountFolds(mapShape, **keywordArguments)
|
|
120
102
|
|
|
121
103
|
moduleSource: ModuleType = getSourceAlgorithm()
|
|
122
104
|
# TODO `countInitialize` is hardcoded
|
|
123
|
-
stateUniversal
|
|
105
|
+
stateUniversal = moduleSource.countInitialize(stateUniversal)
|
|
124
106
|
|
|
125
107
|
if not writeJob:
|
|
126
108
|
return stateUniversal
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
from collections.abc import Sequence
|
|
3
3
|
from typing import Any, cast, TYPE_CHECKING
|
|
4
4
|
from mapFolding.filesystem import getFilenameFoldsTotal, getPathFilenameFoldsTotal
|
|
5
|
-
from mapFolding.someAssemblyRequired import ( ifThis, Make, NodeReplacer, Then,
|
|
6
|
-
from mapFolding.
|
|
5
|
+
from mapFolding.someAssemblyRequired import ( ifThis, Make, NodeReplacer, Then, )
|
|
6
|
+
from mapFolding.someAssemblyRequired.transformationTools import LedgerOfImports
|
|
7
|
+
from mapFolding.theSSOT import ( ComputationState, raiseIfNoneGitHubIssueNumber3, getPathJobRootDEFAULT, )
|
|
7
8
|
from os import PathLike
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
from types import ModuleType
|
|
@@ -16,8 +17,8 @@ import inspect
|
|
|
16
17
|
import numpy
|
|
17
18
|
if TYPE_CHECKING:
|
|
18
19
|
from mapFolding.someAssemblyRequired.synthesizeDataConverters import makeStateJob
|
|
19
|
-
from mapFolding.someAssemblyRequired.
|
|
20
|
-
from mapFolding.someAssemblyRequired.
|
|
20
|
+
from mapFolding.someAssemblyRequired.ingredientsNumba import thisIsNumbaDotJit, decorateCallableWithNumba
|
|
21
|
+
from mapFolding.someAssemblyRequired.ingredientsNumba import ParametersNumba, parametersNumbaDEFAULT
|
|
21
22
|
|
|
22
23
|
def Z0Z_gamma(FunctionDefTarget: ast.FunctionDef, astAssignee: ast.Name, statement: ast.Assign | ast.stmt, identifier: str, arrayTarget: numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.integer[Any]]], allImports: LedgerOfImports) -> tuple[ast.FunctionDef, LedgerOfImports]:
|
|
23
24
|
arrayType = type(arrayTarget)
|
|
@@ -53,7 +54,7 @@ def insertArrayIn_body(FunctionDefTarget: ast.FunctionDef, identifier: str, arra
|
|
|
53
54
|
|
|
54
55
|
def findAndReplaceTrackArrayIn_body(FunctionDefTarget: ast.FunctionDef, identifier: str, arrayTarget: numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.integer[Any]]], allImports: LedgerOfImports) -> tuple[ast.FunctionDef, LedgerOfImports]:
|
|
55
56
|
for statement in FunctionDefTarget.body.copy():
|
|
56
|
-
if
|
|
57
|
+
if True:
|
|
57
58
|
indexAsStr: str = ast.unparse(statement.value.slice) # type: ignore
|
|
58
59
|
arraySlice: numpy.ndarray[Any, numpy.dtype[numpy.integer[Any]]] = arrayTarget[eval(indexAsStr)]
|
|
59
60
|
astAssignee: ast.Name = cast(ast.Name, statement.targets[0]) # type: ignore
|
|
@@ -62,10 +63,10 @@ def findAndReplaceTrackArrayIn_body(FunctionDefTarget: ast.FunctionDef, identifi
|
|
|
62
63
|
|
|
63
64
|
def findAndReplaceArraySubscriptIn_body(FunctionDefTarget: ast.FunctionDef, identifier: str, arrayTarget: numpy.ndarray[tuple[int, ...], numpy.dtype[numpy.integer[Any]]], allImports: LedgerOfImports) -> tuple[ast.FunctionDef, LedgerOfImports]:
|
|
64
65
|
# parameter: I define moduleConstructor
|
|
65
|
-
moduleConstructor =
|
|
66
|
+
moduleConstructor = 'numba'
|
|
66
67
|
|
|
67
68
|
for statement in FunctionDefTarget.body.copy():
|
|
68
|
-
if
|
|
69
|
+
if True:
|
|
69
70
|
indexAsStr: str = ast.unparse(statement.value.slice) # type: ignore
|
|
70
71
|
arraySlice: numpy.ndarray[Any, numpy.dtype[numpy.integer[Any]]] = arrayTarget[eval(indexAsStr)]
|
|
71
72
|
astAssignee: ast.Name = cast(ast.Name, statement.targets[0]) # type: ignore
|
|
@@ -83,7 +84,7 @@ def findAndReplaceArraySubscriptIn_body(FunctionDefTarget: ast.FunctionDef, iden
|
|
|
83
84
|
def removeAssignmentFrom_body(FunctionDefTarget: ast.FunctionDef, identifier: str) -> ast.FunctionDef:
|
|
84
85
|
FunctionDefSherpa: ast.AST | Sequence[ast.AST] | None = NodeReplacer(ifThis.isAnyAssignmentTo(identifier), Then.removeThis).visit(FunctionDefTarget)
|
|
85
86
|
if not FunctionDefSherpa:
|
|
86
|
-
raise
|
|
87
|
+
raise raiseIfNoneGitHubIssueNumber3("Dude, where's my function?")
|
|
87
88
|
else:
|
|
88
89
|
FunctionDefTarget = cast(ast.FunctionDef, FunctionDefSherpa)
|
|
89
90
|
ast.fix_missing_locations(FunctionDefTarget)
|
|
@@ -91,7 +92,7 @@ def removeAssignmentFrom_body(FunctionDefTarget: ast.FunctionDef, identifier: st
|
|
|
91
92
|
|
|
92
93
|
def findAndReplaceAnnAssignIn_body(FunctionDefTarget: ast.FunctionDef, allImports: LedgerOfImports) -> tuple[ast.FunctionDef, LedgerOfImports]:
|
|
93
94
|
"""Unlike most of the other functions, this is generic: it tries to turn an annotation into a construction call."""
|
|
94
|
-
moduleConstructor: str =
|
|
95
|
+
moduleConstructor: str = 'numba'
|
|
95
96
|
for stmt in FunctionDefTarget.body.copy():
|
|
96
97
|
if isinstance(stmt, ast.AnnAssign):
|
|
97
98
|
if isinstance(stmt.target, ast.Name) and isinstance(stmt.value, ast.Constant):
|
|
@@ -141,7 +142,7 @@ def insertReturnStatementIn_body(FunctionDefTarget: ast.FunctionDef, arrayTarget
|
|
|
141
142
|
|
|
142
143
|
datatype: str = 'Z0Z_identifierCountFolds'
|
|
143
144
|
FunctionDefTarget.returns = ast.Name(id=datatype, ctx=ast.Load())
|
|
144
|
-
datatypeModuleScalar: str =
|
|
145
|
+
datatypeModuleScalar: str = 'numba'
|
|
145
146
|
allImports.addImportFromStr(datatypeModuleScalar, datatype)
|
|
146
147
|
|
|
147
148
|
FunctionDefTarget.body.append(returnStatement)
|
|
@@ -297,13 +298,13 @@ def writeJobNumba(mapShape: Sequence[int], algorithmSource: ModuleType, callable
|
|
|
297
298
|
|
|
298
299
|
if not callableTarget:
|
|
299
300
|
if len(setFunctionDef) == 1:
|
|
300
|
-
FunctionDefTarget
|
|
301
|
+
FunctionDefTarget = setFunctionDef.pop()
|
|
301
302
|
callableTarget = FunctionDefTarget.name
|
|
302
303
|
else:
|
|
303
304
|
raise ValueError(f"I did not receive a `callableTarget` and {algorithmSource.__name__=} has more than one callable: {setFunctionDef}. Please select one.")
|
|
304
305
|
else:
|
|
305
306
|
listFunctionDefTarget: list[ast.FunctionDef] = [statement for statement in setFunctionDef if statement.name == callableTarget]
|
|
306
|
-
FunctionDefTarget = listFunctionDefTarget[0] if listFunctionDefTarget else None
|
|
307
|
+
FunctionDefTarget = listFunctionDefTarget[0] if listFunctionDefTarget else None # type: ignore
|
|
307
308
|
if not FunctionDefTarget: raise ValueError(f"I received `{callableTarget=}` and {algorithmSource.__name__=}, but I could not find that function in that source.")
|
|
308
309
|
|
|
309
310
|
# NOTE `allImports` is a complementary container to `FunctionDefTarget`; the `FunctionDefTarget` cannot track its own imports very well.
|
|
@@ -323,7 +324,7 @@ def writeJobNumba(mapShape: Sequence[int], algorithmSource: ModuleType, callable
|
|
|
323
324
|
FunctionDefTarget.args.args.remove(pirateScowl)
|
|
324
325
|
|
|
325
326
|
identifierCounter = 'Z0Z_identifierCountFolds'
|
|
326
|
-
astExprIncrementCounter = ast.Expr(value = Make.astCall(Make.nameDOTname(identifierCounter, 'update'),
|
|
327
|
+
astExprIncrementCounter = ast.Expr(value = Make.astCall(Make.nameDOTname(identifierCounter, 'update'), listArguments=[ast.Constant(value=1)], list_astKeywords=[]))
|
|
327
328
|
FunctionDefTarget= cast(ast.FunctionDef, NodeReplacer(ifThis.isAugAssignTo(identifierCounter), Then.replaceWith(astExprIncrementCounter)).visit(FunctionDefTarget))
|
|
328
329
|
ast.fix_missing_locations(FunctionDefTarget)
|
|
329
330
|
|
|
@@ -344,7 +345,7 @@ def writeJobNumba(mapShape: Sequence[int], algorithmSource: ModuleType, callable
|
|
|
344
345
|
|
|
345
346
|
# TODO create function for assigning value to `totalEstimated`
|
|
346
347
|
totalEstimated: int = Z0Z_totalEstimated
|
|
347
|
-
astLauncher
|
|
348
|
+
astLauncher = makeLauncherTqdmJobNumba(FunctionDefTarget.name, pathFilenameFoldsTotal, totalEstimated, stateJob.foldGroups[-1])
|
|
348
349
|
|
|
349
350
|
allImports.addImportFromStr('numba_progress', 'ProgressBar')
|
|
350
351
|
allImports.addImportFromStr('numba_progress', 'ProgressBarType')
|
|
@@ -361,10 +362,9 @@ def writeJobNumba(mapShape: Sequence[int], algorithmSource: ModuleType, callable
|
|
|
361
362
|
|
|
362
363
|
FunctionDefTarget, allImports = findAndReplaceAnnAssignIn_body(FunctionDefTarget, allImports)
|
|
363
364
|
# NOTE add the perfect decorator
|
|
364
|
-
FunctionDefTarget, allImports = decorateCallableWithNumba(FunctionDefTarget, allImports, parametersNumba)
|
|
365
365
|
if thisIsNumbaDotJit(FunctionDefTarget.decorator_list[0]):
|
|
366
366
|
astCall: ast.Call = cast(ast.Call, FunctionDefTarget.decorator_list[0])
|
|
367
|
-
astCall.func = ast.Name(id=
|
|
367
|
+
astCall.func = ast.Name(id='jit', ctx=ast.Load())
|
|
368
368
|
FunctionDefTarget.decorator_list[0] = astCall
|
|
369
369
|
|
|
370
370
|
# NOTE add imports, make str, remove unused imports
|
|
@@ -400,8 +400,8 @@ if __name__ == '__main__':
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
totalEstimated: int = dictionaryEstimates.get(tuple(mapShape), 10**8)
|
|
403
|
-
from mapFolding.syntheticModules import
|
|
404
|
-
algorithmSource: ModuleType =
|
|
403
|
+
from mapFolding.syntheticModules import numbaCount_doTheNeedful
|
|
404
|
+
algorithmSource: ModuleType = numbaCount_doTheNeedful
|
|
405
405
|
|
|
406
406
|
callableTarget = 'countSequential'
|
|
407
407
|
|
|
@@ -411,7 +411,4 @@ if __name__ == '__main__':
|
|
|
411
411
|
|
|
412
412
|
pathFilenameWriteJob = None
|
|
413
413
|
|
|
414
|
-
Z0Z_setDatatypeModuleScalar('numba')
|
|
415
|
-
Z0Z_setDecoratorCallable('jit')
|
|
416
|
-
|
|
417
414
|
writeJobNumba(mapShape, algorithmSource, callableTarget, parametersNumba, pathFilenameWriteJob, Z0Z_totalEstimated=totalEstimated)
|