mapFolding 0.16.1__py3-none-any.whl → 0.16.2__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 (49) hide show
  1. easyRun/A000682.py +1 -1
  2. easyRun/A005316.py +2 -3
  3. easyRun/NOTcountingFolds.py +3 -3
  4. easyRun/meanders.py +17 -19
  5. mapFolding/algorithms/matrixMeanders.py +15 -28
  6. mapFolding/algorithms/matrixMeandersBeDry.py +34 -116
  7. mapFolding/algorithms/matrixMeandersNumPy.py +117 -70
  8. mapFolding/algorithms/matrixMeandersPandas.py +113 -130
  9. mapFolding/algorithms/oeisIDbyFormula.py +23 -12
  10. mapFolding/algorithms/zCuzDocStoopidoeisIDbyFormula.py +26 -12
  11. mapFolding/basecamp.py +140 -242
  12. mapFolding/dataBaskets.py +14 -30
  13. mapFolding/reference/A000682facts.py +785 -1264
  14. mapFolding/reference/A005316facts.py +958 -923
  15. mapFolding/reference/matrixMeandersAnalysis/signatures.py +2030 -0
  16. mapFolding/someAssemblyRequired/A007822/A007822rawMaterials.py +2 -2
  17. mapFolding/someAssemblyRequired/A007822/makeA007822AsynchronousModules.py +83 -21
  18. mapFolding/someAssemblyRequired/A007822/makeA007822Modules.py +13 -12
  19. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +2 -2
  20. mapFolding/someAssemblyRequired/makingModules_count.py +88 -80
  21. mapFolding/someAssemblyRequired/makingModules_doTheNeedful.py +11 -7
  22. mapFolding/someAssemblyRequired/mapFolding/makeMapFoldingModules.py +3 -3
  23. mapFolding/someAssemblyRequired/meanders/makeMeandersModules.py +7 -8
  24. mapFolding/someAssemblyRequired/toolkitMakeModules.py +9 -9
  25. mapFolding/someAssemblyRequired/transformationTools.py +8 -8
  26. mapFolding/syntheticModules/A007822/algorithm.py +1 -0
  27. mapFolding/syntheticModules/A007822/asynchronous.py +6 -4
  28. mapFolding/syntheticModules/A007822/asynchronousAnnex.py +1 -1
  29. mapFolding/syntheticModules/A007822/asynchronousAnnexNumba.py +2 -17
  30. mapFolding/syntheticModules/A007822/asynchronousNumba.py +35 -8
  31. mapFolding/syntheticModules/A007822/asynchronousTheorem2.py +15 -3
  32. mapFolding/syntheticModules/A007822/asynchronousTrimmed.py +12 -3
  33. mapFolding/syntheticModules/A007822/theorem2.py +6 -0
  34. mapFolding/syntheticModules/A007822/theorem2Numba.py +28 -3
  35. mapFolding/syntheticModules/A007822/theorem2Trimmed.py +7 -1
  36. mapFolding/syntheticModules/daoOfMapFoldingNumba.py +2 -4
  37. mapFolding/syntheticModules/dataPacking.py +3 -5
  38. mapFolding/syntheticModules/meanders/bigInt.py +24 -34
  39. mapFolding/syntheticModules/theorem2.py +6 -0
  40. mapFolding/syntheticModules/theorem2Numba.py +9 -4
  41. mapFolding/syntheticModules/theorem2Trimmed.py +6 -0
  42. mapFolding/tests/test_computations.py +1 -1
  43. mapFolding/zCuzDocStoopid/makeDocstrings.py +2 -0
  44. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/METADATA +1 -1
  45. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/RECORD +49 -48
  46. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/WHEEL +0 -0
  47. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/entry_points.txt +0 -0
  48. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/licenses/LICENSE +0 -0
  49. {mapfolding-0.16.1.dist-info → mapfolding-0.16.2.dist-info}/top_level.txt +0 -0
mapFolding/basecamp.py CHANGED
@@ -1,7 +1,6 @@
1
1
  """Unified interface for map folding computation."""
2
2
 
3
3
  from collections.abc import Sequence
