mapFolding 0.3.12__py3-none-any.whl → 0.4.1__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 (46) hide show
  1. mapFolding/__init__.py +40 -38
  2. mapFolding/basecamp.py +50 -50
  3. mapFolding/beDRY.py +336 -336
  4. mapFolding/oeis.py +262 -262
  5. mapFolding/reference/flattened.py +294 -293
  6. mapFolding/reference/hunterNumba.py +126 -126
  7. mapFolding/reference/irvineJavaPort.py +99 -99
  8. mapFolding/reference/jax.py +153 -153
  9. mapFolding/reference/lunnan.py +148 -148
  10. mapFolding/reference/lunnanNumpy.py +115 -115
  11. mapFolding/reference/lunnanWhile.py +114 -114
  12. mapFolding/reference/rotatedEntryPoint.py +183 -183
  13. mapFolding/reference/total_countPlus1vsPlusN.py +203 -203
  14. mapFolding/someAssemblyRequired/__init__.py +5 -1
  15. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +12 -12
  16. mapFolding/someAssemblyRequired/makeJob.py +46 -52
  17. mapFolding/someAssemblyRequired/synthesizeModuleJAX.py +17 -17
  18. mapFolding/someAssemblyRequired/synthesizeNumba.py +343 -633
  19. mapFolding/someAssemblyRequired/synthesizeNumbaGeneralized.py +325 -0
  20. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +173 -0
  21. mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +77 -0
  22. mapFolding/syntheticModules/__init__.py +0 -0
  23. mapFolding/syntheticModules/numba_countInitialize.py +4 -4
  24. mapFolding/syntheticModules/numba_countParallel.py +4 -4
  25. mapFolding/syntheticModules/numba_countSequential.py +4 -4
  26. mapFolding/syntheticModules/numba_doTheNeedful.py +7 -7
  27. mapFolding/theDao.py +165 -165
  28. mapFolding/theSSOT.py +177 -173
  29. mapFolding/theSSOTnumba.py +90 -74
  30. mapFolding-0.4.1.dist-info/METADATA +154 -0
  31. mapFolding-0.4.1.dist-info/RECORD +42 -0
  32. tests/conftest.py +253 -129
  33. tests/test_computations.py +79 -0
  34. tests/test_oeis.py +76 -85
  35. tests/test_other.py +136 -224
  36. tests/test_tasks.py +19 -23
  37. tests/test_types.py +2 -2
  38. mapFolding/someAssemblyRequired/synthesizeNumbaHardcoding.py +0 -188
  39. mapFolding-0.3.12.dist-info/METADATA +0 -155
  40. mapFolding-0.3.12.dist-info/RECORD +0 -40
  41. tests/conftest_tmpRegistry.py +0 -62
  42. tests/conftest_uniformTests.py +0 -53
  43. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/LICENSE +0 -0
  44. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/WHEEL +0 -0
  45. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/entry_points.txt +0 -0
  46. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/top_level.txt +0 -0
@@ -5,117 +5,117 @@ W. F. Lunnon, Multi-dimensional map-folding, The Computer Journal, Volume 14, Is
5
5
  from typing import Sequence
6
6
 
7
7
  def foldings(p: Sequence[int]) -> int:
