mapFolding 0.4.2__py3-none-any.whl → 0.4.3__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.
@@ -0,0 +1,168 @@
1
+ from collections import defaultdict
2
+ from typing import Any, cast, Dict, Final, Optional, Type, TYPE_CHECKING
3
+ import enum
4
+ import sys
5
+ import numba
6
+ import numpy
7
+
8
+ try:
9
+ from typing import NotRequired
10
+ except ImportError:
11
+ from typing_extensions import NotRequired
12
+
13
+ if TYPE_CHECKING:
14
+ from typing import TypedDict
15
+ else:
16
+ TypedDict = dict
17
+
18
+ @enum.verify(enum.CONTINUOUS, enum.UNIQUE) if sys.version_info >= (3, 11) else lambda x: x
19
+ class EnumIndices(enum.IntEnum):
20
+ @staticmethod
21
+ def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> int:
22
+ """0-indexed."""
23
+ return count
24
+
25
+ def __index__(self) -> int:
26
+ """Adapt enum to the ultra-rare event of indexing a NumPy 'ndarray', which is not the
27
+ same as `array.array`. See NumPy.org; I think it will be very popular someday."""
28
+ return self.value
29
+
30
+ class indexMy(EnumIndices):
31
+ """Indices for scalar values."""
32
+ dimensionsTotal = enum.auto()
33
+ dimensionsUnconstrained = enum.auto()
34
+ gap1ndex = enum.auto()
35
+ gap1ndexCeiling = enum.auto()
36
+ indexDimension = enum.auto()
37
+ indexLeaf = enum.auto()
38
+ indexMiniGap = enum.auto()
39
+ leaf1ndex = enum.auto()
40
+ leafConnectee = enum.auto()
41
+ taskDivisions = enum.auto()
42
+ taskIndex = enum.auto()
43
+
44
+ class indexTrack(EnumIndices):
45
+ """Indices for state tracking array."""
46
+ leafAbove = enum.auto()
47
+ leafBelow = enum.auto()
48
+ countDimensionsGapped = enum.auto()
49
+ gapRangeStart = enum.auto()
50
+
51
+ _datatypeDefault: Final[Dict[str, str]] = {
52
+ 'elephino': 'uint16',
53
+ 'foldsTotal': 'int64',
54
+ 'leavesTotal': 'uint16',
55
+ }
56
+ _datatypeModule = ''
57
+ _datatypeModuleDEFAULT: Final[str] = 'numpy'
58
+
59
+ _datatype: Dict[str, str] = defaultdict(str)
60
+
61
+ def reportDatatypeLimit(identifier: str, datatype: str, sourGrapes: Optional[bool] = False) -> str:
62
+ global _datatype
63
+ if not _datatype[identifier]:
64
+ _datatype[identifier] = datatype
65
+ elif _datatype[identifier] == datatype:
66
+ pass
67
+ elif sourGrapes:
68
+ raise Exception(f"Datatype is '{_datatype[identifier]}' not '{datatype}', so you can take your ball and go home.")
69
+ return _datatype[identifier]
70
+
71
+ def setDatatypeModule(datatypeModule: str, sourGrapes: Optional[bool] = False) -> str:
72
+ global _datatypeModule
73
+ if not _datatypeModule:
74
+ _datatypeModule = datatypeModule
75
+ elif _datatypeModule == datatypeModule:
76
+ pass
77
+ elif sourGrapes:
78
+ raise Exception(f"Datatype module is '{_datatypeModule}' not '{datatypeModule}', so you can take your ball and go home.")
79
+ return _datatypeModule
80
+
81
+ def setDatatypeElephino(datatype: str, sourGrapes: Optional[bool] = False) -> str:
82
+ return reportDatatypeLimit('elephino', datatype, sourGrapes)
83
+
84
+ def setDatatypeFoldsTotal(datatype: str, sourGrapes: Optional[bool] = False) -> str:
85
+ return reportDatatypeLimit('foldsTotal', datatype, sourGrapes)
86
+
87
+ def setDatatypeLeavesTotal(datatype: str, sourGrapes: Optional[bool] = False) -> str:
88
+ return reportDatatypeLimit('leavesTotal', datatype, sourGrapes)
89
+
90
+ def _get_datatype(identifier: str) -> str:
91
+ global _datatype
92
+ if not _datatype[identifier]:
93
+ if identifier in indexMy._member_names_:
94
+ _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('elephino')
95
+ elif identifier in indexTrack._member_names_:
96
+ _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('elephino')
97
+ else:
98
+ _datatype[identifier] = _datatypeDefault.get(identifier) or _get_datatype('foldsTotal')
99
+ return _datatype[identifier]
100
+
101
+ def getDatatypeModule() -> str:
102
+ global _datatypeModule
103
+ if not _datatypeModule:
104
+ _datatypeModule = _datatypeModuleDEFAULT
105
+ return _datatypeModule
106
+
107
+ def setInStone(identifier: str) -> Type[Any]:
108
+ datatypeModule = getDatatypeModule()
109
+ datatypeStr = _get_datatype(identifier)
110
+ return cast(Type[Any], getattr(eval(datatypeModule), datatypeStr))
111
+
112
+ def hackSSOTdtype(identifier: str) -> Type[Any]:
113
+ _hackSSOTdtype={
114
+ 'connectionGraph': 'dtypeLeavesTotal',
115
+ 'dtypeElephino': 'dtypeElephino',
116
+ 'dtypeFoldsTotal': 'dtypeFoldsTotal',
117
+ 'dtypeLeavesTotal': 'dtypeLeavesTotal',
118
+ 'foldGroups': 'dtypeFoldsTotal',
119
+ 'gapsWhere': 'dtypeLeavesTotal',
120
+ 'mapShape': 'dtypeLeavesTotal',
121
+ 'my': 'dtypeElephino',
122
+ 'track': 'dtypeElephino',
123
+ }
124
+ RubeGoldBerg = _hackSSOTdtype[identifier]
125
+ if RubeGoldBerg == 'dtypeElephino':
126
+ return setInStone('elephino')
127
+ elif RubeGoldBerg == 'dtypeFoldsTotal':
128
+ return setInStone('foldsTotal')
129
+ elif RubeGoldBerg == 'dtypeLeavesTotal':
130
+ return setInStone('leavesTotal')
131
+ raise Exception("Dude, you forgot to set a value in `hackSSOTdtype`.")
132
+
133
+ def hackSSOTdatatype(identifier: str) -> str:
134
+ _hackSSOTdatatype={
135
+ 'connectionGraph': 'datatypeLeavesTotal',
136
+ 'countDimensionsGapped': 'datatypeLeavesTotal',
137
+ 'datatypeElephino': 'datatypeElephino',
138
+ 'datatypeFoldsTotal': 'datatypeFoldsTotal',
139
+ 'datatypeLeavesTotal': 'datatypeLeavesTotal',
140
+ 'dimensionsTotal': 'datatypeLeavesTotal',
141
+ 'dimensionsUnconstrained': 'datatypeLeavesTotal',
142
+ 'foldGroups': 'datatypeFoldsTotal',
143
+ 'gap1ndex': 'datatypeLeavesTotal',
144
+ 'gap1ndexCeiling': 'datatypeElephino',
145
+ 'gapRangeStart': 'datatypeElephino',
146
+ 'gapsWhere': 'datatypeLeavesTotal',
147
+ 'groupsOfFolds': 'datatypeFoldsTotal',
148
+ 'indexDimension': 'datatypeLeavesTotal',
149
+ 'indexLeaf': 'datatypeLeavesTotal',
150
+ 'indexMiniGap': 'datatypeElephino',
151
+ 'leaf1ndex': 'datatypeLeavesTotal',
152
+ 'leafAbove': 'datatypeLeavesTotal',
153
+ 'leafBelow': 'datatypeLeavesTotal',
154
+ 'leafConnectee': 'datatypeLeavesTotal',
155
+ 'mapShape': 'datatypeLeavesTotal',
156
+ 'my': 'datatypeElephino',
157
+ 'taskDivisions': 'datatypeLeavesTotal',
158
+ 'taskIndex': 'datatypeLeavesTotal',
159
+ 'track': 'datatypeElephino',
160
+ }
161
+ RubeGoldBerg = _hackSSOTdatatype[identifier]
162
+ if RubeGoldBerg == 'datatypeElephino':
163
+ return _get_datatype('elephino')
164
+ elif RubeGoldBerg == 'datatypeFoldsTotal':
165
+ return _get_datatype('foldsTotal')
166
+ elif RubeGoldBerg == 'datatypeLeavesTotal':
167
+ return _get_datatype('leavesTotal')
168
+ raise Exception("Dude, you forgot to set a value in `hackSSOTdatatype`.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mapFolding
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: Count distinct ways to fold a map (or a strip of stamps)
5
5
  Author-email: Hunter Hogan <HunterHogan@pm.me>
6
6
  License: CC-BY-NC-4.0
@@ -0,0 +1,40 @@
1
+ mapFolding/__init__.py,sha256=1-iO5PCGKlW81fhMDjSLrsKxuSeV-UMcU1NlKW352FM,1347
2
+ mapFolding/basecamp.py,sha256=MyrkAbJZawW6CPVEJ_7iPfCYjngdFHmicSs8Ylq5S1E,3787
3
+ mapFolding/beDRY.py,sha256=tDLddJzQoGvbcttJro8ML2B59KspMkZwIeZdm4hOy_4,16785
4
+ mapFolding/oeis.py,sha256=8c6q3STjgp-c4Reode9PLLYS3c00wCsJW-yfte7NI60,11103
5
+ mapFolding/theDao.py,sha256=PZgx_0X7QfdIpLpEO5mbdVNFMCRuP8PD-f62xU7C4U0,12618
6
+ mapFolding/theSSOT.py,sha256=RQmSsjmysc9izjGLsVseZ0J0nDzG_rKY7QkrOF-47SU,5794
7
+ mapFolding/theSSOTdatatypes.py,sha256=H0d1vAn59VCRPMhn28PtlBEZnjmQjEKofiefgvpBFsg,5955
8
+ mapFolding/reference/flattened.py,sha256=S6D9wiFTlbeoetEqaMLOcA-R22BHOzjqPRujffNxxUM,14875
9
+ mapFolding/reference/hunterNumba.py,sha256=jDS0ORHkIhcJ1rzA5hT49sZHKf3rgJOoGesUCcbKFFY,6054
10
+ mapFolding/reference/irvineJavaPort.py,sha256=7GvBU0tnS6wpFgkYad3465do9jBQW-2bYvbCYyABPHM,3341
11
+ mapFolding/reference/jax.py,sha256=7ji9YWia6Kof0cjcNdiS1GG1rMbC5SBjcyVr_07AeUk,13845
12
+ mapFolding/reference/lunnan.py,sha256=iAbJELfW6RKNMdPcBY9b6rGQ-z1zoRf-1XCurCRMOo8,3951
13
+ mapFolding/reference/lunnanNumpy.py,sha256=rwVP3WIDXimpAuaxhRIuBYU56nVDTKlfGiclw_FkgUU,3765
14
+ mapFolding/reference/lunnanWhile.py,sha256=uRrMT23jTJvoQDlD_FzeIQe_pfMXJG6_bRvs7uhC8z0,3271
15
+ mapFolding/reference/rotatedEntryPoint.py,sha256=USZY3n3zwhSE68ATscUuN66t1qShuEbMI790Gz9JFTw,9352
16
+ mapFolding/reference/total_countPlus1vsPlusN.py,sha256=wpgay-uqPOBd64Z4Pg6tg40j7-4pzWHGMM6v0bnmjhE,6288
17
+ mapFolding/someAssemblyRequired/__init__.py,sha256=wtec_hIz-AKz0_hGdXsWnCKTcCxdMV9-WK6SiIriAeU,396
18
+ mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=nX8tghZClYt7zJd6RpZBXhE_h-CGRHOS17biqiEdf-o,855
19
+ mapFolding/someAssemblyRequired/makeJob.py,sha256=c9sTRUK90snTCcXCvs86VKBH6z_nt3OVFjNs_WgCoIg,2422
20
+ mapFolding/someAssemblyRequired/synthesizeModuleJAX.py,sha256=jatvtYhK5ZJK-YmCKATt7w3icFXXO79cZDAYVrU9bgA,1258
21
+ mapFolding/someAssemblyRequired/synthesizeNumba.py,sha256=eJRZ8ttfaONMq-s3BawswJrHu_m0DUHp4dGpx6uVpuk,16920
22
+ mapFolding/someAssemblyRequired/synthesizeNumbaGeneralized.py,sha256=3FiD6fDGzam6uvgTg7YEsGlLftbBOol2ajvEa4GNTec,16698
23
+ mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=pknX6CeH9iuDTs9tp0gz33T2U5gjO8NMpPnQnnBU2gA,9138
24
+ mapFolding/someAssemblyRequired/synthesizeNumbaModules.py,sha256=V9xpM1r4MQlhXoKLkF2PTg69gid7Ec64pbMc2ZZ2xXo,5590
25
+ mapFolding/syntheticModules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ mapFolding/syntheticModules/numbaCount.py,sha256=VkTHk97gIBRZg7FwX7hCgfunSBK2Gyr4pp3fzHNrLhw,12907
27
+ mapFolding/syntheticModules/numba_doTheNeedful.py,sha256=9syuZEc1KwH3BFp2TmK7-pBuT2N4lVJTiUhqu7ahaKY,1157
28
+ tests/__init__.py,sha256=eg9smg-6VblOr0kisM40CpGnuDtU2JgEEWGDTFVOlW8,57
29
+ tests/conftest.py,sha256=qP-ZCyyqXC4E9W_psMVbHPlXE-8Ue01fBckGqhzlhGQ,11972
30
+ tests/test_computations.py,sha256=WO28l9AmrFY6kbcx9iJr6YNoqLbZ8Lgs7FryH5DG0BI,2856
31
+ tests/test_oeis.py,sha256=C2F6XrI5oRPjc29lykN3e83rIcgl01UwBLB6L-Qz2pE,4733
32
+ tests/test_other.py,sha256=u0vINT5EyVsXTNTR2DZIMpWCg4FH471jjHLRzC2JX7U,8351
33
+ tests/test_tasks.py,sha256=iq6_dh43JQkC2vAWXua0Xe915BKFGbvRJAkmbco854A,2389
34
+ tests/test_types.py,sha256=58tmPG9WOeGGAQbdQK_h_7t4SnENnZugH4WXlI8-L-M,171
35
+ mapFolding-0.4.3.dist-info/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
36
+ mapFolding-0.4.3.dist-info/METADATA,sha256=52v3PWTTXMbJwXFaUQFAnJilfn29HFiESW83sPFUL1M,7633
37
+ mapFolding-0.4.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
38
+ mapFolding-0.4.3.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
39
+ mapFolding-0.4.3.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
40
+ mapFolding-0.4.3.dist-info/RECORD,,
tests/conftest.py CHANGED
@@ -6,11 +6,11 @@ from mapFolding import *
6
6
  from mapFolding import basecamp, getAlgorithmDispatcher, getDispatcherCallable
7
7
  from mapFolding.beDRY import *
8
8
  from mapFolding.someAssemblyRequired import *
9
- from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidInformation, _getOEISidValues
10
9
  from mapFolding.oeis import *
11
10
  from types import ModuleType
12
11
  from typing import Any, Callable, ContextManager, Dict, Generator, List, Literal, NoReturn, Optional, Sequence, Set, Tuple, Type, Union
13
12
  from Z0Z_tools.pytestForYourUse import PytestFor_defineConcurrencyLimit, PytestFor_intInnit, PytestFor_oopsieKwargsie
13
+ import importlib.util
14
14
  import pathlib
15
15
  import pytest
16
16
  import random
@@ -225,6 +225,35 @@ def useAlgorithmSourceDispatcher(useThisDispatcher: Callable) -> Generator[None,
225
225
  useThisDispatcher(getAlgorithmDispatcher())
226
226
  yield
227
227
 
228
+ @pytest.fixture
229
+ def syntheticDispatcherFixture(useThisDispatcher):
230
+ listCallablesInlineHARDCODED: List[str] = ['countInitialize', 'countParallel', 'countSequential']
231
+ listCallablesInline = listCallablesInlineHARDCODED
232
+ callableDispatcher = True
233
+ algorithmSource = None
234
+ relativePathWrite = None
235
+ filenameModuleWrite = 'pytestCount.py'
236
+ formatFilenameWrite = "pytest_{callableTarget}.py"
237
+ listSynthesizedModules: List[youOughtaKnow] = makeFlowNumbaOptimized(listCallablesInline, callableDispatcher, algorithmSource, relativePathWrite, filenameModuleWrite, formatFilenameWrite)
238
+ dispatcherSynthetic = youOughtaKnow('','','')
239
+ for stuff in listSynthesizedModules:
240
+ registrarRecordsTmpObject(stuff.pathFilenameForMe)
241
+ if stuff.callableSynthesized not in listCallablesInline:
242
+ dispatcherSynthetic: youOughtaKnow = stuff
243
+
244
+ dispatcherSpec = importlib.util.spec_from_file_location(dispatcherSynthetic.callableSynthesized, dispatcherSynthetic.pathFilenameForMe)
245
+ if dispatcherSpec is None:
246
+ raise ImportError(f"{dispatcherSynthetic.pathFilenameForMe=}")
247
+ if dispatcherSpec.loader is None:
248
+ raise ImportError(f"Failed to get loader for module {dispatcherSynthetic.pathFilenameForMe}")
249
+
250
+ dispatcherModule = importlib.util.module_from_spec(dispatcherSpec)
251
+ dispatcherSpec.loader.exec_module(dispatcherModule)
252
+ callableDispatcherSynthetic = getattr(dispatcherModule, dispatcherSynthetic.callableSynthesized)
253
+
254
+ useThisDispatcher(callableDispatcherSynthetic)
255
+ return callableDispatcherSynthetic
256
+
228
257
  def uniformTestMessage(expected: Any, actual: Any, functionName: str, *arguments: Any) -> str:
229
258
  """Format assertion message for any test comparison."""
230
259
  return (f"\nTesting: `{functionName}({', '.join(str(parameter) for parameter in arguments)})`\n"
@@ -13,67 +13,31 @@ def test_aOFn_calculate_value(oeisID: str) -> None:
13
13
  for n in settingsOEIS[oeisID]['valuesTestValidation']:
14
14
  standardizedEqualTo(settingsOEIS[oeisID]['valuesKnown'][n], oeisIDfor_n, oeisID, n)
15
15
 
16
- # Python doesn't want me to test this
17
- # @pytest.mark.parametrize('pathFilenameTmpTesting', ['.py'], indirect=True)
18
- # def test_writeJobNumba(listDimensionsTestCountFolds: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int], pathFilenameTmpTesting: Path) -> None:
19
- # from mapFolding.syntheticModules import numba_countSequential
20
- # algorithmSourceHARDCODED: ModuleType = numba_countSequential
21
- # algorithmSource = algorithmSourceHARDCODED
22
- # pathFilenameModule = writeJobNumba(listDimensionsTestCountFolds, algorithmSource, pathFilenameWriteJob=pathFilenameTmpTesting.absolute())
23
-
24
- # Don_Lapre_Road_to_Self_Improvement = importlib.util.spec_from_file_location("__main__", pathFilenameModule)
25
- # if Don_Lapre_Road_to_Self_Improvement is None:
26
- # raise ImportError(f"Failed to create module specification from {pathFilenameModule}")
27
- # if Don_Lapre_Road_to_Self_Improvement.loader is None:
28
- # raise ImportError(f"Failed to get loader for module {pathFilenameModule}")
29
- # module = importlib.util.module_from_spec(Don_Lapre_Road_to_Self_Improvement)
30
-
31
- # module.__name__ = "__main__"
32
- # Don_Lapre_Road_to_Self_Improvement.loader.exec_module(module)
33
-
34
- # pathFilenameFoldsTotal = getPathFilenameFoldsTotal(listDimensionsTestCountFolds)
35
- # standardizedEqualTo(str(foldsTotalKnown[tuple(listDimensionsTestCountFolds)]), pathFilenameFoldsTotal.read_text().strip)
36
-
37
- # def test_makeFlowNumbaOptimized(pathTmpTesting: Path, useThisDispatcher):
38
- # def test_makeFlowNumbaOptimized(useThisDispatcher):
39
- # """To get this to work:
40
- # walk_up=True doesn't work on 3.10, so that has to go
41
- # the _logical_ import must be in the logical path of the package
42
- # fuck python
43
- # """
44
- # listCallablesInlineHARDCODED: List[str] = ['countInitialize', 'countParallel', 'countSequential']
45
- # listCallablesInline = listCallablesInlineHARDCODED
46
- # callableDispatcher = True
47
- # algorithmSource = None
48
- # relativePathWrite = None
49
- # # relativePathWrite = pathTmpTesting.absolute().relative_to(getPathPackage(), walk_up=True)
50
- # formatFilenameWrite = "pytest_{callableTarget}"
51
- # listSynthesizedModules: List[youOughtaKnow] = makeFlowNumbaOptimized(listCallablesInline, callableDispatcher, algorithmSource, relativePathWrite, formatFilenameWrite)
52
- # for stuff in listSynthesizedModules:
53
- # registrarRecordsTmpObject(stuff.pathFilenameForMe)
54
- # if stuff.callableSynthesized not in listCallablesInline:
55
- # dispatcherSynthetic: youOughtaKnow = stuff
56
- # if not dispatcherSynthetic: raise FREAKOUT
57
- # # dispatcherSynthetic: youOughtaKnow = next(filter(lambda x: x.callableSynthesized not in listCallablesInline, listSynthesizedModules))
58
-
59
- # # Import the synthetic dispatcher module to get the callable
60
- # dispatcherSpec = importlib.util.spec_from_file_location(
61
- # dispatcherSynthetic.callableSynthesized,
62
- # dispatcherSynthetic.pathFilenameForMe
63
- # )
64
- # if dispatcherSpec is None:
65
- # raise ImportError(f"Failed to create module specification from {dispatcherSynthetic.pathFilenameForMe}")
66
- # if dispatcherSpec.loader is None:
67
- # raise ImportError(f"Failed to get loader for module {dispatcherSynthetic.pathFilenameForMe}")
68
-
69
- # dispatcherModule = importlib.util.module_from_spec(dispatcherSpec)
70
- # dispatcherSpec.loader.exec_module(dispatcherModule)
71
- # callableDispatcherSynthetic = getattr(dispatcherModule, dispatcherSynthetic.callableSynthesized)
72
-
73
- # useThisDispatcher(callableDispatcherSynthetic)
74
-
75
- # def test_syntheticSequential(listDimensionsTestCountFolds: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int]):
76
- # standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestCountFolds)], countFolds, listDimensionsTestCountFolds)
16
+ @pytest.mark.parametrize('pathFilenameTmpTesting', ['.py'], indirect=True)
17
+ def test_writeJobNumba(listDimensionsTestCountFolds: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int], pathFilenameTmpTesting: Path) -> None:
18
+ from mapFolding.syntheticModules import numbaCount
19
+ algorithmSourceHARDCODED: ModuleType = numbaCount
20
+ algorithmSource = algorithmSourceHARDCODED
21
+ callableTargetHARDCODED = 'countSequential'
22
+ callableTarget = callableTargetHARDCODED
23
+ pathFilenameModule = writeJobNumba(listDimensionsTestCountFolds, algorithmSource, callableTarget, pathFilenameWriteJob=pathFilenameTmpTesting.absolute())
24
+
25
+ Don_Lapre_Road_to_Self_Improvement = importlib.util.spec_from_file_location("__main__", pathFilenameModule)
26
+ if Don_Lapre_Road_to_Self_Improvement is None:
27
+ raise ImportError(f"Failed to create module specification from {pathFilenameModule}")
28
+ if Don_Lapre_Road_to_Self_Improvement.loader is None:
29
+ raise ImportError(f"Failed to get loader for module {pathFilenameModule}")
30
+ module = importlib.util.module_from_spec(Don_Lapre_Road_to_Self_Improvement)
31
+
32
+ module.__name__ = "__main__"
33
+ Don_Lapre_Road_to_Self_Improvement.loader.exec_module(module)
34
+
35
+ pathFilenameFoldsTotal = getPathFilenameFoldsTotal(listDimensionsTestCountFolds)
36
+ registrarRecordsTmpObject(pathFilenameFoldsTotal)
37
+ standardizedEqualTo(str(foldsTotalKnown[tuple(listDimensionsTestCountFolds)]), pathFilenameFoldsTotal.read_text().strip)
38
+
39
+ def test_syntheticParallel(syntheticDispatcherFixture, listDimensionsTestParallelization: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int]):
40
+ standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestParallelization)], countFolds, listDimensionsTestParallelization, None, 'maximum')
77
41
 