4
- from functools import cache
5
4
  from mapFolding import (
6
5
  getPathFilenameFoldsTotal, packageSettings, saveFoldsTotal, saveFoldsTotalFAILearly, validateListDimensions)
7
6
  from os import PathLike
@@ -24,6 +23,7 @@ algorithms directory
24
23
  an enhanced version of `oeisIDfor_n` will be a stable interface for calling by ID and n
25
24
 
26
25
  General flow structure
26
+ basecamp should call `doTheNeedful` instead of `count` and `doTheNeedful` should handle things like `initializeState`.
27
27
  doTheNeedful
28
28
  specific to that version of that algorithm
29
29
  abstracts the API for that algorithm, so that algorithm (such as multidimensional map folding) has a stable interface
@@ -165,7 +165,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
165
165
  from mapFolding.beDRY import getLeavesTotal, getTaskDivisions, setProcessorLimit
166
166
  concurrencyLimit: int = setProcessorLimit(CPUlimit, packageSettings.concurrencyPackage)
167
167
  leavesTotal: int = getLeavesTotal(mapShape)
168
- taskDivisions = getTaskDivisions(computationDivisions, concurrencyLimit, leavesTotal)
168
+ taskDivisions: int = getTaskDivisions(computationDivisions, concurrencyLimit, leavesTotal)
169
169
  del leavesTotal
170
170
  else:
171
171
  concurrencyLimit = 1