8
- """
9
- Run loop with (A, B) on each folding of a p[1] x ... x p[d] map, where A and B are the above and below vectors.
10
-
11
- Parameters:
12
- p: An array of integers representing the dimensions of the map.
13
-
14
- Returns:
15
- G: The number of distinct foldings for the given map dimensions.
16
-
17
- NOTE If there are fewer than two dimensions, any dimensions are not positive, or any dimensions are not integers, the output will be unreliable.
18
- """
19
-
20
- g: int = 0
21
- d: int = len(p)
22
- n: int = 1
23
- for i in range(d):
24
- n = n * p[i]
25
-
26
- # d dimensions and n leaves
27
-
28
- A = [0] * (n + 1)
29
- B = [0] * (n + 1)
30
- count = [0] * (n + 1)
31
- gapter = [0] * (n + 1)
32
- gap = [0] * (n * n + 1)
33
-
34
- # B[m] is the leaf below leaf m in the current folding,
35
- # A[m] the leaf above. count[m] is the no. of sections in which
36
- # there is a gap for the new leaf l below leaf m,
37
- # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
38
- # and later gap[gapter[l]] is the gap where leaf l is currently inserted
39
-
40
- P = [1] * (d + 1)
41
- C = [[0] * (n + 1) for dimension1 in range(d + 1)]
42
- D = [[[0] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)]
43
-
44
- for i in range(1, d + 1):
45
- P[i] = P[i - 1] * p[i - 1]
46
-
47
- for i in range(1, d + 1):
48
- for m in range(1, n + 1):
49
- C[i][m] = ((m - 1) // P[i - 1]) - ((m - 1) // P[i]) * p[i - 1] + 1
50
-
51
- for i in range(1, d + 1):
52
- for l in range(1, n + 1):
53
- for m in range(1, l + 1):
54
- if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2: # !
55
- if C[i][m] == 1:
56
- D[i][l][m] = m
57
- else:
58
- D[i][l][m] = m - P[i - 1]
59
- else:
60
- if C[i][m] == p[i - 1] or m + P[i - 1] > l:
61
- D[i][l][m] = m
62
- else:
63
- D[i][l][m] = m + P[i - 1]
64
- # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
65
- # D[i][l][m] = leaf connected to m in section i when inserting l;
66
-
67
- G: int = 0
68
- l: int = 1
69
-
70
- # kick off with null folding
71
- while l > 0:
72
- if l > n:
73
- G = G + 1
74
- else:
75
- dd: int = 0
76
- gg: int = gapter[l - 1]
77
- g = gg
78
- # dd is the no. of sections in which l is unconstrained,
79
- # gg the no. of possible and g the no. of actual gaps for l, + gapter[l - 1]
80
-
81
- # find the possible gaps for leaf l in each section,
82
- # then discard those not common to all. All possible if dd = d
83
- for i in range(1, d + 1):
84
- if D[i][l][l] == l:
85
- dd = dd + 1
86
- else:
87
- m: int = D[i][l][l]
88
- while m != l:
89
- gap[gg] = m
90
- if count[m] == 0:
91
- gg = gg + 1
92
- count[m] += 1
93
- m = D[i][l][B[m]]
94
-
95
- if dd == d:
96
- for m in range(l):
97
- gap[gg] = m
98
- gg = gg + 1
99
-
100
- for j in range(g, gg):
101
- gap[g] = gap[j]
102
- if count[gap[j]] == d - dd:
103
- g = g + 1
104
- count[gap[j]] = 0
105
-
106
- # for each gap insert leaf l, [the main while loop shall progress],
107
- # remove leaf l
108
- while l > 0 and g == gapter[l - 1]:
109
- l = l - 1
110
- B[A[l]] = B[l]
111
- A[B[l]] = A[l]
112
-
113
- if l > 0:
114
- g = g - 1
115
- A[l] = gap[g]
116
- B[l] = B[A[l]]
117
- B[A[l]] = l
118
- A[B[l]] = l
119
- gapter[l] = g
120
- l = l + 1
121
- return G
8
+ """
9
+ Run loop with (A, B) on each folding of a p[1] x ... x p[d] map, where A and B are the above and below vectors.
10
+
11
+ Parameters:
12
+ p: An array of integers representing the dimensions of the map.
13
+
14
+ Returns:
15
+ G: The number of distinct foldings for the given map dimensions.
16
+
17
+ NOTE If there are fewer than two dimensions, any dimensions are not positive, or any dimensions are not integers, the output will be unreliable.
18
+ """
19
+
20
+ g: int = 0
21
+ d: int = len(p)
22
+ n: int = 1
23
+ for i in range(d):
24
+ n = n * p[i]
25
+
26
+ # d dimensions and n leaves
27
+
28
+ A = [0] * (n + 1)
29
+ B = [0] * (n + 1)
30
+ count = [0] * (n + 1)
31
+ gapter = [0] * (n + 1)
32
+ gap = [0] * (n * n + 1)
33
+
34
+ # B[m] is the leaf below leaf m in the current folding,
35
+ # A[m] the leaf above. count[m] is the no. of sections in which
36
+ # there is a gap for the new leaf l below leaf m,
37
+ # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
38
+ # and later gap[gapter[l]] is the gap where leaf l is currently inserted
39
+
40
+ P = [1] * (d + 1)
41
+ C = [[0] * (n + 1) for dimension1 in range(d + 1)]
42
+ D = [[[0] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)]
43
+
44
+ for i in range(1, d + 1):
45
+ P[i] = P[i - 1] * p[i - 1]
46
+
47
+ for i in range(1, d + 1):
48
+ for m in range(1, n + 1):
49
+ C[i][m] = ((m - 1) // P[i - 1]) - ((m - 1) // P[i]) * p[i - 1] + 1
50
+
51
+ for i in range(1, d + 1):
52
+ for l in range(1, n + 1):
53
+ for m in range(1, l + 1):
54
+ if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2: # !
55
+ if C[i][m] == 1:
56
+ D[i][l][m] = m
57
+ else:
58
+ D[i][l][m] = m - P[i - 1]
59
+ else:
60
+ if C[i][m] == p[i - 1] or m + P[i - 1] > l:
61
+ D[i][l][m] = m
62
+ else:
63
+ D[i][l][m] = m + P[i - 1]
64
+ # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
65
+ # D[i][l][m] = leaf connected to m in section i when inserting l;
66
+
67
+ G: int = 0
68
+ l: int = 1
69
+
70
+ # kick off with null folding
71
+ while l > 0:
72
+ if l > n:
73
+ G = G + 1
74
+ else:
75
+ dd: int = 0
76
+ gg: int = gapter[l - 1]
77
+ g = gg
78
+ # dd is the no. of sections in which l is unconstrained,
79
+ # gg the no. of possible and g the no. of actual gaps for l, + gapter[l - 1]
80
+
81
+ # find the possible gaps for leaf l in each section,
82
+ # then discard those not common to all. All possible if dd = d
83
+ for i in range(1, d + 1):
84
+ if D[i][l][l] == l:
85
+ dd = dd + 1
86
+ else:
87
+ m: int = D[i][l][l]
88
+ while m != l:
89
+ gap[gg] = m
90
+ if count[m] == 0:
91
+ gg = gg + 1
92
+ count[m] += 1
93
+ m = D[i][l][B[m]]
94
+
95
+ if dd == d:
96
+ for m in range(l):
97
+ gap[gg] = m
98
+ gg = gg + 1
99
+
100
+ for j in range(g, gg):
101
+ gap[g] = gap[j]
102
+ if count[gap[j]] == d - dd:
103
+ g = g + 1
104
+ count[gap[j]] = 0
105
+
106
+ # for each gap insert leaf l, [the main while loop shall progress],
107
+ # remove leaf l
108
+ while l > 0 and g == gapter[l - 1]:
109
+ l = l - 1
110
+ B[A[l]] = B[l]
111
+ A[B[l]] = A[l]
112
+
113
+ if l > 0:
114
+ g = g - 1
115
+ A[l] = gap[g]
116
+ B[l] = B[A[l]]
117
+ B[A[l]] = l
118
+ A[B[l]] = l
119
+ gapter[l] = g
120
+ l = l + 1
121
+ return G
@@ -43,198 +43,198 @@ tricky = [
43
43
  COUNTindicesStatic = len(tricky)
44
44
 
45
45
  def countFolds(listDimensions: List[int]):
46
- static = numpy.zeros(COUNTindicesStatic, dtype=numpy.int64)
46
+ static = numpy.zeros(COUNTindicesStatic, dtype=numpy.int64)
47
47
 
48
- listDimensions, static[leavesTotal], D, track,gapsWhere = outfitFoldings(listDimensions)
48
+ listDimensions, static[leavesTotal], D, track,gapsWhere = outfitFoldings(listDimensions)
49
49
 
50
- static[dimensionsTotal] = len(listDimensions)
51
- static[dimensionsPlus1] = static[dimensionsTotal] + 1
50
+ static[dimensionsTotal] = len(listDimensions)
51
+ static[dimensionsPlus1] = static[dimensionsTotal] + 1
52
52
 
53
- # Pass listDimensions and taskDivisions to _sherpa for benchmarking
54
- foldingsTotal = _sherpa(track, gapsWhere, static, D, listDimensions)
55
- return foldingsTotal
53
+ # Pass listDimensions and taskDivisions to _sherpa for benchmarking
54
+ foldingsTotal = _sherpa(track, gapsWhere, static, D, listDimensions)
55
+ return foldingsTotal
56
56
 
57
57
  # @recordBenchmarks()
58
58
  def _sherpa(track: NDArray, gap: NDArray, static: NDArray, D: NDArray, p: List[int]):
59
- """Performance critical section that counts foldings.
60
-
61
- Parameters:
62
- track: Array tracking folding state
63
- gap: Array for potential gaps
64
- static: Array containing static configuration values
65
- D: Array of leaf connections
66
- p: List of dimensions for benchmarking
67
- """
68
- foldingsTotal = countFoldings(track, gap, static, D)
69
- return foldingsTotal
59
+ """Performance critical section that counts foldings.
60
+
61
+ Parameters:
62
+ track: Array tracking folding state
63
+ gap: Array for potential gaps
64
+ static: Array containing static configuration values
65
+ D: Array of leaf connections
66
+ p: List of dimensions for benchmarking
67
+ """
68
+ foldingsTotal = countFoldings(track, gap, static, D)
69
+ return foldingsTotal
70
70
 
71
71
  @njit(cache=True, parallel=False, fastmath=False)
72
72
  def countFoldings(TEMPLATEtrack: NDArray,
73
- TEMPLATEgapsWhere: NDArray,
74
- the: NDArray,
75
- connectionGraph: NDArray
76
- ):
77
-
78
- TEMPLATEmy = numpy.zeros(COUNTindicesDynamic, dtype=numpy.int64)
79
- TEMPLATEmy[leaf1ndex] = 1
80
-
81
- taskDivisions = 0
82
- # taskDivisions = the[leavesTotal]
83
- TEMPLATEmy[taskIndex] = taskDivisions - 1 # the first modulo is leavesTotal - 1
84
-
85
- def prepareWork(track: NDArray,
86
- gapsWhere: NDArray,
87
- my: NDArray) -> tuple[NDArray, NDArray, NDArray]:
88
- foldingsTotal = 0
89
- while True:
90
- if my[leaf1ndex] <= 1 or track[leafBelow][0] == 1:
91
- if my[leaf1ndex] > the[leavesTotal]:
92
- foldingsTotal += the[leavesTotal]
93
- else:
94
- my[unconstrainedLeaf] = 0
95
- my[gap1ndexCeiling] = track[gapRangeStart][my[leaf1ndex] - 1]
96
- my[gap1ndex] = my[gap1ndexCeiling]
97
-
98
- for PREPAREdimension1ndex in range(1, the[dimensionsPlus1]):
99
- if connectionGraph[PREPAREdimension1ndex][my[leaf1ndex]][my[leaf1ndex]] == my[leaf1ndex]:
100
- my[unconstrainedLeaf] += 1
101
- else:
102
- my[leafConnectee] = connectionGraph[PREPAREdimension1ndex][my[leaf1ndex]][my[leaf1ndex]]
103
- while my[leafConnectee] != my[leaf1ndex]:
104
-
105
- if my[leafConnectee] != my[leaf1ndex]:
106
- my[dimension1ndex] = PREPAREdimension1ndex
107
- return track, gapsWhere, my
108
-
109
- if my[leaf1ndex] != the[leavesTotal]:
110
- gapsWhere[my[gap1ndexCeiling]] = my[leafConnectee]
111
- if track[countDimensionsGapped][my[leafConnectee]] == 0:
112
- my[gap1ndexCeiling] += 1
113
- track[countDimensionsGapped][my[leafConnectee]] += 1
114
- else:
115
- print("else")
116
- my[dimension1ndex] = PREPAREdimension1ndex
117
- return track, gapsWhere, my
118
- # PREPAREmy[leafConnectee] % the[leavesTotal] == PREPAREmy[taskIndex]
119
- my[leafConnectee] = connectionGraph[dimension1ndex][my[leaf1ndex]][track[leafBelow][my[leafConnectee]]]
120
-
121
- if my[unconstrainedLeaf] == the[dimensionsTotal]:
122
- for indexLeaf in range(my[leaf1ndex]):
123
- gapsWhere[my[gap1ndexCeiling]] = indexLeaf
124
- my[gap1ndexCeiling] += 1
125
-
126
- for indexMiniGap in range(my[gap1ndex], my[gap1ndexCeiling]):
127
- gapsWhere[my[gap1ndex]] = gapsWhere[indexMiniGap]
128
- if track[countDimensionsGapped][gapsWhere[indexMiniGap]] == the[dimensionsTotal] - my[unconstrainedLeaf]:
129
- my[gap1ndex] += 1
130
- track[countDimensionsGapped][gapsWhere[indexMiniGap]] = 0
131
-
132
- while my[leaf1ndex] > 0 and my[gap1ndex] == track[gapRangeStart][my[leaf1ndex] - 1]:
133
- my[leaf1ndex] -= 1
134
- track[leafBelow][track[leafAbove][my[leaf1ndex]]] = track[leafBelow][my[leaf1ndex]]
135
- track[leafAbove][track[leafBelow][my[leaf1ndex]]] = track[leafAbove][my[leaf1ndex]]
136
-
137
- if my[leaf1ndex] > 0:
138
- my[gap1ndex] -= 1
139
- track[leafAbove][my[leaf1ndex]] = gapsWhere[my[gap1ndex]]
140
- track[leafBelow][my[leaf1ndex]] = track[leafBelow][track[leafAbove][my[leaf1ndex]]]
141
- track[leafBelow][track[leafAbove][my[leaf1ndex]]] = my[leaf1ndex]
142
- track[leafAbove][track[leafBelow][my[leaf1ndex]]] = my[leaf1ndex]
143
- track[gapRangeStart][my[leaf1ndex]] = my[gap1ndex]
144
- my[leaf1ndex] += 1
145
-
146
- RETURNtrack, RETURNgapsWhere, RETURNmy = prepareWork(TEMPLATEtrack.copy(), TEMPLATEgapsWhere.copy(), TEMPLATEmy.copy())
147
-
148
- foldingsTotal = doWork(RETURNtrack.copy(), RETURNgapsWhere.copy(), RETURNmy.copy(), the, connectionGraph, taskDivisions)
149
-
150
- return foldingsTotal
73
+ TEMPLATEgapsWhere: NDArray,
74
+ the: NDArray,
75
+ connectionGraph: NDArray
76
+ ):
77
+
78
+ TEMPLATEmy = numpy.zeros(COUNTindicesDynamic, dtype=numpy.int64)
79
+ TEMPLATEmy[leaf1ndex] = 1
80
+
81
+ taskDivisions = 0
82
+ # taskDivisions = the[leavesTotal]
83
+ TEMPLATEmy[taskIndex] = taskDivisions - 1 # the first modulo is leavesTotal - 1
84
+
85
+ def prepareWork(track: NDArray,
86
+ gapsWhere: NDArray,
87
+ my: NDArray) -> tuple[NDArray, NDArray, NDArray]:
88
+ foldingsTotal = 0
89
+ while True:
90
+ if my[leaf1ndex] <= 1 or track[leafBelow][0] == 1:
91
+ if my[leaf1ndex] > the[leavesTotal]:
92
+ foldingsTotal += the[leavesTotal]
93
+ else:
94
+ my[unconstrainedLeaf] = 0
95
+ my[gap1ndexCeiling] = track[gapRangeStart][my[leaf1ndex] - 1]
96
+ my[gap1ndex] = my[gap1ndexCeiling]
97
+
98
+ for PREPAREdimension1ndex in range(1, the[dimensionsPlus1]):
99
+ if connectionGraph[PREPAREdimension1ndex][my[leaf1ndex]][my[leaf1ndex]] == my[leaf1ndex]:
100
+ my[unconstrainedLeaf] += 1
101
+ else:
102
+ my[leafConnectee] = connectionGraph[PREPAREdimension1ndex][my[leaf1ndex]][my[leaf1ndex]]
103
+ while my[leafConnectee] != my[leaf1ndex]:
104
+
105
+ if my[leafConnectee] != my[leaf1ndex]:
106
+ my[dimension1ndex] = PREPAREdimension1ndex
107
+ return track, gapsWhere, my
108
+
109
+ if my[leaf1ndex] != the[leavesTotal]:
110
+ gapsWhere[my[gap1ndexCeiling]] = my[leafConnectee]
111
+ if track[countDimensionsGapped][my[leafConnectee]] == 0:
112
+ my[gap1ndexCeiling] += 1
113
+ track[countDimensionsGapped][my[leafConnectee]] += 1
114
+ else:
115
+ print("else")
116
+ my[dimension1ndex] = PREPAREdimension1ndex
117
+ return track, gapsWhere, my
118
+ # PREPAREmy[leafConnectee] % the[leavesTotal] == PREPAREmy[taskIndex]
119
+ my[leafConnectee] = connectionGraph[dimension1ndex][my[leaf1ndex]][track[leafBelow][my[leafConnectee]]]
120
+
121
+ if my[unconstrainedLeaf] == the[dimensionsTotal]:
122
+ for indexLeaf in range(my[leaf1ndex]):
123
+ gapsWhere[my[gap1ndexCeiling]] = indexLeaf
124
+ my[gap1ndexCeiling] += 1
125
+
126
+ for indexMiniGap in range(my[gap1ndex], my[gap1ndexCeiling]):
127
+ gapsWhere[my[gap1ndex]] = gapsWhere[indexMiniGap]
128
+ if track[countDimensionsGapped][gapsWhere[indexMiniGap]] == the[dimensionsTotal] - my[unconstrainedLeaf]:
129
+ my[gap1ndex] += 1
130
+ track[countDimensionsGapped][gapsWhere[indexMiniGap]] = 0
131
+
132
+ while my[leaf1ndex] > 0 and my[gap1ndex] == track[gapRangeStart][my[leaf1ndex] - 1]:
133
+ my[leaf1ndex] -= 1
134
+ track[leafBelow][track[leafAbove][my[leaf1ndex]]] = track[leafBelow][my[leaf1ndex]]
135
+ track[leafAbove][track[leafBelow][my[leaf1ndex]]] = track[leafAbove][my[leaf1ndex]]
136
+
137
+ if my[leaf1ndex] > 0:
138
+ my[gap1ndex] -= 1
139
+ track[leafAbove][my[leaf1ndex]] = gapsWhere[my[gap1ndex]]
140
+ track[leafBelow][my[leaf1ndex]] = track[leafBelow][track[leafAbove][my[leaf1ndex]]]
141
+ track[leafBelow][track[leafAbove][my[leaf1ndex]]] = my[leaf1ndex]
142
+ track[leafAbove][track[leafBelow][my[leaf1ndex]]] = my[leaf1ndex]
143
+ track[gapRangeStart][my[leaf1ndex]] = my[gap1ndex]
144
+ my[leaf1ndex] += 1
145
+
146
+ RETURNtrack, RETURNgapsWhere, RETURNmy = prepareWork(TEMPLATEtrack.copy(), TEMPLATEgapsWhere.copy(), TEMPLATEmy.copy())
147
+
148
+ foldingsTotal = doWork(RETURNtrack.copy(), RETURNgapsWhere.copy(), RETURNmy.copy(), the, connectionGraph, taskDivisions)
149
+
150
+ return foldingsTotal
151
151
 
152
152
  @njit(cache=True, parallel=False, fastmath=False)
153
153
  def doWork(track: NDArray,
154
- gapsWhere: NDArray,
155
- my: NDArray,
156
- the: NDArray,
157
- connectionGraph: NDArray,
158
- taskDivisions: int = 0
159
- ):
160
-
161
- papasGotABrandNewBag = True
162
- if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 = True
163
- for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
164
- while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
165
-
166
- thisIsNotTheFirstPass = False
167
-
168
- while papasGotABrandNewBag:
169
- if my[leaf1ndex] <= 1 or track[leafBelow][0] == 1 or if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 == True:
170
- if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 = False
171
- if my[leaf1ndex] > the[leavesTotal] and thisIsNotTheFirstPass:
172
- my[foldingsSubtotal] += the[leavesTotal]
173
- else:
174
- if thisIsNotTheFirstPass:
175
- my[unconstrainedLeaf] = 0
176
- my[gap1ndexCeiling] = track[gapRangeStart][my[leaf1ndex] - 1]
177
- my[gap1ndex] = my[gap1ndexCeiling]
178
-
179
- for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
180
- while for_dimension1ndex_in_range_1_to_dimensionsPlus1 == True:
181
- for_dimension1ndex_in_range_1_to_dimensionsPlus1 = False
182
- if connectionGraph[my[dimension1ndex]][my[leaf1ndex]][my[leaf1ndex]] == my[leaf1ndex] and thisIsNotTheFirstPass:
183
- my[unconstrainedLeaf] += 1
184
- else:
185
- if thisIsNotTheFirstPass:
186
- my[leafConnectee] = connectionGraph[my[dimension1ndex]][my[leaf1ndex]][my[leaf1ndex]]
187
- if my[leafConnectee] != my[leaf1ndex]:
188
- while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
189
-
190
- while while_leaf1ndexConnectee_notEquals_activeLeaf1ndex == True:
191
- while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = False
192
- thisIsNotTheFirstPass = True
193
- if taskDivisions==0 or my[leaf1ndex] != taskDivisions:
194
- myTask = True
195
- else:
196
- modulo = my[leafConnectee] % the[leavesTotal]
197
- if modulo == my[taskIndex]: myTask = True
198
- else:
199
- myTask = False
200
- if myTask:
201
- gapsWhere[my[gap1ndexCeiling]] = my[leafConnectee]
202
- if track[countDimensionsGapped][my[leafConnectee]] == 0:
203
- my[gap1ndexCeiling] += 1
204
- track[countDimensionsGapped][my[leafConnectee]] += 1
205
- my[leafConnectee] = connectionGraph[my[dimension1ndex]][my[leaf1ndex]][track[leafBelow][my[leafConnectee]]]
206
- if my[leafConnectee] != my[leaf1ndex]:
207
- while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
208
- my[dimension1ndex] += 1
209
- if my[dimension1ndex] < the[dimensionsPlus1]:
210
- for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
211
- else:
212
- my[dimension1ndex] = 1
213
-
214
- if my[unconstrainedLeaf] == the[dimensionsTotal]:
215
- for leaf1ndex in range(my[leaf1ndex]):
216
- gapsWhere[my[gap1ndexCeiling]] = leaf1ndex
217
- my[gap1ndexCeiling] += 1
218
-
219
- for indexMiniGap in range(my[gap1ndex], my[gap1ndexCeiling]):
220
- gapsWhere[my[gap1ndex]] = gapsWhere[indexMiniGap]
221
- if track[countDimensionsGapped][gapsWhere[indexMiniGap]] == the[dimensionsTotal] - my[unconstrainedLeaf]:
222
- my[gap1ndex] += 1
223
- track[countDimensionsGapped][gapsWhere[indexMiniGap]] = 0
224
-
225
- while my[leaf1ndex] > 0 and my[gap1ndex] == track[gapRangeStart][my[leaf1ndex] - 1]:
226
- my[leaf1ndex] -= 1
227
- track[leafBelow][track[leafAbove][my[leaf1ndex]]] = track[leafBelow][my[leaf1ndex]]
228
- track[leafAbove][track[leafBelow][my[leaf1ndex]]] = track[leafAbove][my[leaf1ndex]]
229
-
230
- if my[leaf1ndex] > 0:
231
- my[gap1ndex] -= 1
232
- track[leafAbove][my[leaf1ndex]] = gapsWhere[my[gap1ndex]]
233
- track[leafBelow][my[leaf1ndex]] = track[leafBelow][track[leafAbove][my[leaf1ndex]]]
234
- track[leafBelow][track[leafAbove][my[leaf1ndex]]] = my[leaf1ndex]
235
- track[leafAbove][track[leafBelow][my[leaf1ndex]]] = my[leaf1ndex]
236
- track[gapRangeStart][my[leaf1ndex]] = my[gap1ndex]
237
- my[leaf1ndex] += 1
238
-
239
- if my[leaf1ndex] <= 0:
240
- return my[foldingsSubtotal]
154
+ gapsWhere: NDArray,
155
+ my: NDArray,
156
+ the: NDArray,
157
+ connectionGraph: NDArray,
158
+ taskDivisions: int = 0
159
+ ):
160
+
161
+ papasGotABrandNewBag = True
162
+ if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 = True
163
+ for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
164
+ while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
165
+
166
+ thisIsNotTheFirstPass = False
167
+
168
+ while papasGotABrandNewBag:
169
+ if my[leaf1ndex] <= 1 or track[leafBelow][0] == 1 or if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 == True:
170
+ if_activeLeaf1ndex_LTE_1_or_leafBelow_index_0_equals_1 = False
171
+ if my[leaf1ndex] > the[leavesTotal] and thisIsNotTheFirstPass:
172
+ my[foldingsSubtotal] += the[leavesTotal]
173
+ else:
174
+ if thisIsNotTheFirstPass:
175
+ my[unconstrainedLeaf] = 0
176
+ my[gap1ndexCeiling] = track[gapRangeStart][my[leaf1ndex] - 1]
177
+ my[gap1ndex] = my[gap1ndexCeiling]
178
+
179
+ for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
180
+ while for_dimension1ndex_in_range_1_to_dimensionsPlus1 == True:
181
+ for_dimension1ndex_in_range_1_to_dimensionsPlus1 = False
182
+ if connectionGraph[my[dimension1ndex]][my[leaf1ndex]][my[leaf1ndex]] == my[leaf1ndex] and thisIsNotTheFirstPass:
183
+ my[unconstrainedLeaf] += 1
184
+ else:
185
+ if thisIsNotTheFirstPass:
186
+ my[leafConnectee] = connectionGraph[my[dimension1ndex]][my[leaf1ndex]][my[leaf1ndex]]
187
+ if my[leafConnectee] != my[leaf1ndex]:
188
+ while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
189
+
190
+ while while_leaf1ndexConnectee_notEquals_activeLeaf1ndex == True:
191
+ while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = False
192
+ thisIsNotTheFirstPass = True
193
+ if taskDivisions==0 or my[leaf1ndex] != taskDivisions:
194
+ myTask = True
195
+ else:
196
+ modulo = my[leafConnectee] % the[leavesTotal]
197
+ if modulo == my[taskIndex]: myTask = True
198
+ else:
199
+ myTask = False
200
+ if myTask:
201
+ gapsWhere[my[gap1ndexCeiling]] = my[leafConnectee]
202
+ if track[countDimensionsGapped][my[leafConnectee]] == 0:
203
+ my[gap1ndexCeiling] += 1
204
+ track[countDimensionsGapped][my[leafConnectee]] += 1
205
+ my[leafConnectee] = connectionGraph[my[dimension1ndex]][my[leaf1ndex]][track[leafBelow][my[leafConnectee]]]
206
+ if my[leafConnectee] != my[leaf1ndex]:
207
+ while_leaf1ndexConnectee_notEquals_activeLeaf1ndex = True
208
+ my[dimension1ndex] += 1
209
+ if my[dimension1ndex] < the[dimensionsPlus1]:
210
+ for_dimension1ndex_in_range_1_to_dimensionsPlus1 = True
211
+ else:
212
+ my[dimension1ndex] = 1
213
+
214
+ if my[unconstrainedLeaf] == the[dimensionsTotal]:
215
+ for leaf1ndex in range(my[leaf1ndex]):
216
+ gapsWhere[my[gap1ndexCeiling]] = leaf1ndex
217
+ my[gap1ndexCeiling] += 1
218
+
219
+ for indexMiniGap in range(my[gap1ndex], my[gap1ndexCeiling]):
220
+ gapsWhere[my[gap1ndex]] = gapsWhere[indexMiniGap]
221
+ if track[countDimensionsGapped][gapsWhere[indexMiniGap]] == the[dimensionsTotal] - my[unconstrainedLeaf]:
222
+ my[gap1ndex] += 1
223
+ track[countDimensionsGapped][gapsWhere[indexMiniGap]] = 0
224
+
225
+ while my[leaf1ndex] > 0 and my[gap1ndex] == track[gapRangeStart][my[leaf1ndex] - 1]:
226
+ my[leaf1ndex] -= 1
227
+ track[leafBelow][track[leafAbove][my[leaf1ndex]]] = track[leafBelow][my[leaf1ndex]]
228
+ track[leafAbove][track[leafBelow][my[leaf1ndex]]] = track[leafAbove][my[leaf1ndex]]
229
+
230
+ if my[leaf1ndex] > 0:
231
+ my[gap1ndex] -= 1
232
+ track[leafAbove][my[leaf1ndex]] = gapsWhere[my[gap1ndex]]
233
+ track[leafBelow][my[leaf1ndex]] = track[leafBelow][track[leafAbove][my[leaf1ndex]]]
234
+ track[leafBelow][track[leafAbove][my[leaf1ndex]]] = my[leaf1ndex]
235
+ track[leafAbove][track[leafBelow][my[leaf1ndex]]] = my[leaf1ndex]
236
+ track[gapRangeStart][my[leaf1ndex]] = my[gap1ndex]
237
+ my[leaf1ndex] += 1
238
+
239
+ if my[leaf1ndex] <= 0:
240
+ return my[foldingsSubtotal]