mapFolding 0.5.1__py3-none-any.whl → 0.7.0__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 +6 -101
- mapFolding/basecamp.py +12 -10
- mapFolding/beDRY.py +96 -316
- mapFolding/filesystem.py +87 -0
- mapFolding/noHomeYet.py +20 -0
- mapFolding/oeis.py +39 -36
- mapFolding/reference/flattened.py +377 -0
- mapFolding/reference/hunterNumba.py +132 -0
- mapFolding/reference/irvineJavaPort.py +120 -0
- mapFolding/reference/jax.py +208 -0
- mapFolding/reference/lunnan.py +153 -0
- mapFolding/reference/lunnanNumpy.py +123 -0
- mapFolding/reference/lunnanWhile.py +121 -0
- mapFolding/reference/rotatedEntryPoint.py +240 -0
- mapFolding/reference/total_countPlus1vsPlusN.py +211 -0
- mapFolding/someAssemblyRequired/Z0Z_workbench.py +34 -0
- mapFolding/someAssemblyRequired/__init__.py +16 -0
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +21 -0
- mapFolding/someAssemblyRequired/ingredientsNumba.py +100 -0
- mapFolding/someAssemblyRequired/synthesizeCountingFunctions.py +7 -0
- mapFolding/someAssemblyRequired/synthesizeDataConverters.py +135 -0
- mapFolding/someAssemblyRequired/synthesizeNumba.py +91 -0
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +417 -0
- mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +91 -0
- mapFolding/someAssemblyRequired/transformationTools.py +425 -0
- mapFolding/someAssemblyRequired/whatWillBe.py +311 -0
- mapFolding/syntheticModules/__init__.py +0 -0
- mapFolding/syntheticModules/dataNamespaceFlattened.py +30 -0
- mapFolding/syntheticModules/numbaCount.py +90 -0
- mapFolding/syntheticModules/numbaCountExample.py +158 -0
- mapFolding/syntheticModules/numbaCountSequential.py +110 -0
- mapFolding/syntheticModules/numbaCount_doTheNeedful.py +13 -0
- mapFolding/syntheticModules/numba_doTheNeedful.py +12 -0
- mapFolding/syntheticModules/numba_doTheNeedfulExample.py +13 -0
- mapFolding/theDao.py +203 -227
- mapFolding/theSSOT.py +254 -123
- {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/METADATA +10 -8
- mapfolding-0.7.0.dist-info/RECORD +50 -0
- {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/WHEEL +1 -1
- {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/top_level.txt +1 -0
- tests/__init__.py +0 -0
- tests/conftest.py +278 -0
- tests/test_computations.py +49 -0
- tests/test_filesystem.py +52 -0
- tests/test_oeis.py +128 -0
- tests/test_other.py +84 -0
- tests/test_tasks.py +50 -0
- mapFolding/theSSOTdatatypes.py +0 -156
- mapFolding-0.5.1.dist-info/RECORD +0 -14
- {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/LICENSE +0 -0
- {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from mapFolding.theDao import countInitialize, countParallel
|
|
2
|
+
from mapFolding.theSSOT import Array1DElephino, Array1DLeavesTotal, Array3D, ComputationState, DatatypeElephino, DatatypeFoldsTotal, DatatypeLeavesTotal
|
|
3
|
+
from numba import jit
|
|
4
|
+
|
|
5
|
+
@jit(_nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, nopython=True, parallel=False)
|
|
6
|
+
def countSequential(
|
|
7
|
+
connectionGraph: Array3D,
|
|
8
|
+
countDimensionsGapped: Array1DLeavesTotal,
|
|
9
|
+
dimensionsTotal: DatatypeLeavesTotal,
|
|
10
|
+
dimensionsUnconstrained: DatatypeLeavesTotal,
|
|
11
|
+
gap1ndex: DatatypeLeavesTotal,
|
|
12
|
+
gap1ndexCeiling: DatatypeElephino,
|
|
13
|
+
gapRangeStart: Array1DElephino,
|
|
14
|
+
gapsWhere: Array1DLeavesTotal,
|
|
15
|
+
groupsOfFolds: DatatypeFoldsTotal,
|
|
16
|
+
indexDimension: DatatypeLeavesTotal,
|
|
17
|
+
indexMiniGap: DatatypeElephino,
|
|
18
|
+
leaf1ndex: DatatypeElephino,
|
|
19
|
+
leafAbove: Array1DLeavesTotal,
|
|
20
|
+
leafBelow: Array1DLeavesTotal,
|
|
21
|
+
leafConnectee: DatatypeElephino,
|
|
22
|
+
leavesTotal: DatatypeLeavesTotal,
|
|
23
|
+
) -> DatatypeFoldsTotal:
|
|
24
|
+
|
|
25
|
+
while leaf1ndex > 0:
|
|
26
|
+
if leaf1ndex <= 1 or leafBelow[0] == 1:
|
|
27
|
+
if leaf1ndex > leavesTotal:
|
|
28
|
+
groupsOfFolds += 1
|
|
29
|
+
else:
|
|
30
|
+
dimensionsUnconstrained = dimensionsTotal
|
|
31
|
+
gap1ndexCeiling = gapRangeStart[leaf1ndex - 1]
|
|
32
|
+
indexDimension = 0
|
|
33
|
+
while indexDimension < dimensionsTotal:
|
|
34
|
+
leafConnectee = connectionGraph[indexDimension, leaf1ndex, leaf1ndex]
|
|
35
|
+
if leafConnectee == leaf1ndex:
|
|
36
|
+
dimensionsUnconstrained -= 1
|
|
37
|
+
else:
|
|
38
|
+
while leafConnectee != leaf1ndex:
|
|
39
|
+
gapsWhere[gap1ndexCeiling] = leafConnectee
|
|
40
|
+
if countDimensionsGapped[leafConnectee] == 0:
|
|
41
|
+
gap1ndexCeiling += 1
|
|
42
|
+
countDimensionsGapped[leafConnectee] += 1
|
|
43
|
+
leafConnectee = connectionGraph[indexDimension, leaf1ndex, leafBelow[leafConnectee]]
|
|
44
|
+
indexDimension += 1
|
|
45
|
+
indexMiniGap = gap1ndex
|
|
46
|
+
while indexMiniGap < gap1ndexCeiling:
|
|
47
|
+
gapsWhere[gap1ndex] = gapsWhere[indexMiniGap]
|
|
48
|
+
if countDimensionsGapped[gapsWhere[indexMiniGap]] == dimensionsUnconstrained:
|
|
49
|
+
gap1ndex += 1
|
|
50
|
+
countDimensionsGapped[gapsWhere[indexMiniGap]] = 0
|
|
51
|
+
indexMiniGap += 1
|
|
52
|
+
while leaf1ndex > 0 and gap1ndex == gapRangeStart[leaf1ndex - 1]:
|
|
53
|
+
leaf1ndex -= 1
|
|
54
|
+
leafBelow[leafAbove[leaf1ndex]] = leafBelow[leaf1ndex]
|
|
55
|
+
leafAbove[leafBelow[leaf1ndex]] = leafAbove[leaf1ndex]
|
|
56
|
+
if leaf1ndex > 0:
|
|
57
|
+
gap1ndex -= 1
|
|
58
|
+
leafAbove[leaf1ndex] = gapsWhere[gap1ndex]
|
|
59
|
+
leafBelow[leaf1ndex] = leafBelow[leafAbove[leaf1ndex]]
|
|
60
|
+
leafBelow[leafAbove[leaf1ndex]] = leaf1ndex
|
|
61
|
+
leafAbove[leafBelow[leaf1ndex]] = leaf1ndex
|
|
62
|
+
gapRangeStart[leaf1ndex] = gap1ndex
|
|
63
|
+
leaf1ndex += 1
|
|
64
|
+
return groupsOfFolds
|
|
65
|
+
|
|
66
|
+
def flattenData(state: ComputationState) -> ComputationState:
|
|
67
|
+
|
|
68
|
+
state = countInitialize(state)
|
|
69
|
+
if state.taskDivisions > 0:
|
|
70
|
+
return countParallel(state)
|
|
71
|
+
|
|
72
|
+
connectionGraph: Array3D = state.connectionGraph
|
|
73
|
+
countDimensionsGapped: Array1DLeavesTotal = state.countDimensionsGapped
|
|
74
|
+
dimensionsTotal: DatatypeLeavesTotal = state.dimensionsTotal
|
|
75
|
+
dimensionsUnconstrained: DatatypeLeavesTotal = state.dimensionsUnconstrained
|
|
76
|
+
gap1ndex: DatatypeLeavesTotal = state.gap1ndex
|
|
77
|
+
gap1ndexCeiling: DatatypeElephino = state.gap1ndexCeiling
|
|
78
|
+
gapRangeStart: Array1DElephino = state.gapRangeStart
|
|
79
|
+
gapsWhere: Array1DLeavesTotal = state.gapsWhere
|
|
80
|
+
groupsOfFolds: DatatypeFoldsTotal = state.groupsOfFolds
|
|
81
|
+
indexDimension: DatatypeLeavesTotal = state.indexDimension
|
|
82
|
+
indexMiniGap: DatatypeElephino = state.indexMiniGap
|
|
83
|
+
leaf1ndex: DatatypeElephino = state.leaf1ndex
|
|
84
|
+
leafAbove: Array1DLeavesTotal = state.leafAbove
|
|
85
|
+
leafBelow: Array1DLeavesTotal = state.leafBelow
|
|
86
|
+
leafConnectee: DatatypeElephino = state.leafConnectee
|
|
87
|
+
leavesTotal: DatatypeLeavesTotal = state.leavesTotal
|
|
88
|
+
|
|
89
|
+
groupsOfFolds = countSequential(
|
|
90
|
+
connectionGraph = connectionGraph,
|
|
91
|
+
countDimensionsGapped = countDimensionsGapped,
|
|
92
|
+
dimensionsTotal = dimensionsTotal,
|
|
93
|
+
dimensionsUnconstrained = dimensionsUnconstrained,
|
|
94
|
+
gap1ndex = gap1ndex,
|
|
95
|
+
gap1ndexCeiling = gap1ndexCeiling,
|
|
96
|
+
gapRangeStart = gapRangeStart,
|
|
97
|
+
gapsWhere = gapsWhere,
|
|
98
|
+
groupsOfFolds = groupsOfFolds,
|
|
99
|
+
indexDimension = indexDimension,
|
|
100
|
+
indexMiniGap = indexMiniGap,
|
|
101
|
+
leaf1ndex = leaf1ndex,
|
|
102
|
+
leafAbove = leafAbove,
|
|
103
|
+
leafBelow = leafBelow,
|
|
104
|
+
leafConnectee = leafConnectee,
|
|
105
|
+
leavesTotal = leavesTotal,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
state.groupsOfFolds = state.foldGroups[state.taskIndex] = groupsOfFolds
|
|
109
|
+
|
|
110
|
+
return state
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from mapFolding import indexMy
|
|
2
|
+
from mapFolding.syntheticModules.numbaCount import countInitialize, countSequential, countParallel
|
|
3
|
+
from numba import uint16, int64, jit
|
|
4
|
+
from numpy import ndarray, dtype, integer
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
@jit((uint16[:, :, ::1], int64[::1], uint16[::1], uint16[::1], uint16[::1], uint16[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=False, no_cpython_wrapper=False, nopython=True, parallel=False)
|
|
8
|
+
def doTheNeedful(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]], foldGroups: ndarray[tuple[int], dtype[integer[Any]]], gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], mapShape: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
|
|
9
|
+
countInitialize(connectionGraph, gapsWhere, my, track)
|
|
10
|
+
if my[indexMy.taskDivisions] > 0:
|
|
11
|
+
countParallel(connectionGraph, foldGroups, gapsWhere, my, track)
|
|
12
|
+
else:
|
|
13
|
+
countSequential(connectionGraph, foldGroups, gapsWhere, my, track)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from import
|
|
2
|
+
from mapFolding.syntheticModules.numbaCount import countInitialize, countParallel, countSequential
|
|
3
|
+
from mapFolding.theSSOT import ComputationState
|
|
4
|
+
import copy
|
|
5
|
+
|
|
6
|
+
@(ComputationState(ComputationState), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=False, no_cpython_wrapper=False, nopython=True, parallel=False)
|
|
7
|
+
def doTheNeedful(computationStateInitialized: ComputationState) -> ComputationState:
|
|
8
|
+
computationStateInitialized = countInitialize(computationStateInitialized)
|
|
9
|
+
if computationStateInitialized.taskDivisions > 0:
|
|
10
|
+
return countParallel(computationStateInitialized)
|
|
11
|
+
else:
|
|
12
|
+
return countSequential(computationStateInitialized)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from mapFolding import indexMy
|
|
2
|
+
from mapFolding.syntheticModules.numbaCount import countInitialize, countSequential, countParallel
|
|
3
|
+
from numba import uint16, int64, jit
|
|
4
|
+
from numpy import ndarray, dtype, integer
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
@jit((uint16[:, :, ::1], int64[::1], uint16[::1], uint16[::1], uint16[::1], uint16[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=False, no_cpython_wrapper=False, nopython=True, parallel=False)
|
|
8
|
+
def doTheNeedful(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]], foldGroups: ndarray[tuple[int], dtype[integer[Any]]], gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], mapShape: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
|
|
9
|
+
countInitialize(connectionGraph, gapsWhere, my, track)
|
|
10
|
+
if my[indexMy.taskDivisions] > 0:
|
|
11
|
+
countParallel(connectionGraph, foldGroups, gapsWhere, my, track)
|
|
12
|
+
else:
|
|
13
|
+
countSequential(connectionGraph, foldGroups, gapsWhere, my, track)
|
mapFolding/theDao.py
CHANGED
|
@@ -1,232 +1,208 @@
|
|
|
1
|
-
from mapFolding import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
def
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
def
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
def
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def dimensionsUnconstrainedCondition(
|
|
37
|
-
return connectionGraph[
|
|
38
|
-
|
|
39
|
-
def filterCommonGaps(
|
|
40
|
-
gapsWhere[
|
|
41
|
-
if
|
|
42
|
-
incrementActiveGap(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
def
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
def
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
def
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
gapsWhere = gapsWherePARALLEL.copy()
|
|
154
|
-
my = myPARALLEL.copy()
|
|
155
|
-
track = trackPARALLEL.copy()
|
|
156
|
-
|
|
157
|
-
my[indexMy.taskIndex.value] = indexSherpa
|
|
158
|
-
|
|
159
|
-
while activeLeafGreaterThan0(my=my):
|
|
160
|
-
if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
|
|
161
|
-
if activeLeafGreaterThanLeavesTotal(foldGroups=foldGroups, my=my):
|
|
162
|
-
groupsOfFolds += 1
|
|
1
|
+
from mapFolding.theSSOT import ComputationState
|
|
2
|
+
import copy
|
|
3
|
+
|
|
4
|
+
def activeLeafConnectedToItself(state: ComputationState) -> bool:
|
|
5
|
+
return state.leafConnectee == state.leaf1ndex
|
|
6
|
+
|
|
7
|
+
def activeLeafGreaterThan0(state: ComputationState) -> bool:
|
|
8
|
+
return state.leaf1ndex > 0
|
|
9
|
+
|
|
10
|
+
def activeLeafGreaterThanLeavesTotal(state: ComputationState) -> bool:
|
|
11
|
+
return state.leaf1ndex > state.leavesTotal
|
|
12
|
+
|
|
13
|
+
def activeLeafIsTheFirstLeaf(state: ComputationState) -> bool:
|
|
14
|
+
return state.leaf1ndex <= 1
|
|
15
|
+
|
|
16
|
+
def allDimensionsAreUnconstrained(state: ComputationState) -> bool:
|
|
17
|
+
return not state.dimensionsUnconstrained
|
|
18
|
+
|
|
19
|
+
def backtrack(state: ComputationState) -> ComputationState:
|
|
20
|
+
state.leaf1ndex -= 1
|
|
21
|
+
state.leafBelow[state.leafAbove[state.leaf1ndex]] = state.leafBelow[state.leaf1ndex]
|
|
22
|
+
state.leafAbove[state.leafBelow[state.leaf1ndex]] = state.leafAbove[state.leaf1ndex]
|
|
23
|
+
return state
|
|
24
|
+
|
|
25
|
+
def countGaps(state: ComputationState) -> ComputationState:
|
|
26
|
+
state.gapsWhere[state.gap1ndexCeiling] = state.leafConnectee
|
|
27
|
+
if state.countDimensionsGapped[state.leafConnectee] == 0:
|
|
28
|
+
state = incrementGap1ndexCeiling(state)
|
|
29
|
+
state.countDimensionsGapped[state.leafConnectee] += 1
|
|
30
|
+
return state
|
|
31
|
+
|
|
32
|
+
def decrementDimensionsUnconstrained(state: ComputationState) -> ComputationState:
|
|
33
|
+
state.dimensionsUnconstrained -= 1
|
|
34
|
+
return state
|
|
35
|
+
|
|
36
|
+
def dimensionsUnconstrainedCondition(state: ComputationState) -> bool:
|
|
37
|
+
return state.connectionGraph[state.indexDimension, state.leaf1ndex, state.leaf1ndex] == state.leaf1ndex
|
|
38
|
+
|
|
39
|
+
def filterCommonGaps(state: ComputationState) -> ComputationState:
|
|
40
|
+
state.gapsWhere[state.gap1ndex] = state.gapsWhere[state.indexMiniGap]
|
|
41
|
+
if state.countDimensionsGapped[state.gapsWhere[state.indexMiniGap]] == state.dimensionsUnconstrained:
|
|
42
|
+
state = incrementActiveGap(state)
|
|
43
|
+
state.countDimensionsGapped[state.gapsWhere[state.indexMiniGap]] = 0
|
|
44
|
+
return state
|
|
45
|
+
|
|
46
|
+
def incrementActiveGap(state: ComputationState) -> ComputationState:
|
|
47
|
+
state.gap1ndex += 1
|
|
48
|
+
return state
|
|
49
|
+
|
|
50
|
+
def incrementGap1ndexCeiling(state: ComputationState) -> ComputationState:
|
|
51
|
+
state.gap1ndexCeiling += 1
|
|
52
|
+
return state
|
|
53
|
+
|
|
54
|
+
def incrementIndexDimension(state: ComputationState) -> ComputationState:
|
|
55
|
+
state.indexDimension += 1
|
|
56
|
+
return state
|
|
57
|
+
|
|
58
|
+
def incrementIndexMiniGap(state: ComputationState) -> ComputationState:
|
|
59
|
+
state.indexMiniGap += 1
|
|
60
|
+
return state
|
|
61
|
+
|
|
62
|
+
def initializeIndexMiniGap(state: ComputationState) -> ComputationState:
|
|
63
|
+
state.indexMiniGap = state.gap1ndex
|
|
64
|
+
return state
|
|
65
|
+
|
|
66
|
+
def initializeLeafConnectee(state: ComputationState) -> ComputationState:
|
|
67
|
+
state.leafConnectee = state.connectionGraph[state.indexDimension, state.leaf1ndex, state.leaf1ndex]
|
|
68
|
+
return state
|
|
69
|
+
|
|
70
|
+
def initializeVariablesToFindGaps(state: ComputationState) -> ComputationState:
|
|
71
|
+
state.dimensionsUnconstrained = state.dimensionsTotal
|
|
72
|
+
state.gap1ndexCeiling = state.gapRangeStart[state.leaf1ndex - 1]
|
|
73
|
+
state.indexDimension = 0
|
|
74
|
+
return state
|
|
75
|
+
|
|
76
|
+
def insertUnconstrainedLeaf(state: ComputationState) -> ComputationState:
|
|
77
|
+
indexLeaf = 0
|
|
78
|
+
while indexLeaf < state.leaf1ndex:
|
|
79
|
+
state.gapsWhere[state.gap1ndexCeiling] = indexLeaf
|
|
80
|
+
state.gap1ndexCeiling += 1
|
|
81
|
+
indexLeaf += 1
|
|
82
|
+
return state
|
|
83
|
+
|
|
84
|
+
def leafBelowSentinelIs1(state: ComputationState) -> bool:
|
|
85
|
+
return state.leafBelow[0] == 1
|
|
86
|
+
|
|
87
|
+
def loopingLeavesConnectedToActiveLeaf(state: ComputationState) -> bool:
|
|
88
|
+
return state.leafConnectee != state.leaf1ndex
|
|
89
|
+
|
|
90
|
+
def loopingToActiveGapCeiling(state: ComputationState) -> bool:
|
|
91
|
+
return state.indexMiniGap < state.gap1ndexCeiling
|
|
92
|
+
|
|
93
|
+
def loopUpToDimensionsTotal(state: ComputationState) -> bool:
|
|
94
|
+
return state.indexDimension < state.dimensionsTotal
|
|
95
|
+
|
|
96
|
+
def noGapsHere(state: ComputationState) -> bool:
|
|
97
|
+
return (state.leaf1ndex > 0) and (state.gap1ndex == state.gapRangeStart[state.leaf1ndex - 1])
|
|
98
|
+
|
|
99
|
+
def placeLeaf(state: ComputationState) -> ComputationState:
|
|
100
|
+
state.gap1ndex -= 1
|
|
101
|
+
state.leafAbove[state.leaf1ndex] = state.gapsWhere[state.gap1ndex]
|
|
102
|
+
state.leafBelow[state.leaf1ndex] = state.leafBelow[state.leafAbove[state.leaf1ndex]]
|
|
103
|
+
state.leafBelow[state.leafAbove[state.leaf1ndex]] = state.leaf1ndex
|
|
104
|
+
state.leafAbove[state.leafBelow[state.leaf1ndex]] = state.leaf1ndex
|
|
105
|
+
state.gapRangeStart[state.leaf1ndex] = state.gap1ndex
|
|
106
|
+
state.leaf1ndex += 1
|
|
107
|
+
return state
|
|
108
|
+
|
|
109
|
+
def thereIsAnActiveLeaf(state: ComputationState) -> bool:
|
|
110
|
+
return state.leaf1ndex > 0
|
|
111
|
+
|
|
112
|
+
def thisIsMyTaskIndex(state: ComputationState) -> bool:
|
|
113
|
+
return (state.leaf1ndex != state.taskDivisions) or (state.leafConnectee % state.taskDivisions == state.taskIndex)
|
|
114
|
+
|
|
115
|
+
def updateLeafConnectee(state: ComputationState) -> ComputationState:
|
|
116
|
+
state.leafConnectee = state.connectionGraph[state.indexDimension, state.leaf1ndex, state.leafBelow[state.leafConnectee]]
|
|
117
|
+
return state
|
|
118
|
+
|
|
119
|
+
def countInitialize(state: ComputationState) -> ComputationState:
|
|
120
|
+
while activeLeafGreaterThan0(state):
|
|
121
|
+
if activeLeafIsTheFirstLeaf(state) or leafBelowSentinelIs1(state):
|
|
122
|
+
state = initializeVariablesToFindGaps(state)
|
|
123
|
+
while loopUpToDimensionsTotal(state):
|
|
124
|
+
state = initializeLeafConnectee(state)
|
|
125
|
+
if activeLeafConnectedToItself(state):
|
|
126
|
+
state = decrementDimensionsUnconstrained(state)
|
|
127
|
+
else:
|
|
128
|
+
while loopingLeavesConnectedToActiveLeaf(state):
|
|
129
|
+
state = countGaps(state)
|
|
130
|
+
state = updateLeafConnectee(state)
|
|
131
|
+
state = incrementIndexDimension(state)
|
|
132
|
+
if allDimensionsAreUnconstrained(state):
|
|
133
|
+
state = insertUnconstrainedLeaf(state)
|
|
134
|
+
state = initializeIndexMiniGap(state)
|
|
135
|
+
while loopingToActiveGapCeiling(state):
|
|
136
|
+
state = filterCommonGaps(state)
|
|
137
|
+
state = incrementIndexMiniGap(state)
|
|
138
|
+
if thereIsAnActiveLeaf(state):
|
|
139
|
+
state = placeLeaf(state)
|
|
140
|
+
if state.gap1ndex > 0:
|
|
141
|
+
break
|
|
142
|
+
return state
|
|
143
|
+
|
|
144
|
+
def countParallel(statePARALLEL: ComputationState) -> ComputationState:
|
|
145
|
+
stateCOMPLETE = copy.deepcopy(statePARALLEL)
|
|
146
|
+
for indexSherpa in range(statePARALLEL.taskDivisions):
|
|
147
|
+
state = copy.deepcopy(statePARALLEL)
|
|
148
|
+
state.taskIndex = indexSherpa
|
|
149
|
+
while activeLeafGreaterThan0(state):
|
|
150
|
+
if activeLeafIsTheFirstLeaf(state) or leafBelowSentinelIs1(state):
|
|
151
|
+
if activeLeafGreaterThanLeavesTotal(state):
|
|
152
|
+
state.groupsOfFolds += 1
|
|
163
153
|
else:
|
|
164
|
-
initializeVariablesToFindGaps(
|
|
165
|
-
while loopUpToDimensionsTotal(
|
|
166
|
-
if dimensionsUnconstrainedCondition(
|
|
167
|
-
decrementDimensionsUnconstrained(
|
|
154
|
+
state = initializeVariablesToFindGaps(state)
|
|
155
|
+
while loopUpToDimensionsTotal(state):
|
|
156
|
+
if dimensionsUnconstrainedCondition(state):
|
|
157
|
+
state = decrementDimensionsUnconstrained(state)
|
|
168
158
|
else:
|
|
169
|
-
initializeLeafConnectee(
|
|
170
|
-
while loopingLeavesConnectedToActiveLeaf(
|
|
171
|
-
if thisIsMyTaskIndex(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
incrementIndexDimension(
|
|
175
|
-
initializeIndexMiniGap(
|
|
176
|
-
while loopingToActiveGapCeiling(
|
|
177
|
-
|
|
178
|
-
incrementIndexMiniGap(
|
|
179
|
-
while noGapsHere(
|
|
180
|
-
backtrack(
|
|
181
|
-
if thereIsAnActiveLeaf(
|
|
182
|
-
|
|
183
|
-
foldGroups[
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
groupsOfFolds: int = 0
|
|
193
|
-
|
|
194
|
-
while activeLeafGreaterThan0(my=my):
|
|
195
|
-
if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
|
|
196
|
-
if activeLeafGreaterThanLeavesTotal(foldGroups=foldGroups, my=my):
|
|
197
|
-
groupsOfFolds += 1
|
|
159
|
+
state = initializeLeafConnectee(state)
|
|
160
|
+
while loopingLeavesConnectedToActiveLeaf(state):
|
|
161
|
+
if thisIsMyTaskIndex(state):
|
|
162
|
+
state = countGaps(state)
|
|
163
|
+
state = updateLeafConnectee(state)
|
|
164
|
+
state = incrementIndexDimension(state)
|
|
165
|
+
state = initializeIndexMiniGap(state)
|
|
166
|
+
while loopingToActiveGapCeiling(state):
|
|
167
|
+
state = filterCommonGaps(state)
|
|
168
|
+
state = incrementIndexMiniGap(state)
|
|
169
|
+
while noGapsHere(state):
|
|
170
|
+
state = backtrack(state)
|
|
171
|
+
if thereIsAnActiveLeaf(state):
|
|
172
|
+
state = placeLeaf(state)
|
|
173
|
+
stateCOMPLETE.foldGroups[state.taskIndex] = state.groupsOfFolds
|
|
174
|
+
return stateCOMPLETE
|
|
175
|
+
|
|
176
|
+
def countSequential(state: ComputationState) -> ComputationState:
|
|
177
|
+
while activeLeafGreaterThan0(state):
|
|
178
|
+
if activeLeafIsTheFirstLeaf(state) or leafBelowSentinelIs1(state):
|
|
179
|
+
if activeLeafGreaterThanLeavesTotal(state):
|
|
180
|
+
state.groupsOfFolds += 1
|
|
198
181
|
else:
|
|
199
|
-
initializeVariablesToFindGaps(
|
|
200
|
-
while loopUpToDimensionsTotal(
|
|
201
|
-
initializeLeafConnectee(
|
|
202
|
-
if activeLeafConnectedToItself(
|
|
203
|
-
decrementDimensionsUnconstrained(
|
|
182
|
+
state = initializeVariablesToFindGaps(state)
|
|
183
|
+
while loopUpToDimensionsTotal(state):
|
|
184
|
+
state = initializeLeafConnectee(state)
|
|
185
|
+
if activeLeafConnectedToItself(state):
|
|
186
|
+
state = decrementDimensionsUnconstrained(state)
|
|
204
187
|
else:
|
|
205
|
-
while loopingLeavesConnectedToActiveLeaf(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
incrementIndexDimension(
|
|
209
|
-
initializeIndexMiniGap(
|
|
210
|
-
while loopingToActiveGapCeiling(
|
|
211
|
-
|
|
212
|
-
incrementIndexMiniGap(
|
|
213
|
-
while noGapsHere(
|
|
214
|
-
backtrack(
|
|
215
|
-
if thereIsAnActiveLeaf(
|
|
216
|
-
|
|
217
|
-
foldGroups[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
, track: ndarray[tuple[int, int] , dtype[integer[Any]]]
|
|
225
|
-
) -> None:
|
|
226
|
-
|
|
227
|
-
countInitialize(connectionGraph, gapsWhere, my, track)
|
|
228
|
-
|
|
229
|
-
if my[indexMy.taskDivisions.value] > 0:
|
|
230
|
-
countParallel(connectionGraph, foldGroups, gapsWhere, my, track)
|
|
188
|
+
while loopingLeavesConnectedToActiveLeaf(state):
|
|
189
|
+
state = countGaps(state)
|
|
190
|
+
state = updateLeafConnectee(state)
|
|
191
|
+
state = incrementIndexDimension(state)
|
|
192
|
+
state = initializeIndexMiniGap(state)
|
|
193
|
+
while loopingToActiveGapCeiling(state):
|
|
194
|
+
state = filterCommonGaps(state)
|
|
195
|
+
state = incrementIndexMiniGap(state)
|
|
196
|
+
while noGapsHere(state):
|
|
197
|
+
state = backtrack(state)
|
|
198
|
+
if thereIsAnActiveLeaf(state):
|
|
199
|
+
state = placeLeaf(state)
|
|
200
|
+
state.foldGroups[state.taskIndex] = state.groupsOfFolds
|
|
201
|
+
return state
|
|
202
|
+
|
|
203
|
+
def doTheNeedful(state: ComputationState) -> ComputationState:
|
|
204
|
+
state = countInitialize(state)
|
|
205
|
+
if state.taskDivisions > 0:
|
|
206
|
+
return countParallel(state)
|
|
231
207
|
else:
|
|
232
|
-
countSequential(
|
|
208
|
+
return countSequential(state)
|