78
- # def test_syntheticParallel(listDimensionsTestParallelization: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int]):
79
- # standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestParallelization)], countFolds, listDimensionsTestParallelization, None, 'maximum')
42
+ def test_syntheticSequential(syntheticDispatcherFixture, listDimensionsTestCountFolds: List[int], foldsTotalKnown: Dict[Tuple[int, ...], int]):
43
+ standardizedEqualTo(foldsTotalKnown[tuple(listDimensionsTestCountFolds)], countFolds, listDimensionsTestCountFolds)
tests/test_oeis.py CHANGED
@@ -1,10 +1,7 @@
1
1
  from contextlib import redirect_stdout
2
- from datetime import datetime, timedelta
3
- from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidValues, _parseBFileOEIS, _validateOEISid, _getOEISidInformation
4
2
  from tests.conftest import *
5
3
  from urllib.error import URLError
6
4
  import io
7
- import os
8
5
  import pathlib
9
6
  import pytest
10
7
  import random
@@ -16,18 +13,18 @@ import urllib.request
16
13
 
17
14
  @pytest.mark.parametrize("badID", ["A999999", " A999999 ", "A999999extra"])
18
15
  def test__validateOEISid_invalid_id(badID: str) -> None:
19
- standardizedEqualTo(KeyError, _validateOEISid, badID)
16
+ standardizedEqualTo(KeyError, validateOEISid, badID)
20
17
 
