mapFolding 0.3.3__tar.gz → 0.3.4__tar.gz
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.3 → mapfolding-0.3.4}/PKG-INFO +3 -1
- mapfolding-0.3.4/mapFolding/citations/updateCitation.py +67 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/PKG-INFO +3 -1
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/SOURCES.txt +2 -1
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/requires.txt +2 -0
- mapfolding-0.3.4/mapFolding/someAssemblyRequired/__init__.py +2 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/someAssemblyRequired/generalizeSourceCode.py +12 -11
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/someAssemblyRequired/makeJob.py +3 -1
- mapfolding-0.3.4/mapFolding/someAssemblyRequired/synthesizeModules.py +170 -0
- mapfolding-0.3.4/mapFolding/syntheticModules/countInitialize.py +47 -0
- mapfolding-0.3.4/mapFolding/syntheticModules/countParallel.py +54 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/syntheticModules/countSequential.py +6 -3
- {mapfolding-0.3.3 → mapfolding-0.3.4}/pyproject.toml +6 -8
- {mapfolding-0.3.3 → mapfolding-0.3.4}/tests/test_oeis.py +23 -23
- {mapfolding-0.3.3 → mapfolding-0.3.4}/tests/test_other.py +20 -16
- {mapfolding-0.3.3 → mapfolding-0.3.4}/tests/test_tasks.py +17 -6
- mapfolding-0.3.3/mapFolding/someAssemblyRequired/__init__.py +0 -2
- mapfolding-0.3.3/mapFolding/someAssemblyRequired/synthesizeModules.py +0 -78
- mapfolding-0.3.3/mapFolding/syntheticModules/countInitialize.py +0 -44
- mapfolding-0.3.3/mapFolding/syntheticModules/countParallel.py +0 -51
- {mapfolding-0.3.3 → mapfolding-0.3.4}/README.md +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/benchmarks/benchmarking.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/flattened.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/jax.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/lunnan.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/lunnanNumpy.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/lunnanWhile.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
- /mapfolding-0.3.3/mapFolding/someAssemblyRequired/synthesizeJob.py → /mapfolding-0.3.4/mapFolding/someAssemblyRequired/synthesizeModuleJob.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/syntheticModules/__init__.py +0 -0
- {mapfolding-0.3.3 → mapfolding-0.3.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
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
|
|
@@ -29,12 +29,14 @@ Requires-Dist: jupyter; extra == "benchmark"
|
|
|
29
29
|
Requires-Dist: pandas; extra == "benchmark"
|
|
30
30
|
Requires-Dist: tqdm; extra == "benchmark"
|
|
31
31
|
Provides-Extra: testing
|
|
32
|
+
Requires-Dist: cffconvert; extra == "testing"
|
|
32
33
|
Requires-Dist: more_itertools; extra == "testing"
|
|
33
34
|
Requires-Dist: pytest; extra == "testing"
|
|
34
35
|
Requires-Dist: pytest-cov; extra == "testing"
|
|
35
36
|
Requires-Dist: pytest-env; extra == "testing"
|
|
36
37
|
Requires-Dist: pytest-xdist; extra == "testing"
|
|
37
38
|
Requires-Dist: python_minifier; extra == "testing"
|
|
39
|
+
Requires-Dist: tomli; extra == "testing"
|
|
38
40
|
|
|
39
41
|
# Algorithm(s) for counting distinct ways to fold a map (or a strip of stamps)
|
|
40
42
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from cffconvert.cli.create_citation import create_citation
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
import cffconvert
|
|
4
|
+
import pathlib
|
|
5
|
+
import tomli
|
|
6
|
+
import inspect
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
Tentative plan:
|
|
11
|
+
- Commit and push to GitHub
|
|
12
|
+
- GitHub Action gathers information from the sources of truth
|
|
13
|
+
- If the citation needs to be updated, write to both
|
|
14
|
+
- pathFilenameCitationSSOT
|
|
15
|
+
- pathFilenameCitationDOTcffRepo
|
|
16
|
+
- Commit and push to GitHub
|
|
17
|
+
- this complicates things
|
|
18
|
+
- I want the updated citation to be in the `commit` field of itself
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
"""cffconvert.Citation fields and the source of truth
|
|
22
|
+
abstract: pathFilenameCitationSSOT
|
|
23
|
+
authors: pathFilenamePackageSSOT
|
|
24
|
+
cff-version: pathFilenameCitationSSOT
|
|
25
|
+
commit: workflows['Make GitHub Release']
|
|
26
|
+
contact: pathFilenamePackageSSOT
|
|
27
|
+
date-released: workflows['Make GitHub Release']
|
|
28
|
+
doi: pathFilenameCitationSSOT
|
|
29
|
+
identifiers: workflows['Make GitHub Release']
|
|
30
|
+
keywords: pathFilenamePackageSSOT
|
|
31
|
+
license: pathFilenamePackageSSOT
|
|
32
|
+
license-url: pathFilenamePackageSSOT
|
|
33
|
+
message: pathFilenameCitationSSOT
|
|
34
|
+
preferred-citation: pathFilenameCitationSSOT
|
|
35
|
+
references: to be determined
|
|
36
|
+
repository: pathFilenamePackageSSOT
|
|
37
|
+
repository-artifact: (https://pypi.org/pypi/{package_name}/json').json()['releases']
|
|
38
|
+
repository-code: workflows['Make GitHub Release']
|
|
39
|
+
title: pathFilenamePackageSSOT
|
|
40
|
+
type: pathFilenameCitationSSOT
|
|
41
|
+
url: pathFilenamePackageSSOT
|
|
42
|
+
version: pathFilenamePackageSSOT
|
|
43
|
+
"""
|
|
44
|
+
# Prefer reliable, dynamic values over hardcoded ones
|
|
45
|
+
packageName: str = 'mapFolding'
|
|
46
|
+
pathRepoRoot = pathlib.Path(__file__).parent.parent.parent
|
|
47
|
+
pathFilenamePackageSSOT = pathRepoRoot / 'pyproject.toml'
|
|
48
|
+
|
|
49
|
+
filenameGitHubAction = 'updateCitation.yml'
|
|
50
|
+
pathFilenameGitHubAction = pathRepoRoot / '.github' / 'workflows' / filenameGitHubAction
|
|
51
|
+
|
|
52
|
+
filenameCitationDOTcff = 'CITATION.cff'
|
|
53
|
+
pathCitations = pathRepoRoot / packageName / 'citations'
|
|
54
|
+
pathFilenameCitationSSOT = pathCitations / filenameCitationDOTcff
|
|
55
|
+
pathFilenameCitationDOTcffRepo = pathRepoRoot / filenameCitationDOTcff
|
|
56
|
+
|
|
57
|
+
tomlPackageData: Dict[str, Any] = tomli.loads(pathFilenamePackageSSOT.read_text())['project']
|
|
58
|
+
|
|
59
|
+
citationObject: cffconvert.Citation = create_citation(infile=pathFilenameCitationSSOT, url=None)
|
|
60
|
+
|
|
61
|
+
path_cffconvert = pathlib.Path(inspect.getfile(cffconvert)).parent
|
|
62
|
+
pathFilenameSchema = path_cffconvert / "schemas/1.2.0/schema.json"
|
|
63
|
+
scheme: Dict[str, Any] = json.loads(pathFilenameSchema.read_text())
|
|
64
|
+
schemaSpecifications: Dict[str, Any] = scheme['properties']
|
|
65
|
+
|
|
66
|
+
for property, subProperties in schemaSpecifications.items():
|
|
67
|
+
print(property, subProperties.get('items', None))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
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
|
|
@@ -29,12 +29,14 @@ Requires-Dist: jupyter; extra == "benchmark"
|
|
|
29
29
|
Requires-Dist: pandas; extra == "benchmark"
|
|
30
30
|
Requires-Dist: tqdm; extra == "benchmark"
|
|
31
31
|
Provides-Extra: testing
|
|
32
|
+
Requires-Dist: cffconvert; extra == "testing"
|
|
32
33
|
Requires-Dist: more_itertools; extra == "testing"
|
|
33
34
|
Requires-Dist: pytest; extra == "testing"
|
|
34
35
|
Requires-Dist: pytest-cov; extra == "testing"
|
|
35
36
|
Requires-Dist: pytest-env; extra == "testing"
|
|
36
37
|
Requires-Dist: pytest-xdist; extra == "testing"
|
|
37
38
|
Requires-Dist: python_minifier; extra == "testing"
|
|
39
|
+
Requires-Dist: tomli; extra == "testing"
|
|
38
40
|
|
|
39
41
|
# Algorithm(s) for counting distinct ways to fold a map (or a strip of stamps)
|
|
40
42
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
README.md
|
|
2
2
|
pyproject.toml
|
|
3
3
|
mapFolding/benchmarks/benchmarking.py
|
|
4
|
+
mapFolding/citations/updateCitation.py
|
|
4
5
|
mapFolding/mapFolding.egg-info/PKG-INFO
|
|
5
6
|
mapFolding/mapFolding.egg-info/SOURCES.txt
|
|
6
7
|
mapFolding/mapFolding.egg-info/dependency_links.txt
|
|
@@ -20,7 +21,7 @@ mapFolding/someAssemblyRequired/__init__.py
|
|
|
20
21
|
mapFolding/someAssemblyRequired/generalizeSourceCode.py
|
|
21
22
|
mapFolding/someAssemblyRequired/getLLVMforNoReason.py
|
|
22
23
|
mapFolding/someAssemblyRequired/makeJob.py
|
|
23
|
-
mapFolding/someAssemblyRequired/
|
|
24
|
+
mapFolding/someAssemblyRequired/synthesizeModuleJob.py
|
|
24
25
|
mapFolding/someAssemblyRequired/synthesizeModules.py
|
|
25
26
|
mapFolding/syntheticModules/__init__.py
|
|
26
27
|
mapFolding/syntheticModules/countInitialize.py
|
{mapfolding-0.3.3 → mapfolding-0.3.4}/mapFolding/someAssemblyRequired/generalizeSourceCode.py
RENAMED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT
|
|
2
|
+
from typing import Dict, Optional, List, Set, Union
|
|
2
3
|
import ast
|
|
3
4
|
|
|
4
5
|
class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
5
6
|
"""Process AST nodes to inline functions and substitute enum values.
|
|
6
7
|
Also handles function decorators during inlining."""
|
|
7
8
|
|
|
8
|
-
def __init__(self, dictionaryFunctions, dictionaryEnumValues):
|
|
9
|
+
def __init__(self, dictionaryFunctions: Dict[str, ast.FunctionDef], dictionaryEnumValues: Dict[str, int]) -> None:
|
|
9
10
|
self.dictionaryFunctions = dictionaryFunctions
|
|
10
11
|
self.dictionaryEnumValues = dictionaryEnumValues
|
|
11
12
|
self.processed = set()
|
|
12
13
|
|
|
13
|
-
def inlineFunctionBody(self, functionName):
|
|
14
|
+
def inlineFunctionBody(self, functionName: str) -> Optional[ast.FunctionDef]:
|
|
14
15
|
if functionName in self.processed:
|
|
15
16
|
return None
|
|
16
17
|
|
|
@@ -21,7 +22,7 @@ class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
|
21
22
|
self.visit(node)
|
|
22
23
|
return inlineDefinition
|
|
23
24
|
|
|
24
|
-
def visit_Attribute(self, node):
|
|
25
|
+
def visit_Attribute(self, node: ast.Attribute) -> ast.AST:
|
|
25
26
|
# Substitute enum identifiers (e.g., indexMy.leaf1ndex.value)
|
|
26
27
|
if isinstance(node.value, ast.Attribute) and isinstance(node.value.value, ast.Name):
|
|
27
28
|
enumPath = f"{node.value.value.id}.{node.value.attr}.{node.attr}"
|
|
@@ -29,7 +30,7 @@ class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
|
29
30
|
return ast.Constant(value=self.dictionaryEnumValues[enumPath])
|
|
30
31
|
return self.generic_visit(node)
|
|
31
32
|
|
|
32
|
-
def visit_Call(self, node):
|
|
33
|
+
def visit_Call(self, node: ast.Call) -> ast.AST:
|
|
33
34
|
callNode = self.generic_visit(node)
|
|
34
35
|
if isinstance(callNode, ast.Call) and isinstance(callNode.func, ast.Name) and callNode.func.id in self.dictionaryFunctions:
|
|
35
36
|
inlineDefinition = self.inlineFunctionBody(callNode.func.id)
|
|
@@ -39,10 +40,10 @@ class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
|
39
40
|
return self.visit(lastStmt.value)
|
|
40
41
|
elif isinstance(lastStmt, ast.Expr) and lastStmt.value is not None:
|
|
41
42
|
return self.visit(lastStmt.value)
|
|
42
|
-
return None
|
|
43
|
+
return ast.Constant(value=None)
|
|
43
44
|
return callNode
|
|
44
45
|
|
|
45
|
-
def visit_Expr(self, node):
|
|
46
|
+
def visit_Expr(self, node: ast.Expr) -> Union[ast.AST, List[ast.AST]]:
|
|
46
47
|
if isinstance(node.value, ast.Call):
|
|
47
48
|
if isinstance(node.value.func, ast.Name) and node.value.func.id in self.dictionaryFunctions:
|
|
48
49
|
inlineDefinition = self.inlineFunctionBody(node.value.func.id)
|
|
@@ -50,18 +51,18 @@ class RecursiveInlinerWithEnum(ast.NodeTransformer):
|
|
|
50
51
|
return [self.visit(stmt) for stmt in inlineDefinition.body]
|
|
51
52
|
return self.generic_visit(node)
|
|
52
53
|
|
|
53
|
-
def findRequiredImports(node):
|
|
54
|
+
def findRequiredImports(node: ast.AST) -> Set[str]:
|
|
54
55
|
"""Find all modules that need to be imported based on AST analysis.
|
|
55
56
|
NOTE: due to hardcoding, this is a glorified regex. No, wait, this is less versatile than regex."""
|
|
56
57
|
requiredImports = set()
|
|
57
58
|
|
|
58
59
|
class ImportFinder(ast.NodeVisitor):
|
|
59
|
-
def visit_Name(self, node):
|
|
60
|
+
def visit_Name(self, node: ast.Name) -> None:
|
|
60
61
|
if node.id in {'numba'}:
|
|
61
62
|
requiredImports.add(node.id)
|
|
62
63
|
self.generic_visit(node)
|
|
63
64
|
|
|
64
|
-
def visitDecorator(self, node):
|
|
65
|
+
def visitDecorator(self, node: ast.AST) -> None:
|
|
65
66
|
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
66
67
|
if node.func.id == 'jit':
|
|
67
68
|
requiredImports.add('numba')
|
|
@@ -70,7 +71,7 @@ def findRequiredImports(node):
|
|
|
70
71
|
ImportFinder().visit(node)
|
|
71
72
|
return requiredImports
|
|
72
73
|
|
|
73
|
-
def generateImports(requiredImports):
|
|
74
|
+
def generateImports(requiredImports: Set[str]) -> str:
|
|
74
75
|
"""Generate import statements based on required modules."""
|
|
75
76
|
importStatements = {'import numba', 'from mapFolding import indexMy, indexTrack'}
|
|
76
77
|
|
|
@@ -84,7 +85,7 @@ def generateImports(requiredImports):
|
|
|
84
85
|
|
|
85
86
|
return '\n'.join(importStatements)
|
|
86
87
|
|
|
87
|
-
def makeInlineFunction(sourceCode, targetFunctionName, dictionaryEnumValues, skipEnum=False, **keywordArguments):
|
|
88
|
+
def makeInlineFunction(sourceCode: str, targetFunctionName: str, dictionaryEnumValues: Dict[str, int], skipEnum: bool=False, **keywordArguments: Optional[str]):
|
|
88
89
|
datatypeLarge = keywordArguments.get('datatypeLarge', datatypeLargeDEFAULT)
|
|
89
90
|
datatypeMedium = keywordArguments.get('datatypeMedium', datatypeMediumDEFAULT)
|
|
90
91
|
datatypeSmall = keywordArguments.get('datatypeSmall', datatypeSmallDEFAULT)
|
|
@@ -5,8 +5,10 @@ import pathlib
|
|
|
5
5
|
import pickle
|
|
6
6
|
|
|
7
7
|
def makeStateJob(listDimensions: Sequence[int], **keywordArguments: Optional[Type[Any]]) -> pathlib.Path:
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
10
|
+
|
|
11
|
+
from syntheticModules import countInitialize
|
|
10
12
|
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
11
13
|
|
|
12
14
|
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
from mapFolding import indexMy, indexTrack, getAlgorithmSource, ParametersNumba, parametersNumbaDEFAULT, hackSSOTdtype
|
|
2
|
+
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT
|
|
3
|
+
import pathlib
|
|
4
|
+
import inspect
|
|
5
|
+
import numpy
|
|
6
|
+
import numba
|
|
7
|
+
from typing import Dict, Optional, List, Set, Union, Sequence
|
|
8
|
+
import ast
|
|
9
|
+
|
|
10
|
+
algorithmSource = getAlgorithmSource()
|
|
11
|
+
|
|
12
|
+
class RecursiveInliner(ast.NodeTransformer):
|
|
13
|
+
def __init__(self, dictionaryFunctions: Dict[str, ast.FunctionDef]):
|
|
14
|
+
self.dictionaryFunctions = dictionaryFunctions
|
|
15
|
+
self.processed = set()
|
|
16
|
+
|
|
17
|
+
def inlineFunctionBody(self, functionName: str) -> Optional[ast.FunctionDef]:
|
|
18
|
+
if functionName in self.processed:
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
self.processed.add(functionName)
|
|
22
|
+
inlineDefinition = self.dictionaryFunctions[functionName]
|
|
23
|
+
# Recursively process the function body
|
|
24
|
+
for node in ast.walk(inlineDefinition):
|
|
25
|
+
self.visit(node)
|
|
26
|
+
return inlineDefinition
|
|
27
|
+
|
|
28
|
+
def visit_Call(self, node: ast.Call) -> ast.AST:
|
|
29
|
+
callNode = self.generic_visit(node)
|
|
30
|
+
if isinstance(callNode, ast.Call) and isinstance(callNode.func, ast.Name) and callNode.func.id in self.dictionaryFunctions:
|
|
31
|
+
inlineDefinition = self.inlineFunctionBody(callNode.func.id)
|
|
32
|
+
if (inlineDefinition and inlineDefinition.body):
|
|
33
|
+
lastStmt = inlineDefinition.body[-1]
|
|
34
|
+
if isinstance(lastStmt, ast.Return) and lastStmt.value is not None:
|
|
35
|
+
return self.visit(lastStmt.value)
|
|
36
|
+
elif isinstance(lastStmt, ast.Expr) and lastStmt.value is not None:
|
|
37
|
+
return self.visit(lastStmt.value)
|
|
38
|
+
return ast.Constant(value=None)
|
|
39
|
+
return callNode
|
|
40
|
+
|
|
41
|
+
def visit_Expr(self, node: ast.Expr) -> Union[ast.AST, List[ast.AST]]:
|
|
42
|
+
if isinstance(node.value, ast.Call):
|
|
43
|
+
if isinstance(node.value.func, ast.Name) and node.value.func.id in self.dictionaryFunctions:
|
|
44
|
+
inlineDefinition = self.inlineFunctionBody(node.value.func.id)
|
|
45
|
+
if inlineDefinition:
|
|
46
|
+
return [self.visit(stmt) for stmt in inlineDefinition.body]
|
|
47
|
+
return self.generic_visit(node)
|
|
48
|
+
|
|
49
|
+
def decorateCallableWithNumba(astCallable: ast.FunctionDef, parallel: bool=False, **keywordArguments: Optional[str]):
|
|
50
|
+
def makeNumbaParameterSignatureElement(signatureElement: ast.arg):
|
|
51
|
+
if isinstance(signatureElement.annotation, ast.Subscript) and isinstance(signatureElement.annotation.slice, ast.Tuple):
|
|
52
|
+
|
|
53
|
+
annotationShape = signatureElement.annotation.slice.elts[0]
|
|
54
|
+
if isinstance(annotationShape, ast.Subscript) and isinstance(annotationShape.slice, ast.Tuple):
|
|
55
|
+
shapeAsListSlices = [ast.Slice() for axis in range(len(annotationShape.slice.elts))]
|
|
56
|
+
shapeAsListSlices[-1] = ast.Slice(step=ast.Constant(value=1))
|
|
57
|
+
shapeAST = ast.Tuple(elts=shapeAsListSlices, ctx=ast.Load())
|
|
58
|
+
else:
|
|
59
|
+
shapeAST = ast.Slice(step=ast.Constant(value=1))
|
|
60
|
+
|
|
61
|
+
annotationDtype = signatureElement.annotation.slice.elts[1]
|
|
62
|
+
if isinstance(annotationDtype, ast.Subscript) and isinstance(annotationDtype.slice, ast.Attribute):
|
|
63
|
+
datatypeAST = annotationDtype.slice.attr
|
|
64
|
+
else:
|
|
65
|
+
datatypeAST = None
|
|
66
|
+
|
|
67
|
+
ndarrayName = signatureElement.arg
|
|
68
|
+
Z0Z_hackyStr = hackSSOTdtype[ndarrayName]
|
|
69
|
+
Z0Z_hackyStr = Z0Z_hackyStr[0] + 'ata' + Z0Z_hackyStr[1:]
|
|
70
|
+
datatype_attr = keywordArguments.get(Z0Z_hackyStr, None) or datatypeAST or eval(Z0Z_hackyStr+'DEFAULT')
|
|
71
|
+
|
|
72
|
+
datatypeNumba = ast.Attribute(value=ast.Name(id='numba', ctx=ast.Load()), attr=datatype_attr, ctx=ast.Load())
|
|
73
|
+
|
|
74
|
+
return ast.Subscript(value=datatypeNumba, slice=shapeAST, ctx=ast.Load())
|
|
75
|
+
|
|
76
|
+
# callableSourceDecorators = [decorator for decorator in callableInlined.decorator_list]
|
|
77
|
+
|
|
78
|
+
listNumbaParameterSignature: List[ast.Subscript] = []
|
|
79
|
+
for parameter in astCallable.args.args:
|
|
80
|
+
signatureElement = makeNumbaParameterSignatureElement(parameter)
|
|
81
|
+
if signatureElement:
|
|
82
|
+
listNumbaParameterSignature.append(signatureElement)
|
|
83
|
+
|
|
84
|
+
astArgsNumbaSignature = ast.Tuple(elts=listNumbaParameterSignature, ctx=ast.Load())
|
|
85
|
+
|
|
86
|
+
parametersNumba = parametersNumbaDEFAULT if not parallel else ParametersNumba({**parametersNumbaDEFAULT, 'parallel': True})
|
|
87
|
+
listKeywordsNumbaSignature = [ast.keyword(arg=parameterName, value=ast.Constant(value=parameterValue)) for parameterName, parameterValue in parametersNumba.items()]
|
|
88
|
+
|
|
89
|
+
astDecoratorNumba = ast.Call(func=ast.Attribute(value=ast.Name(id='numba', ctx=ast.Load()), attr='jit', ctx=ast.Load()), args=[astArgsNumbaSignature], keywords=listKeywordsNumbaSignature)
|
|
90
|
+
|
|
91
|
+
astCallable.decorator_list = [astDecoratorNumba]
|
|
92
|
+
return astCallable
|
|
93
|
+
|
|
94
|
+
def getDictionaryEnumValues() -> Dict[str, int]:
|
|
95
|
+
dictionaryEnumValues = {}
|
|
96
|
+
for enumIndex in [indexMy, indexTrack]:
|
|
97
|
+
for memberName, memberValue in enumIndex._member_map_.items():
|
|
98
|
+
dictionaryEnumValues[f"{enumIndex.__name__}.{memberName}.value"] = memberValue.value
|
|
99
|
+
return dictionaryEnumValues
|
|
100
|
+
|
|
101
|
+
def unpackArrays(codeInlined: str) -> str:
|
|
102
|
+
dictionaryReplaceScalars = {
|
|
103
|
+
'my[indexMy.dimensionsTotal.value]': 'dimensionsTotal',
|
|
104
|
+
'my[indexMy.dimensionsUnconstrained.value]': 'dimensionsUnconstrained',
|
|
105
|
+
'my[indexMy.gap1ndex.value]': 'gap1ndex',
|
|
106
|
+
'my[indexMy.gap1ndexCeiling.value]': 'gap1ndexCeiling',
|
|
107
|
+
'my[indexMy.indexDimension.value]': 'indexDimension',
|
|
108
|
+
# 'my[indexMy.indexLeaf.value]': 'indexLeaf',
|
|
109
|
+
'my[indexMy.indexMiniGap.value]': 'indexMiniGap',
|
|
110
|
+
'my[indexMy.leaf1ndex.value]': 'leaf1ndex',
|
|
111
|
+
'my[indexMy.leafConnectee.value]': 'leafConnectee',
|
|
112
|
+
# 'my[indexMy.taskDivisions.value]': 'taskDivisions',
|
|
113
|
+
'my[indexMy.taskIndex.value]': 'taskIndex',
|
|
114
|
+
# 'foldGroups[-1]': 'leavesTotal',
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
dictionaryReplaceArrays = {
|
|
118
|
+
"track[indexTrack.leafAbove.value, ": 'leafAbove[',
|
|
119
|
+
"track[indexTrack.leafBelow.value, ": 'leafBelow[',
|
|
120
|
+
'track[indexTrack.countDimensionsGapped.value, ': 'countDimensionsGapped[',
|
|
121
|
+
'track[indexTrack.gapRangeStart.value, ': 'gapRangeStart[',
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
ImaIndent = " "
|
|
125
|
+
linesInitialize = """"""
|
|
126
|
+
|
|
127
|
+
for find, replace in dictionaryReplaceScalars.items():
|
|
128
|
+
linesInitialize += f"{ImaIndent}{replace} = {find}\n"
|
|
129
|
+
codeInlined = codeInlined.replace(find, replace)
|
|
130
|
+
|
|
131
|
+
for find, replace in dictionaryReplaceArrays.items():
|
|
132
|
+
linesInitialize += f"{ImaIndent}{replace[0:-1]} = {find[0:-2]}]\n"
|
|
133
|
+
codeInlined = codeInlined.replace(find, replace)
|
|
134
|
+
|
|
135
|
+
ourGuyOnTheInside = " doFindGaps = True\n"
|
|
136
|
+
linesInitialize = ourGuyOnTheInside + linesInitialize
|
|
137
|
+
|
|
138
|
+
codeInlined = codeInlined.replace(ourGuyOnTheInside, linesInitialize)
|
|
139
|
+
|
|
140
|
+
return codeInlined
|
|
141
|
+
|
|
142
|
+
def inlineMapFoldingNumba(**keywordArguments: Optional[str]):
|
|
143
|
+
dictionaryEnumValues = getDictionaryEnumValues()
|
|
144
|
+
codeSource = inspect.getsource(algorithmSource)
|
|
145
|
+
pathFilenameAlgorithm = pathlib.Path(inspect.getfile(algorithmSource))
|
|
146
|
+
|
|
147
|
+
listPathFilenamesDestination: list[pathlib.Path] = []
|
|
148
|
+
listCallables = [ 'countInitialize', 'countParallel', 'countSequential', ]
|
|
149
|
+
for callableTarget in listCallables:
|
|
150
|
+
codeParsed: ast.Module = ast.parse(codeSource, type_comments=True)
|
|
151
|
+
codeSourceImportStatements = {statement for statement in codeParsed.body if isinstance(statement, (ast.Import, ast.ImportFrom))}
|
|
152
|
+
dictionaryFunctions = {statement.name: statement for statement in codeParsed.body if isinstance(statement, ast.FunctionDef)}
|
|
153
|
+
callableInlinerWorkhorse = RecursiveInliner(dictionaryFunctions)
|
|
154
|
+
parallel = callableTarget == 'countParallel'
|
|
155
|
+
callableInlined = callableInlinerWorkhorse.inlineFunctionBody(callableTarget)
|
|
156
|
+
if callableInlined:
|
|
157
|
+
ast.fix_missing_locations(callableInlined)
|
|
158
|
+
callableDecorated = decorateCallableWithNumba(callableInlined, parallel, **keywordArguments)
|
|
159
|
+
|
|
160
|
+
importsRequired = "\n".join([ast.unparse(importStatement) for importStatement in codeSourceImportStatements])
|
|
161
|
+
callableInlined = ast.unparse(callableDecorated)
|
|
162
|
+
codeUnpacked = unpackArrays(callableInlined) if callableTarget == 'countSequential' else callableInlined
|
|
163
|
+
# inlinedCode = ast.unparse(ast.Module(body=[nodeInlined], type_ignores=[]))
|
|
164
|
+
|
|
165
|
+
pathFilenameDestination = pathFilenameAlgorithm.parent / "syntheticModules" / pathFilenameAlgorithm.with_stem(callableTarget).name
|
|
166
|
+
pathFilenameDestination.write_text(importsRequired + "\n" + codeUnpacked)
|
|
167
|
+
listPathFilenamesDestination.append(pathFilenameDestination)
|
|
168
|
+
|
|
169
|
+
if __name__ == '__main__':
|
|
170
|
+
inlineMapFoldingNumba()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from numpy import integer
|
|
2
|
+
import numba
|
|
3
|
+
import numpy
|
|
4
|
+
from mapFolding import indexMy, indexTrack
|
|
5
|
+
from typing import Any, Tuple
|
|
6
|
+
@numba.jit((numba.uint8[:, :, ::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=False, inline='never', looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nopython=True, parallel=False)
|
|
7
|
+
def countInitialize(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.dtype[integer[Any]]], gapsWhere: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], my: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], track: numpy.ndarray[Tuple[int, int], numpy.dtype[integer[Any]]]):
|
|
8
|
+
while my[indexMy.leaf1ndex.value] > 0:
|
|
9
|
+
if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
|
|
10
|
+
my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
|
|
11
|
+
my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
|
|
12
|
+
my[indexMy.indexDimension.value] = 0
|
|
13
|
+
while my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]:
|
|
14
|
+
if connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]:
|
|
15
|
+
my[indexMy.dimensionsUnconstrained.value] -= 1
|
|
16
|
+
else:
|
|
17
|
+
my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
|
|
18
|
+
while my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]:
|
|
19
|
+
gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
|
|
20
|
+
if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
|
|
21
|
+
my[indexMy.gap1ndexCeiling.value] += 1
|
|
22
|
+
track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
|
|
23
|
+
my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
|
|
24
|
+
my[indexMy.indexDimension.value] += 1
|
|
25
|
+
if not my[indexMy.dimensionsUnconstrained.value]:
|
|
26
|
+
my[indexMy.indexLeaf.value] = 0
|
|
27
|
+
while my[indexMy.indexLeaf.value] < my[indexMy.leaf1ndex.value]:
|
|
28
|
+
gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.indexLeaf.value]
|
|
29
|
+
my[indexMy.gap1ndexCeiling.value] += 1
|
|
30
|
+
my[indexMy.indexLeaf.value] += 1
|
|
31
|
+
my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
|
|
32
|
+
while my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]:
|
|
33
|
+
gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
|
|
34
|
+
if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
|
|
35
|
+
my[indexMy.gap1ndex.value] += 1
|
|
36
|
+
track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
|
|
37
|
+
my[indexMy.indexMiniGap.value] += 1
|
|
38
|
+
if my[indexMy.leaf1ndex.value] > 0:
|
|
39
|
+
my[indexMy.gap1ndex.value] -= 1
|
|
40
|
+
track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
|
|
41
|
+
track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
|
|
42
|
+
track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
|
|
43
|
+
track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
|
|
44
|
+
track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
|
|
45
|
+
my[indexMy.leaf1ndex.value] += 1
|
|
46
|
+
if my[indexMy.gap1ndex.value] > 0:
|
|
47
|
+
return
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from numpy import integer
|
|
2
|
+
from typing import Any, Tuple
|
|
3
|
+
import numba
|
|
4
|
+
from mapFolding import indexMy, indexTrack
|
|
5
|
+
import numpy
|
|
6
|
+
@numba.jit((numba.uint8[:, :, ::1], numba.int64[::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=False, inline='never', looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nopython=True, parallel=True)
|
|
7
|
+
def countParallel(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.dtype[integer[Any]]], foldGroups: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], gapsWherePARALLEL: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], myPARALLEL: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], trackPARALLEL: numpy.ndarray[Tuple[int, int], numpy.dtype[integer[Any]]]):
|
|
8
|
+
for indexSherpa in numba.prange(myPARALLEL[indexMy.taskDivisions.value]):
|
|
9
|
+
gapsWhere = gapsWherePARALLEL.copy()
|
|
10
|
+
my = myPARALLEL.copy()
|
|
11
|
+
my[indexMy.taskIndex.value] = indexSherpa
|
|
12
|
+
track = trackPARALLEL.copy()
|
|
13
|
+
groupsOfFolds: int = 0
|
|
14
|
+
while my[indexMy.leaf1ndex.value] > 0:
|
|
15
|
+
if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
|
|
16
|
+
if my[indexMy.leaf1ndex.value] > foldGroups[-1]:
|
|
17
|
+
groupsOfFolds = groupsOfFolds + 1
|
|
18
|
+
else:
|
|
19
|
+
my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
|
|
20
|
+
my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
|
|
21
|
+
my[indexMy.indexDimension.value] = 0
|
|
22
|
+
while my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]:
|
|
23
|
+
if connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]:
|
|
24
|
+
my[indexMy.dimensionsUnconstrained.value] -= 1
|
|
25
|
+
else:
|
|
26
|
+
my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
|
|
27
|
+
while my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]:
|
|
28
|
+
if my[indexMy.leaf1ndex.value] != my[indexMy.taskDivisions.value] or my[indexMy.leafConnectee.value] % my[indexMy.taskDivisions.value] == my[indexMy.taskIndex.value]:
|
|
29
|
+
gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
|
|
30
|
+
if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
|
|
31
|
+
my[indexMy.gap1ndexCeiling.value] += 1
|
|
32
|
+
track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
|
|
33
|
+
my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
|
|
34
|
+
my[indexMy.indexDimension.value] += 1
|
|
35
|
+
my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
|
|
36
|
+
while my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]:
|
|
37
|
+
gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
|
|
38
|
+
if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
|
|
39
|
+
my[indexMy.gap1ndex.value] += 1
|
|
40
|
+
track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
|
|
41
|
+
my[indexMy.indexMiniGap.value] += 1
|
|
42
|
+
while my[indexMy.leaf1ndex.value] > 0 and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]:
|
|
43
|
+
my[indexMy.leaf1ndex.value] -= 1
|
|
44
|
+
track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
|
|
45
|
+
track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]
|
|
46
|
+
if my[indexMy.leaf1ndex.value] > 0:
|
|
47
|
+
my[indexMy.gap1ndex.value] -= 1
|
|
48
|
+
track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
|
|
49
|
+
track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
|
|
50
|
+
track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
|
|
51
|
+
track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
|
|
52
|
+
track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
|
|
53
|
+
my[indexMy.leaf1ndex.value] += 1
|
|
54
|
+
foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
from
|
|
1
|
+
from numpy import integer
|
|
2
|
+
from typing import Any, Tuple
|
|
2
3
|
import numba
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
from mapFolding import indexMy, indexTrack
|
|
5
|
+
import numpy
|
|
6
|
+
@numba.jit((numba.uint8[:, :, ::1], numba.int64[::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=False, inline='never', looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nopython=True, parallel=False)
|
|
7
|
+
def countSequential(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.dtype[integer[Any]]], foldGroups: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], gapsWhere: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], my: numpy.ndarray[Tuple[int], numpy.dtype[integer[Any]]], track: numpy.ndarray[Tuple[int, int], numpy.dtype[integer[Any]]]):
|
|
5
8
|
doFindGaps = True
|
|
6
9
|
dimensionsTotal = my[indexMy.dimensionsTotal.value]
|
|
7
10
|
dimensionsUnconstrained = my[indexMy.dimensionsUnconstrained.value]
|
|
@@ -15,8 +15,7 @@ classifiers = [
|
|
|
15
15
|
"Operating System :: OS Independent",
|
|
16
16
|
"Programming Language :: Python",
|
|
17
17
|
"Topic :: Scientific/Engineering :: Mathematics",
|
|
18
|
-
"Typing :: Typed",
|
|
19
|
-
]
|
|
18
|
+
"Typing :: Typed",]
|
|
20
19
|
dependencies = ["numba", "numpy", "Z0Z_tools"]
|
|
21
20
|
description = "Count distinct ways to fold a map (or a strip of stamps)"
|
|
22
21
|
keywords = [
|
|
@@ -28,8 +27,7 @@ keywords = [
|
|
|
28
27
|
"folding",
|
|
29
28
|
"map folding",
|
|
30
29
|
"OEIS",
|
|
31
|
-
"stamp folding",
|
|
32
|
-
]
|
|
30
|
+
"stamp folding",]
|
|
33
31
|
license = { text = "CC-BY-NC-4.0" }
|
|
34
32
|
name = "mapFolding"
|
|
35
33
|
optional-dependencies = { benchmark = [
|
|
@@ -38,18 +36,19 @@ optional-dependencies = { benchmark = [
|
|
|
38
36
|
"pandas",
|
|
39
37
|
"tqdm",
|
|
40
38
|
], testing = [
|
|
39
|
+
"cffconvert",
|
|
41
40
|
"more_itertools",
|
|
42
41
|
"pytest",
|
|
43
42
|
"pytest-cov",
|
|
44
43
|
"pytest-env",
|
|
45
44
|
"pytest-xdist",
|
|
46
45
|
"python_minifier",
|
|
47
|
-
] }
|
|
46
|
+
"tomli",] }
|
|
48
47
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
49
48
|
requires-python = ">=3.10,<3.14"
|
|
50
49
|
scripts = { getOEISids = "mapFolding.oeis:getOEISids", clearOEIScache = "mapFolding.oeis:clearOEIScache", OEIS_for_n = "mapFolding.oeis:OEIS_for_n" }
|
|
51
50
|
urls = { Homepage = "https://github.com/hunterhogan/mapFolding", Donate = "https://www.patreon.com/integrated" }
|
|
52
|
-
version = "0.3.
|
|
51
|
+
version = "0.3.4"
|
|
53
52
|
|
|
54
53
|
[tool.coverage]
|
|
55
54
|
report = { exclude_lines = [
|
|
@@ -65,8 +64,7 @@ run = { branch = true, concurrency = [
|
|
|
65
64
|
"mapFolding/someAssemblyRequired/*",
|
|
66
65
|
"Z0Z_*",
|
|
67
66
|
], parallel = true, source = [
|
|
68
|
-
"mapFolding",
|
|
69
|
-
] }
|
|
67
|
+
"mapFolding",] }
|
|
70
68
|
xml = { output = "tests/coverage/coverage.xml" }
|
|
71
69
|
|
|
72
70
|
[tool.pytest.ini_options]
|
|
@@ -12,31 +12,31 @@ import re as regex
|
|
|
12
12
|
import unittest
|
|
13
13
|
import unittest.mock
|
|
14
14
|
import urllib
|
|
15
|
-
|
|
15
|
+
from urllib.error import URLError
|
|
16
16
|
import urllib.request
|
|
17
17
|
|
|
18
18
|
def test_algorithmSourceSequential(oeisID: str, useAlgorithmDirectly):
|
|
19
19
|
for n in settingsOEIS[oeisID]['valuesTestValidation']:
|
|
20
|
-
|
|
20
|
+
standardizedEqualTo(settingsOEIS[oeisID]['valuesKnown'][n], oeisIDfor_n, oeisID, n)
|
|
21
21
|
|
|
22
22
|
def test_aOFn_calculate_value(oeisID: str):
|
|
23
23
|
for n in settingsOEIS[oeisID]['valuesTestValidation']:
|
|
24
|
-
|
|
24
|
+
standardizedEqualTo(settingsOEIS[oeisID]['valuesKnown'][n], oeisIDfor_n, oeisID, n)
|
|
25
25
|
|
|
26
26
|
@pytest.mark.parametrize("badID", ["A999999", " A999999 ", "A999999extra"])
|
|
27
27
|
def test__validateOEISid_invalid_id(badID: str):
|
|
28
|
-
|
|
28
|
+
standardizedEqualTo(KeyError, _validateOEISid, badID)
|
|
29
29
|
|
|
30
30
|
def test__validateOEISid_partially_valid(oeisID_1random: str):
|
|
31
|
-
|
|
31
|
+
standardizedEqualTo(KeyError, _validateOEISid, f"{oeisID_1random}extra")
|
|
32
32
|
|
|
33
33
|
def test__validateOEISid_valid_id(oeisID: str):
|
|
34
|
-
|
|
34
|
+
standardizedEqualTo(oeisID, _validateOEISid, oeisID)
|
|
35
35
|
|
|
36
36
|
def test__validateOEISid_valid_id_case_insensitive(oeisID: str):
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.lower())
|
|
38
|
+
standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.upper())
|
|
39
|
+
standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.swapcase())
|
|
40
40
|
|
|
41
41
|
parameters_test_aOFn_invalid_n = [
|
|
42
42
|
# (2, "ok"), # test the test template
|
|
@@ -48,10 +48,10 @@ badValues, badValuesIDs = zip(*parameters_test_aOFn_invalid_n)
|
|
|
48
48
|
@pytest.mark.parametrize("badN", badValues, ids=badValuesIDs)
|
|
49
49
|
def test_aOFn_invalid_n(oeisID_1random: str, badN):
|
|
50
50
|
"""Check that negative or non-integer n raises ValueError."""
|
|
51
|
-
|
|
51
|
+
standardizedEqualTo(ValueError, oeisIDfor_n, oeisID_1random, badN)
|
|
52
52
|
|
|
53
53
|
def test_aOFn_zeroDim_A001418():
|
|
54
|
-
|
|
54
|
+
standardizedEqualTo(ArithmeticError, oeisIDfor_n, 'A001418', 0)
|
|
55
55
|
|
|
56
56
|
# ===== OEIS Cache Tests =====
|
|
57
57
|
@pytest.mark.parametrize("cacheExists", [True, False])
|
|
@@ -82,11 +82,11 @@ def testCacheScenarios(pathCacheTesting: pathlib.Path, oeisID_1random: str, scen
|
|
|
82
82
|
pathCache.write_text("Invalid content")
|
|
83
83
|
|
|
84
84
|
if scenarioCache == "miss":
|
|
85
|
-
|
|
85
|
+
prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], None, oeisID_1random, pathCacheTesting)
|
|
86
86
|
elif scenarioCache == "expired":
|
|
87
|
-
|
|
87
|
+
prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], setupCacheExpired, oeisID_1random, pathCacheTesting)
|
|
88
88
|
else:
|
|
89
|
-
|
|
89
|
+
prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], setupCacheInvalid, oeisID_1random, pathCacheTesting)
|
|
90
90
|
|
|
91
91
|
def testInvalidFileContent(pathCacheTesting: pathlib.Path, oeisID_1random: str):
|
|
92
92
|
pathFilenameCache = pathCacheTesting / _getFilenameOEISbFile(oeisID=oeisID_1random)
|
|
@@ -107,7 +107,7 @@ def testInvalidFileContent(pathCacheTesting: pathlib.Path, oeisID_1random: str):
|
|
|
107
107
|
|
|
108
108
|
def testParseContentErrors():
|
|
109
109
|
"""Test invalid content parsing."""
|
|
110
|
-
|
|
110
|
+
standardizedEqualTo(ValueError, _parseBFileOEIS, "Invalid content\n1 2\n", 'A001415')
|
|
111
111
|
|
|
112
112
|
def testExtraComments(pathCacheTesting: pathlib.Path, oeisID_1random: str):
|
|
113
113
|
pathFilenameCache = pathCacheTesting / _getFilenameOEISbFile(oeisID=oeisID_1random)
|
|
@@ -126,17 +126,17 @@ def testExtraComments(pathCacheTesting: pathlib.Path, oeisID_1random: str):
|
|
|
126
126
|
|
|
127
127
|
OEISsequence = _getOEISidValues(oeisID_1random)
|
|
128
128
|
# Verify sequence values are correct despite extra comments
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
standardizedEqualTo(2, lambda d: d[1], OEISsequence) # First value
|
|
130
|
+
standardizedEqualTo(8, lambda d: d[4], OEISsequence) # Value after mid-sequence comment
|
|
131
|
+
standardizedEqualTo(10, lambda d: d[5], OEISsequence) # Last value
|
|
132
132
|
|
|
133
133
|
def testNetworkError(monkeypatch: pytest.MonkeyPatch, pathCacheTesting: pathlib.Path):
|
|
134
134
|
"""Test network error handling."""
|
|
135
135
|
def mockUrlopen(*args, **kwargs):
|
|
136
|
-
raise
|
|
136
|
+
raise URLError("Network error")
|
|
137
137
|
|
|
138
138
|
monkeypatch.setattr(urllib.request, 'urlopen', mockUrlopen)
|
|
139
|
-
|
|
139
|
+
standardizedEqualTo(URLError, _getOEISidValues, next(iter(settingsOEIS)))
|
|
140
140
|
|
|
141
141
|
# ===== Command Line Interface Tests =====
|
|
142
142
|
def testHelpText():
|
|
@@ -172,7 +172,7 @@ def testHelpText():
|
|
|
172
172
|
outputStream = io.StringIO()
|
|
173
173
|
with redirect_stdout(outputStream):
|
|
174
174
|
OEIS_for_n()
|
|
175
|
-
|
|
175
|
+
standardizedEqualTo(expectedValue, lambda: int(outputStream.getvalue().strip().split()[0]))
|
|
176
176
|
|
|
177
177
|
def testCLI_InvalidInputs():
|
|
178
178
|
"""Test CLI error handling."""
|
|
@@ -185,14 +185,14 @@ def testCLI_InvalidInputs():
|
|
|
185
185
|
|
|
186
186
|
for arguments, testID in testCases:
|
|
187
187
|
with unittest.mock.patch('sys.argv', arguments):
|
|
188
|
-
|
|
188
|
+
standardizedSystemExit("error", OEIS_for_n)
|
|
189
189
|
|
|
190
190
|
def testCLI_HelpFlag():
|
|
191
191
|
"""Verify --help output contains required information."""
|
|
192
192
|
with unittest.mock.patch('sys.argv', ['OEIS_for_n', '--help']):
|
|
193
193
|
outputStream = io.StringIO()
|
|
194
194
|
with redirect_stdout(outputStream):
|
|
195
|
-
|
|
195
|
+
standardizedSystemExit("nonError", OEIS_for_n)
|
|
196
196
|
|
|
197
197
|
helpOutput = outputStream.getvalue()
|
|
198
198
|
assert "Available OEIS sequences:" in helpOutput
|
|
@@ -10,7 +10,6 @@ import pathlib
|
|
|
10
10
|
import pytest
|
|
11
11
|
import random
|
|
12
12
|
import sys
|
|
13
|
-
import unittest.mock
|
|
14
13
|
|
|
15
14
|
@pytest.mark.parametrize("listDimensions,expected_intInnit,expected_parseListDimensions,expected_validateListDimensions,expected_getLeavesTotal", [
|
|
16
15
|
(None, ValueError, ValueError, ValueError, ValueError), # None instead of list
|
|
@@ -47,20 +46,20 @@ import unittest.mock
|
|
|
47
46
|
])
|
|
48
47
|
def test_listDimensionsAsParameter(listDimensions: None | list[str] | list[int] | list[float] | list[None] | list[bool] | list[list[int]] | list[complex] | range | tuple[int, ...], expected_intInnit: type[ValueError] | list[int] | type[TypeError], expected_parseListDimensions: type[ValueError] | list[int] | type[TypeError], expected_validateListDimensions: type[ValueError] | type[NotImplementedError] | list[int] | type[TypeError], expected_getLeavesTotal: type[ValueError] | int | type[TypeError] | type[OverflowError]) -> None:
|
|
49
48
|
"""Test both validateListDimensions and getLeavesTotal with the same inputs."""
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
standardizedEqualTo(expected_intInnit, intInnit, listDimensions)
|
|
50
|
+
standardizedEqualTo(expected_parseListDimensions, parseDimensions, listDimensions)
|
|
51
|
+
standardizedEqualTo(expected_validateListDimensions, validateListDimensions, listDimensions)
|
|
52
|
+
standardizedEqualTo(expected_getLeavesTotal, getLeavesTotal, listDimensions)
|
|
54
53
|
|
|
55
54
|
def test_getLeavesTotal_edge_cases() -> None:
|
|
56
55
|
"""Test edge cases for getLeavesTotal."""
|
|
57
56
|
# Order independence
|
|
58
|
-
|
|
57
|
+
standardizedEqualTo(getLeavesTotal([2, 3, 4]), getLeavesTotal, [4, 2, 3])
|
|
59
58
|
|
|
60
59
|
# Immutability
|
|
61
60
|
listOriginal = [2, 3]
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
standardizedEqualTo(6, getLeavesTotal, listOriginal)
|
|
62
|
+
standardizedEqualTo([2, 3], lambda x: x, listOriginal) # Check that the list wasn't modified
|
|
64
63
|
|
|
65
64
|
@pytest.mark.parametrize("foldsValue,writeFoldsTarget", [
|
|
66
65
|
(756839, "foldsTotalTest.txt"), # Direct file
|
|
@@ -71,6 +70,7 @@ def test_countFolds_writeFoldsTotal(
|
|
|
71
70
|
listDimensionsTestFunctionality: List[int],
|
|
72
71
|
pathTempTesting: pathlib.Path,
|
|
73
72
|
mockFoldingFunction,
|
|
73
|
+
mockDispatcher,
|
|
74
74
|
foldsValue: int,
|
|
75
75
|
writeFoldsTarget: Optional[str]
|
|
76
76
|
) -> None:
|
|
@@ -86,12 +86,10 @@ def test_countFolds_writeFoldsTotal(
|
|
|
86
86
|
foldsTotalExpected = foldsValue * getLeavesTotal(listDimensionsTestFunctionality)
|
|
87
87
|
mock_countFolds = mockFoldingFunction(foldsValue, listDimensionsTestFunctionality)
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
returned = countFolds(listDimensionsTestFunctionality, pathishWriteFoldsTotal=pathWriteTarget)
|
|
89
|
+
with mockDispatcher(mock_countFolds):
|
|
90
|
+
returned = countFolds(listDimensionsTestFunctionality, pathLikeWriteFoldsTotal=pathWriteTarget)
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
standardComparison(str(foldsTotalExpected), lambda: (pathTempTesting / filenameFoldsTotalExpected).read_text()) # Check file content
|
|
92
|
+
standardizedEqualTo(str(foldsTotalExpected), lambda: (pathTempTesting / filenameFoldsTotalExpected).read_text())
|
|
95
93
|
|
|
96
94
|
@pytest.mark.parametrize("nameOfTest,callablePytest", PytestFor_intInnit())
|
|
97
95
|
def testIntInnit(nameOfTest, callablePytest):
|
|
@@ -113,7 +111,7 @@ def testOopsieKwargsie(nameOfTest, callablePytest):
|
|
|
113
111
|
(1, 1),
|
|
114
112
|
])
|
|
115
113
|
def test_setCPUlimit(CPUlimit, expectedLimit) -> None:
|
|
116
|
-
|
|
114
|
+
standardizedEqualTo(expectedLimit, setCPUlimit, CPUlimit)
|
|
117
115
|
|
|
118
116
|
def test_makeConnectionGraph_nonNegative(listDimensionsTestFunctionality: List[int]) -> None:
|
|
119
117
|
connectionGraph = makeConnectionGraph(listDimensionsTestFunctionality)
|
|
@@ -124,7 +122,6 @@ def test_makeConnectionGraph_datatype(listDimensionsTestFunctionality: List[int]
|
|
|
124
122
|
connectionGraph = makeConnectionGraph(listDimensionsTestFunctionality, datatype=datatype)
|
|
125
123
|
assert connectionGraph.dtype == datatype, f"Expected datatype {datatype}, but got {connectionGraph.dtype}."
|
|
126
124
|
|
|
127
|
-
|
|
128
125
|
"""5 parameters
|
|
129
126
|
listDimensionsTestFunctionality
|
|
130
127
|
|
|
@@ -271,7 +268,7 @@ def test_pathJobDEFAULT_colab():
|
|
|
271
268
|
|
|
272
269
|
def test_saveFoldsTotal_fallback(pathTempTesting: pathlib.Path) -> None:
|
|
273
270
|
foldsTotal = 123
|
|
274
|
-
pathFilename = pathTempTesting / "
|
|
271
|
+
pathFilename = pathTempTesting / "foldsTotal.txt"
|
|
275
272
|
with unittest.mock.patch("pathlib.Path.write_text", side_effect=OSError("Simulated write failure")):
|
|
276
273
|
with unittest.mock.patch("os.getcwd", return_value=str(pathTempTesting)):
|
|
277
274
|
capturedOutput = io.StringIO()
|
|
@@ -279,3 +276,10 @@ def test_saveFoldsTotal_fallback(pathTempTesting: pathlib.Path) -> None:
|
|
|
279
276
|
saveFoldsTotal(pathFilename, foldsTotal)
|
|
280
277
|
fallbackFiles = list(pathTempTesting.glob("foldsTotalYO_*.txt"))
|
|
281
278
|
assert len(fallbackFiles) == 1, "Fallback file was not created upon write failure."
|
|
279
|
+
|
|
280
|
+
def test_makeDataContainer_default_datatype():
|
|
281
|
+
"""Test that makeDataContainer uses dtypeLargeDEFAULT when no datatype is specified."""
|
|
282
|
+
testShape = (3, 4)
|
|
283
|
+
container = makeDataContainer(testShape)
|
|
284
|
+
assert container.dtype == dtypeLargeDEFAULT, f"Expected datatype {dtypeLargeDEFAULT}, but got {container.dtype}"
|
|
285
|
+
assert container.shape == testShape, f"Expected shape {testShape}, but got {container.shape}"
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
from tests.conftest import *
|
|
2
2
|
import pytest
|
|
3
|
-
from typing import List, Dict, Tuple
|
|
3
|
+
from typing import List, Dict, Tuple, Any
|
|
4
4
|
|
|
5
5
|
# TODO add a test. `C` = number of logical cores available. `n = C + 1`. Ensure that `[2,n]` is computed correctly.
|
|
6
6
|
# Or, probably smarter: limit the number of cores, then run a test with C+1.
|
|
7
7
|
|
|
8
8
|
def test_algorithmSourceParallel(listDimensionsTestParallelization: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int], useAlgorithmDirectly) -> None:
|
|
9
|
-
|
|
9
|
+
standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestParallelization)], countFolds, listDimensionsTestParallelization, None, 'maximum')
|
|
10
10
|
|
|
11
11
|
def test_countFoldsComputationDivisionsInvalid(listDimensionsTestFunctionality: List[int]) -> None:
|
|
12
|
-
|
|
12
|
+
standardizedEqualTo(ValueError, countFolds, listDimensionsTestFunctionality, None, {"wrong": "value"})
|
|
13
13
|
|
|
14
14
|
def test_countFoldsComputationDivisionsMaximum(listDimensionsTestParallelization: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int]) -> None:
|
|
15
|
-
|
|
15
|
+
standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestParallelization)], countFolds, listDimensionsTestParallelization, None, 'maximum')
|
|
16
16
|
|
|
17
17
|
@pytest.mark.parametrize("nameOfTest,callablePytest", PytestFor_defineConcurrencyLimit())
|
|
18
18
|
def test_defineConcurrencyLimit(nameOfTest, callablePytest):
|
|
@@ -20,7 +20,7 @@ def test_defineConcurrencyLimit(nameOfTest, callablePytest):
|
|
|
20
20
|
|
|
21
21
|
# @pytest.mark.parametrize("CPUlimitParameter", [{"invalid": True}, ["weird"]])
|
|
22
22
|
# def test_countFolds_cpuLimitOopsie(listDimensionsTestFunctionality: List[int], CPUlimitParameter: Dict[str, bool] | List[str]) -> None:
|
|
23
|
-
#
|
|
23
|
+
# standardizedEqualTo((AttributeError or ValueError), countFolds, listDimensionsTestFunctionality, None, 'cpu', CPUlimitParameter)
|
|
24
24
|
|
|
25
25
|
@pytest.mark.parametrize("computationDivisions, concurrencyLimit, listDimensions, expectedTaskDivisions", [
|
|
26
26
|
(None, 4, [9, 11], 0),
|
|
@@ -30,4 +30,15 @@ def test_defineConcurrencyLimit(nameOfTest, callablePytest):
|
|
|
30
30
|
(20, 4, [3,5], ValueError)
|
|
31
31
|
])
|
|
32
32
|
def test_getTaskDivisions(computationDivisions, concurrencyLimit, listDimensions, expectedTaskDivisions) -> None:
|
|
33
|
-
|
|
33
|
+
standardizedEqualTo(expectedTaskDivisions, getTaskDivisions, computationDivisions, concurrencyLimit, None, listDimensions)
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("expected,parameter", [
|
|
36
|
+
(2, "2"), # string
|
|
37
|
+
(ValueError, [4]), # list
|
|
38
|
+
(ValueError, (2,)), # tuple
|
|
39
|
+
(ValueError, {2}), # set
|
|
40
|
+
(ValueError, {"cores": 2}), # dict
|
|
41
|
+
])
|
|
42
|
+
def test_setCPUlimitMalformedParameter(expected, parameter) -> None:
|
|
43
|
+
"""Test that invalid CPUlimit types are properly handled."""
|
|
44
|
+
standardizedEqualTo(expected, setCPUlimit, parameter)
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
from mapFolding import indexMy, indexTrack, getAlgorithmSource
|
|
2
|
-
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT
|
|
3
|
-
from someAssemblyRequired import makeInlineFunction
|
|
4
|
-
import pathlib
|
|
5
|
-
import inspect
|
|
6
|
-
|
|
7
|
-
algorithmSource = getAlgorithmSource()
|
|
8
|
-
|
|
9
|
-
def getDictionaryEnumValues():
|
|
10
|
-
dictionaryEnumValues = {}
|
|
11
|
-
for enumIndex in [indexMy, indexTrack]:
|
|
12
|
-
for memberName, memberValue in enumIndex._member_map_.items():
|
|
13
|
-
dictionaryEnumValues[f"{enumIndex.__name__}.{memberName}.value"] = memberValue.value
|
|
14
|
-
return dictionaryEnumValues
|
|
15
|
-
|
|
16
|
-
def unpackArrays(codeInlined: str, callableTarget: str) -> str:
|
|
17
|
-
dictionaryReplaceScalars = {
|
|
18
|
-
'my[indexMy.dimensionsTotal.value]': 'dimensionsTotal',
|
|
19
|
-
'my[indexMy.dimensionsUnconstrained.value]': 'dimensionsUnconstrained',
|
|
20
|
-
'my[indexMy.gap1ndex.value]': 'gap1ndex',
|
|
21
|
-
'my[indexMy.gap1ndexCeiling.value]': 'gap1ndexCeiling',
|
|
22
|
-
'my[indexMy.indexDimension.value]': 'indexDimension',
|
|
23
|
-
# 'my[indexMy.indexLeaf.value]': 'indexLeaf',
|
|
24
|
-
'my[indexMy.indexMiniGap.value]': 'indexMiniGap',
|
|
25
|
-
'my[indexMy.leaf1ndex.value]': 'leaf1ndex',
|
|
26
|
-
'my[indexMy.leafConnectee.value]': 'leafConnectee',
|
|
27
|
-
# 'my[indexMy.taskDivisions.value]': 'taskDivisions',
|
|
28
|
-
'my[indexMy.taskIndex.value]': 'taskIndex',
|
|
29
|
-
# 'foldGroups[-1]': 'leavesTotal',
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
dictionaryReplaceArrays = {
|
|
33
|
-
"track[indexTrack.leafAbove.value, ": 'leafAbove[',
|
|
34
|
-
"track[indexTrack.leafBelow.value, ": 'leafBelow[',
|
|
35
|
-
'track[indexTrack.countDimensionsGapped.value, ': 'countDimensionsGapped[',
|
|
36
|
-
'track[indexTrack.gapRangeStart.value, ': 'gapRangeStart[',
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
ImaIndent = " "
|
|
40
|
-
linesInitialize = """"""
|
|
41
|
-
|
|
42
|
-
for find, replace in dictionaryReplaceScalars.items():
|
|
43
|
-
linesInitialize += f"{ImaIndent}{replace} = {find}\n"
|
|
44
|
-
codeInlined = codeInlined.replace(find, replace)
|
|
45
|
-
|
|
46
|
-
for find, replace in dictionaryReplaceArrays.items():
|
|
47
|
-
linesInitialize += f"{ImaIndent}{replace[0:-1]} = {find[0:-2]}]\n"
|
|
48
|
-
codeInlined = codeInlined.replace(find, replace)
|
|
49
|
-
|
|
50
|
-
ourGuyOnTheInside = " doFindGaps = True\n"
|
|
51
|
-
linesInitialize = ourGuyOnTheInside + linesInitialize
|
|
52
|
-
|
|
53
|
-
codeInlined = codeInlined.replace(ourGuyOnTheInside, linesInitialize)
|
|
54
|
-
|
|
55
|
-
return codeInlined
|
|
56
|
-
|
|
57
|
-
def inlineMapFoldingNumba(**keywordArguments):
|
|
58
|
-
datatypeLarge = keywordArguments.get('datatypeLarge', datatypeLargeDEFAULT)
|
|
59
|
-
datatypeMedium = keywordArguments.get('datatypeMedium', datatypeMediumDEFAULT)
|
|
60
|
-
datatypeSmall = keywordArguments.get('datatypeSmall', datatypeSmallDEFAULT)
|
|
61
|
-
dictionaryEnumValues = getDictionaryEnumValues()
|
|
62
|
-
codeSource = inspect.getsource(algorithmSource)
|
|
63
|
-
pathFilenameAlgorithm = pathlib.Path(inspect.getfile(algorithmSource))
|
|
64
|
-
|
|
65
|
-
listCallables = [ 'countInitialize', 'countParallel', 'countSequential', ]
|
|
66
|
-
|
|
67
|
-
listPathFilenamesDestination: list[pathlib.Path] = []
|
|
68
|
-
for callableTarget in listCallables:
|
|
69
|
-
skipEnum = (callableTarget == 'countInitialize')
|
|
70
|
-
skipEnum = (callableTarget == 'countSequential')
|
|
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)
|
|
73
|
-
codeUnpacked = unpackArrays(codeInlined, callableTarget)
|
|
74
|
-
pathFilenameDestination.write_text(importsRequired + "\n" + codeUnpacked)
|
|
75
|
-
listPathFilenamesDestination.append(pathFilenameDestination)
|
|
76
|
-
|
|
77
|
-
if __name__ == '__main__':
|
|
78
|
-
inlineMapFoldingNumba()
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
from mapFolding import indexMy, indexTrack
|
|
2
|
-
import numba
|
|
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)
|
|
4
|
-
def countInitialize(connectionGraph, gapsWhere, my, track):
|
|
5
|
-
while my[7] > 0:
|
|
6
|
-
if my[7] <= 1 or track[1, 0] == 1:
|
|
7
|
-
my[1] = my[0]
|
|
8
|
-
my[3] = track[3, my[7] - 1]
|
|
9
|
-
my[4] = 0
|
|
10
|
-
while my[4] < my[0]:
|
|
11
|
-
if connectionGraph[my[4], my[7], my[7]] == my[7]:
|
|
12
|
-
my[1] -= 1
|
|
13
|
-
else:
|
|
14
|
-
my[8] = connectionGraph[my[4], my[7], my[7]]
|
|
15
|
-
while my[8] != my[7]:
|
|
16
|
-
gapsWhere[my[3]] = my[8]
|
|
17
|
-
if track[2, my[8]] == 0:
|
|
18
|
-
my[3] += 1
|
|
19
|
-
track[2, my[8]] += 1
|
|
20
|
-
my[8] = connectionGraph[my[4], my[7], track[1, my[8]]]
|
|
21
|
-
my[4] += 1
|
|
22
|
-
if not my[1]:
|
|
23
|
-
my[5] = 0
|
|
24
|
-
while my[5] < my[7]:
|
|
25
|
-
gapsWhere[my[3]] = my[5]
|
|
26
|
-
my[3] += 1
|
|
27
|
-
my[5] += 1
|
|
28
|
-
my[6] = my[2]
|
|
29
|
-
while my[6] < my[3]:
|
|
30
|
-
gapsWhere[my[2]] = gapsWhere[my[6]]
|
|
31
|
-
if track[2, gapsWhere[my[6]]] == my[1]:
|
|
32
|
-
my[2] += 1
|
|
33
|
-
track[2, gapsWhere[my[6]]] = 0
|
|
34
|
-
my[6] += 1
|
|
35
|
-
if my[7] > 0:
|
|
36
|
-
my[2] -= 1
|
|
37
|
-
track[0, my[7]] = gapsWhere[my[2]]
|
|
38
|
-
track[1, my[7]] = track[1, track[0, my[7]]]
|
|
39
|
-
track[1, track[0, my[7]]] = my[7]
|
|
40
|
-
track[0, track[1, my[7]]] = my[7]
|
|
41
|
-
track[3, my[7]] = my[2]
|
|
42
|
-
my[7] += 1
|
|
43
|
-
if my[2] > 0:
|
|
44
|
-
return
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
from mapFolding import indexMy, indexTrack
|
|
2
|
-
import numba
|
|
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)
|
|
4
|
-
def countParallel(connectionGraph, foldGroups, gapsWherePARALLEL, myPARALLEL, trackPARALLEL):
|
|
5
|
-
for indexSherpa in numba.prange(myPARALLEL[9]):
|
|
6
|
-
gapsWhere = gapsWherePARALLEL.copy()
|
|
7
|
-
my = myPARALLEL.copy()
|
|
8
|
-
my[10] = indexSherpa
|
|
9
|
-
track = trackPARALLEL.copy()
|
|
10
|
-
groupsOfFolds: int = 0
|
|
11
|
-
while my[7] > 0:
|
|
12
|
-
if my[7] <= 1 or track[1, 0] == 1:
|
|
13
|
-
if my[7] > foldGroups[-1]:
|
|
14
|
-
groupsOfFolds = groupsOfFolds + 1
|
|
15
|
-
else:
|
|
16
|
-
my[1] = my[0]
|
|
17
|
-
my[3] = track[3, my[7] - 1]
|
|
18
|
-
my[4] = 0
|
|
19
|
-
while my[4] < my[0]:
|
|
20
|
-
if connectionGraph[my[4], my[7], my[7]] == my[7]:
|
|
21
|
-
my[1] -= 1
|
|
22
|
-
else:
|
|
23
|
-
my[8] = connectionGraph[my[4], my[7], my[7]]
|
|
24
|
-
while my[8] != my[7]:
|
|
25
|
-
if my[7] != my[9] or my[8] % my[9] == my[10]:
|
|
26
|
-
gapsWhere[my[3]] = my[8]
|
|
27
|
-
if track[2, my[8]] == 0:
|
|
28
|
-
my[3] += 1
|
|
29
|
-
track[2, my[8]] += 1
|
|
30
|
-
my[8] = connectionGraph[my[4], my[7], track[1, my[8]]]
|
|
31
|
-
my[4] += 1
|
|
32
|
-
my[6] = my[2]
|
|
33
|
-
while my[6] < my[3]:
|
|
34
|
-
gapsWhere[my[2]] = gapsWhere[my[6]]
|
|
35
|
-
if track[2, gapsWhere[my[6]]] == my[1]:
|
|
36
|
-
my[2] += 1
|
|
37
|
-
track[2, gapsWhere[my[6]]] = 0
|
|
38
|
-
my[6] += 1
|
|
39
|
-
while my[7] > 0 and my[2] == track[3, my[7] - 1]:
|
|
40
|
-
my[7] -= 1
|
|
41
|
-
track[1, track[0, my[7]]] = track[1, my[7]]
|
|
42
|
-
track[0, track[1, my[7]]] = track[0, my[7]]
|
|
43
|
-
if my[7] > 0:
|
|
44
|
-
my[2] -= 1
|
|
45
|
-
track[0, my[7]] = gapsWhere[my[2]]
|
|
46
|
-
track[1, my[7]] = track[1, track[0, my[7]]]
|
|
47
|
-
track[1, track[0, my[7]]] = my[7]
|
|
48
|
-
track[0, track[1, my[7]]] = my[7]
|
|
49
|
-
track[3, my[7]] = my[2]
|
|
50
|
-
my[7] += 1
|
|
51
|
-
foldGroups[my[10]] = groupsOfFolds
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|