mapFolding 0.2.1__tar.gz → 0.2.3__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 (39) hide show
  1. {mapfolding-0.2.1 → mapfolding-0.2.3}/PKG-INFO +4 -4
  2. {mapfolding-0.2.1 → mapfolding-0.2.3}/README.md +3 -3
  3. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/__init__.py +2 -2
  4. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/babbage.py +2 -2
  5. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/beDRY.py +60 -40
  6. mapfolding-0.2.3/mapFolding/lovelace.py +217 -0
  7. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/oeis.py +37 -35
  8. mapfolding-0.2.3/mapFolding/reference/flattened.py +376 -0
  9. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/hunterNumba.py +44 -44
  10. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/lunnan.py +5 -5
  11. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/lunnanNumpy.py +4 -4
  12. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/lunnanWhile.py +5 -5
  13. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/rotatedEntryPoint.py +68 -68
  14. mapfolding-0.2.3/mapFolding/reference/total_countPlus1vsPlusN.py +211 -0
  15. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/startHere.py +12 -12
  16. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/theSSOT.py +8 -3
  17. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/PKG-INFO +4 -4
  18. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/SOURCES.txt +3 -1
  19. {mapfolding-0.2.1 → mapfolding-0.2.3}/pyproject.toml +3 -2
  20. mapfolding-0.2.3/tests/__init__.py +1 -0
  21. {mapfolding-0.2.1 → mapfolding-0.2.3}/tests/conftest.py +111 -35
  22. mapfolding-0.2.3/tests/pythons_idiotic_namespace.py +1 -0
  23. {mapfolding-0.2.1 → mapfolding-0.2.3}/tests/test_oeis.py +25 -26
  24. mapfolding-0.2.3/tests/test_other.py +198 -0
  25. {mapfolding-0.2.1 → mapfolding-0.2.3}/tests/test_tasks.py +11 -1
  26. mapfolding-0.2.1/mapFolding/importPackages.py +0 -5
  27. mapfolding-0.2.1/mapFolding/lovelace.py +0 -145
  28. mapfolding-0.2.1/tests/__init__.py +0 -1
  29. mapfolding-0.2.1/tests/test_other.py +0 -68
  30. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/JAX/lunnanJAX.py +0 -0
  31. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/JAX/taskJAX.py +0 -0
  32. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/benchmarks/benchmarking.py +0 -0
  33. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/benchmarks/test_benchmarks.py +0 -0
  34. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding/reference/irvineJavaPort.py +0 -0
  35. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/dependency_links.txt +0 -0
  36. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/entry_points.txt +0 -0
  37. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/requires.txt +0 -0
  38. {mapfolding-0.2.1 → mapfolding-0.2.3}/mapFolding.egg-info/top_level.txt +0 -0
  39. {mapfolding-0.2.1 → mapfolding-0.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mapFolding
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Algorithm(s) for counting distinct ways to fold a map (or a strip of stamps)
5
5
  Author-email: Hunter Hogan <HunterHogan@pm.me>
6
6
  Project-URL: homepage, https://github.com/hunterhogan/mapFolding
@@ -25,7 +25,7 @@ Requires-Dist: pytest-xdist; extra == "testing"
25
25
 
26
26
  # Algorithm(s) for counting distinct ways to fold a map (or a strip of stamps)
27
27
 
28
- `mapFolding.countFolds()` will accept arbitrary values for the map's dimensions.
28
+ The function `mapFolding.countFolds()` counts distinct ways to fold maps and strips of stamps. The function accepts two or more dimensions:
29
29
 
30
30
  ```python
31
31
  from mapFolding import countFolds
@@ -34,12 +34,12 @@ foldsTotal = countFolds( [2,10] )
34
34
 
35
35
  The directory [mapFolding/reference](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/reference) has
36
36
 
37
- - a verbatim transcription of the "procedure" published in _The Computer Journal_,
37
+ - a verbatim transcription of Lunnon's "procedure" published in 1971 by _The Computer Journal_,
38
38
  - multiple referential versions of the procedure with explanatory comments including
39
39
  - [hunterNumba.py](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/reference), a one-size-fits-all, self-contained, reasonably fast, contemporary algorithm that is nevertheless infected by _noobaceae ignorancium_, and
40
40
  - miscellaneous notes.
41
41
 
42
- [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml)
42
+ [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml) [![pip install mapFolding](https://img.shields.io/badge/pip%20install-mapFolding-gray.svg?colorB=3b434b)](https://pypi.org/project/mapFolding/) ![Static Badge](https://img.shields.io/badge/stinkin'%20badges-don't%20need-b98e5e) ![PyPI - Downloads](https://img.shields.io/pypi/dd/mapFolding) ![Static Badge](https://img.shields.io/badge/issues-I%20have%20them-brightgreen) ![GitHub repo size](https://img.shields.io/github/repo-size/hunterhogan/mapFolding)
43
43
 
44
44
  ## Simple, easy usage based on OEIS IDs
45
45
 
@@ -1,6 +1,6 @@
1
1
  # Algorithm(s) for counting distinct ways to fold a map (or a strip of stamps)
2
2
 
3
- `mapFolding.countFolds()` will accept arbitrary values for the map's dimensions.
3
+ The function `mapFolding.countFolds()` counts distinct ways to fold maps and strips of stamps. The function accepts two or more dimensions:
4
4
 
5
5
  ```python
6
6
  from mapFolding import countFolds
@@ -9,12 +9,12 @@ foldsTotal = countFolds( [2,10] )
9
9
 
10
10
  The directory [mapFolding/reference](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/reference) has
11
11
 
12
- - a verbatim transcription of the "procedure" published in _The Computer Journal_,
12
+ - a verbatim transcription of Lunnon's "procedure" published in 1971 by _The Computer Journal_,
13
13
  - multiple referential versions of the procedure with explanatory comments including
14
14
  - [hunterNumba.py](https://github.com/hunterhogan/mapFolding/blob/main/mapFolding/reference), a one-size-fits-all, self-contained, reasonably fast, contemporary algorithm that is nevertheless infected by _noobaceae ignorancium_, and
15
15
  - miscellaneous notes.
16
16
 
17
- [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml)
17
+ [![Python Tests](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml/badge.svg)](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml) [![pip install mapFolding](https://img.shields.io/badge/pip%20install-mapFolding-gray.svg?colorB=3b434b)](https://pypi.org/project/mapFolding/) ![Static Badge](https://img.shields.io/badge/stinkin'%20badges-don't%20need-b98e5e) ![PyPI - Downloads](https://img.shields.io/pypi/dd/mapFolding) ![Static Badge](https://img.shields.io/badge/issues-I%20have%20them-brightgreen) ![GitHub repo size](https://img.shields.io/github/repo-size/hunterhogan/mapFolding)
18
18
 
19
19
  ## Simple, easy usage based on OEIS IDs
20
20
 
@@ -1,6 +1,6 @@
1
1
  from .theSSOT import *
2
- from .beDRY import getTaskDivisions, makeConnectionGraph, outfitFoldings, setCPUlimit
3
- from .beDRY import getLeavesTotal, parseDimensions, validateListDimensions
2
+ from Z0Z_tools import defineConcurrencyLimit, intInnit, oopsieKwargsie
3
+ from .beDRY import getFilenameFoldsTotal, outfitCountFolds
4
4
  from .startHere import countFolds
5
5
  from .oeis import oeisIDfor_n, getOEISids, clearOEIScache
6
6
 
@@ -6,7 +6,7 @@ import numba
6
6
  import numpy
7
7
 
8
8
  @numba.jit(cache=True)
9
- def _countFolds(connectionGraph: NDArray[integer[Any]], foldsTotal: NDArray[integer[Any]], mapShape: Tuple[int, ...], my: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]) -> int:
9
+ def _countFolds(connectionGraph: NDArray[integer[Any]], foldsSubTotals: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], mapShape: Tuple[int, ...], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
10
10
  """
11
11
  What in tarnation is this stupid module and function?
12
12
 
@@ -27,4 +27,4 @@ def _countFolds(connectionGraph: NDArray[integer[Any]], foldsTotal: NDArray[inte
27
27
  """
28
28
  # TODO learn if I really must change this jitted function to get the super jit to recompile
29
29
  # print('babbage')
30
- return countFoldsCompiled(connectionGraph, foldsTotal, my, gapsWhere, the, track)
30
+ countFoldsCompiled(connectionGraph=connectionGraph, foldsSubTotals=foldsSubTotals, gapsWhere=gapsWhere, my=my, the=the, track=track)
@@ -1,13 +1,17 @@
1
1
  """A relatively stable API for oft-needed functionality."""
2
- from mapFolding.importPackages import intInnit, defineConcurrencyLimit, oopsieKwargsie
2
+ from mapFolding import dtypeDefault, dtypeLarge
3
3
  from mapFolding import indexMy, indexThe, indexTrack, computationState
4
+ from mapFolding import intInnit, defineConcurrencyLimit, oopsieKwargsie
5
+ from numpy import integer
6
+ from numpy.typing import NDArray
4
7
  from typing import Any, List, Optional, Sequence, Type, Union
5
- import numpy
6
8
  import numba
7
- from numpy.typing import NDArray
8
- from numpy import integer
9
+ import numpy
9
10
  import sys
10
11
 
12
+ def getFilenameFoldsTotal(listDimensions: Sequence[int]) -> str:
13
+ return str(sorted(listDimensions)).replace(' ', '') + '.foldsTotal'
14
+
11
15
  def getLeavesTotal(listDimensions: Sequence[int]) -> int:
12
16
  """
13
17
  How many leaves are in the map.
@@ -32,7 +36,7 @@ def getLeavesTotal(listDimensions: Sequence[int]) -> int:
32
36
 
33
37
  return productDimensions
34
38
 
35
- def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrencyLimit: int, the: NDArray[integer[Any]], CPUlimit: Optional[Union[bool, float, int]], listDimensions: Sequence[int]):
39
+ def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrencyLimit: int, CPUlimit: Optional[Union[bool, float, int]], listDimensions: Sequence[int]):
36
40
  """
37
41
  Determines whether or how to divide the computation into tasks.
38
42
 
@@ -46,15 +50,12 @@ def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrenc
46
50
  - "cpu": limits the divisions to the number of available CPUs, i.e. `concurrencyLimit`
47
51
  concurrencyLimit:
48
52
  Maximum number of concurrent tasks allowed
49
- the:
50
- Array of settings, including `leavesTotal`
51
- CPUlimit: for error reporting
52
53
  listDimensions: for error reporting
54
+ CPUlimit: for error reporting
53
55
 
54
56
  Returns
55
57
  -------
56
- the
57
- Updated settings, including for `taskDivisions`
58
+ taskDivisions:
58
59
 
59
60
  Raises
60
61
  ------
@@ -65,26 +66,27 @@ def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrenc
65
66
  -----
66
67
  Task divisions cannot exceed total leaves to prevent duplicate counting of folds.
67
68
  """
68
-
69
69
  if not computationDivisions:
70
- the[indexThe.taskDivisions] = 0
71
- elif isinstance(computationDivisions, int):
72
- the[indexThe.taskDivisions] = computationDivisions
70
+ return 0
71
+ else:
72
+ leavesTotal = getLeavesTotal(listDimensions)
73
+ if isinstance(computationDivisions, int):
74
+ taskDivisions = computationDivisions
73
75
  elif isinstance(computationDivisions, str):
74
76
  computationDivisions = computationDivisions.lower()
75
77
  if computationDivisions == "maximum":
76
- the[indexThe.taskDivisions] = the[indexThe.leavesTotal]
78
+ taskDivisions = leavesTotal
77
79
  elif computationDivisions == "cpu":
78
- the[indexThe.taskDivisions] = min(concurrencyLimit, the[indexThe.leavesTotal])
80
+ taskDivisions = min(concurrencyLimit, leavesTotal)
79
81
  else:
80
82
  raise ValueError(f"I received {computationDivisions} for the parameter, `computationDivisions`, but the so-called programmer didn't implement code for that.")
81
83
 
82
- if the[indexThe.taskDivisions] > the[indexThe.leavesTotal]:
83
- raise ValueError(f"Problem: `taskDivisions`, ({the[indexThe.taskDivisions]}), is greater than `leavesTotal`, ({the[indexThe.leavesTotal]}), which will cause duplicate counting of the folds.\n\nChallenge: you cannot directly set `taskDivisions` or `leavesTotal`. They are derived from parameters that may or may not still be named `computationDivisions`, `CPUlimit` , and `listDimensions` and from dubious-quality Python code.\n\nFor those parameters, I received {computationDivisions=}, {CPUlimit=}, and {listDimensions=}.\n\nPotential solutions: get a different hobby or set `computationDivisions` to a different value.")
84
+ if taskDivisions > leavesTotal:
85
+ raise ValueError(f"Problem: `taskDivisions`, ({taskDivisions}), is greater than `leavesTotal`, ({leavesTotal}), which will cause duplicate counting of the folds.\n\nChallenge: you cannot directly set `taskDivisions` or `leavesTotal`. They are derived from parameters that may or may not still be named `computationDivisions`, `CPUlimit` , and `listDimensions` and from dubious-quality Python code.\n\nFor those parameters, I received {computationDivisions=}, {CPUlimit=}, and {listDimensions=}.\n\nPotential solutions: get a different hobby or set `computationDivisions` to a different value.")
84
86
 
85
- return the
87
+ return taskDivisions
86
88
 
87
- def makeConnectionGraph(listDimensions: Sequence[int], dtype: Optional[Type] = numpy.int64) -> NDArray[integer[Any]]:
89
+ def makeConnectionGraph(listDimensions: Sequence[int], **keywordArguments: Optional[Type]) -> NDArray[integer[Any]]:
88
90
  """
89
91
  Constructs a multi-dimensional connection graph representing the connections between the leaves of a map with the given dimensions.
90
92
  Also called a Cartesian product decomposition or dimensional product mapping.
@@ -94,16 +96,17 @@ def makeConnectionGraph(listDimensions: Sequence[int], dtype: Optional[Type] = n
94
96
  Returns:
95
97
  connectionGraph: A 3D numpy array with shape of (dimensionsTotal + 1, leavesTotal + 1, leavesTotal + 1).
96
98
  """
99
+ datatype = keywordArguments.get('datatype', dtypeDefault)
97
100
  mapShape = validateListDimensions(listDimensions)
98
101
  leavesTotal = getLeavesTotal(mapShape)
99
- arrayDimensions = numpy.array(mapShape, dtype=dtype)
102
+ arrayDimensions = numpy.array(mapShape, dtype=datatype)
100
103
  dimensionsTotal = len(arrayDimensions)
101
104
 
102
105
  # Step 1: find the cumulative product of the map's dimensions
103
- cumulativeProduct = numpy.multiply.accumulate([1] + mapShape, dtype=dtype)
106
+ cumulativeProduct = numpy.multiply.accumulate([1] + mapShape, dtype=datatype)
104
107
 
105
108
  # Step 2: create a coordinate system
106
- coordinateSystem = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1), dtype=dtype)
109
+ coordinateSystem = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1), dtype=datatype)
107
110
 
108
111
  for dimension1ndex in range(1, dimensionsTotal + 1):
109
112
  for leaf1ndex in range(1, leavesTotal + 1):
@@ -113,7 +116,7 @@ def makeConnectionGraph(listDimensions: Sequence[int], dtype: Optional[Type] = n
113
116
  )
114
117
 
115
118
  # Step 3: create and fill the connection graph
116
- connectionGraph = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1, leavesTotal + 1), dtype=dtype)
119
+ connectionGraph = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1, leavesTotal + 1), dtype=datatype)
117
120
 
118
121
  for dimension1ndex in range(1, dimensionsTotal + 1):
119
122
  for activeLeaf1ndex in range(1, leavesTotal + 1):
@@ -139,7 +142,13 @@ def makeConnectionGraph(listDimensions: Sequence[int], dtype: Optional[Type] = n
139
142
 
140
143
  return connectionGraph
141
144
 
142
- def outfitFoldings(listDimensions: Sequence[int], computationDivisions: Optional[Union[int, str]] = None, CPUlimit: Optional[Union[bool, float, int]] = None, dtypeDefault: Optional[Type] = numpy.int64, dtypeLarge: Optional[Type] = numpy.int64, ) -> computationState:
145
+ def makeDataContainer(shape, datatype: Optional[Type] = None):
146
+ """Create a container, probably numpy.ndarray, with the given shape and datatype."""
147
+ if datatype is None:
148
+ datatype = dtypeDefault
149
+ return numpy.zeros(shape, dtype=datatype)
150
+
151
+ def outfitCountFolds(listDimensions: Sequence[int], computationDivisions: Optional[Union[int, str]] = None, CPUlimit: Optional[Union[bool, float, int]] = None, **keywordArguments: Optional[Type]) -> computationState:
143
152
  """
144
153
  Initializes and configures the computation state for map folding computations.
145
154
 
@@ -148,42 +157,53 @@ def outfitFoldings(listDimensions: Sequence[int], computationDivisions: Optional
148
157
  listDimensions:
149
158
  The dimensions of the map to be folded
150
159
  computationDivisions (None):
151
- Specifies how to divide the computation tasks
160
+ Specifies how to divide computations:
161
+ - None: no division of the computation into tasks; sets task divisions to 0
162
+ - int: direct set the number of task divisions; cannot exceed the map's total leaves
163
+ - "maximum": divides into `leavesTotal`-many `taskDivisions`
164
+ - "cpu": limits the divisions to the number of available CPUs, i.e. `concurrencyLimit`
152
165
  CPUlimit (None):
153
- Limits the CPU usage for computations
154
- dtypeDefault (numpy.int64):
155
- The default numpy dtype to use for arrays
156
- dtypeLarge (numpy.int64):
157
- The numpy dtype to use for larger arrays
166
+ Whether and how to limit the CPU usage. See notes for details.
158
167
 
159
168
  Returns
160
169
  -------
161
170
  computationState
162
171
  An initialized computation state containing:
163
172
  - connectionGraph: Graph representing connections in the map
164
- - foldsTotal: Array tracking total folds
173
+ - foldsSubTotals: Array tracking total folds
165
174
  - mapShape: Validated and sorted dimensions of the map
166
175
  - my: Array for internal state tracking
167
176
  - gapsWhere: Array tracking gap positions
168
- - the: Configured task divisions
177
+ - the: Static settings and metadata
169
178
  - track: Array for tracking computation progress
179
+
180
+ Limits on CPU usage `CPUlimit`:
181
+ - `False`, `None`, or `0`: No limits on CPU usage; uses all available CPUs. All other values will potentially limit CPU usage.
182
+ - `True`: Yes, limit the CPU usage; limits to 1 CPU.
183
+ - Integer `>= 1`: Limits usage to the specified number of CPUs.
184
+ - Decimal value (`float`) between 0 and 1: Fraction of total CPUs to use.
185
+ - Decimal value (`float`) between -1 and 0: Fraction of CPUs to *not* use.
186
+ - Integer `<= -1`: Subtract the absolute value from total CPUs.
170
187
  """
188
+ datatypeDefault = keywordArguments.get('datatypeDefault', dtypeDefault)
189
+ datatypeLarge = keywordArguments.get('datatypeLarge', dtypeLarge)
171
190
 
172
- the = numpy.zeros(len(indexThe), dtype=dtypeDefault)
191
+ the = makeDataContainer(len(indexThe), datatypeDefault)
173
192
 
174
193
  mapShape = tuple(sorted(validateListDimensions(listDimensions)))
175
194
  the[indexThe.leavesTotal] = getLeavesTotal(mapShape)
176
195
  the[indexThe.dimensionsTotal] = len(mapShape)
177
196
  concurrencyLimit = setCPUlimit(CPUlimit)
197
+ the[indexThe.taskDivisions] = getTaskDivisions(computationDivisions, concurrencyLimit, CPUlimit, listDimensions)
178
198
 
179
199
  stateInitialized = computationState(
180
- connectionGraph = makeConnectionGraph(mapShape, dtype=dtypeDefault),
181
- foldsTotal = numpy.zeros(the[indexThe.leavesTotal], dtype=numpy.int64),
200
+ connectionGraph = makeConnectionGraph(mapShape, datatype=datatypeDefault),
201
+ foldsSubTotals = makeDataContainer(the[indexThe.leavesTotal], datatypeLarge),
182
202
  mapShape = mapShape,
183
- my = numpy.zeros(len(indexMy), dtype=dtypeLarge),
184
- gapsWhere = numpy.zeros(int(the[indexThe.leavesTotal]) * int(the[indexThe.leavesTotal]) + 1, dtype=dtypeDefault),
185
- the = getTaskDivisions(computationDivisions, concurrencyLimit, the, CPUlimit, listDimensions),
186
- track = numpy.zeros((len(indexTrack), the[indexThe.leavesTotal] + 1), dtype=dtypeLarge)
203
+ my = makeDataContainer(len(indexMy), datatypeLarge),
204
+ gapsWhere = makeDataContainer(int(the[indexThe.leavesTotal]) * int(the[indexThe.leavesTotal]) + 1, datatypeDefault),
205
+ the = the,
206
+ track = makeDataContainer((len(indexTrack), the[indexThe.leavesTotal] + 1), datatypeLarge)
187
207
  )
188
208
 
189
209
  stateInitialized['my'][indexMy.leaf1ndex.value] = 1
@@ -0,0 +1,217 @@
1
+ from mapFolding import indexMy, indexThe, indexTrack
2
+ from numpy import integer
3
+ from numpy.typing import NDArray
4
+ from typing import Any
5
+ import numba
6
+ import numpy
7
+
8
+ def activeGapIncrement(my: NDArray[integer[Any]]):
9
+ my[indexMy.gap1ndex.value] += 1
10
+
11
+ def activeLeafGreaterThan0Condition(my: NDArray[integer[Any]]):
12
+ return my[indexMy.leaf1ndex.value] > 0
13
+
14
+ def activeLeafGreaterThanLeavesTotalCondition(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
15
+ return my[indexMy.leaf1ndex.value] > the[indexThe.leavesTotal.value]
16
+
17
+ def activeLeafIsTheFirstLeafCondition(my: NDArray[integer[Any]]):
18
+ return my[indexMy.leaf1ndex.value] <= 1
19
+
20
+ def activeLeafNotEqualToTaskDivisionsCondition(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
21
+ return my[indexMy.leaf1ndex.value] != the[indexThe.taskDivisions.value]
22
+
23
+ def allDimensionsAreUnconstrained(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
24
+ return my[indexMy.dimensionsUnconstrained.value] == the[indexThe.dimensionsTotal.value]
25
+
26
+ def backtrack(my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
27
+ my[indexMy.leaf1ndex.value] -= 1
28
+ track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
29
+ track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]
30
+
31
+ def backtrackCondition(my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
32
+ return my[indexMy.leaf1ndex.value] > 0 and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
33
+
34
+ def countGaps(gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
35
+ gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
36
+ if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
37
+ gap1ndexCeilingIncrement(my=my)
38
+ track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
39
+
40
+ def dimension1ndexIncrement(my: NDArray[integer[Any]]):
41
+ my[indexMy.dimension1ndex.value] += 1
42
+
43
+ def dimensionsUnconstrainedCondition(connectionGraph: NDArray[integer[Any]], my: NDArray[integer[Any]]):
44
+ return connectionGraph[my[indexMy.dimension1ndex.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]
45
+
46
+ def dimensionsUnconstrainedIncrement(my: NDArray[integer[Any]]):
47
+ my[indexMy.dimensionsUnconstrained.value] += 1
48
+
49
+ def filterCommonGaps(gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
50
+ gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
51
+ if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == the[indexThe.dimensionsTotal.value] - my[indexMy.dimensionsUnconstrained.value]:
52
+ activeGapIncrement(my=my)
53
+ track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
54
+
55
+ def findGapsInitializeVariables(my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
56
+ my[indexMy.dimensionsUnconstrained.value] = 0
57
+ my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
58
+ my[indexMy.dimension1ndex.value] = 1
59
+
60
+ def foldsSubTotalIncrement(foldsSubTotals: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
61
+ foldsSubTotals[my[indexMy.taskIndex.value]] += the[indexThe.leavesTotal.value]
62
+
63
+ def gap1ndexCeilingIncrement(my: NDArray[integer[Any]]):
64
+ my[indexMy.gap1ndexCeiling.value] += 1
65
+
66
+ def indexMiniGapIncrement(my: NDArray[integer[Any]]):
67
+ my[indexMy.indexMiniGap.value] += 1
68
+
69
+ def indexMiniGapInitialization(my: NDArray[integer[Any]]):
70
+ my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
71
+
72
+ def insertUnconstrainedLeaf(gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]]):
73
+ my[indexMy.indexLeaf.value] = 0
74
+ while my[indexMy.indexLeaf.value] < my[indexMy.leaf1ndex.value]:
75
+ gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.indexLeaf.value]
76
+ my[indexMy.gap1ndexCeiling.value] += 1
77
+ my[indexMy.indexLeaf.value] += 1
78
+
79
+ def leafBelowSentinelIs1Condition(track: NDArray[integer[Any]]):
80
+ return track[indexTrack.leafBelow.value, 0] == 1
81
+
82
+ def leafConnecteeInitialization(connectionGraph: NDArray[integer[Any]], my: NDArray[integer[Any]]):
83
+ my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.dimension1ndex.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
84
+
85
+ def leafConnecteeUpdate(connectionGraph: NDArray[integer[Any]], my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
86
+ my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.dimension1ndex.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
87
+
88
+ def loopingLeavesConnectedToActiveLeaf(my: NDArray[integer[Any]]):
89
+ return my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]
90
+
91
+ def loopingTheDimensions(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
92
+ return my[indexMy.dimension1ndex.value] <= the[indexThe.dimensionsTotal.value]
93
+
94
+ def loopingToActiveGapCeiling(my: NDArray[integer[Any]]):
95
+ return my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]
96
+
97
+ def placeLeaf(gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], track: NDArray[integer[Any]]):
98
+ my[indexMy.gap1ndex.value] -= 1
99
+ track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
100
+ track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
101
+ track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
102
+ track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
103
+ track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
104
+ my[indexMy.leaf1ndex.value] += 1
105
+
106
+ def placeLeafCondition(my: NDArray[integer[Any]]):
107
+ return my[indexMy.leaf1ndex.value] > 0
108
+
109
+ def taskIndexCondition(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
110
+ return my[indexMy.leafConnectee.value] % the[indexThe.taskDivisions.value] == my[indexMy.taskIndex.value]
111
+
112
+ def thereAreComputationDivisionsYouMightSkip(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
113
+ if activeLeafNotEqualToTaskDivisionsCondition(my=my, the=the):
114
+ return True
115
+ if taskIndexCondition(my=my, the=the):
116
+ return True
117
+ return False
118
+
119
+ def initialize(connectionGraph: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
120
+ while activeLeafGreaterThan0Condition(my=my):
121
+ if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
122
+ findGapsInitializeVariables(my=my, track=track)
123
+ while loopingTheDimensions(my=my, the=the):
124
+ if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
125
+ dimensionsUnconstrainedIncrement(my=my)
126
+ else:
127
+ leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
128
+ while loopingLeavesConnectedToActiveLeaf(my=my):
129
+ countGaps(gapsWhere=gapsWhere, my=my, track=track)
130
+ leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
131
+ dimension1ndexIncrement(my=my)
132
+ if allDimensionsAreUnconstrained(my=my, the=the):
133
+ insertUnconstrainedLeaf(gapsWhere=gapsWhere, my=my)
134
+ indexMiniGapInitialization(my=my)
135
+ while loopingToActiveGapCeiling(my=my):
136
+ filterCommonGaps(gapsWhere=gapsWhere, my=my, the=the, track=track)
137
+ indexMiniGapIncrement(my=my)
138
+ if placeLeafCondition(my=my):
139
+ placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
140
+ if my[indexMy.gap1ndex.value] > 0:
141
+ break
142
+
143
+ def countParallel(connectionGraph: NDArray[integer[Any]], foldsSubTotals: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
144
+ while activeLeafGreaterThan0Condition(my=my):
145
+ if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
146
+ if activeLeafGreaterThanLeavesTotalCondition(my=my, the=the):
147
+ foldsSubTotalIncrement(foldsSubTotals=foldsSubTotals, my=my, the=the)
148
+ else:
149
+ findGapsInitializeVariables(my=my, track=track)
150
+ while loopingTheDimensions(my=my, the=the):
151
+ if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
152
+ dimensionsUnconstrainedIncrement(my=my)
153
+ else:
154
+ leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
155
+ while loopingLeavesConnectedToActiveLeaf(my=my):
156
+ if thereAreComputationDivisionsYouMightSkip(my=my, the=the):
157
+ countGaps(gapsWhere=gapsWhere, my=my, track=track)
158
+ leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
159
+ dimension1ndexIncrement(my=my)
160
+ indexMiniGapInitialization(my=my)
161
+ while loopingToActiveGapCeiling(my=my):
162
+ filterCommonGaps(gapsWhere=gapsWhere, my=my, the=the, track=track)
163
+ indexMiniGapIncrement(my=my)
164
+ while backtrackCondition(my=my, track=track):
165
+ backtrack(my=my, track=track)
166
+ if placeLeafCondition(my=my):
167
+ placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
168
+
169
+ def countSequential(connectionGraph: NDArray[integer[Any]], foldsSubTotals: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
170
+ while activeLeafGreaterThan0Condition(my=my):
171
+ if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
172
+ if activeLeafGreaterThanLeavesTotalCondition(my=my, the=the):
173
+ foldsSubTotalIncrement(foldsSubTotals=foldsSubTotals, my=my, the=the)
174
+ else:
175
+ findGapsInitializeVariables(my=my, track=track)
176
+ while loopingTheDimensions(my=my, the=the):
177
+ if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
178
+ dimensionsUnconstrainedIncrement(my=my)
179
+ else:
180
+ leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
181
+ while loopingLeavesConnectedToActiveLeaf(my=my):
182
+ countGaps(gapsWhere=gapsWhere, my=my, track=track)
183
+ leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
184
+ dimension1ndexIncrement(my=my)
185
+ indexMiniGapInitialization(my=my)
186
+ while loopingToActiveGapCeiling(my=my):
187
+ filterCommonGaps(gapsWhere=gapsWhere, my=my, the=the, track=track)
188
+ indexMiniGapIncrement(my=my)
189
+ while backtrackCondition(my=my, track=track):
190
+ backtrack(my=my, track=track)
191
+ if placeLeafCondition(my=my):
192
+ placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
193
+
194
+ @numba.jit(parallel=True, _nrt=True, boundscheck=False, error_model='numpy', fastmath=True, forceinline=True, looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nogil=True, nopython=True)
195
+ def doTaskIndices(connectionGraph: NDArray[integer[Any]], foldsSubTotals: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
196
+
197
+ stateGapsWhere = gapsWhere.copy()
198
+ stateMy = my.copy()
199
+ stateTrack = track.copy()
200
+
201
+ for indexSherpa in numba.prange(the[indexThe.taskDivisions.value]):
202
+ mySherpa = stateMy.copy()
203
+ mySherpa[indexMy.taskIndex.value] = indexSherpa
204
+ countParallel(connectionGraph=connectionGraph, foldsSubTotals=foldsSubTotals, gapsWhere=stateGapsWhere.copy(), my=mySherpa, the=the, track=stateTrack.copy())
205
+
206
+ return foldsSubTotals
207
+
208
+ def countFoldsCompiled(connectionGraph: NDArray[integer[Any]], foldsSubTotals: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], my: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]]):
209
+
210
+ initialize(connectionGraph=connectionGraph, gapsWhere=gapsWhere, my=my, the=the, track=track)
211
+
212
+ if the[indexThe.taskDivisions.value] > 0:
213
+ doTaskIndices(connectionGraph=connectionGraph, foldsSubTotals=foldsSubTotals, gapsWhere=gapsWhere, my=my, the=the, track=track)
214
+ else:
215
+ countSequential(connectionGraph=connectionGraph, foldsSubTotals=foldsSubTotals, gapsWhere=gapsWhere, my=my, the=the, track=track)
216
+
217
+ numba.jit_module(parallel=False, _nrt=True, boundscheck=False, error_model='numpy', fastmath=True, forceinline=True, looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nogil=True, nopython=True)
@@ -65,6 +65,40 @@ settingsOEIShardcodedValues = {
65
65
  oeisIDsImplemented: Final[List[str]] = sorted([oeisID.upper().strip() for oeisID in settingsOEIShardcodedValues.keys()])
66
66
  """Directly implemented OEIS IDs; standardized, e.g., 'A001415'."""
67
67
 
68
+ def _validateOEISid(oeisIDcandidate: str):
69
+ """
70
+ Validates an OEIS sequence ID against implemented sequences.
71
+
72
+ If the provided ID is recognized within the application's implemented
73
+ OEIS sequences, the function returns the verified ID in uppercase.
74
+ Otherwise, a KeyError is raised indicating that the sequence is not
75
+ directly supported.
76
+
77
+ Parameters:
78
+ oeisIDcandidate: The OEIS sequence identifier to validate.
79
+
80
+ Returns:
81
+ oeisID: The validated and possibly modified OEIS sequence ID, if recognized.
82
+
83
+ Raises:
84
+ KeyError: If the provided sequence ID is not directly implemented.
85
+ """
86
+ if oeisIDcandidate in oeisIDsImplemented:
87
+ return oeisIDcandidate
88
+ else:
89
+ oeisIDcleaned = str(oeisIDcandidate).upper().strip()
90
+ if oeisIDcleaned in oeisIDsImplemented:
91
+ return oeisIDcleaned
92
+ else:
93
+ raise KeyError(
94
+ f"OEIS ID {oeisIDcandidate} is not directly implemented.\n"
95
+ f"Available sequences:\n{_formatOEISsequenceInfo()}"
96
+ )
97
+
98
+ def _getFilenameOEISbFile(oeisID: str) -> str:
99
+ oeisID = _validateOEISid(oeisID)
100
+ return f"b{oeisID[1:]}.txt"
101
+
68
102
  def _parseBFileOEIS(OEISbFile: str, oeisID: str) -> Dict[int, int]:
69
103
  """
70
104
  Parses the content of an OEIS b-file for a given sequence ID.
@@ -101,8 +135,6 @@ try:
101
135
  except NameError:
102
136
  _pathCache = pathlib.Path.home() / ".mapFoldingCache"
103
137
 
104
- _formatFilenameCache = "{oeisID}.txt"
105
-
106
138
  def _getOEISidValues(oeisID: str) -> Dict[int, int]:
107
139
  """
108
140
  Retrieves the specified OEIS sequence as a dictionary mapping integer indices
@@ -122,7 +154,7 @@ def _getOEISidValues(oeisID: str) -> Dict[int, int]:
122
154
  IOError: If there is an error reading from or writing to the local cache.
123
155
  """
124
156
 
125
- pathFilenameCache = _pathCache / _formatFilenameCache.format(oeisID=oeisID)
157
+ pathFilenameCache = _pathCache / _getFilenameOEISbFile(oeisID)
126
158
  cacheDays = 7
127
159
 
128
160
  tryCache = False
@@ -137,7 +169,7 @@ def _getOEISidValues(oeisID: str) -> Dict[int, int]:
137
169
  except (ValueError, IOError):
138
170
  tryCache = False
139
171
 
140
- urlOEISbFile = f"https://oeis.org/{oeisID}/b{oeisID[1:]}.txt"
172
+ urlOEISbFile = f"https://oeis.org/{oeisID}/{_getFilenameOEISbFile(oeisID)}"
141
173
  httpResponse: urllib.response.addinfourl = urllib.request.urlopen(urlOEISbFile)
142
174
  OEISbFile = httpResponse.read().decode('utf-8')
143
175
 
@@ -212,36 +244,6 @@ def _formatOEISsequenceInfo() -> str:
212
244
  for oeisID in oeisIDsImplemented
213
245
  )
214
246
 
215
- def _validateOEISid(oeisIDcandidate: str):
216
- """
217
- Validates an OEIS sequence ID against implemented sequences.
218
-
219
- If the provided ID is recognized within the application's implemented
220
- OEIS sequences, the function returns the verified ID in uppercase.
221
- Otherwise, a KeyError is raised indicating that the sequence is not
222
- directly supported.
223
-
224
- Parameters:
225
- oeisIDcandidate: The OEIS sequence identifier to validate.
226
-
227
- Returns:
228
- oeisID: The validated and possibly modified OEIS sequence ID, if recognized.
229
-
230
- Raises:
231
- KeyError: If the provided sequence ID is not directly implemented.
232
- """
233
- if oeisIDcandidate in oeisIDsImplemented:
234
- return oeisIDcandidate
235
- else:
236
- oeisIDcleaned = str(oeisIDcandidate).upper().strip()
237
- if oeisIDcleaned in oeisIDsImplemented:
238
- return oeisIDcleaned
239
- else:
240
- raise KeyError(
241
- f"OEIS ID {oeisIDcandidate} is not directly implemented.\n"
242
- f"Available sequences:\n{_formatOEISsequenceInfo()}"
243
- )
244
-
245
247
  """
246
248
  Section: public functions"""
247
249
 
@@ -308,7 +310,7 @@ def clearOEIScache() -> None:
308
310
  return
309
311
  else:
310
312
  for oeisID in settingsOEIS:
311
- pathFilenameCache = _pathCache / _formatFilenameCache.format(oeisID=oeisID)
313
+ pathFilenameCache = _pathCache / _getFilenameOEISbFile(oeisID)
312
314
  pathFilenameCache.unlink(missing_ok=True)
313
315
 
314
316
  print(f"Cache cleared from {_pathCache}")