mapFolding 0.8.6__tar.gz → 0.9.0__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.
Files changed (62) hide show
  1. mapfolding-0.9.0/PKG-INFO +177 -0
  2. mapfolding-0.9.0/README.md +125 -0
  3. mapfolding-0.9.0/mapFolding/__init__.py +93 -0
  4. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/basecamp.py +32 -17
  5. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/beDRY.py +3 -3
  6. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/oeis.py +83 -2
  7. mapfolding-0.9.0/mapFolding/someAssemblyRequired/__init__.py +87 -0
  8. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/_theTypes.py +11 -15
  9. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/_tool_Make.py +35 -8
  10. mapfolding-0.9.0/mapFolding/someAssemblyRequired/_tool_Then.py +106 -0
  11. mapfolding-0.9.0/mapFolding/someAssemblyRequired/_toolboxAntecedents.py +233 -0
  12. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/_toolboxContainers.py +133 -48
  13. mapfolding-0.9.0/mapFolding/someAssemblyRequired/_toolboxPython.py +183 -0
  14. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +101 -18
  15. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/toolboxNumba.py +83 -48
  16. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/transformationTools.py +220 -138
  17. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/theSSOT.py +147 -54
  18. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/toolboxFilesystem.py +1 -1
  19. mapfolding-0.9.0/mapFolding.egg-info/PKG-INFO +177 -0
  20. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding.egg-info/SOURCES.txt +0 -1
  21. {mapfolding-0.8.6 → mapfolding-0.9.0}/pyproject.toml +3 -3
  22. mapfolding-0.9.0/tests/__init__.py +44 -0
  23. {mapfolding-0.8.6 → mapfolding-0.9.0}/tests/conftest.py +75 -7
  24. {mapfolding-0.8.6 → mapfolding-0.9.0}/tests/test_computations.py +90 -9
  25. mapfolding-0.9.0/tests/test_filesystem.py +49 -0
  26. {mapfolding-0.8.6 → mapfolding-0.9.0}/tests/test_other.py +0 -1
  27. {mapfolding-0.8.6 → mapfolding-0.9.0}/tests/test_tasks.py +1 -1
  28. mapfolding-0.8.6/PKG-INFO +0 -190
  29. mapfolding-0.8.6/README.md +0 -139
  30. mapfolding-0.8.6/mapFolding/__init__.py +0 -46
  31. mapfolding-0.8.6/mapFolding/someAssemblyRequired/__init__.py +0 -66
  32. mapfolding-0.8.6/mapFolding/someAssemblyRequired/_tool_Then.py +0 -72
  33. mapfolding-0.8.6/mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -358
  34. mapfolding-0.8.6/mapFolding/someAssemblyRequired/_toolboxPython.py +0 -62
  35. mapfolding-0.8.6/mapFolding/someAssemblyRequired/newInliner.py +0 -22
  36. mapfolding-0.8.6/mapFolding.egg-info/PKG-INFO +0 -190
  37. mapfolding-0.8.6/tests/__init__.py +0 -0
  38. mapfolding-0.8.6/tests/test_filesystem.py +0 -50
  39. {mapfolding-0.8.6 → mapfolding-0.9.0}/LICENSE +0 -0
  40. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/py.typed +0 -0
  41. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/__init__.py +0 -0
  42. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/flattened.py +0 -0
  43. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/hunterNumba.py +0 -0
  44. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/irvineJavaPort.py +0 -0
  45. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/jaxCount.py +0 -0
  46. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/jobsCompleted/[2x19]/p2x19.py +0 -0
  47. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/jobsCompleted/__init__.py +0 -0
  48. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/jobsCompleted/p2x19/p2x19.py +0 -0
  49. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/lunnanNumpy.py +0 -0
  50. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/lunnanWhile.py +0 -0
  51. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/rotatedEntryPoint.py +0 -0
  52. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/reference/total_countPlus1vsPlusN.py +0 -0
  53. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/someAssemblyRequired/getLLVMforNoReason.py +0 -0
  54. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/syntheticModules/__init__.py +0 -0
  55. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/syntheticModules/numbaCount_doTheNeedful.py +0 -0
  56. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding/theDao.py +0 -0
  57. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding.egg-info/dependency_links.txt +0 -0
  58. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding.egg-info/entry_points.txt +0 -0
  59. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding.egg-info/requires.txt +0 -0
  60. {mapfolding-0.8.6 → mapfolding-0.9.0}/mapFolding.egg-info/top_level.txt +0 -0
  61. {mapfolding-0.8.6 → mapfolding-0.9.0}/setup.cfg +0 -0
  62. {mapfolding-0.8.6 → mapfolding-0.9.0}/tests/test_oeis.py +0 -0
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: mapFolding
3
+ Version: 0.9.0
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: Repository, https://github.com/hunterhogan/mapFolding.git
10
+ Project-URL: Issues, https://github.com/hunterhogan/mapFolding/issues
11
+ Keywords: A001415,A001416,A001417,A001418,A195646,algorithmic optimization,AST manipulation,code generation,code transformation,combinatorics,computational geometry,dataclass transformation,folding pattern enumeration,just-in-time compilation,map folding,Numba optimization,OEIS,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.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
26
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
27
+ Classifier: Topic :: Software Development :: Code Generators
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Classifier: Topic :: Software Development :: Compilers
30
+ Classifier: Typing :: Typed
31
+ Requires-Python: >=3.10
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: autoflake
35
+ Requires-Dist: more_itertools
36
+ Requires-Dist: numba_progress
37
+ Requires-Dist: numba
38
+ Requires-Dist: numpy
39
+ Requires-Dist: platformdirs
40
+ Requires-Dist: python_minifier
41
+ Requires-Dist: tomli
42
+ Requires-Dist: Z0Z_tools
43
+ Provides-Extra: testing
44
+ Requires-Dist: mypy; extra == "testing"
45
+ Requires-Dist: pytest; extra == "testing"
46
+ Requires-Dist: pytest-cov; extra == "testing"
47
+ Requires-Dist: pytest-env; extra == "testing"
48
+ Requires-Dist: pytest-xdist; extra == "testing"
49
+ Requires-Dist: pyupgrade; extra == "testing"
50
+ Requires-Dist: ruff; extra == "testing"
51
+ Dynamic: license-file
52
+
53
+ # mapFolding: High-Performance Algorithm Playground for Computational Enthusiasts 🗺️
54
+
55
+ [![pip install mapFolding](https://img.shields.io/badge/pip%20install-mapFolding-gray.svg?colorB=3b434b)](https://pypi.org/project/mapFolding/)
56
+ [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
57
+ [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-3b434b)](https://creativecommons.org/licenses/by-nc/4.0/)
58
+
59
+ **This package is for you if:**
60
+
61
+ - You're fascinated by computational algorithms and their optimization
62
+ - You want to explore AST transformation techniques for Python performance tuning
63
+ - You're interested in solving mathematical puzzles through code
64
+ - You're learning about Numba and advanced Python optimization
65
+
66
+ **This package is NOT for you if:**
67
+
68
+ - You're looking for a general-purpose folding simulation tool
69
+ - You need commercial-ready mapping software
70
+ - You want simple visualization of folding patterns
71
+
72
+ ## What Does This Package Actually Do?
73
+
74
+ `mapFolding` solves a specific mathematical problem: counting the number of distinct ways to fold a rectangular map. While this may sound niche, it's a fascinating computational challenge that demonstrates:
75
+
76
+ 1. How to transform readable algorithms into blazingly fast implementations
77
+ 2. Advanced techniques for Python optimization using AST manipulation
78
+ 3. Numba acceleration with specialized compilation strategies
79
+ 4. Algorithms for problems that grow combinatorially
80
+
81
+ The package has achieved new computational records, including first-ever calculations for large maps that were previously infeasible.
82
+
83
+ ```python
84
+ # Compute the number of ways to fold a 5×5 grid:
85
+ from mapFolding import oeisIDfor_n
86
+ foldsTotal = oeisIDfor_n('A001418', 5) # Returns 186,086,600
87
+ ```
88
+
89
+ ## Key Benefits for Computational Enthusiasts
90
+
91
+ ### 1. Algorithm Transformation Laboratory
92
+
93
+ See how the same algorithm evolves from readable Python to highly-optimized implementations:
94
+
95
+ ```python
96
+ # The intuitive, readable version:
97
+ def countFolds(mapShape):
98
+ # ...implement readable algorithm...
99
+
100
+ # The transformed, optimized version (auto-generated):
101
+ @numba.jit(nopython=True, parallel=True, fastmath=True)
102
+ def countFolds_optimized(shape_param):
103
+ # ...blazingly fast implementation...
104
+ ```
105
+
106
+ ### 2. Code Generation Framework
107
+
108
+ Study and extend a complete Python code transformation pipeline:
109
+
110
+ - AST analysis and manipulation
111
+ - Dataclass decomposition ("shattering")
112
+ - Automatic import management
113
+ - Type specialization for numerical computing
114
+
115
+ ### 3. Exhaustive Test Framework
116
+
117
+ Leverage a sophisticated test suite for validating your own optimizations:
118
+
119
+ ```python
120
+ # Test your own recipe implementation with just a few lines:
121
+ @pytest.fixture
122
+ def myCustomRecipeFixture(useThisDispatcher, pathTmpTesting):
123
+ myRecipe = RecipeSynthesizeFlow(
124
+ # Your custom configuration here
125
+ )
126
+ # ...transformation code...
127
+ return customDispatcher
128
+
129
+ def test_myCustomImplementation(myCustomRecipeFixture):
130
+ # Automatic validation against known values
131
+ ```
132
+
133
+ ## Installation and Getting Started
134
+
135
+ ```sh
136
+ pip install mapFolding
137
+ ```
138
+
139
+ Try a quick calculation:
140
+
141
+ ```python
142
+ from mapFolding import oeisIDfor_n
143
+
144
+ # Calculate ways to fold a 2×4 map
145
+ result = oeisIDfor_n('A001415', 4) # Returns 8
146
+ print(f"A 2×4 map can be folded {result} different ways")
147
+ ```
148
+
149
+ ## Mathematical Background (For the Curious)
150
+
151
+ The map folding problem was introduced by Lunnon in 1971 and connects to combinatorial geometry, computational complexity, and integer sequence analysis. The calculations provide entries to the Online Encyclopedia of Integer Sequences (OEIS).
152
+
153
+ This package implements several OEIS sequences, including:
154
+
155
+ - A001415: Number of ways to fold a 2×n strip (now calculated up to n=20!)
156
+ - A001418: Number of ways to fold an n×n square grid
157
+
158
+ ## Explore the Repository
159
+
160
+ The repository structure reveals the package's educational value:
161
+
162
+ - `reference/`: Historical implementations and algorithm evolution
163
+ - `someAssemblyRequired/`: Code transformation framework
164
+ - `tests/`: Comprehensive test suite with fixtures for your own implementations
165
+
166
+ ## Who Is This For, Really?
167
+
168
+ If you've read this far and are intrigued by computational puzzles, algorithm optimization, or Python performance techniques, this package offers a playground for exploration. It's particularly valuable for:
169
+
170
+ - Computer science students studying algorithm optimization
171
+ - Python developers exploring Numba and AST manipulation
172
+ - Computational mathematicians interested in combinatorial problems
173
+ - Anyone fascinated by the intersection of mathematics and computing
174
+
175
+ Whether you use it to solve map folding problems or to study its optimization techniques, `mapFolding` offers a unique window into advanced Python programming approaches.
176
+
177
+ [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
@@ -0,0 +1,125 @@
1
+ # mapFolding: High-Performance Algorithm Playground for Computational Enthusiasts 🗺️
2
+
3
+ [![pip install mapFolding](https://img.shields.io/badge/pip%20install-mapFolding-gray.svg?colorB=3b434b)](https://pypi.org/project/mapFolding/)
4
+ [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/pythonTests.yml)
5
+ [![License: CC-BY-NC-4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-3b434b)](https://creativecommons.org/licenses/by-nc/4.0/)
6
+
7
+ **This package is for you if:**
8
+
9
+ - You're fascinated by computational algorithms and their optimization
10
+ - You want to explore AST transformation techniques for Python performance tuning
11
+ - You're interested in solving mathematical puzzles through code
12
+ - You're learning about Numba and advanced Python optimization
13
+
14
+ **This package is NOT for you if:**
15
+
16
+ - You're looking for a general-purpose folding simulation tool
17
+ - You need commercial-ready mapping software
18
+ - You want simple visualization of folding patterns
19
+
20
+ ## What Does This Package Actually Do?
21
+
22
+ `mapFolding` solves a specific mathematical problem: counting the number of distinct ways to fold a rectangular map. While this may sound niche, it's a fascinating computational challenge that demonstrates:
23
+
24
+ 1. How to transform readable algorithms into blazingly fast implementations
25
+ 2. Advanced techniques for Python optimization using AST manipulation
26
+ 3. Numba acceleration with specialized compilation strategies
27
+ 4. Algorithms for problems that grow combinatorially
28
+
29
+ The package has achieved new computational records, including first-ever calculations for large maps that were previously infeasible.
30
+
31
+ ```python
32
+ # Compute the number of ways to fold a 5×5 grid:
33
+ from mapFolding import oeisIDfor_n
34
+ foldsTotal = oeisIDfor_n('A001418', 5) # Returns 186,086,600
35
+ ```
36
+
37
+ ## Key Benefits for Computational Enthusiasts
38
+
39
+ ### 1. Algorithm Transformation Laboratory
40
+
41
+ See how the same algorithm evolves from readable Python to highly-optimized implementations:
42
+
43
+ ```python
44
+ # The intuitive, readable version:
45
+ def countFolds(mapShape):
46
+ # ...implement readable algorithm...
47
+
48
+ # The transformed, optimized version (auto-generated):
49
+ @numba.jit(nopython=True, parallel=True, fastmath=True)
50
+ def countFolds_optimized(shape_param):
51
+ # ...blazingly fast implementation...
52
+ ```
53
+
54
+ ### 2. Code Generation Framework
55
+
56
+ Study and extend a complete Python code transformation pipeline:
57
+
58
+ - AST analysis and manipulation
59
+ - Dataclass decomposition ("shattering")
60
+ - Automatic import management
61
+ - Type specialization for numerical computing
62
+
63
+ ### 3. Exhaustive Test Framework
64
+
65
+ Leverage a sophisticated test suite for validating your own optimizations:
66
+
67
+ ```python
68
+ # Test your own recipe implementation with just a few lines:
69
+ @pytest.fixture
70
+ def myCustomRecipeFixture(useThisDispatcher, pathTmpTesting):
71
+ myRecipe = RecipeSynthesizeFlow(
72
+ # Your custom configuration here
73
+ )
74
+ # ...transformation code...
75
+ return customDispatcher
76
+
77
+ def test_myCustomImplementation(myCustomRecipeFixture):
78
+ # Automatic validation against known values
79
+ ```
80
+
81
+ ## Installation and Getting Started
82
+
83
+ ```sh
84
+ pip install mapFolding
85
+ ```
86
+
87
+ Try a quick calculation:
88
+
89
+ ```python
90
+ from mapFolding import oeisIDfor_n
91
+
92
+ # Calculate ways to fold a 2×4 map
93
+ result = oeisIDfor_n('A001415', 4) # Returns 8
94
+ print(f"A 2×4 map can be folded {result} different ways")
95
+ ```
96
+
97
+ ## Mathematical Background (For the Curious)
98
+
99
+ The map folding problem was introduced by Lunnon in 1971 and connects to combinatorial geometry, computational complexity, and integer sequence analysis. The calculations provide entries to the Online Encyclopedia of Integer Sequences (OEIS).
100
+
101
+ This package implements several OEIS sequences, including:
102
+
103
+ - A001415: Number of ways to fold a 2×n strip (now calculated up to n=20!)
104
+ - A001418: Number of ways to fold an n×n square grid
105
+
106
+ ## Explore the Repository
107
+
108
+ The repository structure reveals the package's educational value:
109
+
110
+ - `reference/`: Historical implementations and algorithm evolution
111
+ - `someAssemblyRequired/`: Code transformation framework
112
+ - `tests/`: Comprehensive test suite with fixtures for your own implementations
113
+
114
+ ## Who Is This For, Really?
115
+
116
+ If you've read this far and are intrigued by computational puzzles, algorithm optimization, or Python performance techniques, this package offers a playground for exploration. It's particularly valuable for:
117
+
118
+ - Computer science students studying algorithm optimization
119
+ - Python developers exploring Numba and AST manipulation
120
+ - Computational mathematicians interested in combinatorial problems
121
+ - Anyone fascinated by the intersection of mathematics and computing
122
+
123
+ Whether you use it to solve map folding problems or to study its optimization techniques, `mapFolding` offers a unique window into advanced Python programming approaches.
124
+
125
+ [![CC-BY-NC-4.0](https://github.com/hunterhogan/mapFolding/blob/main/CC-BY-NC-4.0.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
@@ -0,0 +1,93 @@
1
+ """
2
+ Map folding enumeration and counting algorithms with advanced optimization capabilities.
3
+
4
+ This package implements algorithms to count and enumerate the distinct ways
5
+ a rectangular map can be folded, based on the mathematical problem described
6
+ in Lunnon's 1971 paper. It provides multiple layers of functionality, from
7
+ high-level user interfaces to sophisticated algorithmic optimizations and code
8
+ transformation tools.
9
+
10
+ Core modules:
11
+ - basecamp: Public API with simplified interfaces for end users
12
+ - theDao: Core computational algorithm using a functional state-transformation approach
13
+ - beDRY: Core utility functions implementing consistent data handling, validation, and
14
+ resource management across the package's computational assembly-line
15
+ - theSSOT: Single Source of Truth for configuration, types, and state management
16
+ - toolboxFilesystem: Cross-platform file management services for storing and retrieving
17
+ computation results with robust error handling and fallback mechanisms
18
+ - oeis: Interface to the Online Encyclopedia of Integer Sequences for known results
19
+
20
+ Extended functionality:
21
+ - someAssemblyRequired: Code transformation framework that optimizes the core algorithm
22
+ through AST manipulation, dataclass transformation, and compilation techniques
23
+ - The system converts readable code into high-performance implementations through
24
+ a systematic analysis and transformation pipeline
25
+ - Provides tools to "shatter" complex dataclasses into primitive components,
26
+ enabling compatibility with Numba and other optimization frameworks
27
+ - Creates specialized implementations tailored for specific input parameters
28
+
29
+ Testing and extension:
30
+ - tests: Comprehensive test suite designed for both verification and extension
31
+ - Provides fixtures and utilities that simplify testing of custom implementations
32
+ - Enables users to validate their own recipes and job configurations with minimal code
33
+ - Offers standardized testing patterns that maintain consistency across the codebase
34
+ - See tests/__init__.py for detailed documentation on extending the test suite
35
+
36
+ Special directories:
37
+ - .cache/: Stores cached data from external sources like OEIS to improve performance
38
+ - syntheticModules/: Contains dynamically generated, optimized implementations of the
39
+ core algorithm created by the code transformation framework
40
+ - reference/: Historical implementations and educational resources for algorithm exploration
41
+ - reference/jobsCompleted/: Contains successful computations for previously unknown values,
42
+ including first-ever calculations for 2x19 and 2x20 maps (OEIS A001415)
43
+
44
+ This package balances algorithm readability and understandability with
45
+ high-performance computation capabilities, allowing users to compute map folding
46
+ totals for larger dimensions than previously feasible while also providing
47
+ a foundation for exploring advanced code transformation techniques.
48
+ """
49
+
50
+ __all__ = [
51
+ 'clearOEIScache',
52
+ 'countFolds',
53
+ 'getOEISids',
54
+ 'OEIS_for_n',
55
+ 'oeisIDfor_n',
56
+ ]
57
+
58
+ from mapFolding.theSSOT import (
59
+ Array1DElephino,
60
+ Array1DFoldsTotal,
61
+ Array1DLeavesTotal,
62
+ Array3D,
63
+ ComputationState,
64
+ DatatypeElephino,
65
+ DatatypeFoldsTotal,
66
+ DatatypeLeavesTotal,
67
+ NumPyElephino,
68
+ NumPyFoldsTotal,
69
+ NumPyIntegerType,
70
+ NumPyLeavesTotal,
71
+ raiseIfNoneGitHubIssueNumber3,
72
+ The,
73
+ )
74
+
75
+ from mapFolding.theDao import countInitialize, doTheNeedful
76
+
77
+ from mapFolding.beDRY import (
78
+ outfitCountFolds,
79
+ setProcessorLimit,
80
+ validateListDimensions,
81
+ )
82
+
83
+ from mapFolding.toolboxFilesystem import (
84
+ getPathFilenameFoldsTotal,
85
+ getPathRootJobDEFAULT,
86
+ saveFoldsTotal,
87
+ saveFoldsTotalFAILearly,
88
+ writeStringToHere,
89
+ )
90
+
91
+ from mapFolding.basecamp import countFolds
92
+
93
+ from mapFolding.oeis import clearOEIScache, getFoldsTotalKnown, getOEISids, OEIS_for_n, oeisIDfor_n
@@ -13,9 +13,16 @@ implementation, and optional persistence of results.
13
13
  """
14
14
 
15
15
  from collections.abc import Sequence
16
- from mapFolding.theSSOT import ComputationState, getPackageDispatcher, The
17
- from mapFolding.beDRY import outfitCountFolds, setProcessorLimit, validateListDimensions
18
- from mapFolding.toolboxFilesystem import getPathFilenameFoldsTotal, saveFoldsTotal, saveFoldsTotalFAILearly
16
+ from mapFolding import (
17
+ ComputationState,
18
+ getPathFilenameFoldsTotal,
19
+ outfitCountFolds,
20
+ saveFoldsTotal,
21
+ saveFoldsTotalFAILearly,
22
+ setProcessorLimit,
23
+ The,
24
+ validateListDimensions,
25
+ )
19
26
  from os import PathLike
20
27
  from pathlib import PurePath
21
28
 
@@ -24,18 +31,27 @@ def countFolds(listDimensions: Sequence[int]
24
31
  , computationDivisions: int | str | None = None
25
32
  , CPUlimit: int | float | bool | None = None
26
33
  ) -> int:
27
- """Count the total number of possible foldings for a given map dimensions.
34
+ """
35
+ Count the total number of possible foldings for a given map dimensions.
36
+
37
+ This function serves as the main public interface to the map folding algorithm,
38
+ handling all parameter validation, computation state management, and result
39
+ persistence in a user-friendly way.
28
40
 
29
- Parameters:
30
- listDimensions: List of integers representing the dimensions of the map to be folded.
31
- pathLikeWriteFoldsTotal (None): Path, filename, or pathFilename to write the total fold count to.
32
- If a directory is provided, creates a file with a default name based on map dimensions.
33
- computationDivisions (None):
34
- Whether and how to divide the computational work. See notes for details.
35
- CPUlimit (None): This is only relevant if there are `computationDivisions`: whether and how to limit the CPU usage. See notes for details.
36
- Returns:
37
- foldsTotal: Total number of distinct ways to fold a map of the given dimensions.
41
+ Parameters
42
+ ----------
43
+ listDimensions: List of integers representing the dimensions of the map to be folded.
44
+ pathLikeWriteFoldsTotal (None): Path, filename, or pathFilename to write the total fold count to.
45
+ If a directory is provided, creates a file with a default name based on map dimensions.
46
+ computationDivisions (None):
47
+ Whether and how to divide the computational work. See notes for details.
48
+ CPUlimit (None): This is only relevant if there are `computationDivisions`: whether and how to limit the CPU usage. See notes for details.
49
+ Returns
50
+ -------
51
+ foldsTotal: Total number of distinct ways to fold a map of the given dimensions.
38
52
 
53
+ Notes
54
+ -----
39
55
  Computation divisions:
40
56
  - None: no division of the computation into tasks; sets task divisions to 0
41
57
  - int: direct set the number of task divisions; cannot exceed the map's total leaves
@@ -51,7 +67,8 @@ def countFolds(listDimensions: Sequence[int]
51
67
  - Integer `<= -1`: Subtract the absolute value from total CPUs.
52
68
 
53
69
  N.B.: You probably don't want to divide the computation into tasks.
54
- If you want to compute a large `foldsTotal`, dividing the computation into tasks is usually a bad idea. Dividing the algorithm into tasks is inherently inefficient: efficient division into tasks means there would be no overlap in the work performed by each task. When dividing this algorithm, the amount of overlap is between 50% and 90% by all tasks: at least 50% of the work done by every task must be done by _all_ tasks. If you improve the computation time, it will only change by -10 to -50% depending on (at the very least) the ratio of the map dimensions and the number of leaves. If an undivided computation would take 10 hours on your computer, for example, the computation will still take at least 5 hours but you might reduce the time to 9 hours. Most of the time, however, you will increase the computation time. If logicalCores >= leavesTotal, it will probably be faster. If logicalCores <= 2 * leavesTotal, it will almost certainly be slower for all map dimensions.
70
+
71
+ If you want to compute a large `foldsTotal`, dividing the computation into tasks is usually a bad idea. Dividing the algorithm into tasks is inherently inefficient: efficient division into tasks means there would be no overlap in the work performed by each task. When dividing this algorithm, the amount of overlap is between 50% and 90% by all tasks: at least 50% of the work done by every task must be done by _all_ tasks. If you improve the computation time, it will only change by -10 to -50% depending on (at the very least) the ratio of the map dimensions and the number of leaves. If an undivided computation would take 10 hours on your computer, for example, the computation will still take at least 5 hours but you might reduce the time to 9 hours. Most of the time, however, you will increase the computation time. If logicalCores >= leavesTotal, it will probably be faster. If logicalCores <= 2 * leavesTotal, it will almost certainly be slower for all map dimensions.
55
72
  """
56
73
  mapShape: tuple[int, ...] = validateListDimensions(listDimensions)
57
74
  concurrencyLimit: int = setProcessorLimit(CPUlimit, The.concurrencyPackage)
@@ -63,9 +80,7 @@ def countFolds(listDimensions: Sequence[int]
63
80
  else:
64
81
  pathFilenameFoldsTotal = None
65
82
 
66
- dispatcherCallableProxy = getPackageDispatcher()
67
- computationStateComplete: ComputationState = dispatcherCallableProxy(computationStateInitialized)
68
- # computationStateComplete: ComputationState = The.dispatcher(computationStateInitialized)
83
+ computationStateComplete: ComputationState = The.dispatcher(computationStateInitialized)
69
84
 
70
85
  computationStateComplete.getFoldsTotal()
71
86
 
@@ -19,7 +19,7 @@ These utilities form a stable internal API that other modules depend on, particu
19
19
  produce optimized implementations.
20
20
  """
21
21
  from collections.abc import Sequence
22
- from mapFolding.theSSOT import ComputationState, numpyIntegerType
22
+ from mapFolding import ComputationState, NumPyIntegerType
23
23
  from numpy import dtype as numpy_dtype, int64 as numpy_int64, ndarray
24
24
  from sys import maxsize as sysMaxsize
25
25
  from typing import Any
@@ -165,7 +165,7 @@ def _makeConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int) -> ndarray
165
165
  connectionGraph[indexDimension, activeLeaf1ndex, connectee1ndex] = connectee1ndex + cumulativeProduct[indexDimension]
166
166
  return connectionGraph
167
167
 
168
- def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: type[numpyIntegerType]) -> ndarray[tuple[int, int, int], numpy_dtype[numpyIntegerType]]:
168
+ def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: type[NumPyIntegerType]) -> ndarray[tuple[int, int, int], numpy_dtype[NumPyIntegerType]]:
169
169
  """
170
170
  Create a properly typed connection graph for the map folding algorithm.
171
171
 
@@ -193,7 +193,7 @@ def getConnectionGraph(mapShape: tuple[int, ...], leavesTotal: int, datatype: ty
193
193
  connectionGraph = connectionGraph.astype(datatype)
194
194
  return connectionGraph
195
195
 
196
- def makeDataContainer(shape: int | tuple[int, ...], datatype: type[numpyIntegerType]) -> ndarray[Any, numpy_dtype[numpyIntegerType]]:
196
+ def makeDataContainer(shape: int | tuple[int, ...], datatype: type[NumPyIntegerType]) -> ndarray[Any, numpy_dtype[NumPyIntegerType]]:
197
197
  """
198
198
  Create a typed NumPy array container with initialized values.
199
199
 
@@ -22,8 +22,7 @@ implementation in the package.
22
22
  from collections.abc import Callable
23
23
  from datetime import datetime, timedelta
24
24
  from functools import cache
25
- from mapFolding.theSSOT import The
26
- from mapFolding.toolboxFilesystem import writeStringToHere
25
+ from mapFolding import writeStringToHere, The
27
26
  from pathlib import Path
28
27
  from typing import Any, Final, TYPE_CHECKING
29
28
  import argparse
@@ -162,6 +161,27 @@ def _parseBFileOEIS(OEISbFile: str, oeisID: str) -> dict[int, int]:
162
161
  return OEISsequence
163
162
 
164
163
  def getOEISofficial(pathFilenameCache: Path, url: str) -> None | str:
164
+ """
165
+ Retrieve OEIS sequence data from cache or online source.
166
+
167
+ This function implements a caching strategy for OEIS sequence data, first checking
168
+ if a local cached copy exists and is not expired. If a valid cache exists, it returns
169
+ the cached content; otherwise, it fetches the data from the OEIS website and
170
+ writes it to the cache for future use.
171
+
172
+ Parameters:
173
+ pathFilenameCache: Path to the local cache file.
174
+ url: URL to retrieve the OEIS sequence data from if cache is invalid or missing.
175
+
176
+ Returns:
177
+ oeisInformation: The retrieved OEIS sequence information as a string, or None if
178
+ the information could not be retrieved.
179
+
180
+ Notes:
181
+ The cache expiration period is controlled by the global `cacheDays` variable.
182
+ If the function fails to retrieve data from both cache and online source,
183
+ it will return None and issue a warning.
184
+ """
165
185
  tryCache: bool = False
166
186
  if pathFilenameCache.exists():
167
187
  fileAge: timedelta = datetime.now() - datetime.fromtimestamp(pathFilenameCache.stat().st_mtime)
@@ -175,6 +195,7 @@ def getOEISofficial(pathFilenameCache: Path, url: str) -> None | str:
175
195
  tryCache = False
176
196
 
177
197
  if not tryCache:
198
+ # Change http handling #13
178
199
  httpResponse: urllib.response.addinfourl = urllib.request.urlopen(url)
179
200
  oeisInformation = httpResponse.read().decode('utf-8')
180
201
  writeStringToHere(oeisInformation, pathFilenameCache)
@@ -214,6 +235,27 @@ def getOEISidValues(oeisID: str) -> dict[int, int]:
214
235
  return {-1: -1}
215
236
 
216
237
  def getOEISidInformation(oeisID: str) -> tuple[str, int]:
238
+ """
239
+ Retrieve the description and offset for an OEIS sequence.
240
+
241
+ This function fetches the metadata for a given OEIS sequence ID, including
242
+ its textual description and index offset value. It uses a caching mechanism
243
+ to avoid redundant network requests while ensuring data freshness.
244
+
245
+ Parameters:
246
+ oeisID: The OEIS sequence identifier to retrieve information for.
247
+
248
+ Returns:
249
+ A tuple containing:
250
+ - description: A string describing the sequence's mathematical meaning.
251
+ - offset: An integer representing the starting index of the sequence.
252
+ Usually 0 or 1, depending on the mathematical context.
253
+
254
+ Notes:
255
+ Sequence descriptions are parsed from the machine-readable format of OEIS.
256
+ If information cannot be retrieved, warning messages are issued and
257
+ fallback values are returned.
258
+ """
217
259
  oeisID = validateOEISid(oeisID)
218
260
  pathFilenameCache: Path = pathCache / f"{oeisID}.txt"
219
261
  url: str = f"https://oeis.org/search?q=id:{oeisID}&fmt=text"
@@ -243,6 +285,26 @@ def getOEISidInformation(oeisID: str) -> tuple[str, int]:
243
285
  return description, offset
244
286
 
245
287
  def makeSettingsOEIS() -> dict[str, SettingsOEIS]:
288
+ """
289
+ Construct the comprehensive settings dictionary for all implemented OEIS sequences.
290
+
291
+ This function builds a complete configuration dictionary for all supported OEIS
292
+ sequences by retrieving and combining:
293
+ 1. Sequence values from OEIS b-files
294
+ 2. Sequence metadata (descriptions and offsets)
295
+ 3. Hardcoded mapping functions and test values
296
+
297
+ The resulting dictionary provides a single authoritative source for all OEIS-related
298
+ configurations used throughout the package, including:
299
+ - Mathematical descriptions of each sequence
300
+ - Functions to convert between sequence indices and map dimensions
301
+ - Known sequence values retrieved from OEIS
302
+ - Testing and benchmarking reference values
303
+
304
+ Returns:
305
+ A dictionary mapping OEIS sequence IDs to their complete settings objects,
306
+ containing all metadata and known values needed for computation and validation.
307
+ """
246
308
  settingsTarget: dict[str, SettingsOEIS] = {}
247
309
  for oeisID in oeisIDsImplemented:
248
310
  valuesKnownSherpa: dict[int, int] = getOEISidValues(oeisID)
@@ -277,6 +339,25 @@ def makeDictionaryFoldsTotalKnown() -> dict[tuple[int, ...], int]:
277
339
  return dictionaryMapDimensionsToFoldsTotalKnown
278
340
 
279
341
  def getFoldsTotalKnown(mapShape: tuple[int, ...]) -> int:
342
+ """
343
+ Retrieve the known total number of foldings for a given map shape.
344
+
345
+ This function looks up precalculated folding totals for specific map dimensions
346
+ from OEIS sequences. It serves as a rapid reference for known values without
347
+ requiring computation, and can be used to validate algorithm results.
348
+
349
+ Parameters:
350
+ mapShape: A tuple of integers representing the dimensions of the map.
351
+
352
+ Returns:
353
+ foldingsTotal: The known total number of foldings for the given map shape,
354
+ or -1 if the map shape doesn't match any known values in the OEIS sequences.
355
+
356
+ Notes:
357
+ The function uses a cached dictionary (via makeDictionaryFoldsTotalKnown) to
358
+ efficiently retrieve values without repeatedly parsing OEIS data. Map shape
359
+ tuples are sorted internally to ensure consistent lookup regardless of dimension order.
360
+ """
280
361
  lookupFoldsTotal = makeDictionaryFoldsTotalKnown()
281
362
  return lookupFoldsTotal.get(tuple(mapShape), -1)
282
363