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.
Files changed (51) hide show
  1. mapFolding/__init__.py +6 -101
  2. mapFolding/basecamp.py +12 -10
  3. mapFolding/beDRY.py +96 -316
  4. mapFolding/filesystem.py +87 -0
  5. mapFolding/noHomeYet.py +20 -0
  6. mapFolding/oeis.py +39 -36
  7. mapFolding/reference/flattened.py +377 -0
  8. mapFolding/reference/hunterNumba.py +132 -0
  9. mapFolding/reference/irvineJavaPort.py +120 -0
  10. mapFolding/reference/jax.py +208 -0
  11. mapFolding/reference/lunnan.py +153 -0
  12. mapFolding/reference/lunnanNumpy.py +123 -0
  13. mapFolding/reference/lunnanWhile.py +121 -0
  14. mapFolding/reference/rotatedEntryPoint.py +240 -0
  15. mapFolding/reference/total_countPlus1vsPlusN.py +211 -0
  16. mapFolding/someAssemblyRequired/Z0Z_workbench.py +34 -0
  17. mapFolding/someAssemblyRequired/__init__.py +16 -0
  18. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +21 -0
  19. mapFolding/someAssemblyRequired/ingredientsNumba.py +100 -0
  20. mapFolding/someAssemblyRequired/synthesizeCountingFunctions.py +7 -0
  21. mapFolding/someAssemblyRequired/synthesizeDataConverters.py +135 -0
  22. mapFolding/someAssemblyRequired/synthesizeNumba.py +91 -0
  23. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +417 -0
  24. mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +91 -0
  25. mapFolding/someAssemblyRequired/transformationTools.py +425 -0
  26. mapFolding/someAssemblyRequired/whatWillBe.py +311 -0
  27. mapFolding/syntheticModules/__init__.py +0 -0
  28. mapFolding/syntheticModules/dataNamespaceFlattened.py +30 -0
  29. mapFolding/syntheticModules/numbaCount.py +90 -0
  30. mapFolding/syntheticModules/numbaCountExample.py +158 -0
  31. mapFolding/syntheticModules/numbaCountSequential.py +110 -0
  32. mapFolding/syntheticModules/numbaCount_doTheNeedful.py +13 -0
  33. mapFolding/syntheticModules/numba_doTheNeedful.py +12 -0
  34. mapFolding/syntheticModules/numba_doTheNeedfulExample.py +13 -0
  35. mapFolding/theDao.py +203 -227
  36. mapFolding/theSSOT.py +254 -123
  37. {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/METADATA +10 -8
  38. mapfolding-0.7.0.dist-info/RECORD +50 -0
  39. {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/WHEEL +1 -1
  40. {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/top_level.txt +1 -0
  41. tests/__init__.py +0 -0
  42. tests/conftest.py +278 -0
  43. tests/test_computations.py +49 -0
  44. tests/test_filesystem.py +52 -0
  45. tests/test_oeis.py +128 -0
  46. tests/test_other.py +84 -0
  47. tests/test_tasks.py +50 -0
  48. mapFolding/theSSOTdatatypes.py +0 -156
  49. mapFolding-0.5.1.dist-info/RECORD +0 -14
  50. {mapFolding-0.5.1.dist-info → mapfolding-0.7.0.dist-info}/LICENSE +0 -0
  51. {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 indexMy, indexTrack
2
- from numba import prange
3
- from numpy import dtype, integer, ndarray
4
- from typing import Any
5
-
6
- # `.value` is not necessary for this module or most modules. But, this module is transformed into Numba "jitted" functions, and Numba won't use `Enum` for an ndarray index without `.value`.
7
- def activeLeafConnectedToItself(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
8
- return my[indexMy.leafConnectee.value] == my[indexMy.leaf1ndex.value]
9
-
10
- def activeLeafGreaterThan0(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
11
- return my[indexMy.leaf1ndex.value] > 0
12
-
13
- def activeLeafGreaterThanLeavesTotal(foldGroups: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
14
- return my[indexMy.leaf1ndex.value] > foldGroups[-1]
15
-
16
- def activeLeafIsTheFirstLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
17
- return my[indexMy.leaf1ndex.value] <= 1
18
-
19
- def allDimensionsAreUnconstrained(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
20
- return not my[indexMy.dimensionsUnconstrained.value]
21
-
22
- def backtrack(my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
23
- my[indexMy.leaf1ndex.value] -= 1
24
- track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
25
- track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]
26
-
27
- def countGaps(gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
28
- gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
29
- if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
30
- incrementGap1ndexCeiling(my=my)
31
- track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
32
-
33
- def decrementDimensionsUnconstrained(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
34
- my[indexMy.dimensionsUnconstrained.value] -= 1
35
-
36
- def dimensionsUnconstrainedCondition(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
37
- return connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]
38
-
39
- def filterCommonGaps(gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
40
- gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
41
- if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
42
- incrementActiveGap(my=my)
43
- track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
44
-
45
- def incrementActiveGap(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
46
- my[indexMy.gap1ndex.value] += 1
47
-
48
- def incrementGap1ndexCeiling(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
49
- my[indexMy.gap1ndexCeiling.value] += 1
50
-
51
- def incrementIndexDimension(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
52
- my[indexMy.indexDimension.value] += 1
53
-
54
- def incrementIndexMiniGap(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
55
- my[indexMy.indexMiniGap.value] += 1
56
-
57
- def initializeIndexMiniGap(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
58
- my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
59
-
60
- def initializeLeafConnectee(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
61
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
62
-
63
- def initializeVariablesToFindGaps(my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
64
- my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
65
- my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
66
- my[indexMy.indexDimension.value] = 0
67
-
68
- def insertUnconstrainedLeaf(gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
69
- my[indexMy.indexLeaf.value] = 0
70
- while my[indexMy.indexLeaf.value] < my[indexMy.leaf1ndex.value]:
71
- gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.indexLeaf.value]
72
- my[indexMy.gap1ndexCeiling.value] += 1
73
- my[indexMy.indexLeaf.value] += 1
74
-
75
- def leafBelowSentinelIs1(track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> Any:
76
- return track[indexTrack.leafBelow.value, 0] == 1
77
-
78
- def loopingLeavesConnectedToActiveLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
79
- return my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]
80
-
81
- def loopingToActiveGapCeiling(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
82
- return my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]
83
-
84
- def loopUpToDimensionsTotal(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
85
- return my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]
86
-
87
- def noGapsHere(my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> Any:
88
- return my[indexMy.leaf1ndex.value] > 0 and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
89
-
90
- def placeLeaf(gapsWhere: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
91
- my[indexMy.gap1ndex.value] -= 1
92
- track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
93
- track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
94
- track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
95
- track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
96
- track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
97
- my[indexMy.leaf1ndex.value] += 1
98
-
99
- def thereIsAnActiveLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
100
- return my[indexMy.leaf1ndex.value] > 0
101
-
102
- def thisIsMyTaskIndex(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
103
- return my[indexMy.leaf1ndex.value] != my[indexMy.taskDivisions.value] or my[indexMy.leafConnectee.value] % my[indexMy.taskDivisions.value] == my[indexMy.taskIndex.value]
104
-
105
- def updateLeafConnectee(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
106
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
107
-
108
- def countInitialize(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]]
109
- , gapsWhere: ndarray[tuple[int] , dtype[integer[Any]]]
110
- , my: ndarray[tuple[int] , dtype[integer[Any]]]
111
- , track: ndarray[tuple[int, int] , dtype[integer[Any]]]
112
- ) -> None:
113
-
114
- while activeLeafGreaterThan0(my=my):
115
- if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
116
- initializeVariablesToFindGaps(my=my, track=track)
117
- while loopUpToDimensionsTotal(my=my):
118
- if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
119
- decrementDimensionsUnconstrained(my=my)
120
- else:
121
- initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
122
- while loopingLeavesConnectedToActiveLeaf(my=my):
123
- countGaps(gapsWhere=gapsWhere, my=my, track=track)
124
- updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
125
- incrementIndexDimension(my=my)
126
- if allDimensionsAreUnconstrained(my=my):
127
- insertUnconstrainedLeaf(gapsWhere=gapsWhere, my=my)
128
- initializeIndexMiniGap(my=my)
129
- while loopingToActiveGapCeiling(my=my):
130
- filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
131
- incrementIndexMiniGap(my=my)
132
- if thereIsAnActiveLeaf(my=my):
133
- placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
134
- if my[indexMy.gap1ndex.value] > 0:
135
- return
136
-
137
- def countParallel(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]]
138
- , foldGroups: ndarray[tuple[int] , dtype[integer[Any]]]
139
- , gapsWhere: ndarray[tuple[int] , dtype[integer[Any]]]
140
- , my: ndarray[tuple[int] , dtype[integer[Any]]]
141
- , track: ndarray[tuple[int, int] , dtype[integer[Any]]]
142
- ) -> None:
143
-
144
- gapsWherePARALLEL = gapsWhere.copy()
145
- myPARALLEL = my.copy()
146
- trackPARALLEL = track.copy()
147
-
148
- taskDivisionsPrange = myPARALLEL[indexMy.taskDivisions.value]
149
-
150
- for indexSherpa in prange(taskDivisionsPrange):
151
- groupsOfFolds: int = 0
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(my=my, track=track)
165
- while loopUpToDimensionsTotal(my=my):
166
- if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
167
- decrementDimensionsUnconstrained(my=my)
154
+ state = initializeVariablesToFindGaps(state)
155
+ while loopUpToDimensionsTotal(state):
156
+ if dimensionsUnconstrainedCondition(state):
157
+ state = decrementDimensionsUnconstrained(state)
168
158
  else:
169
- initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
170
- while loopingLeavesConnectedToActiveLeaf(my=my):
171
- if thisIsMyTaskIndex(my=my):
172
- countGaps(gapsWhere=gapsWhere, my=my, track=track)
173
- updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
174
- incrementIndexDimension(my=my)
175
- initializeIndexMiniGap(my=my)
176
- while loopingToActiveGapCeiling(my=my):
177
- filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
178
- incrementIndexMiniGap(my=my)
179
- while noGapsHere(my=my, track=track):
180
- backtrack(my=my, track=track)
181
- if thereIsAnActiveLeaf(my=my):
182
- placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
183
- foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
184
-
185
- def countSequential( connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]]
186
- , foldGroups: ndarray[tuple[int] , dtype[integer[Any]]]
187
- , gapsWhere: ndarray[tuple[int] , dtype[integer[Any]]]
188
- , my: ndarray[tuple[int] , dtype[integer[Any]]]
189
- , track: ndarray[tuple[int, int] , dtype[integer[Any]]]
190
- ) -> None:
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(my=my, track=track)
200
- while loopUpToDimensionsTotal(my=my):
201
- initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
202
- if activeLeafConnectedToItself(my=my):
203
- decrementDimensionsUnconstrained(my=my)
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(my=my):
206
- countGaps(gapsWhere=gapsWhere, my=my, track=track)
207
- updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
208
- incrementIndexDimension(my=my)
209
- initializeIndexMiniGap(my=my)
210
- while loopingToActiveGapCeiling(my=my):
211
- filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
212
- incrementIndexMiniGap(my=my)
213
- while noGapsHere(my=my, track=track):
214
- backtrack(my=my, track=track)
215
- if thereIsAnActiveLeaf(my=my):
216
- placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
217
- foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
218
-
219
- def doTheNeedful(connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]]
220
- , foldGroups: ndarray[tuple[int] , dtype[integer[Any]]]
221
- , gapsWhere: ndarray[tuple[int] , dtype[integer[Any]]]
222
- , mapShape: ndarray[tuple[int] , dtype[integer[Any]]]
223
- , my: ndarray[tuple[int] , dtype[integer[Any]]]
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(connectionGraph, foldGroups, gapsWhere, my, track)
208
+ return countSequential(state)