@@ -181,59 +181,7 @@ def countFolds(listDimensions: Sequence[int] | None = None
181
181
 
182
182
  # Flow control until I can figure out a good way ---------------------------------
183
183
 
184
- if flow == 'daoOfMapFolding':
185
- from mapFolding.dataBaskets import MapFoldingState
186
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
187
-
188
- from mapFolding.algorithms.daoOfMapFolding import doTheNeedful
189
- mapFoldingState = doTheNeedful(mapFoldingState)
190
- foldsTotal = mapFoldingState.foldsTotal
191
-
192
- elif flow == 'numba':
193
- from mapFolding.dataBaskets import MapFoldingState
194
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
195
-
196
- from mapFolding.syntheticModules.daoOfMapFoldingNumba import doTheNeedful
197
- mapFoldingState = doTheNeedful(mapFoldingState)
198
- foldsTotal = mapFoldingState.foldsTotal
199
-
200
- elif flow == 'theorem2' and any(dimension > 2 for dimension in mapShape):
201
- from mapFolding.dataBaskets import MapFoldingState
202
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
203
-
204
- from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds
205
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
206
-
207
- from mapFolding.syntheticModules.theorem2 import count
208
- mapFoldingState = count(mapFoldingState)
209
-
210
- foldsTotal = mapFoldingState.foldsTotal
211
-
212
- elif (flow == 'theorem2Numba' or taskDivisions == 0) and any(dimension > 2 for dimension in mapShape):
213
- from mapFolding.dataBaskets import MapFoldingState
214
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
215
-
216
- from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds
217
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
218
-
219
- from mapFolding.syntheticModules.dataPacking import sequential
220
- mapFoldingState = sequential(mapFoldingState)
221
-
222
- foldsTotal = mapFoldingState.foldsTotal
223
-
224
- elif flow == 'theorem2Trimmed' and any(dimension > 2 for dimension in mapShape):
225
- from mapFolding.dataBaskets import MapFoldingState
226
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
227
-
228
- from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds
229
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
230
-
231
- from mapFolding.syntheticModules.theorem2Trimmed import count
232
- mapFoldingState = count(mapFoldingState)
233
-
234
- foldsTotal = mapFoldingState.foldsTotal
235
-
236
- elif taskDivisions > 1:
184
+ if taskDivisions > 1:
237
185
  from mapFolding.dataBaskets import ParallelMapFoldingState
238
186
  mapFoldingParallelState: ParallelMapFoldingState = ParallelMapFoldingState(mapShape, taskDivisions=taskDivisions)
239
187
 
@@ -246,224 +194,174 @@ def countFolds(listDimensions: Sequence[int] | None = None
246
194
  from mapFolding.dataBaskets import MapFoldingState
247
195
  mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
248
196
 
249
- from mapFolding.algorithms.daoOfMapFolding import doTheNeedful
250
- mapFoldingState = doTheNeedful(mapFoldingState)
251
- foldsTotal = mapFoldingState.foldsTotal
197
+ if flow == 'daoOfMapFolding':
198
+ from mapFolding.algorithms.daoOfMapFolding import doTheNeedful
199
+ mapFoldingState = doTheNeedful(mapFoldingState)
252
200
 
253
- # Follow memorialization instructions ---------------------------------------------
201
+ elif flow == 'numba':
202
+ from mapFolding.syntheticModules.daoOfMapFoldingNumba import doTheNeedful
203
+ mapFoldingState = doTheNeedful(mapFoldingState)
254
204
 
255
- if pathFilenameFoldsTotal is not None:
256
- saveFoldsTotal(pathFilenameFoldsTotal, foldsTotal)
205
+ elif flow == 'theorem2' and any(dimension > 2 for dimension in mapShape):
206
+ from mapFolding.syntheticModules.theorem2 import doTheNeedful
207
+ mapFoldingState = doTheNeedful(mapFoldingState)
257
208
 
258
- return foldsTotal
209
+ elif (flow == 'theorem2Numba' or taskDivisions == 0) and any(dimension > 2 for dimension in mapShape):
210
+ from mapFolding.syntheticModules.initializeState import transitionOnGroupsOfFolds
211
+ mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
259
212
 
260
- @cache
261
- def A000682(n: int, flow: str | None = None) -> int:
262
- """Compute A000682(n)."""
263
- match flow:
264
- case 'matrixNumPy':
265
- from mapFolding.algorithms.matrixMeandersNumPy import doTheNeedful
266
- from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
267
- case 'matrixPandas':
268
- from mapFolding.algorithms.matrixMeandersPandas import doTheNeedful
269
- from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
270
- case _:
271
- from mapFolding.algorithms.matrixMeanders import doTheNeedful
272
- from mapFolding.dataBaskets import MatrixMeandersState as State
213
+ from mapFolding.syntheticModules.dataPacking import sequential
214
+ mapFoldingState = sequential(mapFoldingState)
273
215
 
274
- oeisID = 'A000682'
216
+ elif flow == 'theorem2Trimmed' and any(dimension > 2 for dimension in mapShape):
217
+ from mapFolding.syntheticModules.theorem2Trimmed import doTheNeedful
218
+ mapFoldingState = doTheNeedful(mapFoldingState)
275
219
 
276
- kOfMatrix: int = n - 1
220
+ else:
221
+ from mapFolding.algorithms.daoOfMapFolding import doTheNeedful
222
+ mapFoldingState = doTheNeedful(mapFoldingState)
277
223
 
278
- if n == 1:
279
- return 1
280
- elif n & 0b1:
281
- arcCode: int = 5
282
- else:
283
- arcCode = 1
284
- listCurveLocations: list[int] = [(arcCode << 1) | arcCode]
285
-
286
- MAXIMUMarcCode: int = 1 << (2 * kOfMatrix + 4)
287
- while listCurveLocations[-1] < MAXIMUMarcCode:
288
- arcCode = (arcCode << 4) | 0b101 # == arcCode * 2**4 + 5
289
- listCurveLocations.append((arcCode << 1) | arcCode)
290
-
291
- dictionaryMeanders=dict.fromkeys(listCurveLocations, 1)
292
-
293
- state = State(n, oeisID, kOfMatrix, dictionaryMeanders)
294
-
295
- return doTheNeedful(state) # pyright: ignore[reportArgumentType]
296
-
297
- @cache
298
- def A005316(n: int, flow: str | None = None) -> int:
299
- """Compute A005316(n)."""
300
- match flow:
301
- case 'matrixNumPy':
302
- from mapFolding.algorithms.matrixMeandersNumPy import doTheNeedful
303
- from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
304
- case 'matrixPandas':
305
- from mapFolding.algorithms.matrixMeandersPandas import doTheNeedful
306
- from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
307
- case _:
308
- from mapFolding.algorithms.matrixMeanders import doTheNeedful
309
- from mapFolding.dataBaskets import MatrixMeandersState as State
310
-
311
- oeisID = 'A005316'
312
-
313
- kOfMatrix: int = n - 1
224
+ foldsTotal = mapFoldingState.foldsTotal
314
225
 
315
- if n & 0b1:
316
- dictionaryMeanders: dict[int, int] = {15: 1}
317
- else:
318
- dictionaryMeanders = {22: 1}
226
+ # Follow memorialization instructions ---------------------------------------------
319
227
 
320
- state = State(n, oeisID, kOfMatrix, dictionaryMeanders)
228
+ if pathFilenameFoldsTotal is not None:
229
+ saveFoldsTotal(pathFilenameFoldsTotal, foldsTotal)
321
230
 
322
- return doTheNeedful(state) # pyright: ignore[reportArgumentType]
231
+ return foldsTotal
323
232
 
324
233
  def NOTcountingFolds(oeisID: str, oeis_n: int, flow: str | None = None
325
234
  # , pathLikeWriteFoldsTotal: PathLike[str] | PurePath | None = None # noqa: ERA001
326
235
  , CPUlimit: bool | float | int | None = None # noqa: FBT001
327
236
  ) -> int:
328
237
  """Do stuff."""
329
- countTotal: int = -1
238
+ countTotal: int = -31212012 # ERROR
239
+ matched_oeisID: bool = True
330
240
 
331
241
  match oeisID:
332
242
  case 'A000136':
333
- from mapFolding.algorithms.oeisIDbyFormula import A000136
334
- countTotal = A000136(oeis_n)
243
+ from mapFolding.algorithms.oeisIDbyFormula import A000136 as doTheNeedful
335
244
  case 'A000560':
336
- from mapFolding.algorithms.oeisIDbyFormula import A000560
337
- countTotal = A000560(oeis_n)
338
- case 'A000682':
339
- countTotal = A000682(oeis_n, flow)
245
+ from mapFolding.algorithms.oeisIDbyFormula import A000560 as doTheNeedful
340
246
  case 'A001010':
341
- from mapFolding.algorithms.oeisIDbyFormula import A001010
342
- countTotal = A001010(oeis_n)
247
+ from mapFolding.algorithms.oeisIDbyFormula import A001010 as doTheNeedful
343
248
  case 'A001011':
344
- from mapFolding.algorithms.oeisIDbyFormula import A001011
345
- countTotal = A001011(oeis_n)
249
+ from mapFolding.algorithms.oeisIDbyFormula import A001011 as doTheNeedful
346
250
  case 'A005315':
347
- from mapFolding.algorithms.oeisIDbyFormula import A005315
348
- countTotal = A005315(oeis_n)
349
- case 'A005316':
350
- countTotal = A005316(oeis_n, flow)
351
- case 'A007822':
352
- mapShape: tuple[Literal[1], int] = (1, 2 * oeis_n)
353
- match flow:
354
- case 'asynchronous':
355
- from mapFolding.dataBaskets import MapFoldingState
356
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
357
-
358
- from mapFolding import setProcessorLimit
359
- concurrencyLimit = setProcessorLimit(CPUlimit)
360
-
361
- from mapFolding.syntheticModules.A007822.asynchronous import doTheNeedful
362
- mapFoldingState = doTheNeedful(mapFoldingState)
363
-
364
- case 'asynchronousNumba':
365
- from mapFolding.dataBaskets import MapFoldingState
366
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
367
-
368
- from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds
369
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
370
-
371
- from mapFolding import setProcessorLimit
372
- concurrencyLimit = setProcessorLimit(CPUlimit)
373
-
374
- from mapFolding.syntheticModules.A007822.asynchronousAnnex import initializeConcurrencyManager
375
- initializeConcurrencyManager(maxWorkers=concurrencyLimit, groupsOfFolds=mapFoldingState.groupsOfFolds)
376
- mapFoldingState.groupsOfFolds = 0
377
-
378
- from mapFolding.syntheticModules.A007822.asynchronousNumba import count
379
- mapFoldingState = count(mapFoldingState)
380
-
381
- case 'asynchronousTrimmed':
382
- from mapFolding.dataBaskets import MapFoldingState
383
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
384
-
385
- from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds
386
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
387
-
388
- from mapFolding import setProcessorLimit
389
- concurrencyLimit = setProcessorLimit(CPUlimit)
390
-
391
- from mapFolding.syntheticModules.A007822.asynchronousAnnex import initializeConcurrencyManager
392
- initializeConcurrencyManager(maxWorkers=concurrencyLimit, groupsOfFolds=mapFoldingState.groupsOfFolds)
393
- mapFoldingState.groupsOfFolds = 0
394
-
395
- from mapFolding.syntheticModules.A007822.asynchronousTrimmed import count
396
- mapFoldingState = count(mapFoldingState)
397
-
398
- case 'numba':
399
- from mapFolding.dataBaskets import MapFoldingState
400
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
401
-
402
- from mapFolding.syntheticModules.A007822.algorithmNumba import doTheNeedful
403
- mapFoldingState = doTheNeedful(mapFoldingState)
404
-
405
- case 'theorem2':
406
- from mapFolding.dataBaskets import MapFoldingState
407
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
408
-
409
- from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds
410
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
411
-
412
- from mapFolding.syntheticModules.A007822.theorem2 import count
413
- mapFoldingState = count(mapFoldingState)
414
-
415
- case 'theorem2Numba':
416
- from mapFolding.dataBaskets import MapFoldingState
417
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
418
-
419
- from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds
420
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
421
-
422
- from mapFolding.syntheticModules.A007822.theorem2Numba import count
423
- mapFoldingState = count(mapFoldingState)
424
-
425
- case 'theorem2Trimmed':
426
- from mapFolding.dataBaskets import MapFoldingState
427
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
428
-
429
- from mapFolding.syntheticModules.A007822.initializeState import transitionOnGroupsOfFolds
430
- mapFoldingState = transitionOnGroupsOfFolds(mapFoldingState)
431
-
432
- from mapFolding.syntheticModules.A007822.theorem2Trimmed import count
433
- mapFoldingState = count(mapFoldingState)
434
-
435
- case _:
436
- from mapFolding.dataBaskets import MapFoldingState
437
- mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
438
-
439
- from mapFolding.syntheticModules.A007822.algorithm import doTheNeedful
440
- mapFoldingState = doTheNeedful(mapFoldingState)
441
-
442
- countTotal = mapFoldingState.groupsOfFolds
251
+ from mapFolding.algorithms.oeisIDbyFormula import A005315 as doTheNeedful
443
252
  case 'A060206':
444
- from mapFolding.algorithms.oeisIDbyFormula import A060206
445
- countTotal = A060206(oeis_n)
253
+ from mapFolding.algorithms.oeisIDbyFormula import A060206 as doTheNeedful
446
254
  case 'A077460':
447
- from mapFolding.algorithms.oeisIDbyFormula import A077460
448
- countTotal = A077460(oeis_n)
255
+ from mapFolding.algorithms.oeisIDbyFormula import A077460 as doTheNeedful
449
256
  case 'A078591':
450
- from mapFolding.algorithms.oeisIDbyFormula import A078591
451
- countTotal = A078591(oeis_n)
257
+ from mapFolding.algorithms.oeisIDbyFormula import A078591 as doTheNeedful
452
258
  case 'A178961':
453
- from mapFolding.algorithms.oeisIDbyFormula import A178961
454
- countTotal = A178961(oeis_n)
259
+ from mapFolding.algorithms.oeisIDbyFormula import A178961 as doTheNeedful
455
260
  case 'A223094':
456
- from mapFolding.algorithms.oeisIDbyFormula import A223094
457
- countTotal = A223094(oeis_n)
261
+ from mapFolding.algorithms.oeisIDbyFormula import A223094 as doTheNeedful
458
262
  case 'A259702':
459
- from mapFolding.algorithms.oeisIDbyFormula import A259702
460
- countTotal = A259702(oeis_n)
263
+ from mapFolding.algorithms.oeisIDbyFormula import A259702 as doTheNeedful
461
264
  case 'A301620':
462
- from mapFolding.algorithms.oeisIDbyFormula import A301620
463
- countTotal = A301620(oeis_n)
464
-
265
+ from mapFolding.algorithms.oeisIDbyFormula import A301620 as doTheNeedful
465
266
  case _:
466
- pass
267
+ matched_oeisID = False
268
+ if matched_oeisID:
269
+ countTotal = doTheNeedful(oeis_n) # pyright: ignore[reportPossiblyUnboundVariable]
270
+ else:
271
+ matched_oeisID = True
272
+ match oeisID:
273
+ case 'A000682' | 'A005316':
274
+ match flow:
275
+ case 'matrixNumPy':
276
+ from mapFolding.algorithms.matrixMeandersNumPy import doTheNeedful
277
+ from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
278
+ case 'matrixPandas':
279
+ from mapFolding.algorithms.matrixMeandersPandas import doTheNeedful
280
+ from mapFolding.dataBaskets import MatrixMeandersNumPyState as State
281
+ case _:
282
+ from mapFolding.algorithms.matrixMeanders import doTheNeedful
283
+ from mapFolding.dataBaskets import MatrixMeandersState as State
284
+
285
+ boundary: int = oeis_n - 1
286
+
287
+ if oeisID == 'A000682':
288
+ if oeis_n == 1:
289
+ return 1
290
+ elif oeis_n & 0b1:
291
+ arcCode: int = 0b101
292
+ else:
293
+ arcCode = 0b1
294
+ listArcCodes: list[int] = [(arcCode << 1) | arcCode]
295
+ # 0b1010 | 0b0101 is 0b1111, or 0xf
296
+ # 0b10 | 0b01 is 0b11, or 0x3
297
+
298
+ MAXIMUMarcCode: int = 1 << (2 * boundary + 4)
299
+ while listArcCodes[-1] < MAXIMUMarcCode:
300
+ arcCode = (arcCode << 4) | 0b0101 # e.g., 0b 10000 | 0b 0101 = 0b 10101
301
+ listArcCodes.append((arcCode << 1) | arcCode) # e.g., 0b 101010 | 0b 1010101 = 0b 111111 = 0x3f
302
+ # Thereafter, append 0b1111 or 0xf, so, e.g., 0x3f, 0x3ff, 0x3fff, 0x3ffff, ...
303
+ # See "mapFolding/reference/A000682facts.py"
304
+ dictionaryMeanders=dict.fromkeys(listArcCodes, 1)
305
+
306
+ elif oeisID == 'A005316':
307
+ if oeis_n & 0b1:
308
+ dictionaryMeanders: dict[int, int] = {0b1111: 1} # 0xf
309
+ else:
310
+ dictionaryMeanders = {0b10110: 1}
311
+ else:
312
+ message = f"Programming error: I should never have received `{oeisID = }`."
313
+ raise ValueError(message)
314
+
315
+ state = State(oeis_n, oeisID, boundary, dictionaryMeanders)
316
+ countTotal = doTheNeedful(state) # pyright: ignore[reportArgumentType]
317
+ case 'A007822':
318
+ mapShape: tuple[Literal[1], int] = (1, 2 * oeis_n)
319
+ from mapFolding import setProcessorLimit
320
+ concurrencyLimit: int = setProcessorLimit(CPUlimit)
321
+
322
+ from mapFolding.dataBaskets import MapFoldingState
323
+ mapFoldingState: MapFoldingState = MapFoldingState(mapShape)
324
+
325
+ match flow:
326
+ case 'asynchronous':
327
+ from mapFolding.syntheticModules.A007822.asynchronous import doTheNeedful
328
+ mapFoldingState = doTheNeedful(mapFoldingState, concurrencyLimit)
329
+
330
+ case 'asynchronousNumba':
331
+ from mapFolding.syntheticModules.A007822.asynchronousNumba import doTheNeedful
332
+ mapFoldingState = doTheNeedful(mapFoldingState, concurrencyLimit)
333
+
334
+ case 'asynchronousTheorem2':
335
+ from mapFolding.syntheticModules.A007822.asynchronousTheorem2 import doTheNeedful
336
+ mapFoldingState = doTheNeedful(mapFoldingState, concurrencyLimit)
337
+
338
+ case 'asynchronousTrimmed':
339
+ from mapFolding.syntheticModules.A007822.asynchronousTrimmed import doTheNeedful
340
+ mapFoldingState = doTheNeedful(mapFoldingState, concurrencyLimit)
341
+
342
+ case 'numba':
343
+ from mapFolding.syntheticModules.A007822.algorithmNumba import doTheNeedful
344
+ mapFoldingState = doTheNeedful(mapFoldingState)
345
+
346
+ case 'theorem2':
347
+ from mapFolding.syntheticModules.A007822.theorem2 import doTheNeedful
348
+ mapFoldingState = doTheNeedful(mapFoldingState)
349
+
350
+ case 'theorem2Numba':
351
+ from mapFolding.syntheticModules.A007822.theorem2Numba import doTheNeedful
352
+ mapFoldingState = doTheNeedful(mapFoldingState)
353
+
354
+ case 'theorem2Trimmed':
355
+ from mapFolding.syntheticModules.A007822.theorem2Trimmed import doTheNeedful
356
+ mapFoldingState = doTheNeedful(mapFoldingState)
357
+
358
+ case _:
359
+ from mapFolding.syntheticModules.A007822.algorithm import doTheNeedful
360
+ mapFoldingState = doTheNeedful(mapFoldingState)
361
+
362
+ countTotal = mapFoldingState.groupsOfFolds
363
+ case _:
364
+ matched_oeisID = False
467
365
 
468
366
  return countTotal
469
367
 
mapFolding/dataBaskets.py CHANGED
@@ -22,9 +22,9 @@ access patterns that enable efficient result persistence and retrieval.
22
22
  """
23
23
  from mapFolding import (
24
24
  Array1DElephino, Array1DLeavesTotal, Array3DLeavesTotal, DatatypeElephino, DatatypeFoldsTotal, DatatypeLeavesTotal,
25
- getConnectionGraph, getLeavesTotal, makeDataContainer, ShapeArray, ShapeSlicer)
25
+ getConnectionGraph, getLeavesTotal, makeDataContainer)
26
26
  from numpy.typing import NDArray
27
- from typing import Final, TypeAlias
27
+ from typing import TypeAlias
28
28
  import dataclasses
29
29
  import numpy
30
30
 
@@ -280,21 +280,21 @@ class MatrixMeandersState:
280
280
  """The index of the meanders problem being solved."""
281
281
  oeisID: str
282
282
  """'A000682', semi-meanders, or 'A005316', meanders."""
283
- kOfMatrix: int
284
- """The number of iterations remaining in the transfer matrix algorithm."""
283
+ boundary: int
284
+ """The algorithm analyzes `n` boundaries starting at `boundary = n - 1`."""
285
285
  dictionaryMeanders: dict[int, int]
286
286
  """A Python `dict` (*dict*ionary) of `arcCode` to `crossings`. The values are stored as Python `int`
287
287
  (*int*eger), which may be arbitrarily large. Because of that property, `int` may also be called a 'bignum' (big *num*ber) or
288
288
  'bigint' (big *int*eger)."""
289
289
 
290
290
  bitWidth: int = 0
291
- """At the start of an iteration enumerated by `kOfMatrix`, the number of bits of the largest value `arcCode`. The
291
+ """At the start of an iteration enumerated by `boundary`, the number of bits of the largest value `arcCode`. The
292
292
  `dataclass` computes a `property` from `bitWidth`."""
293
293
 
294
294
  @property
295
295
  def MAXIMUMarcCode(self) -> int:
296
296
  """Compute the maximum value of `arcCode` for the current iteration of the transfer matrix."""
297
- return 1 << (2 * self.kOfMatrix + 4)
297
+ return 1 << (2 * self.boundary + 4)
298
298
 
299
299
  @property
300
300
  def locatorBits(self) -> int:
@@ -317,7 +317,8 @@ class MatrixMeandersState:
317
317
  class MatrixMeandersNumPyState(MatrixMeandersState):
318
318
  """Hold the state of a meanders transfer matrix algorithm computation."""
319
319
 
320
- arrayMeanders: NDArray[numpy.uint64] = dataclasses.field(default_factory=lambda: numpy.empty((0,), dtype=numpy.uint64))
320
+ arrayArcCodes: NDArray[numpy.uint64] = dataclasses.field(default_factory=lambda: numpy.empty((0,), dtype=numpy.uint64))
321
+ arrayCrossings: NDArray[numpy.uint64] = dataclasses.field(default_factory=lambda: numpy.empty((0,), dtype=numpy.uint64))
321
322
 
322
323
  bitWidthLimitArcCode: int | None = None
323
324
  bitWidthLimitCrossings: int | None = None
@@ -330,20 +331,6 @@ class MatrixMeandersNumPyState(MatrixMeandersState):
330
331
  indexTarget: int = 0
331
332
  """What is being indexed depends on the algorithm flavor."""
332
333
 
333
- # TODO Integrate this better into the dataclasses paradigm.
334
- indicesMeanders: Final[int] = 2
335
- indexArcCode, indexCrossings = range(indicesMeanders)
336
-
337
- @property
338
- def slicerArcCode(self) -> ShapeSlicer:
339
- """Get a `ShapeSlicer` to extract the `arcCode` column from `arrayMeanders`."""
340
- return ShapeSlicer(length=..., indices=self.indexArcCode)
341
-
342
- @property
343
- def slicerCrossings(self) -> ShapeSlicer:
344
- """Get a `ShapeSlicer` to extract the `crossings` column from `arrayMeanders`."""
345
- return ShapeSlicer(length=..., indices=self.indexCrossings)
346
-
347
334
  def __post_init__(self) -> None:
348
335
  """Post init."""
349
336
  if self.bitWidthLimitArcCode is None:
@@ -371,16 +358,13 @@ class MatrixMeandersNumPyState(MatrixMeandersState):
371
358
 
372
359
  def makeDictionary(self) -> None:
373
360
  """Convert from NumPy `ndarray` (*Num*erical *Py*thon *n-d*imensional array) to Python `dict` (*dict*ionary)."""
374
- self.dictionaryMeanders = {int(key): int(value) for key, value in zip(
375
- self.arrayMeanders[self.slicerArcCode], self.arrayMeanders[self.slicerCrossings]
376
- , strict=True)}
377
- self.arrayMeanders = numpy.empty((0,), dtype=self.datatypeArcCode)
361
+ self.dictionaryMeanders = {int(key): int(value) for key, value in zip(self.arrayArcCodes, self.arrayCrossings, strict=True)}
362
+ self.arrayArcCodes = numpy.empty((0,), dtype=self.datatypeArcCode)
363
+ self.arrayCrossings = numpy.empty((0,), dtype=self.datatypeCrossings)
378
364
 
379
365
  def makeArray(self) -> None:
380
366
  """Convert from Python `dict` (*dict*ionary) to NumPy `ndarray` (*Num*erical *Py*thon *n-d*imensional array)."""
381
- shape = ShapeArray(length=len(self.dictionaryMeanders), indices=self.indicesMeanders)
382
- self.arrayMeanders = numpy.zeros(shape, dtype=self.datatypeArcCode)
383
- self.arrayMeanders[self.slicerArcCode] = list(self.dictionaryMeanders.keys())
384
- self.arrayMeanders[self.slicerCrossings] = list(self.dictionaryMeanders.values())
385
- self.bitWidth = int(self.arrayMeanders[self.slicerArcCode].max()).bit_length()
367
+ self.arrayArcCodes = numpy.array(list(self.dictionaryMeanders.keys()), dtype=self.datatypeArcCode)
368
+ self.arrayCrossings = numpy.array(list(self.dictionaryMeanders.values()), dtype=self.datatypeCrossings)
369
+ self.bitWidth = int(self.arrayArcCodes.max()).bit_length()
386
370
  self.dictionaryMeanders = {}