mapFolding 0.12.0__py3-none-any.whl → 0.12.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mapFolding/__init__.py +42 -18
- mapFolding/_theSSOT.py +137 -0
- mapFolding/basecamp.py +28 -18
- mapFolding/beDRY.py +21 -19
- mapFolding/dataBaskets.py +170 -18
- mapFolding/datatypes.py +109 -1
- mapFolding/filesystemToolkit.py +38 -33
- mapFolding/oeis.py +209 -93
- mapFolding/someAssemblyRequired/RecipeJob.py +120 -9
- mapFolding/someAssemblyRequired/__init__.py +35 -38
- mapFolding/someAssemblyRequired/_toolIfThis.py +80 -18
- mapFolding/someAssemblyRequired/_toolkitContainers.py +123 -45
- mapFolding/someAssemblyRequired/infoBooth.py +37 -2
- mapFolding/someAssemblyRequired/makeAllModules.py +712 -0
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +111 -48
- mapFolding/someAssemblyRequired/toolkitNumba.py +171 -19
- mapFolding/someAssemblyRequired/transformationTools.py +93 -49
- mapfolding-0.12.2.dist-info/METADATA +167 -0
- mapfolding-0.12.2.dist-info/RECORD +53 -0
- {mapfolding-0.12.0.dist-info → mapfolding-0.12.2.dist-info}/WHEEL +1 -1
- tests/__init__.py +28 -44
- tests/conftest.py +66 -61
- tests/test_computations.py +39 -82
- tests/test_filesystem.py +25 -1
- tests/test_oeis.py +30 -1
- tests/test_other.py +27 -0
- tests/test_tasks.py +31 -1
- mapFolding/someAssemblyRequired/Z0Z_makeAllModules.py +0 -433
- mapFolding/theSSOT.py +0 -34
- mapfolding-0.12.0.dist-info/METADATA +0 -184
- mapfolding-0.12.0.dist-info/RECORD +0 -53
- {mapfolding-0.12.0.dist-info → mapfolding-0.12.2.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.12.0.dist-info → mapfolding-0.12.2.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.12.0.dist-info → mapfolding-0.12.2.dist-info}/top_level.txt +0 -0
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
"""
|
|
2
|
-
AST
|
|
3
|
-
|
|
4
|
-
This module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
Map folding AST transformation system: Core dataclass decomposition and function optimization tools.
|
|
3
|
+
|
|
4
|
+
This module implements the essential transformation capabilities that form the operational core of
|
|
5
|
+
the map folding AST transformation system. Working with the pattern recognition foundation and
|
|
6
|
+
decomposition containers established in the foundational layers, these tools execute the critical
|
|
7
|
+
transformations that convert dataclass-based functions into optimized implementations suitable
|
|
8
|
+
for Numba just-in-time compilation.
|
|
9
|
+
|
|
10
|
+
The transformation process addresses the fundamental incompatibility between dataclass-dependent
|
|
11
|
+
map folding algorithms and Numba's compilation requirements. While dataclass instances provide
|
|
12
|
+
clean, maintainable interfaces for complex mathematical state, Numba cannot directly process
|
|
13
|
+
these objects but excels at optimizing operations on primitive values and tuples. The tools
|
|
14
|
+
bridge this architectural gap through systematic function signature transformation and calling
|
|
15
|
+
convention adaptation.
|
|
16
|
+
|
|
17
|
+
The three-stage transformation pattern implemented here follows a precise sequence: dataclass
|
|
18
|
+
decomposition breaks down dataclass definitions into constituent AST components while extracting
|
|
19
|
+
field definitions and type annotations; function transformation converts functions accepting
|
|
20
|
+
dataclass parameters to functions accepting individual field parameters with updated signatures
|
|
21
|
+
and return types; caller adaptation modifies calling code to unpack dataclass instances, invoke
|
|
22
|
+
transformed functions, and repack results back into dataclass instances.
|
|
23
|
+
|
|
24
|
+
This approach enables seamless integration between high-level dataclass-based interfaces and
|
|
25
|
+
low-level optimized implementations, maintaining code clarity while achieving performance gains
|
|
26
|
+
through specialized compilation paths essential for computationally intensive map folding research.
|
|
19
27
|
"""
|
|
20
28
|
|
|
21
|
-
from astToolkit import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
IfThis,
|
|
25
|
-
ShatteredDataclass,
|
|
26
|
-
)
|
|
27
|
-
from astToolkit import(
|
|
28
|
-
Be,
|
|
29
|
-
extractClassDef,
|
|
30
|
-
IngredientsFunction,
|
|
31
|
-
Make,
|
|
32
|
-
NodeChanger,
|
|
33
|
-
parseLogicalPath2astModule,
|
|
34
|
-
str_nameDOTname,
|
|
35
|
-
Then,
|
|
29
|
+
from astToolkit import (
|
|
30
|
+
Be, ClassIsAndAttribute, extractClassDef, identifierDotAttribute, IngredientsFunction, Make,
|
|
31
|
+
NodeChanger, parseLogicalPath2astModule, Then,
|
|
36
32
|
)
|
|
37
33
|
from astToolkit.transformationTools import unparseFindReplace
|
|
34
|
+
from mapFolding.someAssemblyRequired import DeReConstructField2ast, IfThis, ShatteredDataclass
|
|
38
35
|
from Z0Z_tools import importLogicalPath2Callable
|
|
39
36
|
import ast
|
|
40
37
|
import dataclasses
|
|
41
38
|
|
|
42
|
-
def shatter_dataclassesDOTdataclass(logicalPathModule:
|
|
39
|
+
def shatter_dataclassesDOTdataclass(logicalPathModule: identifierDotAttribute, dataclassIdentifier: str, instanceIdentifier: str) -> ShatteredDataclass:
|
|
43
40
|
"""
|
|
44
41
|
Decompose a dataclass definition into AST components for manipulation and code generation.
|
|
45
42
|
|
|
@@ -59,8 +56,8 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
59
56
|
|
|
60
57
|
Parameters:
|
|
61
58
|
logicalPathModule: The fully qualified module path containing the dataclass definition.
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
dataclassIdentifier: The name of the dataclass to decompose.
|
|
60
|
+
instanceIdentifier: The variable name to use for the dataclass instance in generated code.
|
|
64
61
|
|
|
65
62
|
Returns:
|
|
66
63
|
shatteredDataclass: A ShatteredDataclass containing AST representations of all dataclass components,
|
|
@@ -72,20 +69,20 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
72
69
|
Official_fieldOrder: list[str] = []
|
|
73
70
|
dictionaryDeReConstruction: dict[str, DeReConstructField2ast] = {}
|
|
74
71
|
|
|
75
|
-
dataclassClassDef = extractClassDef(parseLogicalPath2astModule(logicalPathModule),
|
|
76
|
-
if not isinstance(dataclassClassDef, ast.ClassDef):
|
|
72
|
+
dataclassClassDef: ast.ClassDef | None = extractClassDef(parseLogicalPath2astModule(logicalPathModule), dataclassIdentifier)
|
|
73
|
+
if not isinstance(dataclassClassDef, ast.ClassDef):
|
|
74
|
+
raise ValueError(f"I could not find `{dataclassIdentifier = }` in `{logicalPathModule = }`.")
|
|
77
75
|
|
|
78
76
|
countingVariable = None
|
|
79
|
-
for aField in dataclasses.fields(importLogicalPath2Callable(logicalPathModule,
|
|
77
|
+
for aField in dataclasses.fields(importLogicalPath2Callable(logicalPathModule, dataclassIdentifier)): # pyright: ignore [reportArgumentType]
|
|
80
78
|
Official_fieldOrder.append(aField.name)
|
|
81
|
-
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(logicalPathModule, dataclassClassDef,
|
|
79
|
+
dictionaryDeReConstruction[aField.name] = DeReConstructField2ast(logicalPathModule, dataclassClassDef, instanceIdentifier, aField)
|
|
82
80
|
if aField.metadata.get('theCountingIdentifier', False):
|
|
83
81
|
countingVariable = dictionaryDeReConstruction[aField.name].name
|
|
84
|
-
|
|
85
82
|
if countingVariable is None:
|
|
86
|
-
import warnings
|
|
87
|
-
warnings.warn(message=f"I could not find the counting variable in `{
|
|
88
|
-
raise
|
|
83
|
+
# import warnings
|
|
84
|
+
# warnings.warn(message=f"I could not find the counting variable in `{dataclassIdentifier = }` in `{logicalPathModule = }`.", category=UserWarning)
|
|
85
|
+
raise ValueError(f"I could not find the counting variable in `{dataclassIdentifier = }` in `{logicalPathModule = }`.")
|
|
89
86
|
|
|
90
87
|
shatteredDataclass = ShatteredDataclass(
|
|
91
88
|
countingVariableAnnotation=dictionaryDeReConstruction[countingVariable].astAnnotation,
|
|
@@ -100,16 +97,38 @@ def shatter_dataclassesDOTdataclass(logicalPathModule: str_nameDOTname, dataclas
|
|
|
100
97
|
map_stateDOTfield2Name={dictionaryDeReConstruction[field].ast_nameDOTname: dictionaryDeReConstruction[field].astName for field in Official_fieldOrder},
|
|
101
98
|
)
|
|
102
99
|
shatteredDataclass.fragments4AssignmentOrParameters = Make.Tuple(shatteredDataclass.listName4Parameters, ast.Store())
|
|
103
|
-
shatteredDataclass.repack = Make.Assign([Make.Name(
|
|
100
|
+
shatteredDataclass.repack = Make.Assign([Make.Name(instanceIdentifier)], value=Make.Call(Make.Name(dataclassIdentifier), list_keyword=shatteredDataclass.list_keyword_field__field4init))
|
|
104
101
|
shatteredDataclass.signatureReturnAnnotation = Make.Subscript(Make.Name('tuple'), Make.Tuple(shatteredDataclass.listAnnotations))
|
|
105
102
|
|
|
106
103
|
shatteredDataclass.imports.update(*(dictionaryDeReConstruction[field].ledger for field in Official_fieldOrder))
|
|
107
|
-
shatteredDataclass.imports.addImportFrom_asStr(logicalPathModule,
|
|
104
|
+
shatteredDataclass.imports.addImportFrom_asStr(logicalPathModule, dataclassIdentifier)
|
|
108
105
|
|
|
109
106
|
return shatteredDataclass
|
|
110
107
|
|
|
111
108
|
def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
112
|
-
|
|
109
|
+
"""
|
|
110
|
+
Transform a function that operates on dataclass instances to work with individual field parameters.
|
|
111
|
+
|
|
112
|
+
This function performs the core transformation required for Numba compatibility by removing dataclass
|
|
113
|
+
dependencies from function signatures and implementations. It modifies the target function to:
|
|
114
|
+
|
|
115
|
+
1. Replace the single dataclass parameter with individual field parameters.
|
|
116
|
+
2. Update the return type annotation to return a tuple of field values.
|
|
117
|
+
3. Transform return statements to return the tuple of fields.
|
|
118
|
+
4. Replace all dataclass attribute access with direct field variable access.
|
|
119
|
+
|
|
120
|
+
This transformation is essential for creating Numba-compatible functions from dataclass-based
|
|
121
|
+
implementations, as Numba cannot handle dataclass instances directly but can efficiently
|
|
122
|
+
process individual primitive values and tuples.
|
|
123
|
+
|
|
124
|
+
Parameters:
|
|
125
|
+
ingredientsTarget: The function definition and its dependencies to be transformed.
|
|
126
|
+
shatteredDataclass: The decomposed dataclass components providing AST mappings and transformations.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
ingredientsTarget: The modified function ingredients with dataclass dependencies removed.
|
|
130
|
+
"""
|
|
131
|
+
ingredientsTarget.astFunctionDef.args = Make.arguments(list_arg=shatteredDataclass.list_argAnnotated4ArgumentsSpecification)
|
|
113
132
|
ingredientsTarget.astFunctionDef.returns = shatteredDataclass.signatureReturnAnnotation
|
|
114
133
|
changeReturnCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(shatteredDataclass.fragments4AssignmentOrParameters)))
|
|
115
134
|
changeReturnCallable.visit(ingredientsTarget.astFunctionDef)
|
|
@@ -117,10 +136,35 @@ def removeDataclassFromFunction(ingredientsTarget: IngredientsFunction, shattere
|
|
|
117
136
|
return ingredientsTarget
|
|
118
137
|
|
|
119
138
|
def unpackDataclassCallFunctionRepackDataclass(ingredientsCaller: IngredientsFunction, targetCallableIdentifier: str, shatteredDataclass: ShatteredDataclass) -> IngredientsFunction:
|
|
139
|
+
"""
|
|
140
|
+
Transform a caller function to interface with a dataclass-free target function.
|
|
141
|
+
|
|
142
|
+
This function complements `removeDataclassFromFunction` by modifying calling code to work with
|
|
143
|
+
the transformed target function. It implements the unpacking and repacking pattern required
|
|
144
|
+
when a dataclass-based caller needs to invoke a function that has been converted to accept
|
|
145
|
+
individual field parameters instead of dataclass instances.
|
|
146
|
+
|
|
147
|
+
The transformation creates a three-step pattern around the target function call:
|
|
148
|
+
1. Unpack the dataclass instance into individual field variables.
|
|
149
|
+
2. Call the target function with the unpacked field values.
|
|
150
|
+
3. Repack the returned field values back into a dataclass instance.
|
|
151
|
+
|
|
152
|
+
This enables seamless integration between dataclass-based high-level code and optimized
|
|
153
|
+
field-based implementations, maintaining the original interface while enabling performance
|
|
154
|
+
optimizations in the target function.
|
|
155
|
+
|
|
156
|
+
Parameters:
|
|
157
|
+
ingredientsCaller: The calling function definition and its dependencies to be transformed.
|
|
158
|
+
targetCallableIdentifier: The name of the target function being called.
|
|
159
|
+
shatteredDataclass: The decomposed dataclass components providing unpacking and repacking logic.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
ingredientsCaller: The modified caller function with appropriate unpacking and repacking around the target call.
|
|
163
|
+
"""
|
|
120
164
|
astCallTargetCallable = Make.Call(Make.Name(targetCallableIdentifier), shatteredDataclass.listName4Parameters)
|
|
121
|
-
replaceAssignTargetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.
|
|
122
|
-
unpack4targetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.
|
|
123
|
-
repack4targetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.
|
|
165
|
+
replaceAssignTargetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCallIdentifier(targetCallableIdentifier)), Then.replaceWith(Make.Assign([shatteredDataclass.fragments4AssignmentOrParameters], value=astCallTargetCallable)))
|
|
166
|
+
unpack4targetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCallIdentifier(targetCallableIdentifier)), Then.insertThisAbove(shatteredDataclass.listUnpack))
|
|
167
|
+
repack4targetCallable = NodeChanger(ClassIsAndAttribute.valueIs(ast.Assign, IfThis.isCallIdentifier(targetCallableIdentifier)), Then.insertThisBelow([shatteredDataclass.repack]))
|
|
124
168
|
replaceAssignTargetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
125
169
|
unpack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
126
170
|
repack4targetCallable.visit(ingredientsCaller.astFunctionDef)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapFolding
|
|
3
|
+
Version: 0.12.2
|
|
4
|
+
Summary: Map folding algorithm with code transformation framework for optimizing numerical computations
|
|
5
|
+
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
|
+
License: CC-BY-NC-4.0
|
|
7
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
8
|
+
Project-URL: Homepage, https://github.com/hunterhogan/mapFolding
|
|
9
|
+
Project-URL: Issues, https://github.com/hunterhogan/mapFolding/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/hunterhogan/mapFolding.git
|
|
11
|
+
Keywords: A000136,A001415,A001416,A001417,A001418,A195646,AST manipulation,Numba optimization,OEIS,algorithmic optimization,code generation,code transformation,combinatorics,computational geometry,dataclass transformation,folding pattern enumeration,just-in-time compilation,map folding,performance optimization,source code analysis,stamp folding
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
25
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
26
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: Z0Z_tools
|
|
33
|
+
Requires-Dist: astToolkit>=0.5.0
|
|
34
|
+
Requires-Dist: autoflake
|
|
35
|
+
Requires-Dist: numba
|
|
36
|
+
Requires-Dist: numba_progress
|
|
37
|
+
Requires-Dist: numpy
|
|
38
|
+
Requires-Dist: platformdirs
|
|
39
|
+
Requires-Dist: python_minifier
|
|
40
|
+
Requires-Dist: sympy
|
|
41
|
+
Requires-Dist: tomli
|
|
42
|
+
Provides-Extra: testing
|
|
43
|
+
Requires-Dist: mypy; extra == "testing"
|
|
44
|
+
Requires-Dist: pytest; extra == "testing"
|
|
45
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
46
|
+
Requires-Dist: pytest-env; extra == "testing"
|
|
47
|
+
Requires-Dist: pytest-xdist; extra == "testing"
|
|
48
|
+
Requires-Dist: pyupgrade; extra == "testing"
|
|
49
|
+
Requires-Dist: ruff; extra == "testing"
|
|
50
|
+
Requires-Dist: setuptools-scm; extra == "testing"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# mapFolding
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/mapFolding/)
|
|
56
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
|
|
57
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
58
|
+
|
|
59
|
+
A computational framework that starts with Lunnon's 1971 algorithm for counting distinct ways to fold maps and improves it. Plus there is a comprehensive AST transformation system for transforming algorithms for optimization and research.
|
|
60
|
+
|
|
61
|
+
(Yo, the rest is AI generated and I don't have the energy to proofread it. This package helped me compute two previously unknown values: I'm sure others can improve it.)
|
|
62
|
+
|
|
63
|
+
## The Mathematical Problem
|
|
64
|
+
|
|
65
|
+
Map folding is a combinatorial problem: given a rectangular grid of unit squares, how many distinct ways can you fold it? "Distinct" means that foldings producing identical final shapes are counted as one. This problem connects to combinatorial geometry, integer sequences, and computational complexity theory.
|
|
66
|
+
|
|
67
|
+
The calculations extend the Online Encyclopedia of Integer Sequences (OEIS):
|
|
68
|
+
|
|
69
|
+
- **A001415**: 2×n strips (computed through n=20 for the first time)
|
|
70
|
+
- **A001418**: n×n squares
|
|
71
|
+
- **A001416**: 3×n strips
|
|
72
|
+
- **A001417**: n-dimensional hypercubes
|
|
73
|
+
- **A195646**: 3×3×...×3 hypercubes
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from mapFolding import oeisIDfor_n
|
|
77
|
+
|
|
78
|
+
# How many ways can you fold a 2×4 strip?
|
|
79
|
+
foldsTotal = oeisIDfor_n('A001415', 4)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## The Computational Challenge
|
|
83
|
+
|
|
84
|
+
For larger maps, these calculations require hours or days to complete. A 2×20 strip requires processing leaves through billions of recursive operations. The package addresses this through systematic algorithm transformation: converting readable Python implementations into specialized, Numba-optimized modules that achieve order-of-magnitude performance improvements.
|
|
85
|
+
|
|
86
|
+
## What This Package Provides
|
|
87
|
+
|
|
88
|
+
### Core Functionality
|
|
89
|
+
|
|
90
|
+
- **Complete implementation** of Lunnon's recursive algorithm
|
|
91
|
+
- **Mathematical validation** through OEIS integration and caching
|
|
92
|
+
- **Type-safe computational state** management with automatic initialization
|
|
93
|
+
- **Result persistence** for long-running calculations
|
|
94
|
+
|
|
95
|
+
### Algorithm Transformation System
|
|
96
|
+
|
|
97
|
+
- **AST manipulation framework** for converting dataclass-based algorithms to optimized implementations
|
|
98
|
+
- **Automatic code generation** that produces standalone, highly optimized computation modules
|
|
99
|
+
- **Dataclass decomposition** to enable Numba compatibility while preserving readable source code
|
|
100
|
+
- **Comprehensive optimization** including dead code elimination, static value embedding, and aggressive compilation settings
|
|
101
|
+
|
|
102
|
+
### Educational Resources
|
|
103
|
+
|
|
104
|
+
- **Historical implementations** showing algorithm evolution from 1971 to present
|
|
105
|
+
- **Performance comparison** studies demonstrating optimization techniques
|
|
106
|
+
- **Complete test suite** with patterns for validating custom implementations
|
|
107
|
+
- **Reference documentation** for extending the transformation framework
|
|
108
|
+
|
|
109
|
+
## Use Cases
|
|
110
|
+
|
|
111
|
+
**Mathematical Research**: Explore folding pattern properties, extend known sequences, or validate theoretical results against computed values.
|
|
112
|
+
|
|
113
|
+
**Algorithm Optimization Learning**: Study a complete transformation pipeline that converts high-level algorithms into production-ready optimized code.
|
|
114
|
+
|
|
115
|
+
**Performance Computing Education**: Examine techniques for achieving maximum Python performance through Numba integration, AST manipulation, and specialized code generation.
|
|
116
|
+
|
|
117
|
+
**Combinatorial Problem Solving**: Use the framework as a template for optimizing other recursive combinatorial algorithms.
|
|
118
|
+
|
|
119
|
+
## Example Usage
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from mapFolding import countFolds
|
|
123
|
+
|
|
124
|
+
# Count folding patterns for a 3×3 square
|
|
125
|
+
result = countFolds([3, 3])
|
|
126
|
+
|
|
127
|
+
# Access OEIS sequences directly
|
|
128
|
+
from mapFolding import oeisIDfor_n
|
|
129
|
+
strip_foldings = oeisIDfor_n('A001415', 6) # 2×6 strip
|
|
130
|
+
|
|
131
|
+
# Generate optimized code for specific dimensions
|
|
132
|
+
from mapFolding.someAssemblyRequired import makeJobTheorem2Numba
|
|
133
|
+
# Creates specialized modules for maximum performance
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Repository Structure
|
|
137
|
+
|
|
138
|
+
- `mapFolding/`: Core implementation with modular architecture
|
|
139
|
+
- `reference/`: Historical algorithm implementations and performance studies
|
|
140
|
+
- `someAssemblyRequired/`: AST transformation framework
|
|
141
|
+
- `tests/`: Comprehensive validation suite
|
|
142
|
+
- `jobs/`: Generated optimized modules for specific calculations
|
|
143
|
+
|
|
144
|
+
## Performance Characteristics
|
|
145
|
+
|
|
146
|
+
- **Pure Python baseline**: Educational implementations for understanding
|
|
147
|
+
- **NumPy optimization**: ~10× improvement through vectorized operations
|
|
148
|
+
- **Numba compilation**: ~100× improvement through native code generation
|
|
149
|
+
- **Specialized modules**: ~1000× improvement through static optimization and embedded constants
|
|
150
|
+
|
|
151
|
+
Actual performance varies by map dimensions and available hardware.
|
|
152
|
+
|
|
153
|
+
## My recovery
|
|
154
|
+
|
|
155
|
+
[](https://HunterThinks.com/support)
|
|
156
|
+
[](https://www.youtube.com/@HunterHogan)
|
|
157
|
+
|
|
158
|
+
## How to code
|
|
159
|
+
|
|
160
|
+
Coding One Step at a Time:
|
|
161
|
+
|
|
162
|
+
0. WRITE CODE.
|
|
163
|
+
1. Don't write stupid code that's hard to revise.
|
|
164
|
+
2. Write good code.
|
|
165
|
+
3. When revising, write better code.
|
|
166
|
+
|
|
167
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
mapFolding/__init__.py,sha256=wXJ0dhpZUfiXPvh4RQ11FKDJEzV5OYUs8USKFaEXqQ0,3653
|
|
2
|
+
mapFolding/_theSSOT.py,sha256=JNoyZ86gym5z0DS2kruidDJ3zdYAShuqnCLJ85t2TVM,6168
|
|
3
|
+
mapFolding/basecamp.py,sha256=6jLA_41BB86CJD6E3vLr-SV0BiGEfwzcfeOLgujlyZM,9008
|
|
4
|
+
mapFolding/beDRY.py,sha256=S0HO2bX8afDR6mV0xyIsEGBeG4-pRC3YH9jMAWSHpCM,13891
|
|
5
|
+
mapFolding/daoOfMapFolding.py,sha256=ncTIiBfTsM8SNVx9qefZ0bBcBtviWLSk4iPv3Z9nGiE,5442
|
|
6
|
+
mapFolding/dataBaskets.py,sha256=oO9f0PUf3AdNguaKEYnBpk31VhK8NPFMK5GiBSDVFIw,13101
|
|
7
|
+
mapFolding/datatypes.py,sha256=5BLjUv5S6A_0Q23erRGIN8MMm2WD3BVKnH2gfEdZlcs,5189
|
|
8
|
+
mapFolding/filesystemToolkit.py,sha256=ACiNUE7L5MKjllBbUVvzdgYdILXGiOVyl81fDGPwaNc,10254
|
|
9
|
+
mapFolding/oeis.py,sha256=hf3AgQOiFf2Gs0WbS3JYIVNgfPfVlp0T0ZLDvfvi4Lg,21978
|
|
10
|
+
mapFolding/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
mapFolding/reference/__init__.py,sha256=GKcSgYE49NcTISx-JZbELXyq-eRkMeTL5g4DXInWFw0,2206
|
|
12
|
+
mapFolding/reference/flattened.py,sha256=QK1xG9SllqCoi68e86Hyl9d9ATUAAFNpTQI-3zmcp5I,16072
|
|
13
|
+
mapFolding/reference/hunterNumba.py,sha256=iLfyqwGdAh6c5GbapnKsWhAsNsR3O-fyGGHAdohluLw,7258
|
|
14
|
+
mapFolding/reference/irvineJavaPort.py,sha256=UEfIX4QbPLl5jnyfYIyX5YRR3_rYvPUikK8jLehsFko,4076
|
|
15
|
+
mapFolding/reference/jaxCount.py,sha256=TuDNKOnyhQfuixKmIxO9Algv7dvy7KMGhgsV3h96FGE,14853
|
|
16
|
+
mapFolding/reference/lunnonNumpy.py,sha256=mMgrgbrBpe4nmo72ThEI-MGH0OwEHmfMPczSXHp2qKo,4357
|
|
17
|
+
mapFolding/reference/lunnonWhile.py,sha256=ZL8GAQtPs5nJZSgoDl5USrLSS_zs03y98y1Z9E4jOmQ,3799
|
|
18
|
+
mapFolding/reference/rotatedEntryPoint.py,sha256=5ughpKUT2JQhoAKgoDUdYNjgWQYPGV8v-7dWEAdDmfE,10274
|
|
19
|
+
mapFolding/reference/total_countPlus1vsPlusN.py,sha256=yJZAVLVdoXqHag2_N6_6CT-Q6HXBgRro-eny93-Rlpw,9307
|
|
20
|
+
mapFolding/reference/jobsCompleted/__init__.py,sha256=TU93ZGUW1xEkT6d9mQFn_rp5DvRy0ZslEB2Q6MF5ZDc,2596
|
|
21
|
+
mapFolding/reference/jobsCompleted/[2x19]/p2x19.py,sha256=_tvYtfzMWVo2VtUbIAieoscb4N8FFflgTdW4-ljBUuA,19626
|
|
22
|
+
mapFolding/reference/jobsCompleted/p2x19/p2x19.py,sha256=eZEw4Me4ocTt6VXoK2-Sbd5SowZtxRIbN9dZmc7OCVg,6395
|
|
23
|
+
mapFolding/someAssemblyRequired/RecipeJob.py,sha256=kFn27dMWg1k5q5RsU2kw5zXT3TRmUzYHE9EIUdAGvfM,10641
|
|
24
|
+
mapFolding/someAssemblyRequired/__init__.py,sha256=F3MMU6QciBqL8G4cjn_ELCHEnpjytorUQn-vG9t696Q,5769
|
|
25
|
+
mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=mqIZQ_HLkR-5z3_gIghIeQ_WY1XkjVHp9iC1TrPiI9Y,5923
|
|
26
|
+
mapFolding/someAssemblyRequired/_toolkitContainers.py,sha256=ZAwfH6yRunUzSVzl2VZDvJD7lyN7WL6Md7F6Q7suW30,13682
|
|
27
|
+
mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=9RPU6vK_eUg64GtVFI_nZnvUryXw8gfHJs9NyDYHIvg,2745
|
|
28
|
+
mapFolding/someAssemblyRequired/infoBooth.py,sha256=GWiqnHbqk7te_pvVuk4G_gbFa_W2aeSx19w4pakvqfM,2300
|
|
29
|
+
mapFolding/someAssemblyRequired/makeAllModules.py,sha256=RC4FmWyue2reiPttfLEtc7kFGYgp7dR4qBHnOREuYpo,42770
|
|
30
|
+
mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=658vw0JZk-9dMIE_18Op8xY1vxwoLc2K-TQaslGtw58,18372
|
|
31
|
+
mapFolding/someAssemblyRequired/toolkitNumba.py,sha256=nHLkGZ9P0p3NJkiqJFTxej9z0H1BvWWvmSN27rTExqU,14563
|
|
32
|
+
mapFolding/someAssemblyRequired/transformationTools.py,sha256=gveR9Gqgo3JJhMXtHIFTyu0RbgwoTkH-5X7dwiA4jpM,11476
|
|
33
|
+
mapFolding/syntheticModules/__init__.py,sha256=evVFqhCGa-WZKDiLcnQWjs-Bj34eRnfSLqz_d7dFYZY,83
|
|
34
|
+
mapFolding/syntheticModules/countParallel.py,sha256=OK_IB9w4yy9MMAiGvkei5ezPm_00v2nYjPrQZ_IlELg,7733
|
|
35
|
+
mapFolding/syntheticModules/daoOfMapFolding.py,sha256=cfWPABtXyCxJ0BwPI7rhfLh_2UYV_XKAL8lJ4GLNXaQ,5896
|
|
36
|
+
mapFolding/syntheticModules/dataPacking.py,sha256=m_eOZ7sMXIQ9jY5EvC3qgitQTY60n6rksy0ACMJOIC8,2292
|
|
37
|
+
mapFolding/syntheticModules/initializeCount.py,sha256=nWSlJMMfIM3DvZxMn6ISQusUJqRYAjKQyLF5hwLEdBQ,3119
|
|
38
|
+
mapFolding/syntheticModules/theorem2.py,sha256=9jrbZNNX4BWYZW1S0JjvRY2k7RU7I1RNUMV7JdCt1ZY,3017
|
|
39
|
+
mapFolding/syntheticModules/theorem2Numba.py,sha256=-cKjNyxgUMFhEyFVs0VJ7hw4LfrV0WSNK5tPYbQ1oNU,3369
|
|
40
|
+
mapFolding/syntheticModules/theorem2Trimmed.py,sha256=DHW3NxBdtABQYBKm2WRvfQ5kzc2_UwGI2h4ePuYEJoM,2685
|
|
41
|
+
mapfolding-0.12.2.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
|
|
42
|
+
tests/__init__.py,sha256=5RdiZYAl8nPIM1sxB_D0CsN6J8173LOZ0hpR3geTHAU,1312
|
|
43
|
+
tests/conftest.py,sha256=eBo0IIm98402hl_XW5nT06cUvW25ciItv1_zZdM152E,11126
|
|
44
|
+
tests/test_computations.py,sha256=NDOT1kUdY2w-hbxdGhUsr4N4yFjwJW30AnfrDiYYKM0,5184
|
|
45
|
+
tests/test_filesystem.py,sha256=IXTeyfifXe6vLizCo8BiSn5Yx9DEKYEc_hoJRKhQFNk,3899
|
|
46
|
+
tests/test_oeis.py,sha256=KjG10lH5vVLPG5bicdsVt373QeMrHirFJUpO1BR_sos,6272
|
|
47
|
+
tests/test_other.py,sha256=a42U3KB5IlrQNj63nRyg-KLdvF1QTH2aAsH9JpQnl3Q,4933
|
|
48
|
+
tests/test_tasks.py,sha256=-OrpXAlkPMP4pRCW-wAYPd_olf3L_a9dMsJZCOlSUNE,4041
|
|
49
|
+
mapfolding-0.12.2.dist-info/METADATA,sha256=6URs4ApQHjsH3bN7QniWEvCBioRrz0y0h6q9qI6YI28,7977
|
|
50
|
+
mapfolding-0.12.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
51
|
+
mapfolding-0.12.2.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
52
|
+
mapfolding-0.12.2.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
|
|
53
|
+
mapfolding-0.12.2.dist-info/RECORD,,
|
tests/__init__.py
CHANGED
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### For Custom Recipes (RecipeSynthesizeFlow):
|
|
31
|
-
Copy and adapt the `syntheticDispatcherFixture` and associated tests from
|
|
32
|
-
`test_computations.py` to validate your customized code transformation assembly lines.
|
|
33
|
-
|
|
34
|
-
### For Custom Jobs (RecipeJob):
|
|
35
|
-
Copy and adapt the `test_writeJobNumba` function to test specialized job modules
|
|
36
|
-
for specific map shapes with your custom configurations.
|
|
37
|
-
|
|
38
|
-
The entire test infrastructure is built on fixtures and utilities that handle
|
|
39
|
-
complex setup and validation, allowing you to focus on your implementation details
|
|
40
|
-
while leveraging the existing validation framework.
|
|
41
|
-
|
|
42
|
-
See the module docstrings in `test_computations.py` and `conftest.py` for detailed
|
|
43
|
-
guidance on adapting these tests for your own purposes.
|
|
44
|
-
"""
|
|
1
|
+
"""Test suite for the mapFolding package.
|
|
2
|
+
|
|
3
|
+
This test suite provides comprehensive validation of map folding computations,
|
|
4
|
+
file system operations, OEIS integration, task division, and foundational
|
|
5
|
+
utilities. The tests are designed to support multiple audiences and use cases.
|
|
6
|
+
|
|
7
|
+
Test Module Organization:
|
|
8
|
+
- conftest.py: Testing infrastructure and shared fixtures
|
|
9
|
+
- test_computations.py: Core mathematical validation and algorithm testing
|
|
10
|
+
- test_filesystem.py: File operations and path management
|
|
11
|
+
- test_oeis.py: OEIS sequence integration and caching
|
|
12
|
+
- test_other.py: Foundational utilities and data validation
|
|
13
|
+
- test_tasks.py: Task division and work distribution
|
|
14
|
+
|
|
15
|
+
For Contributors:
|
|
16
|
+
The test suite follows Domain-Driven Design principles, organizing tests around
|
|
17
|
+
mathematical concepts rather than implementation details. Use the existing
|
|
18
|
+
patterns as templates when adding new functionality.
|
|
19
|
+
|
|
20
|
+
For Users Adding Custom Modules:
|
|
21
|
+
The test_computations.py module provides the most relevant examples for testing
|
|
22
|
+
custom computational approaches. The standardized testing functions in conftest.py
|
|
23
|
+
ensure consistent error reporting across all tests.
|
|
24
|
+
|
|
25
|
+
For AI Assistants:
|
|
26
|
+
The testing framework emphasizes readable, predictable patterns that maintain
|
|
27
|
+
mathematical correctness while supporting code evolution and optimization.
|
|
28
|
+
"""
|