mapFolding 0.3.2__py3-none-any.whl → 0.3.3__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-0.3.2.dist-info → mapFolding-0.3.3.dist-info}/METADATA +2 -2
- mapFolding-0.3.3.dist-info/RECORD +25 -0
- {mapFolding-0.3.2.dist-info → mapFolding-0.3.3.dist-info}/top_level.txt +1 -0
- someAssemblyRequired/__init__.py +2 -3
- someAssemblyRequired/generalizeSourceCode.py +121 -0
- someAssemblyRequired/makeJob.py +19 -0
- someAssemblyRequired/synthesizeJob.py +35 -35
- someAssemblyRequired/synthesizeModules.py +12 -121
- syntheticModules/__init__.py +3 -0
- {someAssemblyRequired → syntheticModules}/countInitialize.py +0 -1
- {someAssemblyRequired → syntheticModules}/countParallel.py +0 -1
- {someAssemblyRequired → syntheticModules}/countSequential.py +0 -1
- mapFolding-0.3.2.dist-info/RECORD +0 -22
- {mapFolding-0.3.2.dist-info → mapFolding-0.3.3.dist-info}/WHEEL +0 -0
- {mapFolding-0.3.2.dist-info → mapFolding-0.3.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Count distinct ways to fold a map (or a strip of stamps)
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License: CC-BY-NC-4.0
|
|
@@ -52,7 +52,7 @@ The directory [mapFolding/reference](https://github.com/hunterhogan/mapFolding/b
|
|
|
52
52
|
- [hunterNumba.py](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/reference), a one-size-fits-all, self-contained, reasonably fast, contemporary algorithm that is nevertheless infected by _noobaceae ignorancium_, and
|
|
53
53
|
- miscellaneous notes.
|
|
54
54
|
|
|
55
|
-
[](https://pypi.org/project/mapFolding/) [](https://pypi.org/project/mapFolding/) [](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml) [](https://youtu.be/g6f_miE91mk&t=4)   
|
|
56
56
|
|
|
57
57
|
## Simple, easy usage based on OEIS IDs
|
|
58
58
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
benchmarks/benchmarking.py,sha256=HD_0NSvuabblg94ftDre6LFnXShTe8MYj3hIodW-zV0,3076
|
|
2
|
+
reference/flattened.py,sha256=6blZ2Y9G8mu1F3gV8SKndPE398t2VVFlsgKlyeJ765A,16538
|
|
3
|
+
reference/hunterNumba.py,sha256=HWndRgsajOf76rbb2LDNEZ6itsdYbyV-k3wgOFjeR6c,7104
|
|
4
|
+
reference/irvineJavaPort.py,sha256=Sj-63Z-OsGuDoEBXuxyjRrNmmyl0d7Yz_XuY7I47Oyg,4250
|
|
5
|
+
reference/jax.py,sha256=rojyK80lOATtbzxjGOHWHZngQa47CXCLJHZwIdN2MwI,14955
|
|
6
|
+
reference/lunnan.py,sha256=XEcql_gxvCCghb6Or3qwmPbn4IZUbZTaSmw_fUjRxZE,5037
|
|
7
|
+
reference/lunnanNumpy.py,sha256=HqDgSwTOZA-G0oophOEfc4zs25Mv4yw2aoF1v8miOLk,4653
|
|
8
|
+
reference/lunnanWhile.py,sha256=7NY2IKO5XBgol0aWWF_Fi-7oTL9pvu_z6lB0TF1uVHk,4063
|
|
9
|
+
reference/rotatedEntryPoint.py,sha256=z0QyDQtnMvXNj5ntWzzJUQUMFm1-xHGLVhtYzwmczUI,11530
|
|
10
|
+
reference/total_countPlus1vsPlusN.py,sha256=usenM8Yn_G1dqlPl7NKKkcnbohBZVZBXTQRm2S3_EDA,8106
|
|
11
|
+
someAssemblyRequired/__init__.py,sha256=iZpBslk8OnCmaUoqAivva7Hl7GJYrjwRV_owcBbgfcM,87
|
|
12
|
+
someAssemblyRequired/generalizeSourceCode.py,sha256=6LsUe-5uqGXcrtXWrP70BrUgnjkJKrQo8y1KyFZdb-k,6024
|
|
13
|
+
someAssemblyRequired/getLLVMforNoReason.py,sha256=FtJzw2pZS3A4NimWdZsegXaU-vKeCw8m67kcfb5wvGM,894
|
|
14
|
+
someAssemblyRequired/makeJob.py,sha256=W85W7vWsNsu9mBsgU3Cx-FPYIdLLnyzR4GwdcYsWZv4,947
|
|
15
|
+
someAssemblyRequired/synthesizeJob.py,sha256=xLak-ZZ1zQ92jBobhJqbnA1Fua9ofiRvLdK1fmD8s_s,7271
|
|
16
|
+
someAssemblyRequired/synthesizeModules.py,sha256=yR9oFsZe3sbgDe2XoS9MbaIqNz-hOq6qOFzHMhPn4rc,3737
|
|
17
|
+
syntheticModules/__init__.py,sha256=nDtS5UFMKN-F5pTp0qKA0J0I-XR3n3OFxV2bosieBu8,131
|
|
18
|
+
syntheticModules/countInitialize.py,sha256=rRn1gtR1PWxpQ8Mw-_QRZT7ujRP_1H04QizJE9RlZ7o,1839
|
|
19
|
+
syntheticModules/countParallel.py,sha256=aZQvSEeWeJ-47eyMyIisq1baAAl-H6W0RYIlVPv_D_U,2559
|
|
20
|
+
syntheticModules/countSequential.py,sha256=Uf1Zd-r3wsmVoHOWyNOQQiFO6k6xmFG6Oo3dqwAqBQo,3216
|
|
21
|
+
mapFolding-0.3.3.dist-info/METADATA,sha256=SfukFXyZtDIdmQ4Gzgl8ePyov_factyZ4Te7LSh0UYc,7530
|
|
22
|
+
mapFolding-0.3.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
23
|
+
mapFolding-0.3.3.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
24
|
+
mapFolding-0.3.3.dist-info/top_level.txt,sha256=tZHrMCdFq5ghJY_MAv_GhcpmQecelcIcoxgzLnF1-V4,59
|
|
25
|
+
mapFolding-0.3.3.dist-info/RECORD,,
|
someAssemblyRequired/__init__.py
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
from .
|
|
2
|
-
from .
|
|
3
|
-
from .countInitialize import countInitialize
|
|
1
|
+
from .makeJob import makeStateJob
|
|
2
|
+
from .generalizeSourceCode import makeInlineFunction
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT
|
|
2
|
+
import ast
|
|
3
|
+
|
|
4
|
+
class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
5
|
+
"""Process AST nodes to inline functions and substitute enum values.
|
|
6
|
+
Also handles function decorators during inlining."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, dictionaryFunctions, dictionaryEnumValues):
|
|
9
|
+
self.dictionaryFunctions = dictionaryFunctions
|
|
10
|
+
self.dictionaryEnumValues = dictionaryEnumValues
|
|
11
|
+
self.processed = set()
|
|
12
|
+
|
|
13
|
+
def inlineFunctionBody(self, functionName):
|
|
14
|
+
if functionName in self.processed:
|
|
15
|
+
return None
|
|
16
|
+
|
|
17
|
+
self.processed.add(functionName)
|
|
18
|
+
inlineDefinition = self.dictionaryFunctions[functionName]
|
|
19
|
+
# Recursively process the function body
|
|
20
|
+
for node in ast.walk(inlineDefinition):
|
|
21
|
+
self.visit(node)
|
|
22
|
+
return inlineDefinition
|
|
23
|
+
|
|
24
|
+
def visit_Attribute(self, node):
|
|
25
|
+
# Substitute enum identifiers (e.g., indexMy.leaf1ndex.value)
|
|
26
|
+
if isinstance(node.value, ast.Attribute) and isinstance(node.value.value, ast.Name):
|
|
27
|
+
enumPath = f"{node.value.value.id}.{node.value.attr}.{node.attr}"
|
|
28
|
+
if enumPath in self.dictionaryEnumValues:
|
|
29
|
+
return ast.Constant(value=self.dictionaryEnumValues[enumPath])
|
|
30
|
+
return self.generic_visit(node)
|
|
31
|
+
|
|
32
|
+
def visit_Call(self, node):
|
|
33
|
+
callNode = self.generic_visit(node)
|
|
34
|
+
if isinstance(callNode, ast.Call) and isinstance(callNode.func, ast.Name) and callNode.func.id in self.dictionaryFunctions:
|
|
35
|
+
inlineDefinition = self.inlineFunctionBody(callNode.func.id)
|
|
36
|
+
if (inlineDefinition and inlineDefinition.body):
|
|
37
|
+
lastStmt = inlineDefinition.body[-1]
|
|
38
|
+
if isinstance(lastStmt, ast.Return) and lastStmt.value is not None:
|
|
39
|
+
return self.visit(lastStmt.value)
|
|
40
|
+
elif isinstance(lastStmt, ast.Expr) and lastStmt.value is not None:
|
|
41
|
+
return self.visit(lastStmt.value)
|
|
42
|
+
return None
|
|
43
|
+
return callNode
|
|
44
|
+
|
|
45
|
+
def visit_Expr(self, node):
|
|
46
|
+
if isinstance(node.value, ast.Call):
|
|
47
|
+
if isinstance(node.value.func, ast.Name) and node.value.func.id in self.dictionaryFunctions:
|
|
48
|
+
inlineDefinition = self.inlineFunctionBody(node.value.func.id)
|
|
49
|
+
if inlineDefinition:
|
|
50
|
+
return [self.visit(stmt) for stmt in inlineDefinition.body]
|
|
51
|
+
return self.generic_visit(node)
|
|
52
|
+
|
|
53
|
+
def findRequiredImports(node):
|
|
54
|
+
"""Find all modules that need to be imported based on AST analysis.
|
|
55
|
+
NOTE: due to hardcoding, this is a glorified regex. No, wait, this is less versatile than regex."""
|
|
56
|
+
requiredImports = set()
|
|
57
|
+
|
|
58
|
+
class ImportFinder(ast.NodeVisitor):
|
|
59
|
+
def visit_Name(self, node):
|
|
60
|
+
if node.id in {'numba'}:
|
|
61
|
+
requiredImports.add(node.id)
|
|
62
|
+
self.generic_visit(node)
|
|
63
|
+
|
|
64
|
+
def visitDecorator(self, node):
|
|
65
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
66
|
+
if node.func.id == 'jit':
|
|
67
|
+
requiredImports.add('numba')
|
|
68
|
+
self.generic_visit(node)
|
|
69
|
+
|
|
70
|
+
ImportFinder().visit(node)
|
|
71
|
+
return requiredImports
|
|
72
|
+
|
|
73
|
+
def generateImports(requiredImports):
|
|
74
|
+
"""Generate import statements based on required modules."""
|
|
75
|
+
importStatements = {'import numba', 'from mapFolding import indexMy, indexTrack'}
|
|
76
|
+
|
|
77
|
+
importMapping = {
|
|
78
|
+
'numba': 'import numba',
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for moduleName in sorted(requiredImports):
|
|
82
|
+
if moduleName in importMapping:
|
|
83
|
+
importStatements.add(importMapping[moduleName])
|
|
84
|
+
|
|
85
|
+
return '\n'.join(importStatements)
|
|
86
|
+
|
|
87
|
+
def makeInlineFunction(sourceCode, targetFunctionName, dictionaryEnumValues, skipEnum=False, **keywordArguments):
|
|
88
|
+
datatypeLarge = keywordArguments.get('datatypeLarge', datatypeLargeDEFAULT)
|
|
89
|
+
datatypeMedium = keywordArguments.get('datatypeMedium', datatypeMediumDEFAULT)
|
|
90
|
+
datatypeSmall = keywordArguments.get('datatypeSmall', datatypeSmallDEFAULT)
|
|
91
|
+
if skipEnum:
|
|
92
|
+
dictionaryEnumValues = {}
|
|
93
|
+
dictionaryParsed = ast.parse(sourceCode)
|
|
94
|
+
dictionaryFunctions = {
|
|
95
|
+
element.name: element
|
|
96
|
+
for element in dictionaryParsed.body
|
|
97
|
+
if isinstance(element, ast.FunctionDef)
|
|
98
|
+
}
|
|
99
|
+
nodeTarget = dictionaryFunctions[targetFunctionName]
|
|
100
|
+
nodeInliner = RecursiveInlinerWithEnum(dictionaryFunctions, dictionaryEnumValues)
|
|
101
|
+
nodeInlined = nodeInliner.visit(nodeTarget)
|
|
102
|
+
ast.fix_missing_locations(nodeInlined)
|
|
103
|
+
callableInlinedDecorators = [decorator for decorator in nodeInlined.decorator_list]
|
|
104
|
+
|
|
105
|
+
requiredImports = findRequiredImports(nodeInlined)
|
|
106
|
+
importStatements = generateImports(requiredImports)
|
|
107
|
+
importsRequired = importStatements
|
|
108
|
+
dictionaryDecoratorsNumba={
|
|
109
|
+
'countInitialize':
|
|
110
|
+
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
111
|
+
'countParallel':
|
|
112
|
+
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeLarge}[::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=True, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
113
|
+
'countSequential':
|
|
114
|
+
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeLarge}[::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
lineNumbaDecorator = dictionaryDecoratorsNumba[targetFunctionName]
|
|
118
|
+
|
|
119
|
+
# inlinedCode = ast.unparse(ast.Module(body=[nodeInlined], type_ignores=[]))
|
|
120
|
+
callableInlined = lineNumbaDecorator + ast.unparse(nodeInlined)
|
|
121
|
+
return (callableInlined, callableInlinedDecorators, importsRequired)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from mapFolding import getPathFilenameFoldsTotal
|
|
2
|
+
from mapFolding import outfitCountFolds
|
|
3
|
+
from typing import Any, Optional, Sequence, Type
|
|
4
|
+
import pathlib
|
|
5
|
+
import pickle
|
|
6
|
+
|
|
7
|
+
def makeStateJob(listDimensions: Sequence[int], **keywordArguments: Optional[Type[Any]]) -> pathlib.Path:
|
|
8
|
+
from syntheticModules import countInitialize
|
|
9
|
+
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
10
|
+
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
11
|
+
|
|
12
|
+
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
13
|
+
suffix = pathFilenameChopChop.suffix
|
|
14
|
+
pathJob = pathlib.Path(str(pathFilenameChopChop)[0:-len(suffix)])
|
|
15
|
+
pathJob.mkdir(parents=True, exist_ok=True)
|
|
16
|
+
pathFilenameJob = pathJob / 'stateJob.pkl'
|
|
17
|
+
|
|
18
|
+
pathFilenameJob.write_bytes(pickle.dumps(stateUniversal))
|
|
19
|
+
return pathFilenameJob
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
from mapFolding import getPathFilenameFoldsTotal
|
|
2
|
-
from mapFolding import make_dtype,
|
|
3
|
-
from mapFolding import
|
|
4
|
-
from someAssemblyRequired import
|
|
5
|
-
from typing import
|
|
1
|
+
from mapFolding import getPathFilenameFoldsTotal
|
|
2
|
+
from mapFolding import make_dtype, datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT, datatypeModuleDEFAULT
|
|
3
|
+
from mapFolding import computationState
|
|
4
|
+
from someAssemblyRequired import makeStateJob
|
|
5
|
+
from typing import Optional
|
|
6
6
|
import more_itertools
|
|
7
7
|
import inspect
|
|
8
|
+
import importlib
|
|
9
|
+
import importlib.util
|
|
8
10
|
import numpy
|
|
9
11
|
import pathlib
|
|
10
12
|
import pickle
|
|
@@ -12,20 +14,7 @@ import python_minifier
|
|
|
12
14
|
|
|
13
15
|
identifierCallableLaunch = "goGoGadgetAbsurdity"
|
|
14
16
|
|
|
15
|
-
def
|
|
16
|
-
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
17
|
-
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
18
|
-
|
|
19
|
-
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
20
|
-
suffix = pathFilenameChopChop.suffix
|
|
21
|
-
pathJob = pathlib.Path(str(pathFilenameChopChop)[0:-len(suffix)])
|
|
22
|
-
pathJob.mkdir(parents=True, exist_ok=True)
|
|
23
|
-
pathFilenameJob = pathJob / 'stateJob.pkl'
|
|
24
|
-
|
|
25
|
-
pathFilenameJob.write_bytes(pickle.dumps(stateUniversal))
|
|
26
|
-
return pathFilenameJob
|
|
27
|
-
|
|
28
|
-
def convertNDArrayToStr(arrayTarget: numpy.ndarray, identifierName: str) -> str:
|
|
17
|
+
def makeStrRLEcompacted(arrayTarget: numpy.ndarray, identifierName: str) -> str:
|
|
29
18
|
def process_nested_array(arraySlice):
|
|
30
19
|
if isinstance(arraySlice, numpy.ndarray) and arraySlice.ndim > 1:
|
|
31
20
|
return [process_nested_array(arraySlice[index]) for index in range(arraySlice.shape[0])]
|
|
@@ -54,22 +43,25 @@ def convertNDArrayToStr(arrayTarget: numpy.ndarray, identifierName: str) -> str:
|
|
|
54
43
|
return f"{identifierName} = numpy.array({stringMinimized}, dtype=numpy.{arrayTarget.dtype})"
|
|
55
44
|
|
|
56
45
|
def writeModuleWithNumba(listDimensions, **keywordArguments: Optional[str]) -> pathlib.Path:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
datatypeLarge = keywordArguments.get('datatypeLarge', datatypeLargeDEFAULT)
|
|
47
|
+
datatypeMedium = keywordArguments.get('datatypeMedium', datatypeMediumDEFAULT)
|
|
48
|
+
datatypeSmall = keywordArguments.get('datatypeSmall', datatypeSmallDEFAULT)
|
|
49
|
+
datatypeModule = keywordArguments.get('datatypeModule', datatypeModuleDEFAULT)
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
dtypeLarge = make_dtype(datatypeLarge, datatypeModule) # type: ignore
|
|
52
|
+
dtypeMedium = make_dtype(datatypeMedium, datatypeModule) # type: ignore
|
|
53
|
+
dtypeSmall = make_dtype(datatypeSmall, datatypeModule) # type: ignore
|
|
64
54
|
|
|
65
|
-
pathFilenameJob = makeStateJob(listDimensions, dtypeLarge =
|
|
55
|
+
pathFilenameJob = makeStateJob(listDimensions, dtypeLarge = dtypeLarge, dtypeMedium = dtypeMedium, dtypeSmall = dtypeSmall)
|
|
66
56
|
stateJob: computationState = pickle.loads(pathFilenameJob.read_bytes())
|
|
67
57
|
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(stateJob['mapShape'], pathFilenameJob.parent)
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
from syntheticModules import countSequential
|
|
60
|
+
algorithmSource = countSequential
|
|
61
|
+
codeSource = inspect.getsource(algorithmSource)
|
|
70
62
|
|
|
71
63
|
# forceinline=True might actually be useful
|
|
72
|
-
parametersNumba = f"numba.types.{
|
|
64
|
+
parametersNumba = f"numba.types.{datatypeLarge}(), \
|
|
73
65
|
cache=True, \
|
|
74
66
|
nopython=True, \
|
|
75
67
|
fastmath=True, \
|
|
@@ -96,14 +88,14 @@ no_cpython_wrapper=False, \
|
|
|
96
88
|
ImaIndent = ' '
|
|
97
89
|
linesDataDynamic = """"""
|
|
98
90
|
linesDataDynamic = "\n".join([linesDataDynamic
|
|
99
|
-
, ImaIndent + f"foldsTotal = numba.types.{
|
|
100
|
-
, ImaIndent +
|
|
101
|
-
, ImaIndent +
|
|
91
|
+
, ImaIndent + f"foldsTotal = numba.types.{datatypeLarge}(0)"
|
|
92
|
+
, ImaIndent + makeStrRLEcompacted(stateJob['foldGroups'], 'foldGroups')
|
|
93
|
+
, ImaIndent + makeStrRLEcompacted(stateJob['gapsWhere'], 'gapsWhere')
|
|
102
94
|
])
|
|
103
95
|
|
|
104
96
|
linesDataStatic = """"""
|
|
105
97
|
linesDataStatic = "\n".join([linesDataStatic
|
|
106
|
-
, ImaIndent +
|
|
98
|
+
, ImaIndent + makeStrRLEcompacted(stateJob['connectionGraph'], 'connectionGraph')
|
|
107
99
|
])
|
|
108
100
|
|
|
109
101
|
my = stateJob['my']
|
|
@@ -127,7 +119,7 @@ no_cpython_wrapper=False, \
|
|
|
127
119
|
elif 'track[indexTrack.' in lineSource:
|
|
128
120
|
# leafAbove = track[indexTrack.leafAbove.value]
|
|
129
121
|
identifier, statement = lineSource.split('=')
|
|
130
|
-
lineSource = ImaIndent +
|
|
122
|
+
lineSource = ImaIndent + makeStrRLEcompacted(eval(statement.strip()), identifier.strip())
|
|
131
123
|
|
|
132
124
|
linesAlgorithm = "\n".join([linesAlgorithm
|
|
133
125
|
, lineSource
|
|
@@ -163,8 +155,16 @@ if __name__ == '__main__':
|
|
|
163
155
|
return pathFilenameDestination
|
|
164
156
|
|
|
165
157
|
if __name__ == '__main__':
|
|
166
|
-
listDimensions = [
|
|
158
|
+
listDimensions = [6,6]
|
|
167
159
|
datatypeLarge = 'int64'
|
|
168
160
|
datatypeMedium = 'uint8'
|
|
169
161
|
datatypeSmall = datatypeMedium
|
|
170
|
-
writeModuleWithNumba(listDimensions, datatypeLarge=datatypeLarge, datatypeMedium=datatypeMedium, datatypeSmall=datatypeSmall)
|
|
162
|
+
pathFilenameModule = writeModuleWithNumba(listDimensions, datatypeLarge=datatypeLarge, datatypeMedium=datatypeMedium, datatypeSmall=datatypeSmall)
|
|
163
|
+
# Induce numba.jit compilation
|
|
164
|
+
moduleSpec = importlib.util.spec_from_file_location(pathFilenameModule.stem, pathFilenameModule)
|
|
165
|
+
if moduleSpec is None:
|
|
166
|
+
raise ImportError(f"Could not load module specification from {pathFilenameModule}")
|
|
167
|
+
module = importlib.util.module_from_spec(moduleSpec)
|
|
168
|
+
if moduleSpec.loader is None:
|
|
169
|
+
raise ImportError(f"Could not load module from {moduleSpec}")
|
|
170
|
+
moduleSpec.loader.exec_module(module)
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
from mapFolding import indexMy, indexTrack,
|
|
2
|
-
import
|
|
1
|
+
from mapFolding import indexMy, indexTrack, getAlgorithmSource
|
|
2
|
+
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT
|
|
3
|
+
from someAssemblyRequired import makeInlineFunction
|
|
3
4
|
import pathlib
|
|
4
5
|
import inspect
|
|
5
6
|
|
|
6
|
-
algorithmSource =
|
|
7
|
-
|
|
8
|
-
dictionaryDecorators={
|
|
9
|
-
'countInitialize':
|
|
10
|
-
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
11
|
-
'countParallel':
|
|
12
|
-
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeLarge}[::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=True, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
13
|
-
'countSequential':
|
|
14
|
-
f'@numba.jit((numba.{datatypeSmall}[:,:,::1], numba.{datatypeLarge}[::1], numba.{datatypeMedium}[::1], numba.{datatypeSmall}[::1], numba.{datatypeMedium}[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)\n',
|
|
15
|
-
}
|
|
7
|
+
algorithmSource = getAlgorithmSource()
|
|
16
8
|
|
|
17
9
|
def getDictionaryEnumValues():
|
|
18
10
|
dictionaryEnumValues = {}
|
|
@@ -21,110 +13,6 @@ def getDictionaryEnumValues():
|
|
|
21
13
|
dictionaryEnumValues[f"{enumIndex.__name__}.{memberName}.value"] = memberValue.value
|
|
22
14
|
return dictionaryEnumValues
|
|
23
15
|
|
|
24
|
-
class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
25
|
-
"""Process AST nodes to inline functions and substitute enum values.
|
|
26
|
-
Also handles function decorators during inlining."""
|
|
27
|
-
|
|
28
|
-
def __init__(self, dictionaryFunctions, dictionaryEnumValues):
|
|
29
|
-
self.dictionaryFunctions = dictionaryFunctions
|
|
30
|
-
self.dictionaryEnumValues = dictionaryEnumValues
|
|
31
|
-
self.processed = set()
|
|
32
|
-
|
|
33
|
-
def inlineFunctionBody(self, functionName):
|
|
34
|
-
if functionName in self.processed:
|
|
35
|
-
return None
|
|
36
|
-
|
|
37
|
-
self.processed.add(functionName)
|
|
38
|
-
inlineDefinition = self.dictionaryFunctions[functionName]
|
|
39
|
-
# Recursively process the function body
|
|
40
|
-
for node in ast.walk(inlineDefinition):
|
|
41
|
-
self.visit(node)
|
|
42
|
-
return inlineDefinition
|
|
43
|
-
|
|
44
|
-
def visit_Attribute(self, node):
|
|
45
|
-
# Substitute enum identifiers (e.g., indexMy.leaf1ndex.value)
|
|
46
|
-
if isinstance(node.value, ast.Attribute) and isinstance(node.value.value, ast.Name):
|
|
47
|
-
enumPath = f"{node.value.value.id}.{node.value.attr}.{node.attr}"
|
|
48
|
-
if enumPath in self.dictionaryEnumValues:
|
|
49
|
-
return ast.Constant(value=self.dictionaryEnumValues[enumPath])
|
|
50
|
-
return self.generic_visit(node)
|
|
51
|
-
|
|
52
|
-
def visit_Call(self, node):
|
|
53
|
-
callNode = self.generic_visit(node)
|
|
54
|
-
if isinstance(callNode, ast.Call) and isinstance(callNode.func, ast.Name) and callNode.func.id in self.dictionaryFunctions:
|
|
55
|
-
inlineDefinition = self.inlineFunctionBody(callNode.func.id)
|
|
56
|
-
if (inlineDefinition and inlineDefinition.body):
|
|
57
|
-
lastStmt = inlineDefinition.body[-1]
|
|
58
|
-
if isinstance(lastStmt, ast.Return) and lastStmt.value is not None:
|
|
59
|
-
return self.visit(lastStmt.value)
|
|
60
|
-
elif isinstance(lastStmt, ast.Expr) and lastStmt.value is not None:
|
|
61
|
-
return self.visit(lastStmt.value)
|
|
62
|
-
return None
|
|
63
|
-
return callNode
|
|
64
|
-
|
|
65
|
-
def visit_Expr(self, node):
|
|
66
|
-
if isinstance(node.value, ast.Call):
|
|
67
|
-
if isinstance(node.value.func, ast.Name) and node.value.func.id in self.dictionaryFunctions:
|
|
68
|
-
inlineDefinition = self.inlineFunctionBody(node.value.func.id)
|
|
69
|
-
if inlineDefinition:
|
|
70
|
-
return [self.visit(stmt) for stmt in inlineDefinition.body]
|
|
71
|
-
return self.generic_visit(node)
|
|
72
|
-
|
|
73
|
-
def findRequiredImports(node):
|
|
74
|
-
"""Find all modules that need to be imported based on AST analysis.
|
|
75
|
-
NOTE: due to hardcoding, this is a glorified regex. No, wait, this is less versatile than regex."""
|
|
76
|
-
requiredImports = set()
|
|
77
|
-
|
|
78
|
-
class ImportFinder(ast.NodeVisitor):
|
|
79
|
-
def visit_Name(self, node):
|
|
80
|
-
if node.id in {'numba'}:
|
|
81
|
-
requiredImports.add(node.id)
|
|
82
|
-
self.generic_visit(node)
|
|
83
|
-
|
|
84
|
-
def visitDecorator(self, node):
|
|
85
|
-
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
86
|
-
if node.func.id == 'jit':
|
|
87
|
-
requiredImports.add('numba')
|
|
88
|
-
self.generic_visit(node)
|
|
89
|
-
|
|
90
|
-
ImportFinder().visit(node)
|
|
91
|
-
return requiredImports
|
|
92
|
-
|
|
93
|
-
def generateImports(requiredImports):
|
|
94
|
-
"""Generate import statements based on required modules."""
|
|
95
|
-
importStatements = {'import numba', 'from mapFolding import indexMy, indexTrack'}
|
|
96
|
-
|
|
97
|
-
importMapping = {
|
|
98
|
-
'numba': 'import numba',
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for moduleName in sorted(requiredImports):
|
|
102
|
-
if moduleName in importMapping:
|
|
103
|
-
importStatements.add(importMapping[moduleName])
|
|
104
|
-
|
|
105
|
-
return '\n'.join(importStatements)
|
|
106
|
-
|
|
107
|
-
def inlineFunctions(sourceCode, targetFunctionName, dictionaryEnumValues, skipEnum=False):
|
|
108
|
-
if skipEnum:
|
|
109
|
-
dictionaryEnumValues = {}
|
|
110
|
-
dictionaryParsed = ast.parse(sourceCode)
|
|
111
|
-
dictionaryFunctions = {
|
|
112
|
-
element.name: element
|
|
113
|
-
for element in dictionaryParsed.body
|
|
114
|
-
if isinstance(element, ast.FunctionDef)
|
|
115
|
-
}
|
|
116
|
-
nodeTarget = dictionaryFunctions[targetFunctionName]
|
|
117
|
-
nodeInliner = RecursiveInlinerWithEnum(dictionaryFunctions, dictionaryEnumValues)
|
|
118
|
-
nodeInlined = nodeInliner.visit(nodeTarget)
|
|
119
|
-
ast.fix_missing_locations(nodeInlined)
|
|
120
|
-
|
|
121
|
-
requiredImports = findRequiredImports(nodeInlined)
|
|
122
|
-
importStatements = generateImports(requiredImports)
|
|
123
|
-
|
|
124
|
-
lineNumbaDecorator = dictionaryDecorators[targetFunctionName]
|
|
125
|
-
inlinedCode = importStatements + '\n\n' + lineNumbaDecorator + ast.unparse(ast.Module(body=[nodeInlined], type_ignores=[]))
|
|
126
|
-
return inlinedCode
|
|
127
|
-
|
|
128
16
|
def unpackArrays(codeInlined: str, callableTarget: str) -> str:
|
|
129
17
|
dictionaryReplaceScalars = {
|
|
130
18
|
'my[indexMy.dimensionsTotal.value]': 'dimensionsTotal',
|
|
@@ -166,7 +54,10 @@ def unpackArrays(codeInlined: str, callableTarget: str) -> str:
|
|
|
166
54
|
|
|
167
55
|
return codeInlined
|
|
168
56
|
|
|
169
|
-
def
|
|
57
|
+
def inlineMapFoldingNumba(**keywordArguments):
|
|
58
|
+
datatypeLarge = keywordArguments.get('datatypeLarge', datatypeLargeDEFAULT)
|
|
59
|
+
datatypeMedium = keywordArguments.get('datatypeMedium', datatypeMediumDEFAULT)
|
|
60
|
+
datatypeSmall = keywordArguments.get('datatypeSmall', datatypeSmallDEFAULT)
|
|
170
61
|
dictionaryEnumValues = getDictionaryEnumValues()
|
|
171
62
|
codeSource = inspect.getsource(algorithmSource)
|
|
172
63
|
pathFilenameAlgorithm = pathlib.Path(inspect.getfile(algorithmSource))
|
|
@@ -177,11 +68,11 @@ def Z0Z_inlineMapFolding():
|
|
|
177
68
|
for callableTarget in listCallables:
|
|
178
69
|
skipEnum = (callableTarget == 'countInitialize')
|
|
179
70
|
skipEnum = (callableTarget == 'countSequential')
|
|
180
|
-
pathFilenameDestination = pathFilenameAlgorithm.parent / "
|
|
181
|
-
codeInlined =
|
|
71
|
+
pathFilenameDestination = pathFilenameAlgorithm.parent / "syntheticModules" / pathFilenameAlgorithm.with_stem(callableTarget).name
|
|
72
|
+
codeInlined, callableInlinedDecorators, importsRequired = makeInlineFunction(codeSource, callableTarget, dictionaryEnumValues, skipEnum, datatypeLarge=datatypeLarge, datatypeMedium=datatypeMedium, datatypeSmall=datatypeSmall)
|
|
182
73
|
codeUnpacked = unpackArrays(codeInlined, callableTarget)
|
|
183
|
-
pathFilenameDestination.write_text(codeUnpacked)
|
|
74
|
+
pathFilenameDestination.write_text(importsRequired + "\n" + codeUnpacked)
|
|
184
75
|
listPathFilenamesDestination.append(pathFilenameDestination)
|
|
185
76
|
|
|
186
77
|
if __name__ == '__main__':
|
|
187
|
-
|
|
78
|
+
inlineMapFoldingNumba()
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from mapFolding import indexMy, indexTrack
|
|
2
2
|
import numba
|
|
3
|
-
|
|
4
3
|
@numba.jit((numba.uint8[:,:,::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)
|
|
5
4
|
def countInitialize(connectionGraph, gapsWhere, my, track):
|
|
6
5
|
while my[7] > 0:
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from mapFolding import indexMy, indexTrack
|
|
2
2
|
import numba
|
|
3
|
-
|
|
4
3
|
@numba.jit((numba.uint8[:,:,::1], numba.int64[::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:,::1]), parallel=True, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)
|
|
5
4
|
def countParallel(connectionGraph, foldGroups, gapsWherePARALLEL, myPARALLEL, trackPARALLEL):
|
|
6
5
|
for indexSherpa in numba.prange(myPARALLEL[9]):
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from mapFolding import indexMy, indexTrack
|
|
2
2
|
import numba
|
|
3
|
-
|
|
4
3
|
@numba.jit((numba.uint8[:,:,::1], numba.int64[::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:,::1]), parallel=False, boundscheck=False, cache=True, error_model="numpy", fastmath=True, looplift=False, nogil=True, nopython=True)
|
|
5
4
|
def countSequential(connectionGraph, foldGroups, gapsWhere, my, track):
|
|
6
5
|
doFindGaps = True
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
benchmarks/benchmarking.py,sha256=HD_0NSvuabblg94ftDre6LFnXShTe8MYj3hIodW-zV0,3076
|
|
2
|
-
reference/flattened.py,sha256=6blZ2Y9G8mu1F3gV8SKndPE398t2VVFlsgKlyeJ765A,16538
|
|
3
|
-
reference/hunterNumba.py,sha256=HWndRgsajOf76rbb2LDNEZ6itsdYbyV-k3wgOFjeR6c,7104
|
|
4
|
-
reference/irvineJavaPort.py,sha256=Sj-63Z-OsGuDoEBXuxyjRrNmmyl0d7Yz_XuY7I47Oyg,4250
|
|
5
|
-
reference/jax.py,sha256=rojyK80lOATtbzxjGOHWHZngQa47CXCLJHZwIdN2MwI,14955
|
|
6
|
-
reference/lunnan.py,sha256=XEcql_gxvCCghb6Or3qwmPbn4IZUbZTaSmw_fUjRxZE,5037
|
|
7
|
-
reference/lunnanNumpy.py,sha256=HqDgSwTOZA-G0oophOEfc4zs25Mv4yw2aoF1v8miOLk,4653
|
|
8
|
-
reference/lunnanWhile.py,sha256=7NY2IKO5XBgol0aWWF_Fi-7oTL9pvu_z6lB0TF1uVHk,4063
|
|
9
|
-
reference/rotatedEntryPoint.py,sha256=z0QyDQtnMvXNj5ntWzzJUQUMFm1-xHGLVhtYzwmczUI,11530
|
|
10
|
-
reference/total_countPlus1vsPlusN.py,sha256=usenM8Yn_G1dqlPl7NKKkcnbohBZVZBXTQRm2S3_EDA,8106
|
|
11
|
-
someAssemblyRequired/__init__.py,sha256=nDtS5UFMKN-F5pTp0qKA0J0I-XR3n3OFxV2bosieBu8,131
|
|
12
|
-
someAssemblyRequired/countInitialize.py,sha256=hwo9SW_IvB-bgKNfaGvjl40yayFEmZZmeywiEMDSQDw,1840
|
|
13
|
-
someAssemblyRequired/countParallel.py,sha256=4MfRYLBA2IBxRiXb04voNcxSDAtmZOe7lrji1c3kFls,2560
|
|
14
|
-
someAssemblyRequired/countSequential.py,sha256=8YILeL3rflOhW1ts78ZSgYkPYXMPfusYOPkPtf8Xa3M,3217
|
|
15
|
-
someAssemblyRequired/getLLVMforNoReason.py,sha256=FtJzw2pZS3A4NimWdZsegXaU-vKeCw8m67kcfb5wvGM,894
|
|
16
|
-
someAssemblyRequired/synthesizeJob.py,sha256=xrcEW-QQPKogYh3O0TaRBSZEd8HgMLtXBTeS0Ps_pns,7500
|
|
17
|
-
someAssemblyRequired/synthesizeModules.py,sha256=4mDgzfhm36zIDT8LlcPZzfGfoxRi1Z5rb4rgkAWVtkQ,8625
|
|
18
|
-
mapFolding-0.3.2.dist-info/METADATA,sha256=ejEa_RncO5HszEWrbPK7VdUPEvJaufxfQVVsLm46fdA,7526
|
|
19
|
-
mapFolding-0.3.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
20
|
-
mapFolding-0.3.2.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
21
|
-
mapFolding-0.3.2.dist-info/top_level.txt,sha256=yHhQq-bIJhB4pZcof5hXDTIjan0nxcFuOEWb7gy1DuU,42
|
|
22
|
-
mapFolding-0.3.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|