mapFolding 0.3.4__tar.gz → 0.3.6__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.4 → mapfolding-0.3.6}/PKG-INFO +3 -2
- mapfolding-0.3.6/mapFolding/citations/updateCitation.py +116 -0
- mapfolding-0.3.6/mapFolding/citations/updateCitationgpt.py +125 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/PKG-INFO +3 -2
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/SOURCES.txt +4 -3
- mapfolding-0.3.6/mapFolding/someAssemblyRequired/__init__.py +1 -0
- mapfolding-0.3.6/mapFolding/someAssemblyRequired/makeJob.py +34 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/someAssemblyRequired/synthesizeModuleJob.py +26 -39
- mapfolding-0.3.6/mapFolding/someAssemblyRequired/synthesizeModules.py +216 -0
- mapfolding-0.3.4/mapFolding/syntheticModules/countInitialize.py → mapfolding-0.3.6/mapFolding/syntheticModules/Initialize.py +6 -5
- mapfolding-0.3.4/mapFolding/syntheticModules/countParallel.py → mapfolding-0.3.6/mapFolding/syntheticModules/Parallel.py +6 -5
- mapfolding-0.3.4/mapFolding/syntheticModules/countSequential.py → mapfolding-0.3.6/mapFolding/syntheticModules/Sequential.py +16 -15
- mapfolding-0.3.6/mapFolding/syntheticModules/__init__.py +4 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/pyproject.toml +4 -3
- mapfolding-0.3.4/mapFolding/citations/updateCitation.py +0 -67
- mapfolding-0.3.4/mapFolding/someAssemblyRequired/__init__.py +0 -2
- mapfolding-0.3.4/mapFolding/someAssemblyRequired/makeJob.py +0 -21
- mapfolding-0.3.4/mapFolding/someAssemblyRequired/synthesizeModules.py +0 -170
- mapfolding-0.3.4/mapFolding/syntheticModules/__init__.py +0 -3
- {mapfolding-0.3.4 → mapfolding-0.3.6}/README.md +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/benchmarks/benchmarking.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/dependency_links.txt +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/entry_points.txt +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/requires.txt +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/mapFolding.egg-info/top_level.txt +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/flattened.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/hunterNumba.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/irvineJavaPort.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/jax.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/lunnan.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/lunnanNumpy.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/lunnanWhile.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/rotatedEntryPoint.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/someAssemblyRequired/generalizeSourceCode.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/setup.cfg +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/tests/test_oeis.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/tests/test_other.py +0 -0
- {mapfolding-0.3.4 → mapfolding-0.3.6}/tests/test_tasks.py +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.6
|
|
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
|
|
7
|
-
Project-URL:
|
|
7
|
+
Project-URL: homepage, https://github.com/hunterhogan/mapFolding
|
|
8
8
|
Project-URL: Donate, https://www.patreon.com/integrated
|
|
9
|
+
Project-URL: repository, https://github.com/hunterhogan/mapFolding.git
|
|
9
10
|
Keywords: A001415,A001416,A001417,A001418,A195646,folding,map folding,OEIS,stamp folding
|
|
10
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
12
|
Classifier: Environment :: Console
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from cffconvert.cli.create_citation import create_citation
|
|
2
|
+
from cffconvert.cli.validate_or_write_output import validate_or_write_output
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
import cffconvert
|
|
5
|
+
import pathlib
|
|
6
|
+
import packaging.metadata
|
|
7
|
+
import tomli
|
|
8
|
+
import inspect
|
|
9
|
+
import json
|
|
10
|
+
import ruamel.yaml
|
|
11
|
+
import packaging
|
|
12
|
+
from packaging.metadata import Metadata as PyPAMetadata
|
|
13
|
+
import packaging.utils
|
|
14
|
+
import packaging.version
|
|
15
|
+
|
|
16
|
+
def addPypaMetadata(citation: cffconvert.Citation, metadata: PyPAMetadata) -> cffconvert.Citation:
|
|
17
|
+
# https://github.com/citation-file-format/cff-initializer-javascript
|
|
18
|
+
"""
|
|
19
|
+
keywords: pathFilenamePackageSSOT; packaging.metadata.Metadata.keywords
|
|
20
|
+
license: pathFilenamePackageSSOT; packaging.metadata.Metadata.license_expression
|
|
21
|
+
title: pathFilenamePackageSSOT; packaging.metadata.Metadata.name
|
|
22
|
+
url: pathFilenamePackageSSOT; packaging.metadata.Metadata.project_urls: homepage
|
|
23
|
+
repository: pathFilenamePackageSSOT; packaging.metadata.Metadata.project_urls: repository
|
|
24
|
+
version: pathFilenamePackageSSOT; packaging.metadata.Metadata.version
|
|
25
|
+
"""
|
|
26
|
+
return citation
|
|
27
|
+
|
|
28
|
+
def getPypaMetadata(packageData: Dict[str, Any]) -> PyPAMetadata:
|
|
29
|
+
# https://packaging.python.org/en/latest/specifications/core-metadata/
|
|
30
|
+
dictionaryProjectURLs = {}
|
|
31
|
+
for urlKey, urlValue in packageData.get('urls', {}).items():
|
|
32
|
+
if urlKey.lower() in ('homepage', 'repository'):
|
|
33
|
+
dictionaryProjectURLs[urlKey] = urlValue
|
|
34
|
+
|
|
35
|
+
metadataRaw = packaging.metadata.RawMetadata(
|
|
36
|
+
keywords=packageData.get('keywords', []),
|
|
37
|
+
license_expression=packageData.get('license', {}).get('text', ''),
|
|
38
|
+
metadata_version='2.4',
|
|
39
|
+
name=packaging.utils.canonicalize_name(packageData.get('name', None), validate=True),
|
|
40
|
+
project_urls=dictionaryProjectURLs,
|
|
41
|
+
version=packageData.get('version', None),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
metadata = PyPAMetadata().from_raw(metadataRaw)
|
|
45
|
+
return metadata
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
Tentative plan:
|
|
49
|
+
- Commit and push to GitHub
|
|
50
|
+
- GitHub Action gathers information from the sources of truth
|
|
51
|
+
- If the citation needs to be updated, write to both
|
|
52
|
+
- pathFilenameCitationSSOT
|
|
53
|
+
- pathFilenameCitationDOTcffRepo
|
|
54
|
+
- Commit and push to GitHub
|
|
55
|
+
- this complicates things
|
|
56
|
+
- I want the updated citation to be in the `commit` field of itself
|
|
57
|
+
"""
|
|
58
|
+
"""cffconvert.Citation fields and the source of truth
|
|
59
|
+
abstract: pathFilenameCitationSSOT
|
|
60
|
+
authors: pathFilenamePackageSSOT
|
|
61
|
+
cff-version: pathFilenameCitationSSOT
|
|
62
|
+
commit: workflows['Make GitHub Release']
|
|
63
|
+
contact: pathFilenamePackageSSOT
|
|
64
|
+
date-released: workflows['Make GitHub Release']
|
|
65
|
+
doi: pathFilenameCitationSSOT
|
|
66
|
+
identifiers: workflows['Make GitHub Release']
|
|
67
|
+
license-url: pathFilenamePackageSSOT
|
|
68
|
+
message: pathFilenameCitationSSOT
|
|
69
|
+
preferred-citation: pathFilenameCitationSSOT
|
|
70
|
+
references: to be determined
|
|
71
|
+
repository-artifact: (https://pypi.org/pypi/{package_name}/json').json()['releases']
|
|
72
|
+
repository-code: workflows['Make GitHub Release']
|
|
73
|
+
type: pathFilenameCitationSSOT
|
|
74
|
+
|
|
75
|
+
keywords: pathFilenamePackageSSOT; packaging.metadata.Metadata.keywords
|
|
76
|
+
license: pathFilenamePackageSSOT; packaging.metadata.Metadata.license_expression
|
|
77
|
+
title: pathFilenamePackageSSOT; packaging.metadata.Metadata.name
|
|
78
|
+
url: pathFilenamePackageSSOT; packaging.metadata.Metadata.project_urls: homepage
|
|
79
|
+
repository: pathFilenamePackageSSOT; packaging.metadata.Metadata.project_urls: repository
|
|
80
|
+
version: pathFilenamePackageSSOT; packaging.metadata.Metadata.version
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
def logistics():
|
|
84
|
+
# Prefer reliable, dynamic values over hardcoded ones
|
|
85
|
+
packageName: str = 'mapFolding'
|
|
86
|
+
pathRepoRoot = pathlib.Path(__file__).parent.parent.parent
|
|
87
|
+
pathFilenamePackageSSOT = pathRepoRoot / 'pyproject.toml'
|
|
88
|
+
filenameGitHubAction = 'updateCitation.yml'
|
|
89
|
+
pathFilenameGitHubAction = pathRepoRoot / '.github' / 'workflows' / filenameGitHubAction
|
|
90
|
+
|
|
91
|
+
filenameCitationDOTcff = 'CITATION.cff'
|
|
92
|
+
pathCitations = pathRepoRoot / packageName / 'citations'
|
|
93
|
+
pathFilenameCitationSSOT = pathCitations / filenameCitationDOTcff
|
|
94
|
+
pathFilenameCitationDOTcffRepo = pathRepoRoot / filenameCitationDOTcff
|
|
95
|
+
|
|
96
|
+
citationObject: cffconvert.Citation = create_citation(infile=pathFilenameCitationSSOT, url=None)
|
|
97
|
+
print(citationObject._parse().as_cff())
|
|
98
|
+
|
|
99
|
+
tomlPackageData: Dict[str, Any] = tomli.loads(pathFilenamePackageSSOT.read_text())['project']
|
|
100
|
+
# https://packaging.python.org/en/latest/specifications/pyproject-toml/
|
|
101
|
+
pypaMetadata: PyPAMetadata = getPypaMetadata(tomlPackageData)
|
|
102
|
+
|
|
103
|
+
validate_or_write_output(outfile=pathFilenameCitationSSOT, outputformat='cff', validate_only=False, citation=citationObject)
|
|
104
|
+
validate_or_write_output(outfile=pathFilenameCitationDOTcffRepo, outputformat='cff', validate_only=False, citation=citationObject)
|
|
105
|
+
|
|
106
|
+
if __name__ == '__main__':
|
|
107
|
+
logistics()
|
|
108
|
+
|
|
109
|
+
# print(f"{pypaMetadata.name=}, {pypaMetadata.version=}, {pypaMetadata.keywords=}, {pypaMetadata.license_expression=}, {pypaMetadata.project_urls=}")
|
|
110
|
+
# path_cffconvert = pathlib.Path(inspect.getfile(cffconvert)).parent
|
|
111
|
+
# pathFilenameSchema = path_cffconvert / "schemas/1.2.0/schema.json"
|
|
112
|
+
# scheme: Dict[str, Any] = json.loads(pathFilenameSchema.read_text())
|
|
113
|
+
# schemaSpecifications: Dict[str, Any] = scheme['properties']
|
|
114
|
+
|
|
115
|
+
# for property, subProperties in schemaSpecifications.items():
|
|
116
|
+
# print(property, subProperties.get('items', None))
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from cffconvert.cli.create_citation import create_citation
|
|
2
|
+
from cffconvert.cli.validate_or_write_output import validate_or_write_output
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
import cffconvert
|
|
5
|
+
import pathlib
|
|
6
|
+
import packaging.metadata
|
|
7
|
+
import tomli
|
|
8
|
+
import ruamel.yaml
|
|
9
|
+
import packaging
|
|
10
|
+
from packaging.metadata import Metadata as PyPAMetadata
|
|
11
|
+
import packaging.utils
|
|
12
|
+
import packaging.version
|
|
13
|
+
|
|
14
|
+
def addPypaMetadata(citation: cffconvert.Citation, metadata: PyPAMetadata) -> cffconvert.Citation:
|
|
15
|
+
"""
|
|
16
|
+
Map the PyPA metadata to the citation's internal representation.
|
|
17
|
+
|
|
18
|
+
Mapping:
|
|
19
|
+
- title: metadata.name
|
|
20
|
+
- version: metadata.version (converted to string)
|
|
21
|
+
- keywords: metadata.keywords
|
|
22
|
+
- license: metadata.license_expression
|
|
23
|
+
- url: from project URLs (homepage)
|
|
24
|
+
- repository: from project URLs (repository)
|
|
25
|
+
"""
|
|
26
|
+
# Access the internal dictionary (used for conversion)
|
|
27
|
+
citationData: Dict[str, Any] = citation._cffobj
|
|
28
|
+
|
|
29
|
+
# Update title from PyPA metadata name
|
|
30
|
+
if metadata.name:
|
|
31
|
+
citationData["title"] = metadata.name
|
|
32
|
+
|
|
33
|
+
# Update version from PyPA metadata version
|
|
34
|
+
if metadata.version:
|
|
35
|
+
citationData["version"] = str(metadata.version)
|
|
36
|
+
|
|
37
|
+
# Update keywords from PyPA metadata keywords
|
|
38
|
+
if metadata.keywords:
|
|
39
|
+
citationData["keywords"] = metadata.keywords
|
|
40
|
+
|
|
41
|
+
# Update license from PyPA metadata license_expression
|
|
42
|
+
if metadata.license_expression:
|
|
43
|
+
citationData["license"] = metadata.license_expression
|
|
44
|
+
|
|
45
|
+
# Retrieve the project URLs that were attached in getPypaMetadata
|
|
46
|
+
projectURLs: Dict[str, str] = getattr(metadata, "_project_urls", {})
|
|
47
|
+
|
|
48
|
+
# Update the homepage URL
|
|
49
|
+
if "homepage" in projectURLs:
|
|
50
|
+
citationData["url"] = projectURLs["homepage"]
|
|
51
|
+
|
|
52
|
+
# Update the repository URL
|
|
53
|
+
if "repository" in projectURLs:
|
|
54
|
+
citationData["repository"] = projectURLs["repository"]
|
|
55
|
+
|
|
56
|
+
return citation
|
|
57
|
+
|
|
58
|
+
def getPypaMetadata(packageData: Dict[str, Any]) -> PyPAMetadata:
|
|
59
|
+
"""
|
|
60
|
+
Create a PyPA metadata object (version 2.4) from packageData.
|
|
61
|
+
|
|
62
|
+
Mapping for project URLs:
|
|
63
|
+
- 'homepage' and 'repository' are accepted from packageData['urls'].
|
|
64
|
+
"""
|
|
65
|
+
dictionaryProjectURLs: Dict[str, str] = {}
|
|
66
|
+
for urlKey, urlValue in packageData.get("urls", {}).items():
|
|
67
|
+
lowerUrlKey = urlKey.lower()
|
|
68
|
+
if lowerUrlKey in ("homepage", "repository"):
|
|
69
|
+
dictionaryProjectURLs[lowerUrlKey] = urlValue
|
|
70
|
+
|
|
71
|
+
metadataRaw = packaging.metadata.RawMetadata(
|
|
72
|
+
keywords=packageData.get("keywords", []),
|
|
73
|
+
license_expression=packageData.get("license", {}).get("text", ""),
|
|
74
|
+
metadata_version="2.4",
|
|
75
|
+
name=packaging.utils.canonicalize_name(packageData.get("name", None), validate=True),
|
|
76
|
+
project_urls=dictionaryProjectURLs,
|
|
77
|
+
version=packageData.get("version", None),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
metadata = PyPAMetadata().from_raw(metadataRaw)
|
|
81
|
+
# Attach the project URLs dictionary so it can be used later.
|
|
82
|
+
setattr(metadata, "_project_urls", dictionaryProjectURLs)
|
|
83
|
+
return metadata
|
|
84
|
+
|
|
85
|
+
def logistics():
|
|
86
|
+
# Determine paths from your SSOT.
|
|
87
|
+
packageName: str = "mapFolding"
|
|
88
|
+
pathRepoRoot = pathlib.Path(__file__).parent.parent.parent
|
|
89
|
+
pathFilenamePackageSSOT = pathRepoRoot / "pyproject.toml"
|
|
90
|
+
filenameGitHubAction = "updateCitation.yml"
|
|
91
|
+
pathFilenameGitHubAction = pathRepoRoot / ".github" / "workflows" / filenameGitHubAction
|
|
92
|
+
|
|
93
|
+
filenameCitationDOTcff = "CITATION.cff"
|
|
94
|
+
pathCitations = pathRepoRoot / packageName / "citations"
|
|
95
|
+
pathFilenameCitationSSOT = pathCitations / filenameCitationDOTcff
|
|
96
|
+
pathFilenameCitationDOTcffRepo = pathRepoRoot / filenameCitationDOTcff
|
|
97
|
+
|
|
98
|
+
# Create a citation object from the SSOT citation file.
|
|
99
|
+
citationObject: cffconvert.Citation = create_citation(infile=pathFilenameCitationSSOT, url=None)
|
|
100
|
+
# Print the current citation in CFF format (for debugging) using the as_cff method.
|
|
101
|
+
print(citationObject.as_cff())
|
|
102
|
+
|
|
103
|
+
# Load package metadata from pyproject.toml.
|
|
104
|
+
tomlPackageData: Dict[str, Any] = tomli.loads(pathFilenamePackageSSOT.read_text())["project"]
|
|
105
|
+
pypaMetadata: PyPAMetadata = getPypaMetadata(tomlPackageData)
|
|
106
|
+
|
|
107
|
+
# Map the PyPA metadata into the citation's internal representation.
|
|
108
|
+
citationObject = addPypaMetadata(citation=citationObject, metadata=pypaMetadata)
|
|
109
|
+
|
|
110
|
+
# Validate and write out the updated citation file in both locations.
|
|
111
|
+
# validate_or_write_output(
|
|
112
|
+
# outfile=pathFilenameCitationSSOT,
|
|
113
|
+
# outputformat="cff",
|
|
114
|
+
# validate_only=False,
|
|
115
|
+
# citation=citationObject,
|
|
116
|
+
# )
|
|
117
|
+
validate_or_write_output(
|
|
118
|
+
outfile=pathFilenameCitationDOTcffRepo,
|
|
119
|
+
outputformat="cff",
|
|
120
|
+
validate_only=False,
|
|
121
|
+
citation=citationObject,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
logistics()
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.6
|
|
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
|
|
7
|
-
Project-URL:
|
|
7
|
+
Project-URL: homepage, https://github.com/hunterhogan/mapFolding
|
|
8
8
|
Project-URL: Donate, https://www.patreon.com/integrated
|
|
9
|
+
Project-URL: repository, https://github.com/hunterhogan/mapFolding.git
|
|
9
10
|
Keywords: A001415,A001416,A001417,A001418,A195646,folding,map folding,OEIS,stamp folding
|
|
10
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
11
12
|
Classifier: Environment :: Console
|
|
@@ -2,6 +2,7 @@ README.md
|
|
|
2
2
|
pyproject.toml
|
|
3
3
|
mapFolding/benchmarks/benchmarking.py
|
|
4
4
|
mapFolding/citations/updateCitation.py
|
|
5
|
+
mapFolding/citations/updateCitationgpt.py
|
|
5
6
|
mapFolding/mapFolding.egg-info/PKG-INFO
|
|
6
7
|
mapFolding/mapFolding.egg-info/SOURCES.txt
|
|
7
8
|
mapFolding/mapFolding.egg-info/dependency_links.txt
|
|
@@ -23,10 +24,10 @@ mapFolding/someAssemblyRequired/getLLVMforNoReason.py
|
|
|
23
24
|
mapFolding/someAssemblyRequired/makeJob.py
|
|
24
25
|
mapFolding/someAssemblyRequired/synthesizeModuleJob.py
|
|
25
26
|
mapFolding/someAssemblyRequired/synthesizeModules.py
|
|
27
|
+
mapFolding/syntheticModules/Initialize.py
|
|
28
|
+
mapFolding/syntheticModules/Parallel.py
|
|
29
|
+
mapFolding/syntheticModules/Sequential.py
|
|
26
30
|
mapFolding/syntheticModules/__init__.py
|
|
27
|
-
mapFolding/syntheticModules/countInitialize.py
|
|
28
|
-
mapFolding/syntheticModules/countParallel.py
|
|
29
|
-
mapFolding/syntheticModules/countSequential.py
|
|
30
31
|
tests/test_oeis.py
|
|
31
32
|
tests/test_other.py
|
|
32
33
|
tests/test_tasks.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .makeJob import makeStateJob
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from mapFolding import getPathFilenameFoldsTotal, computationState
|
|
2
|
+
from mapFolding import outfitCountFolds
|
|
3
|
+
from typing import Any, Literal, Optional, Sequence, Type, overload
|
|
4
|
+
import pathlib
|
|
5
|
+
import pickle
|
|
6
|
+
|
|
7
|
+
@overload
|
|
8
|
+
def makeStateJob(listDimensions: Sequence[int], writeJob: Literal[True] = True
|
|
9
|
+
, **keywordArguments: Optional[Type[Any]]) -> pathlib.Path:
|
|
10
|
+
...
|
|
11
|
+
|
|
12
|
+
@overload
|
|
13
|
+
def makeStateJob(listDimensions: Sequence[int], writeJob: Literal[False] = False
|
|
14
|
+
, **keywordArguments: Optional[Type[Any]]) -> computationState:
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
def makeStateJob(listDimensions: Sequence[int], writeJob: bool = True, **keywordArguments: Optional[Type[Any]]) -> computationState | pathlib.Path:
|
|
18
|
+
|
|
19
|
+
stateUniversal: computationState = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
20
|
+
|
|
21
|
+
from mapFolding.syntheticModules import countInitialize
|
|
22
|
+
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
23
|
+
|
|
24
|
+
if not writeJob:
|
|
25
|
+
return stateUniversal
|
|
26
|
+
|
|
27
|
+
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
28
|
+
suffix = pathFilenameChopChop.suffix
|
|
29
|
+
pathJob = pathlib.Path(str(pathFilenameChopChop)[0:-len(suffix)])
|
|
30
|
+
pathJob.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
pathFilenameJob = pathJob / 'stateJob.pkl'
|
|
32
|
+
|
|
33
|
+
pathFilenameJob.write_bytes(pickle.dumps(stateUniversal))
|
|
34
|
+
return pathFilenameJob
|
{mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/someAssemblyRequired/synthesizeModuleJob.py
RENAMED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
from mapFolding import getPathFilenameFoldsTotal
|
|
1
|
+
from mapFolding import getPathFilenameFoldsTotal, indexMy, indexTrack
|
|
2
2
|
from mapFolding import make_dtype, datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT, datatypeModuleDEFAULT
|
|
3
|
-
from mapFolding import computationState
|
|
4
3
|
from someAssemblyRequired import makeStateJob
|
|
5
4
|
from typing import Optional
|
|
6
|
-
import more_itertools
|
|
7
|
-
import inspect
|
|
8
5
|
import importlib
|
|
9
6
|
import importlib.util
|
|
7
|
+
import inspect
|
|
8
|
+
import more_itertools
|
|
10
9
|
import numpy
|
|
11
10
|
import pathlib
|
|
12
|
-
import pickle
|
|
13
11
|
import python_minifier
|
|
14
12
|
|
|
15
13
|
identifierCallableLaunch = "goGoGadgetAbsurdity"
|
|
@@ -52,33 +50,15 @@ def writeModuleWithNumba(listDimensions, **keywordArguments: Optional[str]) -> p
|
|
|
52
50
|
dtypeMedium = make_dtype(datatypeMedium, datatypeModule) # type: ignore
|
|
53
51
|
dtypeSmall = make_dtype(datatypeSmall, datatypeModule) # type: ignore
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(stateJob['mapShape'], pathFilenameJob.parent)
|
|
53
|
+
stateJob = makeStateJob(listDimensions, writeJob=False, dtypeLarge = dtypeLarge, dtypeMedium = dtypeMedium, dtypeSmall = dtypeSmall)
|
|
54
|
+
pathFilenameFoldsTotal = getPathFilenameFoldsTotal(stateJob['mapShape'])
|
|
58
55
|
|
|
59
56
|
from syntheticModules import countSequential
|
|
60
57
|
algorithmSource = countSequential
|
|
61
58
|
codeSource = inspect.getsource(algorithmSource)
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
cache=True, \
|
|
66
|
-
nopython=True, \
|
|
67
|
-
fastmath=True, \
|
|
68
|
-
forceinline=True, \
|
|
69
|
-
inline='always', \
|
|
70
|
-
looplift=False, \
|
|
71
|
-
_nrt=True, \
|
|
72
|
-
error_model='numpy', \
|
|
73
|
-
parallel=False, \
|
|
74
|
-
boundscheck=False, \
|
|
75
|
-
no_cfunc_wrapper=False, \
|
|
76
|
-
no_cpython_wrapper=False, \
|
|
77
|
-
"
|
|
78
|
-
# no_cfunc_wrapper=True, \
|
|
79
|
-
# no_cpython_wrapper=True, \
|
|
80
|
-
|
|
81
|
-
lineNumba = f"@numba.jit({parametersNumba})"
|
|
60
|
+
if datatypeLarge:
|
|
61
|
+
lineNumba = f"@numba.jit(numba.types.{datatypeLarge}(), cache=True, nopython=True, fastmath=True, forceinline=True, inline='always', looplift=False, _nrt=True, error_model='numpy', parallel=False, boundscheck=False, no_cfunc_wrapper=True, no_cpython_wrapper=False)"
|
|
82
62
|
|
|
83
63
|
linesImport = "\n".join([
|
|
84
64
|
"import numpy"
|
|
@@ -88,8 +68,8 @@ no_cpython_wrapper=False, \
|
|
|
88
68
|
ImaIndent = ' '
|
|
89
69
|
linesDataDynamic = """"""
|
|
90
70
|
linesDataDynamic = "\n".join([linesDataDynamic
|
|
91
|
-
, ImaIndent + f"foldsTotal = numba.types.{datatypeLarge}(0)"
|
|
92
|
-
, ImaIndent + makeStrRLEcompacted(stateJob['foldGroups'], 'foldGroups')
|
|
71
|
+
# , ImaIndent + f"foldsTotal = numba.types.{datatypeLarge}(0)"
|
|
72
|
+
# , ImaIndent + makeStrRLEcompacted(stateJob['foldGroups'], 'foldGroups')
|
|
93
73
|
, ImaIndent + makeStrRLEcompacted(stateJob['gapsWhere'], 'gapsWhere')
|
|
94
74
|
])
|
|
95
75
|
|
|
@@ -112,14 +92,22 @@ no_cpython_wrapper=False, \
|
|
|
112
92
|
, linesDataDynamic
|
|
113
93
|
, linesDataStatic
|
|
114
94
|
])
|
|
95
|
+
elif 'taskIndex' in lineSource:
|
|
96
|
+
continue
|
|
115
97
|
elif 'my[indexMy.' in lineSource:
|
|
98
|
+
if 'dimensionsTotal' in lineSource:
|
|
99
|
+
continue
|
|
116
100
|
# leaf1ndex = my[indexMy.leaf1ndex.value]
|
|
117
101
|
identifier, statement = lineSource.split('=')
|
|
118
|
-
lineSource = ImaIndent + identifier.strip() +
|
|
102
|
+
lineSource = ImaIndent + identifier.strip() + f"=numba.types.{datatypeSmall}({str(eval(statement.strip()))})"
|
|
119
103
|
elif 'track[indexTrack.' in lineSource:
|
|
120
104
|
# leafAbove = track[indexTrack.leafAbove.value]
|
|
121
105
|
identifier, statement = lineSource.split('=')
|
|
122
106
|
lineSource = ImaIndent + makeStrRLEcompacted(eval(statement.strip()), identifier.strip())
|
|
107
|
+
elif 'foldGroups[-1]' in lineSource:
|
|
108
|
+
lineSource = lineSource.replace('foldGroups[-1]', str(stateJob['foldGroups'][-1]))
|
|
109
|
+
elif 'dimensionsTotal' in lineSource:
|
|
110
|
+
lineSource = lineSource.replace('dimensionsTotal', str(stateJob['my'][indexMy.dimensionsTotal]))
|
|
123
111
|
|
|
124
112
|
linesAlgorithm = "\n".join([linesAlgorithm
|
|
125
113
|
, lineSource
|
|
@@ -135,11 +123,11 @@ if __name__ == '__main__':
|
|
|
135
123
|
|
|
136
124
|
linesWriteFoldsTotal = """"""
|
|
137
125
|
linesWriteFoldsTotal = "\n".join([linesWriteFoldsTotal
|
|
138
|
-
, "
|
|
139
|
-
, " print(
|
|
126
|
+
, f" groupsOfFolds *= {str(stateJob['foldGroups'][-1])}"
|
|
127
|
+
, " print(groupsOfFolds)"
|
|
140
128
|
, " with numba.objmode():"
|
|
141
|
-
, f" open('{pathFilenameFoldsTotal.as_posix()}', 'w').write(str(
|
|
142
|
-
, " return
|
|
129
|
+
, f" open('{pathFilenameFoldsTotal.as_posix()}', 'w').write(str(groupsOfFolds))"
|
|
130
|
+
, " return groupsOfFolds"
|
|
143
131
|
])
|
|
144
132
|
|
|
145
133
|
linesAll = "\n".join([
|
|
@@ -149,7 +137,7 @@ if __name__ == '__main__':
|
|
|
149
137
|
, linesLaunch
|
|
150
138
|
])
|
|
151
139
|
|
|
152
|
-
pathFilenameDestination =
|
|
140
|
+
pathFilenameDestination = pathFilenameFoldsTotal.with_suffix(".py")
|
|
153
141
|
pathFilenameDestination.write_text(linesAll)
|
|
154
142
|
|
|
155
143
|
return pathFilenameDestination
|
|
@@ -160,11 +148,10 @@ if __name__ == '__main__':
|
|
|
160
148
|
datatypeMedium = 'uint8'
|
|
161
149
|
datatypeSmall = datatypeMedium
|
|
162
150
|
pathFilenameModule = writeModuleWithNumba(listDimensions, datatypeLarge=datatypeLarge, datatypeMedium=datatypeMedium, datatypeSmall=datatypeSmall)
|
|
151
|
+
|
|
163
152
|
# Induce numba.jit compilation
|
|
164
153
|
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}")
|
|
154
|
+
if moduleSpec is None: raise ImportError(f"Could not load module specification from {pathFilenameModule}")
|
|
167
155
|
module = importlib.util.module_from_spec(moduleSpec)
|
|
168
|
-
if moduleSpec.loader is None:
|
|
169
|
-
raise ImportError(f"Could not load module from {moduleSpec}")
|
|
156
|
+
if moduleSpec.loader is None: raise ImportError(f"Could not load module from {moduleSpec}")
|
|
170
157
|
moduleSpec.loader.exec_module(module)
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
from mapFolding import indexMy, indexTrack, getAlgorithmSource, ParametersNumba, parametersNumbaDEFAULT, hackSSOTdtype
|
|
2
|
+
from mapFolding import datatypeLargeDEFAULT, datatypeMediumDEFAULT, datatypeSmallDEFAULT, EnumIndices
|
|
3
|
+
import pathlib
|
|
4
|
+
import inspect
|
|
5
|
+
import numpy
|
|
6
|
+
import numba
|
|
7
|
+
from typing import Dict, Optional, List, Union, Sequence, Type, cast
|
|
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]) -> ast.FunctionDef:
|
|
50
|
+
def makeNumbaParameterSignatureElement(signatureElement: ast.arg):
|
|
51
|
+
if isinstance(signatureElement.annotation, ast.Subscript) and isinstance(signatureElement.annotation.slice, ast.Tuple):
|
|
52
|
+
annotationShape = signatureElement.annotation.slice.elts[0]
|
|
53
|
+
if isinstance(annotationShape, ast.Subscript) and isinstance(annotationShape.slice, ast.Tuple):
|
|
54
|
+
shapeAsListSlices: Sequence[ast.expr] = [ast.Slice() for axis in range(len(annotationShape.slice.elts))]
|
|
55
|
+
shapeAsListSlices[-1] = ast.Slice(step=ast.Constant(value=1))
|
|
56
|
+
shapeAST = ast.Tuple(elts=list(shapeAsListSlices), ctx=ast.Load())
|
|
57
|
+
else:
|
|
58
|
+
shapeAST = ast.Slice(step=ast.Constant(value=1))
|
|
59
|
+
|
|
60
|
+
annotationDtype = signatureElement.annotation.slice.elts[1]
|
|
61
|
+
if (isinstance(annotationDtype, ast.Subscript) and isinstance(annotationDtype.slice, ast.Attribute)):
|
|
62
|
+
datatypeAST = annotationDtype.slice.attr
|
|
63
|
+
else:
|
|
64
|
+
datatypeAST = None
|
|
65
|
+
|
|
66
|
+
ndarrayName = signatureElement.arg
|
|
67
|
+
Z0Z_hackyStr = hackSSOTdtype[ndarrayName]
|
|
68
|
+
Z0Z_hackyStr = Z0Z_hackyStr[0] + 'ata' + Z0Z_hackyStr[1:]
|
|
69
|
+
datatype_attr = keywordArguments.get(Z0Z_hackyStr, None) or datatypeAST or eval(Z0Z_hackyStr+'DEFAULT')
|
|
70
|
+
|
|
71
|
+
datatypeNumba = ast.Attribute(value=ast.Name(id='numba', ctx=ast.Load()), attr=datatype_attr, ctx=ast.Load())
|
|
72
|
+
|
|
73
|
+
return ast.Subscript(value=datatypeNumba, slice=shapeAST, ctx=ast.Load())
|
|
74
|
+
|
|
75
|
+
# callableSourceDecorators = [decorator for decorator in callableInlined.decorator_list]
|
|
76
|
+
|
|
77
|
+
listNumbaParameterSignature: Sequence[ast.expr] = []
|
|
78
|
+
for parameter in astCallable.args.args:
|
|
79
|
+
signatureElement = makeNumbaParameterSignatureElement(parameter)
|
|
80
|
+
if (signatureElement):
|
|
81
|
+
listNumbaParameterSignature.append(signatureElement)
|
|
82
|
+
|
|
83
|
+
astArgsNumbaSignature = ast.Tuple(elts=listNumbaParameterSignature, ctx=ast.Load())
|
|
84
|
+
|
|
85
|
+
if astCallable.name == 'countInitialize':
|
|
86
|
+
parametersNumba = {}
|
|
87
|
+
else:
|
|
88
|
+
parametersNumba = parametersNumbaDEFAULT if not parallel else ParametersNumba({**parametersNumbaDEFAULT, 'parallel': True})
|
|
89
|
+
listKeywordsNumbaSignature = [ast.keyword(arg=parameterName, value=ast.Constant(value=parameterValue)) for parameterName, parameterValue in parametersNumba.items()]
|
|
90
|
+
|
|
91
|
+
astDecoratorNumba = ast.Call(func=ast.Attribute(value=ast.Name(id='numba', ctx=ast.Load()), attr='jit', ctx=ast.Load()), args=[astArgsNumbaSignature], keywords=listKeywordsNumbaSignature)
|
|
92
|
+
|
|
93
|
+
astCallable.decorator_list = [astDecoratorNumba]
|
|
94
|
+
return astCallable
|
|
95
|
+
|
|
96
|
+
class UnpackArrayAccesses(ast.NodeTransformer):
|
|
97
|
+
"""AST transformer that replaces array accesses with simpler variables."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, enumIndexClass: Type[EnumIndices], arrayName: str):
|
|
100
|
+
self.enumIndexClass = enumIndexClass
|
|
101
|
+
self.arrayName = arrayName
|
|
102
|
+
self.substitutions = {}
|
|
103
|
+
|
|
104
|
+
def extract_member_name(self, node: ast.AST) -> Optional[str]:
|
|
105
|
+
"""Recursively extract enum member name from any node in the AST."""
|
|
106
|
+
if isinstance(node, ast.Attribute) and node.attr == 'value':
|
|
107
|
+
innerAttribute = node.value
|
|
108
|
+
while isinstance(innerAttribute, ast.Attribute):
|
|
109
|
+
if (isinstance(innerAttribute.value, ast.Name) and innerAttribute.value.id == self.enumIndexClass.__name__):
|
|
110
|
+
return innerAttribute.attr
|
|
111
|
+
innerAttribute = innerAttribute.value
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
def transform_slice_element(self, node: ast.AST) -> ast.AST:
|
|
115
|
+
"""Transform any enum references within a slice element."""
|
|
116
|
+
if isinstance(node, ast.Subscript):
|
|
117
|
+
if isinstance(node.slice, ast.Attribute):
|
|
118
|
+
member_name = self.extract_member_name(node.slice)
|
|
119
|
+
if member_name:
|
|
120
|
+
return ast.Name(id=member_name, ctx=node.ctx)
|
|
121
|
+
elif isinstance(node, ast.Tuple):
|
|
122
|
+
# Handle tuple slices by transforming each element
|
|
123
|
+
return ast.Tuple(elts=cast(List[ast.expr], [self.transform_slice_element(elt) for elt in node.elts]), ctx=node.ctx)
|
|
124
|
+
elif isinstance(node, ast.Attribute):
|
|
125
|
+
member_name = self.extract_member_name(node)
|
|
126
|
+
if member_name:
|
|
127
|
+
return ast.Name(id=member_name, ctx=ast.Load())
|
|
128
|
+
return node
|
|
129
|
+
|
|
130
|
+
def visit_Subscript(self, node: ast.Subscript) -> ast.AST:
|
|
131
|
+
# Recursively visit any nested subscripts in value or slice
|
|
132
|
+
node.value = self.visit(node.value)
|
|
133
|
+
node.slice = self.visit(node.slice)
|
|
134
|
+
# If node.value is not our arrayName, just return node
|
|
135
|
+
if not (isinstance(node.value, ast.Name) and node.value.id == self.arrayName):
|
|
136
|
+
return node
|
|
137
|
+
|
|
138
|
+
# Handle scalar array access
|
|
139
|
+
if isinstance(node.slice, ast.Attribute):
|
|
140
|
+
memberName = self.extract_member_name(node.slice)
|
|
141
|
+
if memberName:
|
|
142
|
+
self.substitutions[memberName] = ('scalar', node)
|
|
143
|
+
return ast.Name(id=memberName, ctx=ast.Load())
|
|
144
|
+
|
|
145
|
+
# Handle array slice access
|
|
146
|
+
if isinstance(node.slice, ast.Tuple) and node.slice.elts:
|
|
147
|
+
firstElement = node.slice.elts[0]
|
|
148
|
+
memberName = self.extract_member_name(firstElement)
|
|
149
|
+
sliceRemainder = [self.visit(elem) for elem in node.slice.elts[1:]]
|
|
150
|
+
if memberName:
|
|
151
|
+
self.substitutions[memberName] = ('array', node)
|
|
152
|
+
if len(sliceRemainder) == 0:
|
|
153
|
+
return ast.Name(id=memberName, ctx=ast.Load())
|
|
154
|
+
return ast.Subscript(value=ast.Name(id=memberName, ctx=ast.Load()), slice=ast.Tuple(elts=sliceRemainder, ctx=ast.Load()) if len(sliceRemainder) > 1 else sliceRemainder[0], ctx=ast.Load())
|
|
155
|
+
|
|
156
|
+
# If single-element tuple, unwrap
|
|
157
|
+
if isinstance(node.slice, ast.Tuple) and len(node.slice.elts) == 1:
|
|
158
|
+
node.slice = node.slice.elts[0]
|
|
159
|
+
|
|
160
|
+
return node
|
|
161
|
+
|
|
162
|
+
def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef:
|
|
163
|
+
node = cast(ast.FunctionDef, self.generic_visit(node))
|
|
164
|
+
|
|
165
|
+
initializations = []
|
|
166
|
+
for name, (kind, original_node) in self.substitutions.items():
|
|
167
|
+
if kind == 'scalar':
|
|
168
|
+
initializations.append(ast.Assign(targets=[ast.Name(id=name, ctx=ast.Store())], value=original_node))
|
|
169
|
+
else: # array
|
|
170
|
+
initializations.append(
|
|
171
|
+
ast.Assign(
|
|
172
|
+
targets=[ast.Name(id=name, ctx=ast.Store())],
|
|
173
|
+
value=ast.Subscript(value=ast.Name(id=self.arrayName, ctx=ast.Load()),
|
|
174
|
+
slice=ast.Attribute(value=ast.Attribute(
|
|
175
|
+
value=ast.Name(id=self.enumIndexClass.__name__, ctx=ast.Load()),
|
|
176
|
+
attr=name, ctx=ast.Load()), attr='value', ctx=ast.Load()), ctx=ast.Load())))
|
|
177
|
+
|
|
178
|
+
node.body = initializations + node.body
|
|
179
|
+
return node
|
|
180
|
+
|
|
181
|
+
def inlineMapFoldingNumba(**keywordArguments: Optional[str]):
|
|
182
|
+
codeSource = inspect.getsource(algorithmSource)
|
|
183
|
+
pathFilenameAlgorithm = pathlib.Path(inspect.getfile(algorithmSource))
|
|
184
|
+
|
|
185
|
+
listPathFilenamesDestination: list[pathlib.Path] = []
|
|
186
|
+
listCallables = [ 'countInitialize', 'countParallel', 'countSequential', ]
|
|
187
|
+
for callableTarget in listCallables:
|
|
188
|
+
codeParsed: ast.Module = ast.parse(codeSource, type_comments=True)
|
|
189
|
+
codeSourceImportStatements = {statement for statement in codeParsed.body if isinstance(statement, (ast.Import, ast.ImportFrom))}
|
|
190
|
+
dictionaryFunctions = {statement.name: statement for statement in codeParsed.body if isinstance(statement, ast.FunctionDef)}
|
|
191
|
+
callableInlinerWorkhorse = RecursiveInliner(dictionaryFunctions)
|
|
192
|
+
parallel = callableTarget == 'countParallel'
|
|
193
|
+
callableInlined = callableInlinerWorkhorse.inlineFunctionBody(callableTarget)
|
|
194
|
+
if callableInlined:
|
|
195
|
+
ast.fix_missing_locations(callableInlined)
|
|
196
|
+
callableDecorated = decorateCallableWithNumba(callableInlined, parallel, **keywordArguments)
|
|
197
|
+
|
|
198
|
+
if callableTarget == 'countSequential':
|
|
199
|
+
myUnpacker = UnpackArrayAccesses(indexMy, 'my')
|
|
200
|
+
callableDecorated = cast(ast.FunctionDef, myUnpacker.visit(callableDecorated))
|
|
201
|
+
ast.fix_missing_locations(callableDecorated)
|
|
202
|
+
|
|
203
|
+
trackUnpacker = UnpackArrayAccesses(indexTrack, 'track')
|
|
204
|
+
callableDecorated = cast(ast.FunctionDef, trackUnpacker.visit(callableDecorated))
|
|
205
|
+
ast.fix_missing_locations(callableDecorated)
|
|
206
|
+
|
|
207
|
+
moduleAST = ast.Module(body=cast(List[ast.stmt], list(codeSourceImportStatements) + [callableDecorated]), type_ignores=[])
|
|
208
|
+
ast.fix_missing_locations(moduleAST)
|
|
209
|
+
moduleSource = ast.unparse(moduleAST)
|
|
210
|
+
|
|
211
|
+
pathFilenameDestination = pathFilenameAlgorithm.parent / "syntheticModules" / pathFilenameAlgorithm.with_stem(callableTarget).name[5:None]
|
|
212
|
+
pathFilenameDestination.write_text(moduleSource)
|
|
213
|
+
listPathFilenamesDestination.append(pathFilenameDestination)
|
|
214
|
+
|
|
215
|
+
if __name__ == '__main__':
|
|
216
|
+
inlineMapFoldingNumba()
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
from numpy import integer
|
|
2
1
|
import numba
|
|
3
|
-
import
|
|
2
|
+
from numpy import integer
|
|
4
3
|
from mapFolding import indexMy, indexTrack
|
|
4
|
+
import numpy
|
|
5
5
|
from typing import Any, Tuple
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
@numba.jit((numba.uint8[:, :, ::1], numba.uint8[::1], numba.uint8[::1], numba.uint8[:, ::1]))
|
|
7
8
|
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]
|
|
9
|
+
while my[indexMy.leaf1ndex.value]:
|
|
9
10
|
if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
|
|
10
11
|
my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
|
|
11
12
|
my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
|
|
@@ -35,7 +36,7 @@ def countInitialize(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.d
|
|
|
35
36
|
my[indexMy.gap1ndex.value] += 1
|
|
36
37
|
track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
|
|
37
38
|
my[indexMy.indexMiniGap.value] += 1
|
|
38
|
-
if my[indexMy.leaf1ndex.value]
|
|
39
|
+
if my[indexMy.leaf1ndex.value]:
|
|
39
40
|
my[indexMy.gap1ndex.value] -= 1
|
|
40
41
|
track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
|
|
41
42
|
track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
|
|
@@ -3,18 +3,19 @@ from typing import Any, Tuple
|
|
|
3
3
|
import numba
|
|
4
4
|
from mapFolding import indexMy, indexTrack
|
|
5
5
|
import numpy
|
|
6
|
+
|
|
6
7
|
@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
8
|
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
9
|
for indexSherpa in numba.prange(myPARALLEL[indexMy.taskDivisions.value]):
|
|
10
|
+
groupsOfFolds = numba.types.int64(0)
|
|
9
11
|
gapsWhere = gapsWherePARALLEL.copy()
|
|
10
12
|
my = myPARALLEL.copy()
|
|
11
13
|
my[indexMy.taskIndex.value] = indexSherpa
|
|
12
14
|
track = trackPARALLEL.copy()
|
|
13
|
-
|
|
14
|
-
while my[indexMy.leaf1ndex.value] > 0:
|
|
15
|
+
while my[indexMy.leaf1ndex.value]:
|
|
15
16
|
if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
|
|
16
17
|
if my[indexMy.leaf1ndex.value] > foldGroups[-1]:
|
|
17
|
-
groupsOfFolds
|
|
18
|
+
groupsOfFolds += 1
|
|
18
19
|
else:
|
|
19
20
|
my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
|
|
20
21
|
my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
|
|
@@ -39,11 +40,11 @@ def countParallel(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.dty
|
|
|
39
40
|
my[indexMy.gap1ndex.value] += 1
|
|
40
41
|
track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
|
|
41
42
|
my[indexMy.indexMiniGap.value] += 1
|
|
42
|
-
while my[indexMy.leaf1ndex.value]
|
|
43
|
+
while my[indexMy.leaf1ndex.value] and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]:
|
|
43
44
|
my[indexMy.leaf1ndex.value] -= 1
|
|
44
45
|
track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
|
|
45
46
|
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]
|
|
47
|
+
if my[indexMy.leaf1ndex.value]:
|
|
47
48
|
my[indexMy.gap1ndex.value] -= 1
|
|
48
49
|
track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
|
|
49
50
|
track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
from numpy import integer
|
|
2
|
-
from typing import Any, Tuple
|
|
3
2
|
import numba
|
|
3
|
+
from typing import Any, Tuple
|
|
4
4
|
from mapFolding import indexMy, indexTrack
|
|
5
5
|
import numpy
|
|
6
|
+
|
|
6
7
|
@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
8
|
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]]]):
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
leafBelow = track[indexTrack.leafBelow.value]
|
|
10
|
+
gapRangeStart = track[indexTrack.gapRangeStart.value]
|
|
11
|
+
countDimensionsGapped = track[indexTrack.countDimensionsGapped.value]
|
|
12
|
+
leafAbove = track[indexTrack.leafAbove.value]
|
|
13
|
+
leaf1ndex = my[indexMy.leaf1ndex.value]
|
|
10
14
|
dimensionsUnconstrained = my[indexMy.dimensionsUnconstrained.value]
|
|
11
|
-
|
|
15
|
+
dimensionsTotal = my[indexMy.dimensionsTotal.value]
|
|
12
16
|
gap1ndexCeiling = my[indexMy.gap1ndexCeiling.value]
|
|
13
17
|
indexDimension = my[indexMy.indexDimension.value]
|
|
14
|
-
indexMiniGap = my[indexMy.indexMiniGap.value]
|
|
15
|
-
leaf1ndex = my[indexMy.leaf1ndex.value]
|
|
16
18
|
leafConnectee = my[indexMy.leafConnectee.value]
|
|
19
|
+
indexMiniGap = my[indexMy.indexMiniGap.value]
|
|
20
|
+
gap1ndex = my[indexMy.gap1ndex.value]
|
|
17
21
|
taskIndex = my[indexMy.taskIndex.value]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
gapRangeStart = track[indexTrack.gapRangeStart.value]
|
|
22
|
-
groupsOfFolds: int = 0
|
|
23
|
-
while leaf1ndex > 0:
|
|
22
|
+
groupsOfFolds = numba.types.int64(0)
|
|
23
|
+
doFindGaps = True
|
|
24
|
+
while leaf1ndex:
|
|
24
25
|
if (doFindGaps := (leaf1ndex <= 1 or leafBelow[0] == 1)) and leaf1ndex > foldGroups[-1]:
|
|
25
|
-
groupsOfFolds
|
|
26
|
+
groupsOfFolds += 1
|
|
26
27
|
elif doFindGaps:
|
|
27
28
|
dimensionsUnconstrained = dimensionsTotal
|
|
28
29
|
gap1ndexCeiling = gapRangeStart[leaf1ndex - 1]
|
|
@@ -46,11 +47,11 @@ def countSequential(connectionGraph: numpy.ndarray[Tuple[int, int, int], numpy.d
|
|
|
46
47
|
gap1ndex += 1
|
|
47
48
|
countDimensionsGapped[gapsWhere[indexMiniGap]] = 0
|
|
48
49
|
indexMiniGap += 1
|
|
49
|
-
while leaf1ndex
|
|
50
|
+
while leaf1ndex and gap1ndex == gapRangeStart[leaf1ndex - 1]:
|
|
50
51
|
leaf1ndex -= 1
|
|
51
52
|
leafBelow[leafAbove[leaf1ndex]] = leafBelow[leaf1ndex]
|
|
52
53
|
leafAbove[leafBelow[leaf1ndex]] = leafAbove[leaf1ndex]
|
|
53
|
-
if leaf1ndex
|
|
54
|
+
if leaf1ndex:
|
|
54
55
|
gap1ndex -= 1
|
|
55
56
|
leafAbove[leaf1ndex] = gapsWhere[gap1ndex]
|
|
56
57
|
leafBelow[leaf1ndex] = leafBelow[leafAbove[leaf1ndex]]
|
|
@@ -28,7 +28,8 @@ keywords = [
|
|
|
28
28
|
"map folding",
|
|
29
29
|
"OEIS",
|
|
30
30
|
"stamp folding",]
|
|
31
|
-
license = { text = "CC-BY-NC-4.0" }
|
|
31
|
+
license = { 'text' = "CC-BY-NC-4.0" }
|
|
32
|
+
maintainers = []
|
|
32
33
|
name = "mapFolding"
|
|
33
34
|
optional-dependencies = { benchmark = [
|
|
34
35
|
"ipywidgets",
|
|
@@ -47,8 +48,8 @@ optional-dependencies = { benchmark = [
|
|
|
47
48
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
48
49
|
requires-python = ">=3.10,<3.14"
|
|
49
50
|
scripts = { getOEISids = "mapFolding.oeis:getOEISids", clearOEIScache = "mapFolding.oeis:clearOEIScache", OEIS_for_n = "mapFolding.oeis:OEIS_for_n" }
|
|
50
|
-
urls = {
|
|
51
|
-
version = "0.3.
|
|
51
|
+
urls = { homepage = "https://github.com/hunterhogan/mapFolding", Donate = "https://www.patreon.com/integrated", repository = "https://github.com/hunterhogan/mapFolding.git" }
|
|
52
|
+
version = "0.3.6"
|
|
52
53
|
|
|
53
54
|
[tool.coverage]
|
|
54
55
|
report = { exclude_lines = [
|
|
@@ -1,67 +0,0 @@
|
|
|
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,21 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=None, CPUlimit=None, **keywordArguments)
|
|
10
|
-
|
|
11
|
-
from syntheticModules import countInitialize
|
|
12
|
-
countInitialize(stateUniversal['connectionGraph'], stateUniversal['gapsWhere'], stateUniversal['my'], stateUniversal['track'])
|
|
13
|
-
|
|
14
|
-
pathFilenameChopChop = getPathFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
15
|
-
suffix = pathFilenameChopChop.suffix
|
|
16
|
-
pathJob = pathlib.Path(str(pathFilenameChopChop)[0:-len(suffix)])
|
|
17
|
-
pathJob.mkdir(parents=True, exist_ok=True)
|
|
18
|
-
pathFilenameJob = pathJob / 'stateJob.pkl'
|
|
19
|
-
|
|
20
|
-
pathFilenameJob.write_bytes(pickle.dumps(stateUniversal))
|
|
21
|
-
return pathFilenameJob
|
|
@@ -1,170 +0,0 @@
|
|
|
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()
|
|
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
|
{mapfolding-0.3.4 → mapfolding-0.3.6}/mapFolding/someAssemblyRequired/generalizeSourceCode.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|