mapFolding 0.4.2__py3-none-any.whl → 0.5.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 (32) hide show
  1. mapFolding/__init__.py +3 -2
  2. mapFolding/basecamp.py +12 -14
  3. mapFolding/beDRY.py +81 -58
  4. mapFolding/oeis.py +35 -33
  5. mapFolding/someAssemblyRequired/makeJob.py +8 -7
  6. mapFolding/someAssemblyRequired/synthesizeModuleJAX.py +1 -3
  7. mapFolding/someAssemblyRequired/synthesizeNumba.py +57 -60
  8. mapFolding/someAssemblyRequired/synthesizeNumbaGeneralized.py +102 -30
  9. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +18 -36
  10. mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +77 -31
  11. mapFolding/syntheticModules/numbaCount.py +158 -0
  12. mapFolding/syntheticModules/numba_doTheNeedful.py +5 -12
  13. mapFolding/theDao.py +105 -105
  14. mapFolding/theSSOT.py +80 -205
  15. mapFolding/theSSOTdatatypes.py +166 -0
  16. {mapFolding-0.4.2.dist-info → mapFolding-0.5.0.dist-info}/METADATA +2 -1
  17. mapFolding-0.5.0.dist-info/RECORD +39 -0
  18. tests/conftest.py +84 -26
  19. tests/test_computations.py +29 -66
  20. tests/test_oeis.py +8 -12
  21. tests/test_other.py +11 -7
  22. tests/test_tasks.py +5 -5
  23. mapFolding/syntheticModules/numba_countInitialize.py +0 -52
  24. mapFolding/syntheticModules/numba_countParallel.py +0 -65
  25. mapFolding/syntheticModules/numba_countSequential.py +0 -67
  26. mapFolding/theSSOTnumba.py +0 -125
  27. mapFolding-0.4.2.dist-info/RECORD +0 -42
  28. tests/test_types.py +0 -5
  29. {mapFolding-0.4.2.dist-info → mapFolding-0.5.0.dist-info}/LICENSE +0 -0
  30. {mapFolding-0.4.2.dist-info → mapFolding-0.5.0.dist-info}/WHEEL +0 -0
  31. {mapFolding-0.4.2.dist-info → mapFolding-0.5.0.dist-info}/entry_points.txt +0 -0
  32. {mapFolding-0.4.2.dist-info → mapFolding-0.5.0.dist-info}/top_level.txt +0 -0
mapFolding/theDao.py CHANGED
@@ -1,96 +1,93 @@
1
1
  from mapFolding import indexMy, indexTrack
2
2
  from numba import prange
3
3
  from numpy import dtype, integer, ndarray
4
- from typing import Any, Tuple
4
+ from typing import Any
5
5
 