21
18
  def test__validateOEISid_partially_valid(oeisID_1random: str) -> None:
22
- standardizedEqualTo(KeyError, _validateOEISid, f"{oeisID_1random}extra")
19
+ standardizedEqualTo(KeyError, validateOEISid, f"{oeisID_1random}extra")
23
20
 
24
21
  def test__validateOEISid_valid_id(oeisID: str) -> None:
25
- standardizedEqualTo(oeisID, _validateOEISid, oeisID)
22
+ standardizedEqualTo(oeisID, validateOEISid, oeisID)
26
23
 
27
24
  def test__validateOEISid_valid_id_case_insensitive(oeisID: str) -> None:
28
- standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.lower())
29
- standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.upper())
30
- standardizedEqualTo(oeisID.upper(), _validateOEISid, oeisID.swapcase())
25
+ standardizedEqualTo(oeisID.upper(), validateOEISid, oeisID.lower())
26
+ standardizedEqualTo(oeisID.upper(), validateOEISid, oeisID.upper())
27
+ standardizedEqualTo(oeisID.upper(), validateOEISid, oeisID.swapcase())
31
28
 
32
29
  parameters_test_aOFn_invalid_n = [
33
30
  # (2, "ok"), # test the test template
@@ -68,7 +65,7 @@ def testNetworkError(monkeypatch: pytest.MonkeyPatch, pathCacheTesting: pathlib.
68
65
  raise URLError("Network error")
69
66
 
70
67
  monkeypatch.setattr(urllib.request, 'urlopen', mockUrlopen)
71
- standardizedEqualTo(URLError, _getOEISidValues, next(iter(settingsOEIS)))
68
+ standardizedEqualTo(URLError, getOEISidValues, next(iter(settingsOEIS)))
72
69
 
73
70
  # ===== Command Line Interface Tests =====
74
71
  def testHelpText() -> None:
@@ -1,52 +0,0 @@
1
- from mapFolding import indexMy
2
- from mapFolding import indexTrack
3
- from numba import jit
4
- from numba import uint8
5
- from numpy import dtype
6
- from numpy import ndarray
7
- from numpy import integer
8
- from typing import Tuple
9
- from typing import Any
10
-
11
- @jit((uint8[:, :, ::1], uint8[::1], uint8[::1], uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=False, no_cpython_wrapper=False, nopython=True, parallel=False)
12
- def countInitialize(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]], gapsWhere: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> None:
13
- while my[indexMy.leaf1ndex.value]:
14
- if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
15
- my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
16
- my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
17
- my[indexMy.indexDimension.value] = 0
18
- while my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]:
19
- if connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]:
20
- my[indexMy.dimensionsUnconstrained.value] -= 1
21
- else:
22
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
23
- while my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]:
24
- gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
25
- if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
26
- my[indexMy.gap1ndexCeiling.value] += 1
27
- track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
28
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
29
- my[indexMy.indexDimension.value] += 1
30
- if not my[indexMy.dimensionsUnconstrained.value]:
31
- my[indexMy.indexLeaf.value] = 0
32
- while my[indexMy.indexLeaf.value] < my[indexMy.leaf1ndex.value]:
33
- gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.indexLeaf.value]
34
- my[indexMy.gap1ndexCeiling.value] += 1
35
- my[indexMy.indexLeaf.value] += 1
36
- my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
37
- while my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]:
38
- gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
39
- if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
40
- my[indexMy.gap1ndex.value] += 1
41
- track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
42
- my[indexMy.indexMiniGap.value] += 1
43
- if my[indexMy.leaf1ndex.value]:
44
- my[indexMy.gap1ndex.value] -= 1
45
- track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
46
- track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
47
- track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
48
- track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
49
- track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
50
- my[indexMy.leaf1ndex.value] += 1
51
- if my[indexMy.gap1ndex.value] > 0:
52
- return
@@ -1,65 +0,0 @@
1
- from mapFolding import indexMy
2
- from mapFolding import indexTrack
3
- from numba import prange
4
- from numba import int64
5
- from numba import jit
6
- from numba import uint8
7
- from numpy import dtype
8
- from numpy import ndarray
9
- from numpy import integer
10
- from typing import Tuple
11
- from typing import Any
12
-
13
- @jit((uint8[:, :, ::1], int64[::1], uint8[::1], uint8[::1], uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nopython=True, parallel=True)
14
- def countParallel(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]], foldGroups: ndarray[Tuple[int], dtype[integer[Any]]], gapsWhere: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> None:
15
- gapsWherePARALLEL = gapsWhere.copy()
16
- myPARALLEL = my.copy()
17
- trackPARALLEL = track.copy()
18
- taskDivisionsPrange = myPARALLEL[indexMy.taskDivisions.value]
19
- for indexSherpa in prange(taskDivisionsPrange):
20
- groupsOfFolds: int = 0
21
- gapsWhere = gapsWherePARALLEL.copy()
22
- my = myPARALLEL.copy()
23
- track = trackPARALLEL.copy()
24
- my[indexMy.taskIndex.value] = indexSherpa
25
- while my[indexMy.leaf1ndex.value]:
26
- if my[indexMy.leaf1ndex.value] <= 1 or track[indexTrack.leafBelow.value, 0] == 1:
27
- if my[indexMy.leaf1ndex.value] > foldGroups[-1]:
28
- groupsOfFolds += 1
29
- else:
30
- my[indexMy.dimensionsUnconstrained.value] = my[indexMy.dimensionsTotal.value]
31
- my[indexMy.gap1ndexCeiling.value] = track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]
32
- my[indexMy.indexDimension.value] = 0
33
- while my[indexMy.indexDimension.value] < my[indexMy.dimensionsTotal.value]:
34
- if connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]] == my[indexMy.leaf1ndex.value]:
35
- my[indexMy.dimensionsUnconstrained.value] -= 1
36
- else:
37
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], my[indexMy.leaf1ndex.value]]
38
- while my[indexMy.leafConnectee.value] != my[indexMy.leaf1ndex.value]:
39
- if my[indexMy.leaf1ndex.value] != my[indexMy.taskDivisions.value] or my[indexMy.leafConnectee.value] % my[indexMy.taskDivisions.value] == my[indexMy.taskIndex.value]:
40
- gapsWhere[my[indexMy.gap1ndexCeiling.value]] = my[indexMy.leafConnectee.value]
41
- if track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] == 0:
42
- my[indexMy.gap1ndexCeiling.value] += 1
43
- track[indexTrack.countDimensionsGapped.value, my[indexMy.leafConnectee.value]] += 1
44
- my[indexMy.leafConnectee.value] = connectionGraph[my[indexMy.indexDimension.value], my[indexMy.leaf1ndex.value], track[indexTrack.leafBelow.value, my[indexMy.leafConnectee.value]]]
45
- my[indexMy.indexDimension.value] += 1
46
- my[indexMy.indexMiniGap.value] = my[indexMy.gap1ndex.value]
47
- while my[indexMy.indexMiniGap.value] < my[indexMy.gap1ndexCeiling.value]:
48
- gapsWhere[my[indexMy.gap1ndex.value]] = gapsWhere[my[indexMy.indexMiniGap.value]]
49
- if track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] == my[indexMy.dimensionsUnconstrained.value]:
50
- my[indexMy.gap1ndex.value] += 1
51
- track[indexTrack.countDimensionsGapped.value, gapsWhere[my[indexMy.indexMiniGap.value]]] = 0
52
- my[indexMy.indexMiniGap.value] += 1
53
- while my[indexMy.leaf1ndex.value] and my[indexMy.gap1ndex.value] == track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value] - 1]:
54
- my[indexMy.leaf1ndex.value] -= 1
55
- track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]
56
- track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]
57
- if my[indexMy.leaf1ndex.value]:
58
- my[indexMy.gap1ndex.value] -= 1
59
- track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]] = gapsWhere[my[indexMy.gap1ndex.value]]
60
- track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]] = track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]]
61
- track[indexTrack.leafBelow.value, track[indexTrack.leafAbove.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
62
- track[indexTrack.leafAbove.value, track[indexTrack.leafBelow.value, my[indexMy.leaf1ndex.value]]] = my[indexMy.leaf1ndex.value]
63
- track[indexTrack.gapRangeStart.value, my[indexMy.leaf1ndex.value]] = my[indexMy.gap1ndex.value]
64
- my[indexMy.leaf1ndex.value] += 1
65
- foldGroups[my[indexMy.taskIndex.value]] = groupsOfFolds
@@ -1,67 +0,0 @@
1
- from mapFolding import indexMy
2
- from mapFolding import indexTrack
3
- from numba import int64
4
- from numba import jit
5
- from numba import uint8
6
- from numpy import dtype
7
- from numpy import ndarray
8
- from numpy import integer
9
- from typing import Tuple
10
- from typing import Any
11
-
12
- @jit((uint8[:, :, ::1], int64[::1], uint8[::1], uint8[::1], uint8[:, ::1]), _nrt=True, boundscheck=False, cache=True, error_model='numpy', fastmath=True, forceinline=True, inline='always', looplift=False, no_cfunc_wrapper=True, no_cpython_wrapper=True, nopython=True, parallel=False)
13
- def countSequential(connectionGraph: ndarray[Tuple[int, int, int], dtype[integer[Any]]], foldGroups: ndarray[Tuple[int], dtype[integer[Any]]], gapsWhere: ndarray[Tuple[int], dtype[integer[Any]]], my: ndarray[Tuple[int], dtype[integer[Any]]], track: ndarray[Tuple[int, int], dtype[integer[Any]]]) -> None:
14
- leafBelow = track[indexTrack.leafBelow.value]
15
- gapRangeStart = track[indexTrack.gapRangeStart.value]
16
- countDimensionsGapped = track[indexTrack.countDimensionsGapped.value]
17
- leafAbove = track[indexTrack.leafAbove.value]
18
- leaf1ndex = my[indexMy.leaf1ndex.value]
19
- dimensionsUnconstrained = my[indexMy.dimensionsUnconstrained.value]
20
- dimensionsTotal = my[indexMy.dimensionsTotal.value]
21
- gap1ndexCeiling = my[indexMy.gap1ndexCeiling.value]
22
- indexDimension = my[indexMy.indexDimension.value]
23
- leafConnectee = my[indexMy.leafConnectee.value]
24
- indexMiniGap = my[indexMy.indexMiniGap.value]
25
- gap1ndex = my[indexMy.gap1ndex.value]
26
- taskIndex = my[indexMy.taskIndex.value]
27
- groupsOfFolds: int = 0
28
- while leaf1ndex:
29
- if leaf1ndex <= 1 or leafBelow[0] == 1:
30
- if leaf1ndex > foldGroups[-1]:
31
- groupsOfFolds += 1
32
- else:
33
- dimensionsUnconstrained = dimensionsTotal
34
- gap1ndexCeiling = gapRangeStart[leaf1ndex - 1]
35
- indexDimension = 0
36
- while indexDimension < dimensionsTotal:
37
- leafConnectee = connectionGraph[indexDimension, leaf1ndex, leaf1ndex]
38
- if leafConnectee == leaf1ndex:
39
- dimensionsUnconstrained -= 1
40
- else:
41
- while leafConnectee != leaf1ndex:
42
- gapsWhere[gap1ndexCeiling] = leafConnectee
43
- if countDimensionsGapped[leafConnectee] == 0:
44
- gap1ndexCeiling += 1
45
- countDimensionsGapped[leafConnectee] += 1
46
- leafConnectee = connectionGraph[indexDimension, leaf1ndex, leafBelow[leafConnectee]]
47
- indexDimension += 1
48
- indexMiniGap = gap1ndex
49
- while indexMiniGap < gap1ndexCeiling:
50
- gapsWhere[gap1ndex] = gapsWhere[indexMiniGap]
51
- if countDimensionsGapped[gapsWhere[indexMiniGap]] == dimensionsUnconstrained:
52
- gap1ndex += 1
53
- countDimensionsGapped[gapsWhere[indexMiniGap]] = 0
54
- indexMiniGap += 1
55
- while leaf1ndex and gap1ndex == gapRangeStart[leaf1ndex - 1]:
56
- leaf1ndex -= 1
57
- leafBelow[leafAbove[leaf1ndex]] = leafBelow[leaf1ndex]
58
- leafAbove[leafBelow[leaf1ndex]] = leafAbove[leaf1ndex]
59
- if leaf1ndex:
60
- gap1ndex -= 1
61
- leafAbove[leaf1ndex] = gapsWhere[gap1ndex]
62
- leafBelow[leaf1ndex] = leafBelow[leafAbove[leaf1ndex]]
63
- leafBelow[leafAbove[leaf1ndex]] = leaf1ndex
64
- leafAbove[leafBelow[leaf1ndex]] = leaf1ndex
65
- gapRangeStart[leaf1ndex] = gap1ndex
66
- leaf1ndex += 1
67
- foldGroups[taskIndex] = groupsOfFolds