mapFolding 0.12.2__py3-none-any.whl → 0.13.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/__init__.py +4 -2
- mapFolding/_theSSOT.py +32 -88
- mapFolding/{datatypes.py → _theTypes.py} +25 -3
- mapFolding/basecamp.py +38 -33
- mapFolding/beDRY.py +79 -54
- mapFolding/dataBaskets.py +123 -93
- mapFolding/filesystemToolkit.py +140 -91
- mapFolding/oeis.py +243 -145
- mapFolding/reference/flattened.py +1 -1
- mapFolding/someAssemblyRequired/RecipeJob.py +116 -100
- mapFolding/someAssemblyRequired/__init__.py +40 -15
- mapFolding/someAssemblyRequired/_toolIfThis.py +82 -54
- mapFolding/someAssemblyRequired/_toolkitContainers.py +19 -16
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +35 -26
- mapFolding/someAssemblyRequired/makeAllModules.py +353 -283
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +83 -84
- mapFolding/someAssemblyRequired/makeJobTheorem2codon.py +256 -0
- mapFolding/someAssemblyRequired/toolkitNumba.py +80 -50
- mapFolding/someAssemblyRequired/transformationTools.py +63 -40
- {tests → mapFolding/tests}/__init__.py +2 -2
- {tests → mapFolding/tests}/conftest.py +232 -63
- {tests → mapFolding/tests}/test_computations.py +58 -18
- {tests → mapFolding/tests}/test_filesystem.py +10 -13
- {tests → mapFolding/tests}/test_oeis.py +5 -18
- {tests → mapFolding/tests}/test_other.py +9 -9
- {tests → mapFolding/tests}/test_tasks.py +7 -9
- {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/METADATA +24 -37
- mapfolding-0.13.0.dist-info/RECORD +54 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/top_level.txt +0 -1
- mapfolding-0.12.2.dist-info/RECORD +0 -53
- {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/WHEEL +0 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.12.2.dist-info → mapfolding-0.13.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -25,15 +25,12 @@ to low-level optimized functions while maintaining semantic equivalence and type
|
|
|
25
25
|
the compilation process.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
from astToolkit import
|
|
29
|
-
ClassIsAndAttribute, DOT, hasDOTtarget_NameOrAttributeOrSubscript, identifierDotAttribute,
|
|
30
|
-
LedgerOfImports, Make, NodeTourist, Then,
|
|
31
|
-
)
|
|
28
|
+
from astToolkit import Be, DOT, identifierDotAttribute, LedgerOfImports, Make, NodeTourist, Then
|
|
32
29
|
from collections.abc import Callable
|
|
33
30
|
from copy import deepcopy
|
|
31
|
+
from hunterMakesPy import raiseIfNone
|
|
34
32
|
from mapFolding.someAssemblyRequired import IfThis
|
|
35
33
|
from typing import Any, cast
|
|
36
|
-
from Z0Z_tools import raiseIfNone
|
|
37
34
|
import ast
|
|
38
35
|
import dataclasses
|
|
39
36
|
|
|
@@ -43,8 +40,7 @@ dummyTuple = Make.Tuple([Make.Name("dummyElement")])
|
|
|
43
40
|
|
|
44
41
|
@dataclasses.dataclass
|
|
45
42
|
class ShatteredDataclass:
|
|
46
|
-
"""
|
|
47
|
-
Container for decomposed dataclass components organized as AST nodes for code generation.
|
|
43
|
+
"""Container for decomposed dataclass components organized as AST nodes for code generation.
|
|
48
44
|
|
|
49
45
|
This class holds the decomposed representation of a dataclass, breaking it down into individual
|
|
50
46
|
AST components that can be manipulated and recombined for different code generation contexts.
|
|
@@ -59,6 +55,7 @@ class ShatteredDataclass:
|
|
|
59
55
|
dataclass fields into individual parameters) and result reconstruction (packing individual
|
|
60
56
|
values back into dataclass instances).
|
|
61
57
|
"""
|
|
58
|
+
|
|
62
59
|
countingVariableAnnotation: ast.expr
|
|
63
60
|
"""Type annotation for the counting variable extracted from the dataclass."""
|
|
64
61
|
|
|
@@ -194,11 +191,16 @@ class DeReConstructField2ast:
|
|
|
194
191
|
scalar types, and complex type annotations, creating appropriate constructor
|
|
195
192
|
calls and import requirements.
|
|
196
193
|
|
|
197
|
-
Parameters
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
194
|
+
Parameters
|
|
195
|
+
----------
|
|
196
|
+
dataclassesDOTdataclassLogicalPathModule : identifierDotAttribute
|
|
197
|
+
Module path containing the dataclass
|
|
198
|
+
dataclassClassDef : ast.ClassDef
|
|
199
|
+
AST class definition for type annotation extraction
|
|
200
|
+
dataclassesDOTdataclassInstanceIdentifier : str
|
|
201
|
+
Instance variable name for attribute access
|
|
202
|
+
field : dataclasses.Field[Any]
|
|
203
|
+
Dataclass field to transform
|
|
202
204
|
"""
|
|
203
205
|
self.compare = field.compare
|
|
204
206
|
self.default = field.default if field.default is not dataclasses.MISSING else None
|
|
@@ -215,9 +217,10 @@ class DeReConstructField2ast:
|
|
|
215
217
|
self.ast_keyword_field__field = Make.keyword(self.name, self.astName)
|
|
216
218
|
self.ast_nameDOTname = Make.Attribute(Make.Name(dataclassesDOTdataclassInstanceIdentifier), self.name)
|
|
217
219
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
self.astAnnotation = raiseIfNone(NodeTourist[ast.AnnAssign, ast.Name | None](
|
|
221
|
+
findThis = Be.AnnAssign.targetIs(IfThis.isNameIdentifier(self.name))
|
|
222
|
+
, doThat = Then.extractIt(cast("Callable[[ast.AnnAssign], ast.Name | None]", DOT.annotation))
|
|
223
|
+
).captureLastMatch(dataclassClassDef))
|
|
221
224
|
|
|
222
225
|
self.ast_argAnnotated = Make.arg(self.name, self.astAnnotation)
|
|
223
226
|
|
|
@@ -228,7 +231,7 @@ class DeReConstructField2ast:
|
|
|
228
231
|
self.ledger.addImportFrom_asStr(moduleWithLogicalPath, annotationType)
|
|
229
232
|
self.ledger.addImportFrom_asStr(moduleWithLogicalPath, 'dtype')
|
|
230
233
|
axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Name('uint8'))
|
|
231
|
-
dtype_asnameName: ast.Name =
|
|
234
|
+
dtype_asnameName: ast.Name = self.astAnnotation
|
|
232
235
|
if dtype_asnameName.id == 'Array3D':
|
|
233
236
|
axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Tuple([Make.Name('uint8'), Make.Name('uint8'), Make.Name('uint8')]))
|
|
234
237
|
ast_expr = Make.Subscript(Make.Name(annotationType), Make.Tuple([axesSubscript, Make.Subscript(Make.Name('dtype'), dtype_asnameName)]))
|
|
@@ -24,34 +24,43 @@ While originally part of a tighter integration with the code generation assembly
|
|
|
24
24
|
this module now operates as a standalone utility that can be applied to any module
|
|
25
25
|
containing Numba-compiled functions.
|
|
26
26
|
"""
|
|
27
|
-
from importlib.machinery import ModuleSpec
|
|
28
27
|
from pathlib import Path
|
|
29
|
-
from
|
|
28
|
+
from typing import TYPE_CHECKING
|
|
30
29
|
import importlib.util
|
|
31
30
|
import llvmlite.binding
|
|
32
31
|
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from importlib.machinery import ModuleSpec
|
|
34
|
+
from types import ModuleType
|
|
35
|
+
|
|
33
36
|
def writeModuleLLVM(pathFilename: Path, identifierCallable: str) -> Path:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
"""Import the generated module directly and get its LLVM IR.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
pathFilename : Path
|
|
42
|
+
Path to the Python module file containing the Numba-compiled function
|
|
43
|
+
identifierCallable : str
|
|
44
|
+
Name of the function within the module to extract LLVM IR from
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
pathFilenameLLVM : Path
|
|
49
|
+
Path to the generated .ll file containing the extracted LLVM IR
|
|
50
|
+
|
|
51
|
+
For an example of the output, see reference/jobsCompleted/[2x19]/[2x19].ll,
|
|
52
|
+
which contains the IR for the historically significant 2x19 map calculation.
|
|
53
|
+
"""
|
|
54
|
+
specTarget: ModuleSpec | None = importlib.util.spec_from_file_location("generatedModule", pathFilename)
|
|
55
|
+
if specTarget is None or specTarget.loader is None:
|
|
56
|
+
message = f"Could not create module spec or loader for {pathFilename}"
|
|
57
|
+
raise ImportError(message)
|
|
58
|
+
moduleTarget: ModuleType = importlib.util.module_from_spec(specTarget)
|
|
59
|
+
specTarget.loader.exec_module(moduleTarget)
|
|
60
|
+
|
|
61
|
+
# Get LLVM IR and write to file
|
|
62
|
+
linesLLVM = moduleTarget.__dict__[identifierCallable].inspect_llvm()[()]
|
|
63
|
+
moduleLLVM: llvmlite.binding.ModuleRef = llvmlite.binding.module.parse_assembly(linesLLVM)
|
|
64
|
+
pathFilenameLLVM: Path = pathFilename.with_suffix(".ll")
|
|
65
|
+
pathFilenameLLVM.write_text(str(moduleLLVM))
|
|
66
|
+
return pathFilenameLLVM
|