mapFolding 0.2.2__py3-none-any.whl → 0.2.3__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 +1 -2
- mapFolding/babbage.py +2 -2
- mapFolding/beDRY.py +26 -12
- mapFolding/lovelace.py +194 -122
- mapFolding/reference/flattened.py +376 -0
- mapFolding/startHere.py +10 -8
- mapFolding/theSSOT.py +2 -2
- {mapFolding-0.2.2.dist-info → mapFolding-0.2.3.dist-info}/METADATA +4 -4
- {mapFolding-0.2.2.dist-info → mapFolding-0.2.3.dist-info}/RECORD +16 -14
- tests/__init__.py +1 -1
- tests/conftest.py +24 -6
- tests/pythons_idiotic_namespace.py +1 -0
- tests/test_other.py +108 -15
- {mapFolding-0.2.2.dist-info → mapFolding-0.2.3.dist-info}/WHEEL +0 -0
- {mapFolding-0.2.2.dist-info → mapFolding-0.2.3.dist-info}/entry_points.txt +0 -0
- {mapFolding-0.2.2.dist-info → mapFolding-0.2.3.dist-info}/top_level.txt +0 -0
mapFolding/__init__.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from .theSSOT import *
|
|
2
2
|
from Z0Z_tools import defineConcurrencyLimit, intInnit, oopsieKwargsie
|
|
3
|
-
from .beDRY import
|
|
4
|
-
from .beDRY import getLeavesTotal, parseDimensions, validateListDimensions
|
|
3
|
+
from .beDRY import getFilenameFoldsTotal, outfitCountFolds
|
|
5
4
|
from .startHere import countFolds
|
|
6
5
|
from .oeis import oeisIDfor_n, getOEISids, clearOEIScache
|
|
7
6
|
|
mapFolding/babbage.py
CHANGED
|
@@ -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]],
|
|
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
|
-
|
|
30
|
+
countFoldsCompiled(connectionGraph=connectionGraph, foldsSubTotals=foldsSubTotals, gapsWhere=gapsWhere, my=my, the=the, track=track)
|
mapFolding/beDRY.py
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"""A relatively stable API for oft-needed functionality."""
|
|
2
|
-
from mapFolding import
|
|
2
|
+
from mapFolding import dtypeDefault, dtypeLarge
|
|
3
3
|
from mapFolding import indexMy, indexThe, indexTrack, computationState
|
|
4
|
-
from mapFolding import
|
|
4
|
+
from mapFolding import intInnit, defineConcurrencyLimit, oopsieKwargsie
|
|
5
|
+
from numpy import integer
|
|
6
|
+
from numpy.typing import NDArray
|
|
5
7
|
from typing import Any, List, Optional, Sequence, Type, Union
|
|
6
|
-
import numpy
|
|
7
8
|
import numba
|
|
8
|
-
|
|
9
|
-
from numpy import integer
|
|
9
|
+
import numpy
|
|
10
10
|
import sys
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
def getFilenameFoldsTotal(listDimensions: Sequence[int]) -> str:
|
|
13
|
+
return str(sorted(listDimensions)).replace(' ', '') + '.foldsTotal'
|
|
12
14
|
|
|
13
15
|
def getLeavesTotal(listDimensions: Sequence[int]) -> int:
|
|
14
16
|
"""
|
|
@@ -146,7 +148,7 @@ def makeDataContainer(shape, datatype: Optional[Type] = None):
|
|
|
146
148
|
datatype = dtypeDefault
|
|
147
149
|
return numpy.zeros(shape, dtype=datatype)
|
|
148
150
|
|
|
149
|
-
def
|
|
151
|
+
def outfitCountFolds(listDimensions: Sequence[int], computationDivisions: Optional[Union[int, str]] = None, CPUlimit: Optional[Union[bool, float, int]] = None, **keywordArguments: Optional[Type]) -> computationState:
|
|
150
152
|
"""
|
|
151
153
|
Initializes and configures the computation state for map folding computations.
|
|
152
154
|
|
|
@@ -155,21 +157,33 @@ def outfitFoldings(listDimensions: Sequence[int], computationDivisions: Optional
|
|
|
155
157
|
listDimensions:
|
|
156
158
|
The dimensions of the map to be folded
|
|
157
159
|
computationDivisions (None):
|
|
158
|
-
Specifies how to divide
|
|
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`
|
|
159
165
|
CPUlimit (None):
|
|
160
|
-
|
|
166
|
+
Whether and how to limit the CPU usage. See notes for details.
|
|
161
167
|
|
|
162
168
|
Returns
|
|
163
169
|
-------
|
|
164
170
|
computationState
|
|
165
171
|
An initialized computation state containing:
|
|
166
172
|
- connectionGraph: Graph representing connections in the map
|
|
167
|
-
-
|
|
173
|
+
- foldsSubTotals: Array tracking total folds
|
|
168
174
|
- mapShape: Validated and sorted dimensions of the map
|
|
169
175
|
- my: Array for internal state tracking
|
|
170
176
|
- gapsWhere: Array tracking gap positions
|
|
171
177
|
- the: Static settings and metadata
|
|
172
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.
|
|
173
187
|
"""
|
|
174
188
|
datatypeDefault = keywordArguments.get('datatypeDefault', dtypeDefault)
|
|
175
189
|
datatypeLarge = keywordArguments.get('datatypeLarge', dtypeLarge)
|
|
@@ -181,10 +195,10 @@ def outfitFoldings(listDimensions: Sequence[int], computationDivisions: Optional
|
|
|
181
195
|
the[indexThe.dimensionsTotal] = len(mapShape)
|
|
182
196
|
concurrencyLimit = setCPUlimit(CPUlimit)
|
|
183
197
|
the[indexThe.taskDivisions] = getTaskDivisions(computationDivisions, concurrencyLimit, CPUlimit, listDimensions)
|
|
184
|
-
|
|
198
|
+
|
|
185
199
|
stateInitialized = computationState(
|
|
186
200
|
connectionGraph = makeConnectionGraph(mapShape, datatype=datatypeDefault),
|
|
187
|
-
|
|
201
|
+
foldsSubTotals = makeDataContainer(the[indexThe.leavesTotal], datatypeLarge),
|
|
188
202
|
mapShape = mapShape,
|
|
189
203
|
my = makeDataContainer(len(indexMy), datatypeLarge),
|
|
190
204
|
gapsWhere = makeDataContainer(int(the[indexThe.leavesTotal]) * int(the[indexThe.leavesTotal]) + 1, datatypeDefault),
|
mapFolding/lovelace.py
CHANGED
|
@@ -1,145 +1,217 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
def activeGapIncrement(my: NDArray[integer[Any]]):
|
|
9
|
+
my[indexMy.gap1ndex.value] += 1
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
def activeLeafGreaterThan0Condition(my: NDArray[integer[Any]]):
|
|
12
|
+
return my[indexMy.leaf1ndex.value] > 0
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
def activeLeafGreaterThanLeavesTotalCondition(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
|
|
15
|
+
return my[indexMy.leaf1ndex.value] > the[indexThe.leavesTotal.value]
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
def activeLeafIsTheFirstLeafCondition(my: NDArray[integer[Any]]):
|
|
18
|
+
return my[indexMy.leaf1ndex.value] <= 1
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
def activeLeafNotEqualToTaskDivisionsCondition(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
|
|
21
|
+
return my[indexMy.leaf1ndex.value] != the[indexThe.taskDivisions.value]
|
|
14
22
|
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
from mapFolding import indexMy, indexThe, indexTrack
|
|
18
|
-
from numpy import integer
|
|
19
|
-
from numpy.typing import NDArray
|
|
20
|
-
from typing import Any, Tuple, Optional
|
|
21
|
-
import numba
|
|
22
|
-
import numpy
|
|
23
|
+
def allDimensionsAreUnconstrained(my: NDArray[integer[Any]], the: NDArray[integer[Any]]):
|
|
24
|
+
return my[indexMy.dimensionsUnconstrained.value] == the[indexThe.dimensionsTotal.value]
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return my[indexMy.leaf1ndex.value] != the[indexThe.taskDivisions.value] or \
|
|
29
|
-
(my[indexMy.leafConnectee.value] % the[indexThe.taskDivisions.value]) == my[indexMy.taskIndex.value]
|
|
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
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if initializeUnconstrainedLeaf:
|
|
34
|
-
return my[indexMy.dimensionsUnconstrained.value] == the[indexThe.dimensionsTotal.value]
|
|
35
|
-
else:
|
|
36
|
-
return False
|
|
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]
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if
|
|
41
|
-
|
|
42
|
-
|
|
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)
|
|
43
140
|
if my[indexMy.gap1ndex.value] > 0:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
|
|
52
|
-
if my[indexMy.leaf1ndex.value] > the[indexThe.leavesTotal.value]:
|
|
53
|
-
foldsTotal[my[indexMy.taskIndex.value]] += the[indexThe.leavesTotal.value]
|
|
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)
|
|
54
148
|
else:
|
|
55
|
-
my
|
|
56
|
-
my
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if connectionGraph[my[indexMy.dimension1ndex.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]:
|
|
60
|
-
my[indexMy.dimensionsUnconstrained.value] += 1
|
|
149
|
+
findGapsInitializeVariables(my=my, track=track)
|
|
150
|
+
while loopingTheDimensions(my=my, the=the):
|
|
151
|
+
if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
|
|
152
|
+
dimensionsUnconstrainedIncrement(my=my)
|
|
61
153
|
else:
|
|
62
|
-
|
|
63
|
-
while my
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
my
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if
|
|
100
|
-
|
|
101
|
-
return foldsTotal, my, gapsWhere, track
|
|
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)
|
|
102
193
|
|
|
103
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)
|
|
104
|
-
def doTaskIndices(connectionGraph: NDArray[integer[Any]],
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
Run the counting algorithm but with conditional execution of a few lines of code, so each task has an incomplete count that does not overlap with other tasks."""
|
|
108
|
-
stateFoldsSubTotal = foldsTotal.copy()
|
|
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()
|
|
109
198
|
stateMy = my.copy()
|
|
110
|
-
statePotentialGaps = gapsWhere.copy()
|
|
111
199
|
stateTrack = track.copy()
|
|
112
200
|
|
|
113
201
|
for indexSherpa in numba.prange(the[indexThe.taskDivisions.value]):
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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())
|
|
117
205
|
|
|
118
|
-
|
|
206
|
+
return foldsSubTotals
|
|
119
207
|
|
|
120
|
-
|
|
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]]):
|
|
121
209
|
|
|
122
|
-
|
|
123
|
-
def countFoldsCompileBranch(connectionGraph: NDArray[integer[Any]], foldsTotal: NDArray[integer[Any]], my: NDArray[integer[Any]], gapsWhere: NDArray[integer[Any]], the: NDArray[integer[Any]], track: NDArray[integer[Any]], obviousFlagForNumba: bool) -> NDArray[integer[Any]]:
|
|
124
|
-
"""Allegedly, `obviousFlagForNumba` allows Numba to compile two versions: one for parallel execution and one leaner version for sequential execution."""
|
|
125
|
-
if obviousFlagForNumba:
|
|
126
|
-
foldsTotal, _1, _2, _3 = doWhile(connectionGraph, foldsTotal, my, gapsWhere, the, track, initializeUnconstrainedLeaf=False)
|
|
127
|
-
else:
|
|
128
|
-
foldsTotal = doTaskIndices(connectionGraph, foldsTotal, my, gapsWhere, the, track)
|
|
210
|
+
initialize(connectionGraph=connectionGraph, gapsWhere=gapsWhere, my=my, the=the, track=track)
|
|
129
211
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# ^ Receive the data structures.
|
|
135
|
-
|
|
136
|
-
# Initialize baseline values primarily to eliminate the need for the logic of `insertUnconstrainedLeaf`
|
|
137
|
-
_0, my, gapsWhere, track = doWhile(connectionGraph, foldsTotal, my, gapsWhere, the, track, initializeUnconstrainedLeaf=True)
|
|
138
|
-
|
|
139
|
-
obviousFlagForNumba = the[indexThe.taskDivisions.value] == int(False)
|
|
140
|
-
|
|
141
|
-
# Call the function that will branch to sequential or parallel counting
|
|
142
|
-
foldsTotal = countFoldsCompileBranch(connectionGraph, foldsTotal, my, gapsWhere, the, track, obviousFlagForNumba)
|
|
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)
|
|
143
216
|
|
|
144
|
-
|
|
145
|
-
return numpy.sum(foldsTotal).item()
|
|
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)
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"""The algorithm flattened into semantic sections.
|
|
2
|
+
This version is not maintained, so you may see differences from the current version."""
|
|
3
|
+
from numpy import integer
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
from typing import List, Any, Final, Optional, Union, Sequence, Tuple, Type, TypedDict
|
|
6
|
+
import enum
|
|
7
|
+
import numpy
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
def countFolds(listDimensions: Sequence[int], computationDivisions = None, CPUlimit: Optional[Union[int, float, bool]] = None):
|
|
11
|
+
def doWhile():
|
|
12
|
+
|
|
13
|
+
while activeLeafGreaterThan0Condition():
|
|
14
|
+
|
|
15
|
+
if activeLeafIsTheFirstLeafCondition() or leafBelowSentinelIs1Condition():
|
|
16
|
+
|
|
17
|
+
if activeLeafGreaterThanLeavesTotalCondition():
|
|
18
|
+
foldsSubTotalsIncrement()
|
|
19
|
+
|
|
20
|
+
else:
|
|
21
|
+
|
|
22
|
+
findGapsInitializeVariables()
|
|
23
|
+
while loopingTheDimensions():
|
|
24
|
+
|
|
25
|
+
if dimensionsUnconstrainedCondition():
|
|
26
|
+
dimensionsUnconstrainedIncrement()
|
|
27
|
+
|
|
28
|
+
else:
|
|
29
|
+
|
|
30
|
+
leafConnecteeInitialization()
|
|
31
|
+
while loopingLeavesConnectedToActiveLeaf():
|
|
32
|
+
if thereAreComputationDivisionsYouMightSkip():
|
|
33
|
+
countGaps()
|
|
34
|
+
leafConnecteeUpdate()
|
|
35
|
+
|
|
36
|
+
dimension1ndexIncrement()
|
|
37
|
+
|
|
38
|
+
if allDimensionsAreUnconstrained():
|
|
39
|
+
insertUnconstrainedLeaf()
|
|
40
|
+
|
|
41
|
+
indexMiniGapInitialization()
|
|
42
|
+
while loopingToActiveGapCeiling():
|
|
43
|
+
filterCommonGaps()
|
|
44
|
+
indexMiniGapIncrement()
|
|
45
|
+
|
|
46
|
+
while backtrackCondition():
|
|
47
|
+
backtrack()
|
|
48
|
+
|
|
49
|
+
if placeLeafCondition():
|
|
50
|
+
placeLeaf()
|
|
51
|
+
|
|
52
|
+
def activeGapIncrement():
|
|
53
|
+
my[indexMy.gap1ndex] += 1
|
|
54
|
+
|
|
55
|
+
def activeLeafGreaterThan0Condition():
|
|
56
|
+
return my[indexMy.leaf1ndex] > 0
|
|
57
|
+
|
|
58
|
+
def activeLeafGreaterThanLeavesTotalCondition():
|
|
59
|
+
return my[indexMy.leaf1ndex] > the[indexThe.leavesTotal]
|
|
60
|
+
|
|
61
|
+
def activeLeafIsTheFirstLeafCondition():
|
|
62
|
+
return my[indexMy.leaf1ndex] <= 1
|
|
63
|
+
|
|
64
|
+
def activeLeafNotEqualToTaskDivisionsCondition():
|
|
65
|
+
return my[indexMy.leaf1ndex] != the[indexThe.taskDivisions]
|
|
66
|
+
|
|
67
|
+
def allDimensionsAreUnconstrained():
|
|
68
|
+
return my[indexMy.dimensionsUnconstrained] == the[indexThe.dimensionsTotal]
|
|
69
|
+
|
|
70
|
+
def backtrack():
|
|
71
|
+
my[indexMy.leaf1ndex] -= 1
|
|
72
|
+
track[indexTrack.leafBelow, track[indexTrack.leafAbove, my[indexMy.leaf1ndex]]] = track[indexTrack.leafBelow, my[indexMy.leaf1ndex]]
|
|
73
|
+
track[indexTrack.leafAbove, track[indexTrack.leafBelow, my[indexMy.leaf1ndex]]] = track[indexTrack.leafAbove, my[indexMy.leaf1ndex]]
|
|
74
|
+
|
|
75
|
+
def backtrackCondition():
|
|
76
|
+
return my[indexMy.leaf1ndex] > 0 and my[indexMy.gap1ndex] == track[indexTrack.gapRangeStart, my[indexMy.leaf1ndex] - 1]
|
|
77
|
+
|
|
78
|
+
def computationDivisionsCondition():
|
|
79
|
+
return the[indexThe.taskDivisions] == int(False)
|
|
80
|
+
|
|
81
|
+
def countGaps():
|
|
82
|
+
gapsWhere[my[indexMy.gap1ndexCeiling]] = my[indexMy.leafConnectee]
|
|
83
|
+
if track[indexTrack.countDimensionsGapped, my[indexMy.leafConnectee]] == 0:
|
|
84
|
+
gap1ndexCeilingIncrement()
|
|
85
|
+
track[indexTrack.countDimensionsGapped, my[indexMy.leafConnectee]] += 1
|
|
86
|
+
|
|
87
|
+
def dimension1ndexIncrement():
|
|
88
|
+
my[indexMy.dimension1ndex] += 1
|
|
89
|
+
|
|
90
|
+
def dimensionsUnconstrainedCondition():
|
|
91
|
+
return connectionGraph[my[indexMy.dimension1ndex], my[indexMy.leaf1ndex], my[indexMy.leaf1ndex]] == my[indexMy.leaf1ndex]
|
|
92
|
+
|
|
93
|
+
def dimensionsUnconstrainedIncrement():
|
|
94
|
+
my[indexMy.dimensionsUnconstrained] += 1
|
|
95
|
+
|
|
96
|
+
def filterCommonGaps():
|
|
97
|
+
gapsWhere[my[indexMy.gap1ndex]] = gapsWhere[my[indexMy.indexMiniGap]]
|
|
98
|
+
if track[indexTrack.countDimensionsGapped, gapsWhere[my[indexMy.indexMiniGap]]] == the[indexThe.dimensionsTotal] - my[indexMy.dimensionsUnconstrained]:
|
|
99
|
+
activeGapIncrement()
|
|
100
|
+
track[indexTrack.countDimensionsGapped, gapsWhere[my[indexMy.indexMiniGap]]] = 0
|
|
101
|
+
|
|
102
|
+
def findGapsInitializeVariables():
|
|
103
|
+
my[indexMy.dimensionsUnconstrained] = 0
|
|
104
|
+
my[indexMy.gap1ndexCeiling] = track[indexTrack.gapRangeStart, my[indexMy.leaf1ndex] - 1]
|
|
105
|
+
my[indexMy.dimension1ndex] = 1
|
|
106
|
+
|
|
107
|
+
def foldsSubTotalsIncrement():
|
|
108
|
+
foldsSubTotals[my[indexMy.taskIndex]] += the[indexThe.leavesTotal]
|
|
109
|
+
|
|
110
|
+
def gap1ndexCeilingIncrement():
|
|
111
|
+
my[indexMy.gap1ndexCeiling] += 1
|
|
112
|
+
|
|
113
|
+
def indexMiniGapIncrement():
|
|
114
|
+
my[indexMy.indexMiniGap] += 1
|
|
115
|
+
|
|
116
|
+
def indexMiniGapInitialization():
|
|
117
|
+
my[indexMy.indexMiniGap] = my[indexMy.gap1ndex]
|
|
118
|
+
|
|
119
|
+
def insertUnconstrainedLeaf():
|
|
120
|
+
my[indexMy.indexLeaf] = 0
|
|
121
|
+
while my[indexMy.indexLeaf] < my[indexMy.leaf1ndex]:
|
|
122
|
+
gapsWhere[my[indexMy.gap1ndexCeiling]] = my[indexMy.indexLeaf]
|
|
123
|
+
my[indexMy.gap1ndexCeiling] += 1
|
|
124
|
+
my[indexMy.indexLeaf] += 1
|
|
125
|
+
|
|
126
|
+
def leafBelowSentinelIs1Condition():
|
|
127
|
+
return track[indexTrack.leafBelow, 0] == 1
|
|
128
|
+
|
|
129
|
+
def leafConnecteeInitialization():
|
|
130
|
+
my[indexMy.leafConnectee] = connectionGraph[my[indexMy.dimension1ndex], my[indexMy.leaf1ndex], my[indexMy.leaf1ndex]]
|
|
131
|
+
|
|
132
|
+
def leafConnecteeUpdate():
|
|
133
|
+
my[indexMy.leafConnectee] = connectionGraph[my[indexMy.dimension1ndex], my[indexMy.leaf1ndex], track[indexTrack.leafBelow, my[indexMy.leafConnectee]]]
|
|
134
|
+
|
|
135
|
+
def loopingLeavesConnectedToActiveLeaf():
|
|
136
|
+
return my[indexMy.leafConnectee] != my[indexMy.leaf1ndex]
|
|
137
|
+
|
|
138
|
+
def loopingTheDimensions():
|
|
139
|
+
return my[indexMy.dimension1ndex] <= the[indexThe.dimensionsTotal]
|
|
140
|
+
|
|
141
|
+
def loopingToActiveGapCeiling():
|
|
142
|
+
return my[indexMy.indexMiniGap] < my[indexMy.gap1ndexCeiling]
|
|
143
|
+
|
|
144
|
+
def placeLeaf():
|
|
145
|
+
my[indexMy.gap1ndex] -= 1
|
|
146
|
+
track[indexTrack.leafAbove, my[indexMy.leaf1ndex]] = gapsWhere[my[indexMy.gap1ndex]]
|
|
147
|
+
track[indexTrack.leafBelow, my[indexMy.leaf1ndex]] = track[indexTrack.leafBelow, track[indexTrack.leafAbove, my[indexMy.leaf1ndex]]]
|
|
148
|
+
track[indexTrack.leafBelow, track[indexTrack.leafAbove, my[indexMy.leaf1ndex]]] = my[indexMy.leaf1ndex]
|
|
149
|
+
track[indexTrack.leafAbove, track[indexTrack.leafBelow, my[indexMy.leaf1ndex]]] = my[indexMy.leaf1ndex]
|
|
150
|
+
track[indexTrack.gapRangeStart, my[indexMy.leaf1ndex]] = my[indexMy.gap1ndex]
|
|
151
|
+
my[indexMy.leaf1ndex] += 1
|
|
152
|
+
|
|
153
|
+
def placeLeafCondition():
|
|
154
|
+
return my[indexMy.leaf1ndex] > 0
|
|
155
|
+
|
|
156
|
+
def taskIndexCondition():
|
|
157
|
+
return my[indexMy.leafConnectee] % the[indexThe.taskDivisions] == my[indexMy.taskIndex]
|
|
158
|
+
|
|
159
|
+
def thereAreComputationDivisionsYouMightSkip():
|
|
160
|
+
if computationDivisionsCondition():
|
|
161
|
+
return True
|
|
162
|
+
if activeLeafNotEqualToTaskDivisionsCondition():
|
|
163
|
+
return True
|
|
164
|
+
if taskIndexCondition():
|
|
165
|
+
return True
|
|
166
|
+
return False
|
|
167
|
+
|
|
168
|
+
stateUniversal = outfitFoldings(listDimensions, computationDivisions=computationDivisions, CPUlimit=CPUlimit)
|
|
169
|
+
connectionGraph: Final[numpy.ndarray] = stateUniversal['connectionGraph']
|
|
170
|
+
foldsSubTotals = stateUniversal['foldsSubTotals']
|
|
171
|
+
gapsWhere = stateUniversal['gapsWhere']
|
|
172
|
+
my = stateUniversal['my']
|
|
173
|
+
the: Final[numpy.ndarray] = stateUniversal['the']
|
|
174
|
+
track = stateUniversal['track']
|
|
175
|
+
|
|
176
|
+
if the[indexThe.taskDivisions] == int(False):
|
|
177
|
+
doWhile()
|
|
178
|
+
else:
|
|
179
|
+
stateUniversal['my'] = my.copy()
|
|
180
|
+
stateUniversal['gapsWhere'] = gapsWhere.copy()
|
|
181
|
+
stateUniversal['track'] = track.copy()
|
|
182
|
+
for indexSherpa in range(the[indexThe.taskDivisions]):
|
|
183
|
+
my = stateUniversal['my'].copy()
|
|
184
|
+
my[indexMy.taskIndex] = indexSherpa
|
|
185
|
+
gapsWhere = stateUniversal['gapsWhere'].copy()
|
|
186
|
+
track = stateUniversal['track'].copy()
|
|
187
|
+
doWhile()
|
|
188
|
+
|
|
189
|
+
return numpy.sum(foldsSubTotals).item()
|
|
190
|
+
|
|
191
|
+
@enum.verify(enum.CONTINUOUS, enum.UNIQUE) if sys.version_info >= (3, 11) else lambda x: x
|
|
192
|
+
class EnumIndices(enum.IntEnum):
|
|
193
|
+
"""Base class for index enums."""
|
|
194
|
+
@staticmethod
|
|
195
|
+
def _generate_next_value_(name, start, count, last_values):
|
|
196
|
+
"""0-indexed."""
|
|
197
|
+
return count
|
|
198
|
+
|
|
199
|
+
def __index__(self) -> int:
|
|
200
|
+
"""Adapt enum to the ultra-rare event of indexing a NumPy 'ndarray', which is not the
|
|
201
|
+
same as `array.array`. See NumPy.org; I think it will be very popular someday."""
|
|
202
|
+
return self
|
|
203
|
+
|
|
204
|
+
class indexMy(EnumIndices):
|
|
205
|
+
"""Indices for dynamic values."""
|
|
206
|
+
dimension1ndex = enum.auto()
|
|
207
|
+
dimensionsUnconstrained = enum.auto()
|
|
208
|
+
gap1ndex = enum.auto()
|
|
209
|
+
gap1ndexCeiling = enum.auto()
|
|
210
|
+
indexLeaf = enum.auto()
|
|
211
|
+
indexMiniGap = enum.auto()
|
|
212
|
+
leaf1ndex = enum.auto()
|
|
213
|
+
leafConnectee = enum.auto()
|
|
214
|
+
taskIndex = enum.auto()
|
|
215
|
+
|
|
216
|
+
class indexThe(EnumIndices):
|
|
217
|
+
"""Indices for static values."""
|
|
218
|
+
dimensionsTotal = enum.auto()
|
|
219
|
+
leavesTotal = enum.auto()
|
|
220
|
+
taskDivisions = enum.auto()
|
|
221
|
+
|
|
222
|
+
class indexTrack(EnumIndices):
|
|
223
|
+
"""Indices for state tracking array."""
|
|
224
|
+
leafAbove = enum.auto()
|
|
225
|
+
leafBelow = enum.auto()
|
|
226
|
+
countDimensionsGapped = enum.auto()
|
|
227
|
+
gapRangeStart = enum.auto()
|
|
228
|
+
|
|
229
|
+
class computationState(TypedDict):
|
|
230
|
+
connectionGraph: NDArray[integer[Any]]
|
|
231
|
+
foldsSubTotals: NDArray[integer[Any]]
|
|
232
|
+
mapShape: Tuple[int, ...]
|
|
233
|
+
my: NDArray[integer[Any]]
|
|
234
|
+
gapsWhere: NDArray[integer[Any]]
|
|
235
|
+
the: NDArray[integer[Any]]
|
|
236
|
+
track: NDArray[integer[Any]]
|
|
237
|
+
|
|
238
|
+
dtypeLarge = numpy.int64
|
|
239
|
+
dtypeDefault = dtypeLarge
|
|
240
|
+
|
|
241
|
+
def getLeavesTotal(listDimensions: Sequence[int]) -> int:
|
|
242
|
+
"""
|
|
243
|
+
How many leaves are in the map.
|
|
244
|
+
|
|
245
|
+
Parameters:
|
|
246
|
+
listDimensions: A list of integers representing dimensions.
|
|
247
|
+
|
|
248
|
+
Returns:
|
|
249
|
+
productDimensions: The product of all positive integer dimensions.
|
|
250
|
+
"""
|
|
251
|
+
listNonNegative = parseDimensions(listDimensions, 'listDimensions')
|
|
252
|
+
listPositive = [dimension for dimension in listNonNegative if dimension > 0]
|
|
253
|
+
|
|
254
|
+
if not listPositive:
|
|
255
|
+
return 0
|
|
256
|
+
else:
|
|
257
|
+
productDimensions = 1
|
|
258
|
+
for dimension in listPositive:
|
|
259
|
+
if dimension > sys.maxsize // productDimensions:
|
|
260
|
+
raise OverflowError(f"I received {dimension=} in {listDimensions=}, but the product of the dimensions exceeds the maximum size of an integer on this system.")
|
|
261
|
+
productDimensions *= dimension
|
|
262
|
+
|
|
263
|
+
return productDimensions
|
|
264
|
+
|
|
265
|
+
def getTaskDivisions(computationDivisions: Optional[Union[int, str]], concurrencyLimit: int, CPUlimit: Optional[Union[bool, float, int]], listDimensions: Sequence[int]):
|
|
266
|
+
if not computationDivisions:
|
|
267
|
+
return 0
|
|
268
|
+
else:
|
|
269
|
+
leavesTotal = getLeavesTotal(listDimensions)
|
|
270
|
+
if isinstance(computationDivisions, int):
|
|
271
|
+
taskDivisions = computationDivisions
|
|
272
|
+
elif isinstance(computationDivisions, str):
|
|
273
|
+
computationDivisions = computationDivisions.lower()
|
|
274
|
+
if computationDivisions == "maximum":
|
|
275
|
+
taskDivisions = leavesTotal
|
|
276
|
+
elif computationDivisions == "cpu":
|
|
277
|
+
taskDivisions = min(concurrencyLimit, leavesTotal)
|
|
278
|
+
else:
|
|
279
|
+
raise ValueError("Not my problem.")
|
|
280
|
+
|
|
281
|
+
if taskDivisions > leavesTotal:
|
|
282
|
+
raise ValueError("What are you doing?")
|
|
283
|
+
|
|
284
|
+
return taskDivisions
|
|
285
|
+
|
|
286
|
+
def makeConnectionGraph(listDimensions: Sequence[int], **keywordArguments: Optional[Type]) -> NDArray[integer[Any]]:
|
|
287
|
+
datatype = keywordArguments.get('datatype', dtypeDefault)
|
|
288
|
+
mapShape = validateListDimensions(listDimensions)
|
|
289
|
+
leavesTotal = getLeavesTotal(mapShape)
|
|
290
|
+
arrayDimensions = numpy.array(mapShape, dtype=datatype)
|
|
291
|
+
dimensionsTotal = len(arrayDimensions)
|
|
292
|
+
|
|
293
|
+
cumulativeProduct = numpy.multiply.accumulate([1] + mapShape, dtype=datatype)
|
|
294
|
+
coordinateSystem = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1), dtype=datatype)
|
|
295
|
+
for dimension1ndex in range(1, dimensionsTotal + 1):
|
|
296
|
+
for leaf1ndex in range(1, leavesTotal + 1):
|
|
297
|
+
coordinateSystem[dimension1ndex, leaf1ndex] = ( ((leaf1ndex - 1) // cumulativeProduct[dimension1ndex - 1]) % arrayDimensions[dimension1ndex - 1] + 1 )
|
|
298
|
+
|
|
299
|
+
connectionGraph = numpy.zeros((dimensionsTotal + 1, leavesTotal + 1, leavesTotal + 1), dtype=datatype)
|
|
300
|
+
for dimension1ndex in range(1, dimensionsTotal + 1):
|
|
301
|
+
for activeLeaf1ndex in range(1, leavesTotal + 1):
|
|
302
|
+
for connectee1ndex in range(1, activeLeaf1ndex + 1):
|
|
303
|
+
isFirstCoord = coordinateSystem[dimension1ndex, connectee1ndex] == 1
|
|
304
|
+
isLastCoord = coordinateSystem[dimension1ndex, connectee1ndex] == arrayDimensions[dimension1ndex - 1]
|
|
305
|
+
exceedsActive = connectee1ndex + cumulativeProduct[dimension1ndex - 1] > activeLeaf1ndex
|
|
306
|
+
isEvenParity = (coordinateSystem[dimension1ndex, activeLeaf1ndex] & 1) == (coordinateSystem[dimension1ndex, connectee1ndex] & 1)
|
|
307
|
+
|
|
308
|
+
if (isEvenParity and isFirstCoord) or (not isEvenParity and (isLastCoord or exceedsActive)):
|
|
309
|
+
connectionGraph[dimension1ndex, activeLeaf1ndex, connectee1ndex] = connectee1ndex
|
|
310
|
+
elif isEvenParity and not isFirstCoord:
|
|
311
|
+
connectionGraph[dimension1ndex, activeLeaf1ndex, connectee1ndex] = connectee1ndex - cumulativeProduct[dimension1ndex - 1]
|
|
312
|
+
elif not isEvenParity and not (isLastCoord or exceedsActive):
|
|
313
|
+
connectionGraph[dimension1ndex, activeLeaf1ndex, connectee1ndex] = connectee1ndex + cumulativeProduct[dimension1ndex - 1]
|
|
314
|
+
else:
|
|
315
|
+
connectionGraph[dimension1ndex, activeLeaf1ndex, connectee1ndex] = connectee1ndex
|
|
316
|
+
return connectionGraph
|
|
317
|
+
|
|
318
|
+
def makeDataContainer(shape, datatype: Optional[Type] = None):
|
|
319
|
+
if datatype is None:
|
|
320
|
+
datatype = dtypeDefault
|
|
321
|
+
return numpy.zeros(shape, dtype=datatype)
|
|
322
|
+
|
|
323
|
+
def outfitFoldings(listDimensions: Sequence[int], computationDivisions: Optional[Union[int, str]] = None, CPUlimit: Optional[Union[bool, float, int]] = None, **keywordArguments: Optional[Type]) -> computationState:
|
|
324
|
+
datatypeDefault = keywordArguments.get('datatypeDefault', dtypeDefault)
|
|
325
|
+
datatypeLarge = keywordArguments.get('datatypeLarge', dtypeLarge)
|
|
326
|
+
|
|
327
|
+
the = makeDataContainer(len(indexThe), datatypeDefault)
|
|
328
|
+
|
|
329
|
+
mapShape = tuple(sorted(validateListDimensions(listDimensions)))
|
|
330
|
+
the[indexThe.leavesTotal] = getLeavesTotal(mapShape)
|
|
331
|
+
the[indexThe.dimensionsTotal] = len(mapShape)
|
|
332
|
+
concurrencyLimit = setCPUlimit(CPUlimit)
|
|
333
|
+
the[indexThe.taskDivisions] = getTaskDivisions(computationDivisions, concurrencyLimit, CPUlimit, listDimensions)
|
|
334
|
+
|
|
335
|
+
stateInitialized = computationState(
|
|
336
|
+
connectionGraph = makeConnectionGraph(mapShape, datatype=datatypeDefault),
|
|
337
|
+
foldsSubTotals = makeDataContainer(the[indexThe.leavesTotal], datatypeLarge),
|
|
338
|
+
mapShape = mapShape,
|
|
339
|
+
my = makeDataContainer(len(indexMy), datatypeLarge),
|
|
340
|
+
gapsWhere = makeDataContainer(int(the[indexThe.leavesTotal]) * int(the[indexThe.leavesTotal]) + 1, datatypeDefault),
|
|
341
|
+
the = the,
|
|
342
|
+
track = makeDataContainer((len(indexTrack), the[indexThe.leavesTotal] + 1), datatypeLarge)
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
stateInitialized['my'][indexMy.leaf1ndex] = 1
|
|
346
|
+
return stateInitialized
|
|
347
|
+
|
|
348
|
+
def parseDimensions(dimensions: Sequence[int], parameterName: str = 'unnamed parameter') -> List[int]:
|
|
349
|
+
# listValidated = intInnit(dimensions, parameterName)
|
|
350
|
+
listNOTValidated = dimensions if isinstance(dimensions, (list, tuple)) else list(dimensions)
|
|
351
|
+
listNonNegative = []
|
|
352
|
+
for dimension in listNOTValidated:
|
|
353
|
+
if dimension < 0:
|
|
354
|
+
raise ValueError(f"Dimension {dimension} must be non-negative")
|
|
355
|
+
listNonNegative.append(dimension)
|
|
356
|
+
if not listNonNegative:
|
|
357
|
+
raise ValueError("At least one dimension must be non-negative")
|
|
358
|
+
return listNonNegative
|
|
359
|
+
|
|
360
|
+
def setCPUlimit(CPUlimit: Union[bool, float, int, None]) -> int:
|
|
361
|
+
# if not (CPUlimit is None or isinstance(CPUlimit, (bool, int, float))):
|
|
362
|
+
# CPUlimit = oopsieKwargsie(CPUlimit)
|
|
363
|
+
# concurrencyLimit = defineConcurrencyLimit(CPUlimit)
|
|
364
|
+
# numba.set_num_threads(concurrencyLimit)
|
|
365
|
+
concurrencyLimitHARDCODED = 1
|
|
366
|
+
concurrencyLimit = concurrencyLimitHARDCODED
|
|
367
|
+
return concurrencyLimit
|
|
368
|
+
|
|
369
|
+
def validateListDimensions(listDimensions: Sequence[int]) -> List[int]:
|
|
370
|
+
if not listDimensions:
|
|
371
|
+
raise ValueError(f"listDimensions is a required parameter.")
|
|
372
|
+
listNonNegative = parseDimensions(listDimensions, 'listDimensions')
|
|
373
|
+
dimensionsValid = [dimension for dimension in listNonNegative if dimension > 0]
|
|
374
|
+
if len(dimensionsValid) < 2:
|
|
375
|
+
raise NotImplementedError(f"This function requires listDimensions, {listDimensions}, to have at least two dimensions greater than 0. You may want to look at https://oeis.org/.")
|
|
376
|
+
return sorted(dimensionsValid)
|
mapFolding/startHere.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from mapFolding import
|
|
1
|
+
from mapFolding import outfitCountFolds, getFilenameFoldsTotal
|
|
2
2
|
from typing import Optional, Sequence, Type, Union
|
|
3
3
|
import os
|
|
4
4
|
import pathlib
|
|
@@ -15,7 +15,7 @@ def countFolds(listDimensions: Sequence[int], writeFoldsTotal: Optional[Union[st
|
|
|
15
15
|
CPUlimit (None): This is only relevant if there are `computationDivisions`: whether and how to limit the CPU usage. See notes for details.
|
|
16
16
|
**keywordArguments: Additional arguments including `dtypeDefault` and `dtypeLarge` for data type specifications.
|
|
17
17
|
Returns:
|
|
18
|
-
|
|
18
|
+
foldsSubTotals: Total number of distinct ways to fold a map of the given dimensions.
|
|
19
19
|
|
|
20
20
|
Computation divisions:
|
|
21
21
|
- None: no division of the computation into tasks; sets task divisions to 0
|
|
@@ -34,20 +34,22 @@ def countFolds(listDimensions: Sequence[int], writeFoldsTotal: Optional[Union[st
|
|
|
34
34
|
N.B.: You probably don't want to divide the computation into tasks.
|
|
35
35
|
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.
|
|
36
36
|
"""
|
|
37
|
-
stateUniversal =
|
|
37
|
+
stateUniversal = outfitCountFolds(listDimensions, computationDivisions=computationDivisions, CPUlimit=CPUlimit, **keywordArguments)
|
|
38
38
|
|
|
39
39
|
pathFilenameFoldsTotal = None
|
|
40
40
|
if writeFoldsTotal is not None:
|
|
41
41
|
pathFilenameFoldsTotal = pathlib.Path(writeFoldsTotal)
|
|
42
42
|
if pathFilenameFoldsTotal.is_dir():
|
|
43
|
-
filenameFoldsTotalDEFAULT =
|
|
43
|
+
filenameFoldsTotalDEFAULT = getFilenameFoldsTotal(stateUniversal['mapShape'])
|
|
44
44
|
pathFilenameFoldsTotal = pathFilenameFoldsTotal / filenameFoldsTotalDEFAULT
|
|
45
45
|
pathFilenameFoldsTotal.parent.mkdir(parents=True, exist_ok=True)
|
|
46
46
|
|
|
47
47
|
# NOTE Don't import a module with a numba.jit function until you want the function to compile and to freeze all settings for that function.
|
|
48
48
|
from mapFolding.babbage import _countFolds
|
|
49
|
-
|
|
50
|
-
#
|
|
49
|
+
_countFolds(**stateUniversal)
|
|
50
|
+
# foldsSubTotals = benchmarkSherpa(**stateUniversal)
|
|
51
|
+
|
|
52
|
+
foldsTotal = stateUniversal['foldsSubTotals'].sum().item()
|
|
51
53
|
|
|
52
54
|
if pathFilenameFoldsTotal is not None:
|
|
53
55
|
try:
|
|
@@ -63,6 +65,6 @@ def countFolds(listDimensions: Sequence[int], writeFoldsTotal: Optional[Union[st
|
|
|
63
65
|
# from typing import Any, Tuple
|
|
64
66
|
# from mapFolding.benchmarks.benchmarking import recordBenchmarks
|
|
65
67
|
# @recordBenchmarks()
|
|
66
|
-
# def benchmarkSherpa(connectionGraph: NDArray[integer[Any]],
|
|
68
|
+
# def benchmarkSherpa(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]]):
|
|
67
69
|
# from mapFolding.babbage import _countFolds
|
|
68
|
-
# return _countFolds(connectionGraph,
|
|
70
|
+
# return _countFolds(connectionGraph, foldsSubTotals, gapsWhere, mapShape, my, the, track)
|
mapFolding/theSSOT.py
CHANGED
|
@@ -15,7 +15,7 @@ except NameError:
|
|
|
15
15
|
_pathModule = pathlib.Path.cwd()
|
|
16
16
|
|
|
17
17
|
pathJobDEFAULT = _pathModule / "jobs"
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
if 'google.colab' in sys.modules:
|
|
20
20
|
pathJobDEFAULT = pathlib.Path("/content/drive/MyDrive") / "jobs"
|
|
21
21
|
|
|
@@ -59,7 +59,7 @@ class indexTrack(EnumIndices):
|
|
|
59
59
|
|
|
60
60
|
class computationState(TypedDict):
|
|
61
61
|
connectionGraph: numpy.typing.NDArray[numpy.integer[Any]]
|
|
62
|
-
|
|
62
|
+
foldsSubTotals: numpy.ndarray[numpy.int64, numpy.dtype[numpy.int64]]
|
|
63
63
|
mapShape: Tuple[int, ...]
|
|
64
64
|
my: numpy.typing.NDArray[numpy.integer[Any]]
|
|
65
65
|
gapsWhere: numpy.typing.NDArray[numpy.integer[Any]]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: mapFolding
|
|
3
|
-
Version: 0.2.
|
|
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()`
|
|
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
|
|
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
|
-
[](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml)
|
|
42
|
+
[](https://github.com/hunterhogan/mapFolding/actions/workflows/unittests.yml) [](https://pypi.org/project/mapFolding/)    
|
|
43
43
|
|
|
44
44
|
## Simple, easy usage based on OEIS IDs
|
|
45
45
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
mapFolding/__init__.py,sha256=
|
|
2
|
-
mapFolding/babbage.py,sha256=
|
|
3
|
-
mapFolding/beDRY.py,sha256=
|
|
4
|
-
mapFolding/lovelace.py,sha256=
|
|
1
|
+
mapFolding/__init__.py,sha256=wnf2EzHR2unVha6-Y0gRoSPaE4PDdT4VngINa_dfT2E,337
|
|
2
|
+
mapFolding/babbage.py,sha256=LCtyapF8SKsECqBifqbLm7bR_i4n8VJ647w_TQxnQvE,1930
|
|
3
|
+
mapFolding/beDRY.py,sha256=UE4IRrb5lXN4nTuUghHfieNm2FBHgz7oBj_EqUgkadI,13800
|
|
4
|
+
mapFolding/lovelace.py,sha256=r4dkTGh_AgaVsWOsdPRdpPWVx3TjVjbWfPCVu3UTm6U,13495
|
|
5
5
|
mapFolding/oeis.py,sha256=_-fLGc1ybZ2eFxoiBrSmojMexeg6ROxtrLaBF2BzMn4,12144
|
|
6
|
-
mapFolding/startHere.py,sha256=
|
|
7
|
-
mapFolding/theSSOT.py,sha256=
|
|
6
|
+
mapFolding/startHere.py,sha256=glGxmefrWpxyuqrzXrbCvIo84yvPnv8l8l7Rmff2sAo,5105
|
|
7
|
+
mapFolding/theSSOT.py,sha256=rAyx034y33QC7IiRKaW89CMGGvqe2p-QBc3_fO-zEGM,2101
|
|
8
8
|
mapFolding/JAX/lunnanJAX.py,sha256=xMZloN47q-MVfjdYOM1hi9qR4OnLq7qALmGLMraevQs,14819
|
|
9
9
|
mapFolding/JAX/taskJAX.py,sha256=yJNeH0rL6EhJ6ppnATHF0Zf81CDMC10bnPnimVxE1hc,20037
|
|
10
10
|
mapFolding/benchmarks/benchmarking.py,sha256=kv85F6V9pGhZvTOImArOuxyg5rywA_T6JLH_qFXM8BM,3018
|
|
11
11
|
mapFolding/benchmarks/test_benchmarks.py,sha256=c4ANeR3jgqpKXFoxDeZkmAHxSuenMwsjmrhKJ1_XPqY,3659
|
|
12
|
+
mapFolding/reference/flattened.py,sha256=X9nvRzg7YDcpCtSDTL4YiidjshlX9rg2e6JVCY6i2u0,16547
|
|
12
13
|
mapFolding/reference/hunterNumba.py,sha256=0giUyqAFzP-XKcq3Kz8wIWCK0BVFhjABVJ1s-w4Jhu0,7109
|
|
13
14
|
mapFolding/reference/irvineJavaPort.py,sha256=Sj-63Z-OsGuDoEBXuxyjRrNmmyl0d7Yz_XuY7I47Oyg,4250
|
|
14
15
|
mapFolding/reference/lunnan.py,sha256=XEcql_gxvCCghb6Or3qwmPbn4IZUbZTaSmw_fUjRxZE,5037
|
|
@@ -16,13 +17,14 @@ mapFolding/reference/lunnanNumpy.py,sha256=HqDgSwTOZA-G0oophOEfc4zs25Mv4yw2aoF1v
|
|
|
16
17
|
mapFolding/reference/lunnanWhile.py,sha256=7NY2IKO5XBgol0aWWF_Fi-7oTL9pvu_z6lB0TF1uVHk,4063
|
|
17
18
|
mapFolding/reference/rotatedEntryPoint.py,sha256=z0QyDQtnMvXNj5ntWzzJUQUMFm1-xHGLVhtYzwmczUI,11530
|
|
18
19
|
mapFolding/reference/total_countPlus1vsPlusN.py,sha256=usenM8Yn_G1dqlPl7NKKkcnbohBZVZBXTQRm2S3_EDA,8106
|
|
19
|
-
tests/__init__.py,sha256=
|
|
20
|
-
tests/conftest.py,sha256=
|
|
20
|
+
tests/__init__.py,sha256=eg9smg-6VblOr0kisM40CpGnuDtU2JgEEWGDTFVOlW8,57
|
|
21
|
+
tests/conftest.py,sha256=WE3DETPaQ4zuUiw8pweTry4rp1PxvUPgeb8CN8eh5JI,13574
|
|
22
|
+
tests/pythons_idiotic_namespace.py,sha256=oOLDBergQqqhGuRpsXUnFD-R_6AlJipNKYHw-kk_OKw,33
|
|
21
23
|
tests/test_oeis.py,sha256=vxnwO-cSR68htkyMh9QMVv-lvxBo6qlwPg1Rbx4JylY,7963
|
|
22
|
-
tests/test_other.py,sha256=
|
|
24
|
+
tests/test_other.py,sha256=5DwOZsjezBHZzr4-9qEnybBYJEGsozBm2n9p0KYvs9E,10664
|
|
23
25
|
tests/test_tasks.py,sha256=Nwe4iuSjwGZvsw5CXCcic7tkBxgM5JX9mrGZMDYhAwE,1785
|
|
24
|
-
mapFolding-0.2.
|
|
25
|
-
mapFolding-0.2.
|
|
26
|
-
mapFolding-0.2.
|
|
27
|
-
mapFolding-0.2.
|
|
28
|
-
mapFolding-0.2.
|
|
26
|
+
mapFolding-0.2.3.dist-info/METADATA,sha256=nEQXgDmmuu2NJko4R4gPUdjIrm1upUGwMIOn0s0JOOc,6442
|
|
27
|
+
mapFolding-0.2.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
28
|
+
mapFolding-0.2.3.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
|
|
29
|
+
mapFolding-0.2.3.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
|
|
30
|
+
mapFolding-0.2.3.dist-info/RECORD,,
|
tests/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
from .conftest import makeDictionaryFoldsTotalKnown
|
|
1
|
+
from tests.conftest import makeDictionaryFoldsTotalKnown
|
tests/conftest.py
CHANGED
|
@@ -14,10 +14,10 @@ from Z0Z_tools.pytest_parseParameters import makeTestSuiteConcurrencyLimit
|
|
|
14
14
|
from Z0Z_tools.pytest_parseParameters import makeTestSuiteIntInnit
|
|
15
15
|
from Z0Z_tools.pytest_parseParameters import makeTestSuiteOopsieKwargsie
|
|
16
16
|
from mapFolding import countFolds, pathJobDEFAULT, indexMy, indexThe, indexTrack
|
|
17
|
-
from mapFolding import defineConcurrencyLimit, intInnit, oopsieKwargsie
|
|
18
|
-
from mapFolding import
|
|
19
|
-
from mapFolding import
|
|
20
|
-
from mapFolding import
|
|
17
|
+
from mapFolding import defineConcurrencyLimit, intInnit, oopsieKwargsie, outfitCountFolds
|
|
18
|
+
from mapFolding import oeisIDfor_n, getOEISids, clearOEIScache, getFilenameFoldsTotal
|
|
19
|
+
from mapFolding.beDRY import getLeavesTotal, parseDimensions, validateListDimensions
|
|
20
|
+
from mapFolding.beDRY import getTaskDivisions, makeConnectionGraph, setCPUlimit
|
|
21
21
|
from mapFolding.beDRY import makeDataContainer
|
|
22
22
|
from mapFolding.oeis import OEIS_for_n
|
|
23
23
|
from mapFolding.oeis import _getFilenameOEISbFile
|
|
@@ -26,6 +26,7 @@ from mapFolding.oeis import _parseBFileOEIS
|
|
|
26
26
|
from mapFolding.oeis import _validateOEISid
|
|
27
27
|
from mapFolding.oeis import oeisIDsImplemented
|
|
28
28
|
from mapFolding.oeis import settingsOEIS
|
|
29
|
+
from mapFolding import *
|
|
29
30
|
|
|
30
31
|
__all__ = [
|
|
31
32
|
'OEIS_for_n',
|
|
@@ -37,10 +38,11 @@ __all__ = [
|
|
|
37
38
|
'countFolds',
|
|
38
39
|
'defineConcurrencyLimit',
|
|
39
40
|
'expectSystemExit',
|
|
41
|
+
'getFilenameFoldsTotal',
|
|
40
42
|
'getLeavesTotal',
|
|
41
43
|
'getOEISids',
|
|
42
|
-
'indexThe',
|
|
43
44
|
'getTaskDivisions',
|
|
45
|
+
'indexThe',
|
|
44
46
|
'intInnit',
|
|
45
47
|
'makeConnectionGraph',
|
|
46
48
|
'makeDataContainer',
|
|
@@ -50,7 +52,7 @@ __all__ = [
|
|
|
50
52
|
'oeisIDfor_n',
|
|
51
53
|
'oeisIDsImplemented',
|
|
52
54
|
'oopsieKwargsie',
|
|
53
|
-
'
|
|
55
|
+
'outfitCountFolds',
|
|
54
56
|
'parseDimensions',
|
|
55
57
|
'setCPUlimit',
|
|
56
58
|
'settingsOEIS',
|
|
@@ -227,6 +229,22 @@ def oeisID_1random() -> str:
|
|
|
227
229
|
"""Return one random valid OEIS ID."""
|
|
228
230
|
return random.choice(oeisIDsImplemented)
|
|
229
231
|
|
|
232
|
+
@pytest.fixture
|
|
233
|
+
def mockFoldingFunction():
|
|
234
|
+
"""Creates a mock function that simulates _countFolds behavior."""
|
|
235
|
+
def make_mock(foldsValue: int, listDimensions: List[int]):
|
|
236
|
+
arraySize = getLeavesTotal(listDimensions)
|
|
237
|
+
# The array needs to sum to our target value
|
|
238
|
+
mock_array = makeDataContainer(arraySize)
|
|
239
|
+
mock_array[arraySize - 1] = foldsValue # Put entire value in last position
|
|
240
|
+
|
|
241
|
+
def mock_countfolds(**keywordArguments):
|
|
242
|
+
keywordArguments['foldsSubTotals'][:] = mock_array
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
return mock_countfolds
|
|
246
|
+
return make_mock
|
|
247
|
+
|
|
230
248
|
"""
|
|
231
249
|
Section: Standardized test structures"""
|
|
232
250
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from mapFolding.theSSOT import *
|
tests/test_other.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import List
|
|
3
|
-
from .conftest import *
|
|
2
|
+
from typing import List, Optional, Dict, Any, Union
|
|
3
|
+
from tests.conftest import *
|
|
4
|
+
from tests.pythons_idiotic_namespace import *
|
|
4
5
|
import pytest
|
|
5
6
|
import sys
|
|
6
7
|
import unittest.mock
|
|
7
8
|
import numpy
|
|
8
9
|
import numba
|
|
9
10
|
|
|
10
|
-
# TODO test `outfitFoldings`; no negative values in arrays; compare datatypes to the typeddict; commpare the connection graph to making a graPH
|
|
11
|
-
|
|
12
11
|
@pytest.mark.parametrize("listDimensions,expected_intInnit,expected_parseListDimensions,expected_validateListDimensions,expected_getLeavesTotal", [
|
|
13
12
|
(None, ValueError, ValueError, ValueError, ValueError), # None instead of list
|
|
14
13
|
(['a'], ValueError, ValueError, ValueError, ValueError), # string
|
|
@@ -59,18 +58,34 @@ def test_getLeavesTotal_edge_cases() -> None:
|
|
|
59
58
|
standardComparison(6, getLeavesTotal, listOriginal)
|
|
60
59
|
standardComparison([2, 3], lambda x: x, listOriginal) # Check that the list wasn't modified
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
@pytest.mark.parametrize("foldsValue,writeFoldsTarget", [
|
|
62
|
+
(756839, "foldsTotalTest.txt"), # Direct file
|
|
63
|
+
(2640919, "foldsTotalTest.txt"), # Direct file
|
|
64
|
+
(7715177, None), # Directory, will use default filename
|
|
65
|
+
])
|
|
66
|
+
def test_countFolds_writeFoldsTotal(
|
|
67
|
+
listDimensionsTestFunctionality: List[int],
|
|
68
|
+
pathTempTesting: Path,
|
|
69
|
+
mockFoldingFunction,
|
|
70
|
+
foldsValue: int,
|
|
71
|
+
writeFoldsTarget: Optional[str]
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Test writing folds total to either a file or directory."""
|
|
74
|
+
# For directory case, use the directory path directly
|
|
75
|
+
if writeFoldsTarget is None:
|
|
76
|
+
pathWriteTarget = pathTempTesting
|
|
77
|
+
filenameFoldsTotalExpected = getFilenameFoldsTotal(listDimensionsTestFunctionality)
|
|
78
|
+
else:
|
|
79
|
+
pathWriteTarget = pathTempTesting / writeFoldsTarget
|
|
80
|
+
filenameFoldsTotalExpected = writeFoldsTarget
|
|
81
|
+
|
|
82
|
+
mock_countFolds = mockFoldingFunction(foldsValue, listDimensionsTestFunctionality)
|
|
83
|
+
|
|
84
|
+
with unittest.mock.patch("mapFolding.babbage._countFolds", side_effect=mock_countFolds):
|
|
85
|
+
returned = countFolds(listDimensionsTestFunctionality, writeFoldsTotal=pathWriteTarget)
|
|
66
86
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
returned = countFolds(listDimensionsTestFunctionality, writeFoldsTotal=pathTempTesting)
|
|
70
|
-
standardComparison(67890, lambda: returned)
|
|
71
|
-
# Construct expected filename from sorted dimensions
|
|
72
|
-
expectedName = str(sorted(listDimensionsTestFunctionality)).replace(' ', '') + '.foldsTotal'
|
|
73
|
-
standardComparison("67890", lambda: (pathTempTesting / expectedName).read_text())
|
|
87
|
+
standardComparison(foldsValue, lambda: returned) # Check return value
|
|
88
|
+
standardComparison(str(foldsValue), lambda: (pathTempTesting / filenameFoldsTotalExpected).read_text()) # Check file content
|
|
74
89
|
|
|
75
90
|
def test_intInnit() -> None:
|
|
76
91
|
"""Test integer parsing using the test suite generator."""
|
|
@@ -103,3 +118,81 @@ def test_makeConnectionGraph_nonNegative(listDimensionsTestFunctionality: List[i
|
|
|
103
118
|
def test_makeConnectionGraph_datatype(listDimensionsTestFunctionality: List[int], datatype) -> None:
|
|
104
119
|
connectionGraph = makeConnectionGraph(listDimensionsTestFunctionality, datatype=datatype)
|
|
105
120
|
assert connectionGraph.dtype == datatype, f"Expected datatype {datatype}, but got {connectionGraph.dtype}."
|
|
121
|
+
|
|
122
|
+
# @pytest.mark.parametrize("computationDivisions,CPUlimit,datatypeOverrides", [
|
|
123
|
+
# (None, None, {}), # Basic case
|
|
124
|
+
# ("maximum", True, {"datatypeDefault": numpy.int32}), # Max divisions, min CPU, custom dtype
|
|
125
|
+
# ("cpu", 4, {"datatypeLarge": numpy.int64}), # CPU-based divisions, fixed CPU limit
|
|
126
|
+
# (3, 0.5, {}), # Fixed divisions, fractional CPU
|
|
127
|
+
# ])
|
|
128
|
+
# def test_outfitCountFolds(
|
|
129
|
+
# listDimensionsTestFunctionality: List[int],
|
|
130
|
+
# computationDivisions: Optional[Union[int, str]],
|
|
131
|
+
# CPUlimit: Optional[Union[bool, float, int]],
|
|
132
|
+
# datatypeOverrides: Dict[str, Any]
|
|
133
|
+
# ) -> None:
|
|
134
|
+
# """Test outfitCountFolds as a nexus of configuration and initialization.
|
|
135
|
+
|
|
136
|
+
# Strategy:
|
|
137
|
+
# 1. Validate structure against computationState TypedDict
|
|
138
|
+
# 2. Compare with direct function calls
|
|
139
|
+
# 3. Verify enum-based indexing
|
|
140
|
+
# 4. Check datatypes and shapes
|
|
141
|
+
# """
|
|
142
|
+
# # Get initialized state
|
|
143
|
+
# stateInitialized = outfitCountFolds(
|
|
144
|
+
# listDimensionsTestFunctionality,
|
|
145
|
+
# computationDivisions=computationDivisions,
|
|
146
|
+
# CPUlimit=CPUlimit,
|
|
147
|
+
# **datatypeOverrides
|
|
148
|
+
# )
|
|
149
|
+
|
|
150
|
+
# # 1. TypedDict structure validation
|
|
151
|
+
# for keyRequired in computationState.__annotations__:
|
|
152
|
+
# assert keyRequired in stateInitialized, f"Missing required key: {keyRequired}"
|
|
153
|
+
# assert stateInitialized[keyRequired] is not None, f"Key has None value: {keyRequired}"
|
|
154
|
+
|
|
155
|
+
# # Type checking
|
|
156
|
+
# expectedType = computationState.__annotations__[keyRequired]
|
|
157
|
+
# assert isinstance(stateInitialized[keyRequired], expectedType), \
|
|
158
|
+
# f"Type mismatch for {keyRequired}: expected {expectedType}, got {type(stateInitialized[keyRequired])}"
|
|
159
|
+
|
|
160
|
+
# # 2. Compare with direct function calls
|
|
161
|
+
# directMapShape = tuple(sorted(validateListDimensions(listDimensionsTestFunctionality)))
|
|
162
|
+
# assert stateInitialized['mapShape'] == directMapShape
|
|
163
|
+
|
|
164
|
+
# directConnectionGraph = makeConnectionGraph(
|
|
165
|
+
# directMapShape,
|
|
166
|
+
# datatype=datatypeOverrides.get('datatypeDefault', dtypeDefault)
|
|
167
|
+
# )
|
|
168
|
+
# assert numpy.array_equal(stateInitialized['connectionGraph'], directConnectionGraph)
|
|
169
|
+
|
|
170
|
+
# # 3. Enum-based indexing validation
|
|
171
|
+
# for arrayName, indexEnum in [
|
|
172
|
+
# ('my', indexMy),
|
|
173
|
+
# ('the', indexThe),
|
|
174
|
+
# ('track', indexTrack)
|
|
175
|
+
# ]:
|
|
176
|
+
# array = stateInitialized[arrayName]
|
|
177
|
+
# assert array.shape[0] >= len(indexEnum), \
|
|
178
|
+
# f"Array {arrayName} too small for enum {indexEnum.__name__}"
|
|
179
|
+
|
|
180
|
+
# # Test each enum index
|
|
181
|
+
# for enumMember in indexEnum:
|
|
182
|
+
# assert array[enumMember.value] >= 0, \
|
|
183
|
+
# f"Negative value at {arrayName}[{enumMember.name}]"
|
|
184
|
+
|
|
185
|
+
# # 4. Special value checks
|
|
186
|
+
# assert stateInitialized['my'][indexMy.leaf1ndex.value] == 1, \
|
|
187
|
+
# "Initial leaf index should be 1"
|
|
188
|
+
|
|
189
|
+
# # 5. Shape consistency
|
|
190
|
+
# leavesTotal = getLeavesTotal(listDimensionsTestFunctionality)
|
|
191
|
+
# assert stateInitialized['foldsSubTotals'].shape == (leavesTotal,), \
|
|
192
|
+
# "foldsSubTotals shape mismatch"
|
|
193
|
+
# assert stateInitialized['gapsWhere'].shape == (leavesTotal * leavesTotal + 1,), \
|
|
194
|
+
# "gapsWhere shape mismatch"
|
|
195
|
+
# assert stateInitialized['track'].shape == (len(indexTrack), leavesTotal + 1), \
|
|
196
|
+
# "track shape mismatch"
|
|
197
|
+
|
|
198
|
+
# TODO test `outfitCountFolds`; no negative values in arrays; compare datatypes to the typeddict; compare the connection graph to making a graph
|
|
File without changes
|
|
File without changes
|
|
File without changes
|