6
- def activeGapIncrement(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
7
- # `.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`.
8
- my[indexMy.gap1ndex.value] += 1
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
9
 
10
- def activeLeafGreaterThan0Condition(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
11
- return my[indexMy.leaf1ndex.value]
10
+ def activeLeafGreaterThan0(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
11
+ return my[indexMy.leaf1ndex.value] > 0
12
12
 
13
- def activeLeafGreaterThanLeavesTotalCondition(foldGroups: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
13
+ def activeLeafGreaterThanLeavesTotal(foldGroups: ndarray[tuple[int], dtype[integer[Any]]], my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
14
14
  return my[indexMy.leaf1ndex.value] > foldGroups[-1]
15
15
 
16
- def activeLeafIsTheFirstLeafCondition(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
16
+ def activeLeafIsTheFirstLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
17
17
  return my[indexMy.leaf1ndex.value] <= 1
18
18
 
19
- def allDimensionsAreUnconstrained(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
19
+ def allDimensionsAreUnconstrained(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
20
20
  return not my[indexMy.dimensionsUnconstrained.value]
21
21
 
22
- def backtrack(my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> None:
22
+ def backtrack(my: ndarray[tuple[int], dtype[integer[Any]]], track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> None:
23
23
  my[indexMy.leaf1ndex.value] -= 1
24
24
  track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
25
25
  track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]
26
26
 
27
- def backtrackCondition(my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> Any:
28
- return my[indexMy.leaf1ndex.value] and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
29
-
30
- def gap1ndexCeilingIncrement(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
31
- my[indexMy.gap1ndexCeiling.value] += 1
32
-
33
- 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:
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:
34
28
  gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
35
29
  if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
36
- gap1ndexCeilingIncrement(my=my)
30
+ incrementGap1ndexCeiling(my=my)
37
31
  track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
38
32
 
39
- def dimensionsUnconstrainedCondition(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
40
- return connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]
41
-
42
- def dimensionsUnconstrainedDecrement(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
33
+ def decrementDimensionsUnconstrained(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
43
34
  my[indexMy.dimensionsUnconstrained.value] -= 1
44
35
 
45
- 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:
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:
46
40
  gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
47
41
  if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
48
- activeGapIncrement(my=my)
42
+ incrementActiveGap(my=my)
49
43
  track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
50
44
 
51
- def findGapsInitializeVariables(my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> None:
52
- my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
53
- my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
54
- my[indexMy.indexDimension.value] = 0
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
55
50
 
56
- def indexDimensionIncrement(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
51
+ def incrementIndexDimension(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
57
52
  my[indexMy.indexDimension.value] += 1
58
53
 
59
- def indexMiniGapIncrement(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
54
+ def incrementIndexMiniGap(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
60
55
  my[indexMy.indexMiniGap.value] += 1
61
56
 
62
- def indexMiniGapInitialization(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
57
+ def initializeIndexMiniGap(my: ndarray[tuple[int], dtype[integer[Any]]]) -> None:
63
58
  my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
64
59
 
65
- def insertUnconstrainedLeaf(gapsWhere: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
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:
66
69
  my[indexMy.indexLeaf.value] = 0
67
70
  while my[indexMy.indexLeaf.value] < my[indexMy.leaf1ndex.value]:
68
71
  gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.indexLeaf.value]
69
72
  my[indexMy.gap1ndexCeiling.value] += 1
70
73
  my[indexMy.indexLeaf.value] += 1
71
74
 
72
- def leafBelowSentinelIs1Condition(track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> Any:
75
+ def leafBelowSentinelIs1(track: ndarray[tuple[int, int], dtype[integer[Any]]]) -> Any:
73
76
  return track[indexTrack.leafBelow.value, 0] == 1
74
77
 
75
- def leafConnecteeInitialization(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]]) -> None:
76
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
77
-
78
- def leafConnecteeUpdate(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:
79
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
80
-
81
- def activeLeafConnectedToItself(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
82
- return my[indexMy.leafConnectee.value] == my[indexMy.leaf1ndex.value]
83
-
84
- def loopingLeavesConnectedToActiveLeaf(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
78
+ def loopingLeavesConnectedToActiveLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
85
79
  return my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]
86
80
 
87
- def loopUpToDimensionsTotal(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
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:
88
85
  return my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]
89
86
 
90
- def loopingToActiveGapCeiling(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
91
- return my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]
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]
92
89
 
93
- 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:
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:
94
91
  my[indexMy.gap1ndex.value] -= 1
95
92
  track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
96
93
  track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
@@ -99,46 +96,49 @@ def placeLeaf(gapsWhere: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[T
99
96
  track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
100
97
  my[indexMy.leaf1ndex.value] += 1
101
98
 
102
- def placeLeafCondition(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
103
- return my[indexMy.leaf1ndex.value]
99
+ def thereIsAnActiveLeaf(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
100
+ return my[indexMy.leaf1ndex.value] > 0
104
101
 
105
- def thereAreComputationDivisionsYouMightSkip(my: ndarray[Tuple[int], dtype[integer[Any]]]) -> Any:
102
+ def thisIsMyTaskIndex(my: ndarray[tuple[int], dtype[integer[Any]]]) -> Any:
106
103
  return my[indexMy.leaf1ndex.value] != my[indexMy.taskDivisions.value] or my[indexMy.leafConnectee.value] % my[indexMy.taskDivisions.value] == my[indexMy.taskIndex.value]
107
104
 
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]]]
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
112
  ) -> None:
113
113
 
114
- while activeLeafGreaterThan0Condition(my=my):
115
- if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
116
- findGapsInitializeVariables(my=my, track=track)
114
+ while activeLeafGreaterThan0(my=my):
115
+ if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
116
+ initializeVariablesToFindGaps(my=my, track=track)
117
117
  while loopUpToDimensionsTotal(my=my):
118
118
  if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
119
- dimensionsUnconstrainedDecrement(my=my)
119
+ decrementDimensionsUnconstrained(my=my)
120
120
  else:
121
- leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
121
+ initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
122
122
  while loopingLeavesConnectedToActiveLeaf(my=my):
123
123
  countGaps(gapsWhere=gapsWhere, my=my, track=track)
124
- leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
125
- indexDimensionIncrement(my=my)
124
+ updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
125
+ incrementIndexDimension(my=my)
126
126
  if allDimensionsAreUnconstrained(my=my):
127
127
  insertUnconstrainedLeaf(gapsWhere=gapsWhere, my=my)
128
- indexMiniGapInitialization(my=my)
128
+ initializeIndexMiniGap(my=my)
129
129
  while loopingToActiveGapCeiling(my=my):
130
130
  filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
131
- indexMiniGapIncrement(my=my)
132
- if placeLeafCondition(my=my):
131
+ incrementIndexMiniGap(my=my)
132
+ if thereIsAnActiveLeaf(my=my):
133
133
  placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
134
134
  if my[indexMy.gap1ndex.value] > 0:
135
135
  return
136
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]]]
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
142
  ) -> None:
143
143
 
144
144
  gapsWherePARALLEL = gapsWhere.copy()
@@ -156,72 +156,72 @@ def countParallel(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[A
156
156
 
157
157
  my[indexMy.taskIndex.value] = indexSherpa
158
158
 
159
- while activeLeafGreaterThan0Condition(my=my):
160
- if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
161
- if activeLeafGreaterThanLeavesTotalCondition(foldGroups=foldGroups, my=my):
159
+ while activeLeafGreaterThan0(my=my):
160
+ if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
161
+ if activeLeafGreaterThanLeavesTotal(foldGroups=foldGroups, my=my):
162
162
  groupsOfFolds += 1
163
163
  else:
164
- findGapsInitializeVariables(my=my, track=track)
164
+ initializeVariablesToFindGaps(my=my, track=track)
165
165
  while loopUpToDimensionsTotal(my=my):
166
166
  if dimensionsUnconstrainedCondition(connectionGraph=connectionGraph, my=my):
167
- dimensionsUnconstrainedDecrement(my=my)
167
+ decrementDimensionsUnconstrained(my=my)
168
168
  else:
169
- leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
169
+ initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
170
170
  while loopingLeavesConnectedToActiveLeaf(my=my):
171
- if thereAreComputationDivisionsYouMightSkip(my=my):
171
+ if thisIsMyTaskIndex(my=my):
172
172
  countGaps(gapsWhere=gapsWhere, my=my, track=track)
173
- leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
174
- indexDimensionIncrement(my=my)
175
- indexMiniGapInitialization(my=my)
173
+ updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
174
+ incrementIndexDimension(my=my)
175
+ initializeIndexMiniGap(my=my)
176
176
  while loopingToActiveGapCeiling(my=my):
177
177
  filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
178
- indexMiniGapIncrement(my=my)
179
- while backtrackCondition(my=my, track=track):
178
+ incrementIndexMiniGap(my=my)
179
+ while noGapsHere(my=my, track=track):
180
180
  backtrack(my=my, track=track)
181
- if placeLeafCondition(my=my):
181
+ if thereIsAnActiveLeaf(my=my):
182
182
  placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
183
183
  foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
184
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]]]
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
190
  ) -> None:
191
191
 
192
192
  groupsOfFolds: int = 0
193
193
 
194
- while activeLeafGreaterThan0Condition(my=my):
195
- if activeLeafIsTheFirstLeafCondition(my=my) or leafBelowSentinelIs1Condition(track=track):
196
- if activeLeafGreaterThanLeavesTotalCondition(foldGroups=foldGroups, my=my):
194
+ while activeLeafGreaterThan0(my=my):
195
+ if activeLeafIsTheFirstLeaf(my=my) or leafBelowSentinelIs1(track=track):
196
+ if activeLeafGreaterThanLeavesTotal(foldGroups=foldGroups, my=my):
197
197
  groupsOfFolds += 1
198
198
  else:
199
- findGapsInitializeVariables(my=my, track=track)
199
+ initializeVariablesToFindGaps(my=my, track=track)
200
200
  while loopUpToDimensionsTotal(my=my):
201
- leafConnecteeInitialization(connectionGraph=connectionGraph, my=my)
201
+ initializeLeafConnectee(connectionGraph=connectionGraph, my=my)
202
202
  if activeLeafConnectedToItself(my=my):
203
- dimensionsUnconstrainedDecrement(my=my)
203
+ decrementDimensionsUnconstrained(my=my)
204
204
  else:
205
205
  while loopingLeavesConnectedToActiveLeaf(my=my):
206
206
  countGaps(gapsWhere=gapsWhere, my=my, track=track)
207
- leafConnecteeUpdate(connectionGraph=connectionGraph, my=my, track=track)
208
- indexDimensionIncrement(my=my)
209
- indexMiniGapInitialization(my=my)
207
+ updateLeafConnectee(connectionGraph=connectionGraph, my=my, track=track)
208
+ incrementIndexDimension(my=my)
209
+ initializeIndexMiniGap(my=my)
210
210
  while loopingToActiveGapCeiling(my=my):
211
211
  filterCommonGaps(gapsWhere=gapsWhere, my=my, track=track)
212
- indexMiniGapIncrement(my=my)
213
- while backtrackCondition(my=my, track=track):
212
+ incrementIndexMiniGap(my=my)
213
+ while noGapsHere(my=my, track=track):
214
214
  backtrack(my=my, track=track)
215
- if placeLeafCondition(my=my):
215
+ if thereIsAnActiveLeaf(my=my):
216
216
  placeLeaf(gapsWhere=gapsWhere, my=my, track=track)
217
217
  foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
218
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]]]
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
225
  ) -> None:
226
226
 
227
227
  countInitialize(connectionGraph, gapsWhere, my, track)
mapFolding/theSSOT.py CHANGED
@@ -1,80 +1,67 @@
1
- from collections import defaultdict
2
- from mapFolding.theSSOTnumba import *
1
+ from collections.abc import Callable
2
+ from mapFolding.theSSOTdatatypes import (
3
+ EnumIndices,
4
+ indexMy,
5
+ indexTrack,
6
+ reportDatatypeLimit,
7
+ setDatatypeModule,
8
+ setDatatypeElephino,
9
+ setDatatypeFoldsTotal,
10
+ setDatatypeLeavesTotal,
11
+ getDatatypeModule,
12
+ setInStone,
13
+ hackSSOTdtype,
14
+ hackSSOTdatatype,
15
+ )
16
+ from numba.core.compiler import CompilerBase as numbaCompilerBase
3
17
  from numpy import dtype, integer, ndarray
18
+ from pathlib import Path
19
+ from sys import modules as sysModules
4
20
  from types import ModuleType
5
- from typing import Any, Callable, cast, Dict, Final, Optional, Tuple, Type, TYPE_CHECKING
6
- import enum
7
- import numba
8
- import numpy
9
- import numpy.typing
10
- import pathlib
11
- import sys
21
+ from typing import Any, Final, TYPE_CHECKING, cast
12
22
 
13
23
  try:
14
24
  from typing import NotRequired
15
- except ImportError:
16
- from typing_extensions import NotRequired
25
+ except Exception:
26
+ from typing_extensions import NotRequired # type: ignore
17
27
 
18
28
  if TYPE_CHECKING:
19
29
  from typing import TypedDict
20
30
  else:
21
31
  TypedDict = dict
22
32
 
23
- """I have hobbled together:
24
- TypedDict, Enum, defaultdict, and lookup dictionaries to make DIY immutability and delayed realization/instantiation.
25
- Nevertheless, I am both confident that all of these processes will be replaced and completely ignorant of what will replace them."""
26
-
27
33
  """Technical concepts I am likely using and likely want to use more effectively:
28
34
  - Configuration Registry
29
35
  - Write-Once, Read-Many (WORM) / Immutable Initialization
30
36
  - Lazy Initialization
31
- - Separation of Concerns: in the sense that configuration is separated from business logic
32
-
33
- Furthermore, I want to more clearly divorce the concept of a single _source_ of (a) truth from
34
- the _authority_ of that truth. The analogy to a registry of ownership is still apt: the registry
35
- is, at most, a single (or centralized) source of truth, but it is merely the place to register/record
36
- the truth determined by some other authority.
37
+ - Separation of configuration from business logic
37
38
 
38
- And, I almost certainly want to change the semiotics from "authority" (of truth) to "power" (to create a truth).
39
- Here, "power" is a direct analogy to https://hunterthinks.com/opinion/a-hohfeldian-primer.
39
+ delay realization/instantiation until a concrete value is desired
40
+ moment of truth: when the value is needed, not when the value is defined
40
41
  """
41
42
 
42
- "delay realization/instantiation until a concrete value is desired"
43
-
44
- "moment of truth: when the value is needed, not when the value is defined"
45
-
46
- """What is a (not too complicated, integer) datatype?
47
- - ecosystem/module
48
- - must apathy|value|list of values
49
- - mustn't apathy|value|list of values
50
- - bit width
51
- - bits maximum apathy|value
52
- - bits minimum apathy|value
53
- - magnitude maximum apathy|value
54
- - ?magnitude minimum apathy|value
55
- - signedness apathy|non-negative|non-positive|both
56
- """
57
-
58
43
  myPackageNameIs = "mapFolding"
59
44
 
60
45
  moduleOfSyntheticModules = "syntheticModules"
61
- formatModuleNameDEFAULT = "numba_{callableTarget}"
46
+ # TODO I'm not sure if this is the right tool for the job.
47
+ formatFilenameModuleDEFAULT = "numba_{callableTarget}.py"
48
+ dispatcherCallableNameDEFAULT = "doTheNeedful"
62
49
 
63
- def getPathPackage() -> pathlib.Path:
50
+ def getPathPackage() -> Path:
64
51
  import importlib, inspect
65
- pathPackage = pathlib.Path(inspect.getfile(importlib.import_module(myPackageNameIs)))
52
+ pathPackage = Path(inspect.getfile(importlib.import_module(myPackageNameIs)))
66
53
  if pathPackage.is_file():
67
54
  pathPackage = pathPackage.parent
68
55
  return pathPackage
69
56
 
70
- def getPathJobRootDEFAULT() -> pathlib.Path:
71
- if 'google.colab' in sys.modules:
72
- pathJobDEFAULT = pathlib.Path("/content/drive/MyDrive") / "jobs"
57
+ def getPathJobRootDEFAULT() -> Path:
58
+ if 'google.colab' in sysModules:
59
+ pathJobDEFAULT = Path("/content/drive/MyDrive") / "jobs"
73
60
  else:
74
61
  pathJobDEFAULT = getPathPackage() / "jobs"
75
62
  return pathJobDEFAULT
76
63
 
77
- def getPathSyntheticModules() -> pathlib.Path:
64
+ def getPathSyntheticModules() -> Path:
78
65
  pathSyntheticModules = getPathPackage() / moduleOfSyntheticModules
79
66
  return pathSyntheticModules
80
67
 
@@ -92,165 +79,12 @@ def getDispatcherCallable() -> Callable[..., None]:
92
79
 
93
80
  # NOTE I want this _concept_, not necessarily this method, to be well implemented and usable everywhere: Python, Numba, Jax, CUDA, idc
94
81
  class computationState(TypedDict):
95
- connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]]
96
- foldGroups: ndarray[Tuple[int] , dtype[integer[Any]]]
97
- gapsWhere: ndarray[Tuple[int] , dtype[integer[Any]]]
98
- mapShape: ndarray[Tuple[int] , dtype[integer[Any]]]
99
- my: ndarray[Tuple[int] , dtype[integer[Any]]]
100
- track: ndarray[Tuple[int, int] , dtype[integer[Any]]]
101
-
102
- @enum.verify(enum.CONTINUOUS, enum.UNIQUE) if sys.version_info >= (3, 11) else lambda x: x
103
- class EnumIndices(enum.IntEnum):
104
- """Base class for index enums."""
105
- @staticmethod
106
- def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> int:
107
- """0-indexed."""
108
- return count
109
-
110
- def __index__(self) -> int:
111
- """Adapt enum to the ultra-rare event of indexing a NumPy 'ndarray', which is not the
112
- same as `array.array`. See NumPy.org; I think it will be very popular someday."""
113
- return self.value
114
-
115
- class indexMy(EnumIndices):
116
- """Indices for scalar values."""
117
- dimensionsTotal = enum.auto()
118
- dimensionsUnconstrained = enum.auto()
119
- gap1ndex = enum.auto()
120
- gap1ndexCeiling = enum.auto()
121
- indexDimension = enum.auto()
122
- indexLeaf = enum.auto()
123
- indexMiniGap = enum.auto()
124
- leaf1ndex = enum.auto()
125
- leafConnectee = enum.auto()
126
- taskDivisions = enum.auto()
127
- taskIndex = enum.auto()
128
-
129
- class indexTrack(EnumIndices):
130
- """Indices for state tracking array."""
131
- leafAbove = enum.auto()
132
- leafBelow = enum.auto()
133
- countDimensionsGapped = enum.auto()
134
- gapRangeStart = enum.auto()
135
-
136
- _datatypeDefault: Final[Dict[str, str]] = {
137
- 'elephino': 'uint8',
138
- 'foldsTotal': 'int64',
139
- 'leavesTotal': 'uint8',
140
- }
141
- _datatypeModule = ''
142
- _datatypeModuleDEFAULT: Final[str] = 'numpy'
143
-
144
- _datatype: Dict[str, str] = defaultdict(str)
145
-
146
- def reportDatatypeLimit(identifier: str, datatype: str, sourGrapes: Optional[bool] = False) -> str:
147
- global _datatype
148
- if not _datatype[identifier]:
149
- _datatype[identifier] = datatype
150
- elif _datatype[identifier] == datatype:
151
- pass
152
- elif sourGrapes:
153
- raise Exception(f"Datatype is '{_datatype[identifier]}' not '{datatype}', so you can take your ball and go home.")
154
- return _datatype[identifier]
155
-
156
- def setDatatypeModule(datatypeModule: str, sourGrapes: Optional[bool] = False) -> str:
157
- global _datatypeModule
158
- if not _datatypeModule:
159
- _datatypeModule = datatypeModule
160
- elif _datatypeModule == datatypeModule:
161
- pass
162
- elif sourGrapes:
163
- raise Exception(f"Datatype module is '{_datatypeModule}' not '{datatypeModule}', so you can take your ball and go home.")
164
- return _datatypeModule
165
-
166
- def setDatatypeElephino(datatype: str, sourGrapes: Optional[bool] = False) -> str:
167
- return reportDatatypeLimit('elephino', datatype, sourGrapes)
168
-
169
- def setDatatypeFoldsTotal(datatype: str, sourGrapes: Optional[bool] = False) -> str:
170
- return reportDatatypeLimit('foldsTotal', datatype, sourGrapes)
171
-
172
- def setDatatypeLeavesTotal(datatype: str, sourGrapes: Optional[bool] = False) -> str:
173
- return reportDatatypeLimit('leavesTotal', datatype, sourGrapes)
174
-
175
- def _get_datatype(identifier: str) -> str:
176
- global _datatype
177
- if not _datatype[identifier]:
178
- if identifier in indexMy._member_names_:
179
- _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('elephino')
180
- elif identifier in indexTrack._member_names_:
181
- _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('elephino')
182
- else:
183
- _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('foldsTotal')
184
- return _datatype[identifier]
185
-
186
- def _getDatatypeModule() -> str:
187
- global _datatypeModule
188
- if not _datatypeModule:
189
- _datatypeModule = _datatypeModuleDEFAULT
190
- return _datatypeModule
191
-
192
- def setInStone(identifier: str) -> Type[Any]:
193
- datatypeModule = _getDatatypeModule()
194
- datatypeStr = _get_datatype(identifier)
195
- return cast(Type[Any], getattr(eval(datatypeModule), datatypeStr))
196
-
197
- def hackSSOTdtype(identifier: str) -> Type[Any]:
198
- _hackSSOTdtype={
199
- 'connectionGraph': 'dtypeLeavesTotal',
200
- 'dtypeElephino': 'dtypeElephino',
201
- 'dtypeFoldsTotal': 'dtypeFoldsTotal',
202
- 'dtypeLeavesTotal': 'dtypeLeavesTotal',
203
- 'foldGroups': 'dtypeFoldsTotal',
204
- 'gapsWhere': 'dtypeLeavesTotal',
205
- 'mapShape': 'dtypeLeavesTotal',
206
- 'my': 'dtypeElephino',
207
- 'track': 'dtypeElephino',
208
- }
209
- RubeGoldBerg = _hackSSOTdtype[identifier]
210
- if RubeGoldBerg == 'dtypeElephino':
211
- return setInStone('elephino')
212
- elif RubeGoldBerg == 'dtypeFoldsTotal':
213
- return setInStone('foldsTotal')
214
- elif RubeGoldBerg == 'dtypeLeavesTotal':
215
- return setInStone('leavesTotal')
216
- raise Exception("Dude, you forgot to set a value in `hackSSOTdtype`.")
217
-
218
- def hackSSOTdatatype(identifier: str) -> str:
219
- _hackSSOTdatatype={
220
- 'connectionGraph': 'datatypeLeavesTotal',
221
- 'countDimensionsGapped': 'datatypeLeavesTotal',
222
- 'datatypeElephino': 'datatypeElephino',
223
- 'datatypeFoldsTotal': 'datatypeFoldsTotal',
224
- 'datatypeLeavesTotal': 'datatypeLeavesTotal',
225
- 'dimensionsTotal': 'datatypeLeavesTotal',
226
- 'dimensionsUnconstrained': 'datatypeLeavesTotal',
227
- 'foldGroups': 'datatypeFoldsTotal',
228
- 'gap1ndex': 'datatypeLeavesTotal',
229
- 'gap1ndexCeiling': 'datatypeElephino',
230
- 'gapRangeStart': 'datatypeElephino',
231
- 'gapsWhere': 'datatypeLeavesTotal',
232
- 'groupsOfFolds': 'datatypeFoldsTotal',
233
- 'indexDimension': 'datatypeLeavesTotal',
234
- 'indexLeaf': 'datatypeLeavesTotal',
235
- 'indexMiniGap': 'datatypeElephino',
236
- 'leaf1ndex': 'datatypeLeavesTotal',
237
- 'leafAbove': 'datatypeLeavesTotal',
238
- 'leafBelow': 'datatypeLeavesTotal',
239
- 'leafConnectee': 'datatypeLeavesTotal',
240
- 'mapShape': 'datatypeLeavesTotal',
241
- 'my': 'datatypeElephino',
242
- 'taskDivisions': 'datatypeLeavesTotal',
243
- 'taskIndex': 'datatypeLeavesTotal',
244
- 'track': 'datatypeElephino',
245
- }
246
- RubeGoldBerg = _hackSSOTdatatype[identifier]
247
- if RubeGoldBerg == 'datatypeElephino':
248
- return _get_datatype('elephino')
249
- elif RubeGoldBerg == 'datatypeFoldsTotal':
250
- return _get_datatype('foldsTotal')
251
- elif RubeGoldBerg == 'datatypeLeavesTotal':
252
- return _get_datatype('leavesTotal')
253
- raise Exception("Dude, you forgot to set a value in `hackSSOTdatatype`.")
82
+ connectionGraph: ndarray[tuple[int, int, int], dtype[integer[Any]]]
83
+ foldGroups: ndarray[tuple[int] , dtype[integer[Any]]]
84
+ gapsWhere: ndarray[tuple[int] , dtype[integer[Any]]]
85
+ mapShape: ndarray[tuple[int] , dtype[integer[Any]]]
86
+ my: ndarray[tuple[int] , dtype[integer[Any]]]
87
+ track: ndarray[tuple[int, int] , dtype[integer[Any]]]
254
88
 
255
89
  _datatypeModuleScalar = 'numba'
256
90
  _decoratorCallable = 'jit'
@@ -277,3 +111,44 @@ class FREAKOUT(Exception):
277
111
  # TODO Learn how to assign theDao.py the power to set this truth
278
112
  # while using theSSOT.py as the SSOT.
279
113
  Z0Z_identifierCountFolds = 'groupsOfFolds'
114
+
115
+ class ParametersNumba(TypedDict):
116
+ _dbg_extend_lifetimes: NotRequired[bool]
117
+ _dbg_optnone: NotRequired[bool]
118
+ _nrt: NotRequired[bool]
119
+ boundscheck: NotRequired[bool]
120
+ cache: bool
121
+ debug: NotRequired[bool]
122
+ error_model: str
123
+ fastmath: bool
124
+ forceinline: bool
125
+ forceobj: NotRequired[bool]
126
+ inline: str
127
+ locals: NotRequired[dict[str, Any]]
128
+ looplift: bool
129
+ no_cfunc_wrapper: bool
130
+ no_cpython_wrapper: bool
131
+ no_rewrites: NotRequired[bool]
132
+ nogil: NotRequired[bool]
133
+ nopython: bool
134
+ parallel: bool
135
+ pipeline_class: NotRequired[type[numbaCompilerBase]]
136
+ signature_or_function: NotRequired[Any | Callable | str | tuple]
137
+ target: NotRequired[str]
138
+
139
+ parametersNumbaFailEarly: Final[ParametersNumba] = { '_nrt': True, 'boundscheck': True, 'cache': True, 'error_model': 'python', 'fastmath': False, 'forceinline': True, 'inline': 'always', 'looplift': False, 'no_cfunc_wrapper': False, 'no_cpython_wrapper': False, 'nopython': True, 'parallel': False, }
140
+ """For a production function: speed is irrelevant, error discovery is paramount, must be compatible with anything downstream."""
141
+
142
+ parametersNumbaDEFAULT: Final[ParametersNumba] = { '_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, }
143
+ """Middle of the road: fast, lean, but will talk to non-jitted functions."""
144
+
145
+ parametersNumbaParallelDEFAULT: Final[ParametersNumba] = { **parametersNumbaDEFAULT, '_nrt': True, 'parallel': True, }
146
+ """Middle of the road: fast, lean, but will talk to non-jitted functions."""
147
+
148
+ parametersNumbaSuperJit: Final[ParametersNumba] = { **parametersNumbaDEFAULT, 'no_cfunc_wrapper': True, 'no_cpython_wrapper': True, }
149
+ """Speed, no helmet, no talking to non-jitted functions."""
150
+
151
+ parametersNumbaSuperJitParallel: Final[ParametersNumba] = { **parametersNumbaSuperJit, '_nrt': True, 'parallel': True, }
152
+ """Speed, no helmet, concurrency, no talking to non-jitted functions."""
153
+
154
+ parametersNumbaMinimum: Final[ParametersNumba] = { '_nrt': True, 'boundscheck': True, 'cache': True, 'error_model': 'numpy', 'fastmath': True, 'forceinline': False, 'inline': 'always', 'looplift': False, 'no_cfunc_wrapper': False, 'no_cpython_wrapper': False, 'nopython': False, 'forceobj': True, 'parallel': False, }