mapFolding 0.3.9__py3-none-any.whl → 0.3.11__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,39 @@
1
+ mapFolding/__init__.py,sha256=-6hIljicU0Ql3yWpw8prpLGSQGUCHsNrSuf7zDNs_Ko,1169
2
+ mapFolding/basecamp.py,sha256=DISWQIzAF7o7WPUn2QZxMu3Ruwc0zkVPgceeUTUcfqo,3988
3
+ mapFolding/beDRY.py,sha256=Gsj7NEBztbPoKszPibhW6pO9xwjAIPgaW411A_Quwz8,18654
4
+ mapFolding/oeis.py,sha256=2kFIAnBu0Bs4rHceXqs1RyyEBM6A_5fR5562B4ShxVg,12311
5
+ mapFolding/theDao.py,sha256=7_2oRHzKL4PI6nzOHBGoNfkEiVL38Yg1ccEhPgQpu-w,14386
6
+ mapFolding/theSSOT.py,sha256=oFBmNHq-gJVgGszjY1qk2IWSYGsZgTik7jZvHOfvQcw,9886
7
+ mapFolding/theSSOTnumba.py,sha256=zewnChuGSF3fxfv9RiVdcjjiP7-CmbCAAgD3T7du1hQ,5632
8
+ mapFolding/reference/flattened.py,sha256=6blZ2Y9G8mu1F3gV8SKndPE398t2VVFlsgKlyeJ765A,16538
9
+ mapFolding/reference/hunterNumba.py,sha256=HWndRgsajOf76rbb2LDNEZ6itsdYbyV-k3wgOFjeR6c,7104
10
+ mapFolding/reference/irvineJavaPort.py,sha256=Sj-63Z-OsGuDoEBXuxyjRrNmmyl0d7Yz_XuY7I47Oyg,4250
11
+ mapFolding/reference/jax.py,sha256=rojyK80lOATtbzxjGOHWHZngQa47CXCLJHZwIdN2MwI,14955
12
+ mapFolding/reference/lunnan.py,sha256=XEcql_gxvCCghb6Or3qwmPbn4IZUbZTaSmw_fUjRxZE,5037
13
+ mapFolding/reference/lunnanNumpy.py,sha256=HqDgSwTOZA-G0oophOEfc4zs25Mv4yw2aoF1v8miOLk,4653
14
+ mapFolding/reference/lunnanWhile.py,sha256=7NY2IKO5XBgol0aWWF_Fi-7oTL9pvu_z6lB0TF1uVHk,4063
15
+ mapFolding/reference/rotatedEntryPoint.py,sha256=z0QyDQtnMvXNj5ntWzzJUQUMFm1-xHGLVhtYzwmczUI,11530
16
+ mapFolding/reference/total_countPlus1vsPlusN.py,sha256=usenM8Yn_G1dqlPl7NKKkcnbohBZVZBXTQRm2S3_EDA,8106
17
+ mapFolding/someAssemblyRequired/__init__.py,sha256=3JnAKXfaYPtmxV_4AnZ6KpCosT_0GFV5Nw7K8sz4-Uo,34
18
+ mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=FtJzw2pZS3A4NimWdZsegXaU-vKeCw8m67kcfb5wvGM,894
19
+ mapFolding/someAssemblyRequired/makeJob.py,sha256=2RtRAHBMDAiOsJpnj1-J1Yso3beQu5hk8bUfgE367Zs,2592
20
+ mapFolding/someAssemblyRequired/synthesizeModuleJAX.py,sha256=TU8lgoMr77pctvvmlfbT-XstQk4j6Jo8JcIuvAiCuMU,1316
21
+ mapFolding/someAssemblyRequired/synthesizeNumba.py,sha256=KjAh32G3TE2_SD9hA2tJvB8l6NvdkZXbVqqobxshoj4,39568
22
+ mapFolding/syntheticModules/numba_countInitialize.py,sha256=5AfZQkyYR5FB4YCe_S09dCGZpmVv0FDP95HXFjZjVgE,4274
23
+ mapFolding/syntheticModules/numba_countParallel.py,sha256=Lyas0W7M74jJctVpuIi1p4o_HQOlduVT-dXmtsGPWb8,5517
24
+ mapFolding/syntheticModules/numba_countSequential.py,sha256=kmVwhBafv26GIFt7mAA1fIcFn3LqNkvNfdXU0P8Yq0s,3675
25
+ mapFolding/syntheticModules/numba_doTheNeedful.py,sha256=xbKeYWACpbVMNitWPQeTr8l-YY6Y228Lu_JRDjsAPfE,1369
26
+ tests/__init__.py,sha256=eg9smg-6VblOr0kisM40CpGnuDtU2JgEEWGDTFVOlW8,57
27
+ tests/conftest.py,sha256=tGRYkHfwVKGoMklBSQiTD8cTu-QL1wUSZd-52Xlnm50,7676
28
+ tests/conftest_tmpRegistry.py,sha256=0XpGe7s2aJcjdEAqKs10vceW0_JAaK-Rp1UoPaL-BIo,2450
29
+ tests/conftest_uniformTests.py,sha256=2v9UJbKgbrus3UyWXsanEHLksBskbnP0MD8iKVPaIBo,2178
30
+ tests/test_oeis.py,sha256=F89HJ27y54NXcR2wMeBS4ea6R7EaEqpF_GkcU-BrsK4,5694
31
+ tests/test_other.py,sha256=UpS0_WUfWA3wONuZwip5AMmzNmmBwYD7reQDZ9ziL_o,12224
32
+ tests/test_tasks.py,sha256=ap_tKjHUN95vjzKo3xzBAQ3kMbdMJ_XXbOv9YIBJ5pY,2826
33
+ tests/test_types.py,sha256=HklNCGThFiqQ89AOMkE7YkcfAPiZE32DpD3GMDUPQVc,177
34
+ mapFolding-0.3.11.dist-info/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
35
+ mapFolding-0.3.11.dist-info/METADATA,sha256=PyhvxPMeeQH30FYdX_MN-hYO4X2siMUarCi-11a4Kx4,7785
36
+ mapFolding-0.3.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
+ mapFolding-0.3.11.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
38
+ mapFolding-0.3.11.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
39
+ mapFolding-0.3.11.dist-info/RECORD,,
tests/conftest.py CHANGED
@@ -18,7 +18,7 @@ from mapFolding import *
18
18
  from mapFolding import basecamp
19
19
  from mapFolding import getAlgorithmCallable, getDispatcherCallable
20
20
  from mapFolding.beDRY import *
21
- from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidValues
21
+ from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidValues, _getOEISidInformation
22
22
  from mapFolding.oeis import *
23
23
  from Z0Z_tools.pytestForYourUse import PytestFor_defineConcurrencyLimit, PytestFor_intInnit, PytestFor_oopsieKwargsie
24
24
  from typing import Any, Callable, ContextManager, Dict, Generator, List, Optional, Sequence, Set, Tuple, Type, Union
@@ -40,7 +40,7 @@ def makeDictionaryFoldsTotalKnown() -> Dict[Tuple[int,...], int]:
40
40
  dictionaryMapDimensionsToFoldsTotalKnown[tuple(dimensions)] = foldingsTotal
41
41
 
42
42
  # Are we in a place that has jobs?
43
- pathJobDEFAULT = getPathJobDEFAULT()
43
+ pathJobDEFAULT = getPathJobRootDEFAULT()
44
44
  if pathJobDEFAULT.exists():
45
45
  # Are there foldsTotal files?
46
46
  for pathFilenameFoldsTotal in pathJobDEFAULT.rglob('*.foldsTotal'):
@@ -181,44 +181,3 @@ def useAlgorithmDirectly() -> Generator[None, Any, None]:
181
181
 
182
182
  # Restore original function
183
183
  basecamp.getDispatcherCallable = original_dispatcher
184
-
185
- """
186
- Section: Prototype test structures before moving to uniformTests.py"""
187
-
188
- def prototypeCacheTest(
189
- expected: Any,
190
- setupCacheFile: Optional[Callable[[pathlib.Path, str], None]],
191
- oeisID: str,
192
- pathCache: pathlib.Path
193
- ) -> None:
194
- """Template for tests involving OEIS cache operations.
195
-
196
- Parameters
197
- expected: Expected value or exception from _getOEISidValues
198
- setupCacheFile: Function to prepare the cache file before test
199
- oeisID: OEIS ID to test
200
- pathCache: Temporary cache directory path
201
- """
202
- pathFilenameCache = pathCache / _getFilenameOEISbFile(oeisID)
203
-
204
- # Setup cache file if provided
205
- if setupCacheFile:
206
- setupCacheFile(pathFilenameCache, oeisID)
207
-
208
- # Run test
209
- try:
210
- actual: Any = _getOEISidValues(oeisID)
211
- messageActual = actual
212
- except Exception as actualError:
213
- actual = type(actualError)
214
- messageActual = type(actualError).__name__
215
-
216
- # Compare results
217
- if isinstance(expected, type) and issubclass(expected, Exception):
218
- messageExpected = expected.__name__
219
- assert isinstance(actual, expected), uniformTestMessage(
220
- messageExpected, messageActual, "_getOEISidValues", oeisID)
221
- else:
222
- messageExpected = expected
223
- assert actual == expected, uniformTestMessage(
224
- messageExpected, messageActual, "_getOEISidValues", oeisID)
tests/test_oeis.py CHANGED
@@ -1,8 +1,9 @@
1
1
  from contextlib import redirect_stdout
2
2
  from datetime import datetime, timedelta
3
- from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidValues, _parseBFileOEIS, _validateOEISid
3
+ from mapFolding.oeis import _getFilenameOEISbFile, _getOEISidValues, _parseBFileOEIS, _validateOEISid, _getOEISidInformation
4
4
  from tests.conftest import *
5
- from typing import Optional, NoReturn, Tuple, Union
5
+ from typing import NoReturn
6
+ from urllib.error import URLError
6
7
  import io
7
8
  import os
8
9
  import pathlib
@@ -12,7 +13,6 @@ import re as regex
12
13
  import unittest
13
14
  import unittest.mock
14
15
  import urllib
15
- from urllib.error import URLError
16
16
  import urllib.request
17
17
 
18
18
  def test_algorithmSourceSequential(oeisID: str, useAlgorithmDirectly: None) -> None:
@@ -63,73 +63,14 @@ def test_clearOEIScache(mock_unlink: unittest.mock.MagicMock, mock_exists: unitt
63
63
  clearOEIScache()
64
64
 
65
65
  if cacheExists:
66
- assert mock_unlink.call_count == len(settingsOEIS)
67
- mock_unlink.assert_has_calls([unittest.mock.call(missing_ok=True)] * len(settingsOEIS))
66
+ # Each OEIS ID has two cache files
67
+ expected_calls = len(settingsOEIS) * 2
68
+ assert mock_unlink.call_count == expected_calls
69
+ mock_unlink.assert_has_calls([unittest.mock.call(missing_ok=True)] * expected_calls)
68
70
  else:
69
71
  mock_exists.assert_called_once()
70
72
  mock_unlink.assert_not_called()
71
73
 
72
- @pytest.mark.parametrize("scenarioCache", ["miss", "expired", "invalid"])
73
- def testCacheScenarios(pathCacheTesting: pathlib.Path, oeisID_1random: str, scenarioCache: str) -> None:
74
- """Test cache scenarios: missing file, expired file, and invalid file."""
75
-
76
- def setupCacheExpired(pathCache: pathlib.Path, oeisID: str) -> None:
77
- pathCache.write_text("# Old cache content")
78
- oldModificationTime = datetime.now() - timedelta(days=30)
79
- os.utime(pathCache, times=(oldModificationTime.timestamp(), oldModificationTime.timestamp()))
80
-
81
- def setupCacheInvalid(pathCache: pathlib.Path, oeisID: str) -> None:
82
- pathCache.write_text("Invalid content")
83
-
84
- if scenarioCache == "miss":
85
- prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], None, oeisID_1random, pathCacheTesting)
86
- elif scenarioCache == "expired":
87
- prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], setupCacheExpired, oeisID_1random, pathCacheTesting)
88
- else:
89
- prototypeCacheTest(settingsOEIS[oeisID_1random]['valuesKnown'], setupCacheInvalid, oeisID_1random, pathCacheTesting)
90
-
91
- def testInvalidFileContent(pathCacheTesting: pathlib.Path, oeisID_1random: str) -> None:
92
- pathFilenameCache = pathCacheTesting / _getFilenameOEISbFile(oeisID=oeisID_1random)
93
-
94
- # Write invalid content to cache
95
- pathFilenameCache.write_text("# A999999\n1 1\n2 2\n")
96
- modificationTimeOriginal = pathFilenameCache.stat().st_mtime
97
-
98
- # Function should detect invalid content, fetch fresh data, and update cache
99
- OEISsequence = _getOEISidValues(oeisID_1random)
100
-
101
- # Verify the function succeeded
102
- assert OEISsequence is not None
103
- # Verify cache was updated (modification time changed)
104
- assert pathFilenameCache.stat().st_mtime > modificationTimeOriginal
105
- # Verify cache now contains correct sequence ID
106
- assert f"# {oeisID_1random}" in pathFilenameCache.read_text()
107
-
108
- def testParseContentErrors() -> None:
109
- """Test invalid content parsing."""
110
- standardizedEqualTo(ValueError, _parseBFileOEIS, "Invalid content\n1 2\n", 'A001415')
111
-
112
- def testExtraComments(pathCacheTesting: pathlib.Path, oeisID_1random: str) -> None:
113
- pathFilenameCache = pathCacheTesting / _getFilenameOEISbFile(oeisID=oeisID_1random)
114
-
115
- # Write content with extra comment lines
116
- contentWithExtraComments = f"""# {oeisID_1random}
117
- # Normal place for comment line 1
118
- # Abnormal comment line
119
- 1 2
120
- 2 4
121
- 3 6
122
- # Another comment in the middle
123
- 4 8
124
- 5 10"""
125
- pathFilenameCache.write_text(contentWithExtraComments)
126
-
127
- OEISsequence = _getOEISidValues(oeisID_1random)
128
- # Verify sequence values are correct despite extra comments
129
- standardizedEqualTo(2, lambda d: d[1], OEISsequence) # First value
130
- standardizedEqualTo(8, lambda d: d[4], OEISsequence) # Value after mid-sequence comment
131
- standardizedEqualTo(10, lambda d: d[5], OEISsequence) # Last value
132
-
133
74
  def testNetworkError(monkeypatch: pytest.MonkeyPatch, pathCacheTesting: pathlib.Path) -> None:
134
75
  """Test network error handling."""
135
76
  def mockUrlopen(*args: Any, **kwargs: Any) -> NoReturn:
tests/test_other.py CHANGED
@@ -61,35 +61,36 @@ def test_getLeavesTotal_edge_cases() -> None:
61
61
  standardizedEqualTo(6, getLeavesTotal, listOriginal)
62
62
  standardizedEqualTo([2, 3], lambda x: x, listOriginal) # Check that the list wasn't modified
63
63
 
64
- @pytest.mark.parametrize("foldsValue,writeFoldsTarget", [
65
- (756839, "foldsTotalTest.txt"), # Direct file
66
- (2640919, "foldsTotalTest.txt"), # Direct file
67
- (7715177, None), # Directory, will use default filename
68
- ])
69
- def test_countFolds_writeFoldsTotal(
70
- listDimensionsTestFunctionality: List[int],
71
- pathTempTesting: pathlib.Path,
72
- mockFoldingFunction: Callable[..., Callable[..., None]],
73
- mockDispatcher: Callable[[Callable[..., None]], Any],
74
- foldsValue: int,
75
- writeFoldsTarget: Optional[str]
76
- ) -> None:
77
- """Test writing folds total to either a file or directory."""
78
- # For directory case, use the directory path directly
79
- if writeFoldsTarget is None:
80
- pathWriteTarget = pathTempTesting
81
- filenameFoldsTotalExpected = getFilenameFoldsTotal(listDimensionsTestFunctionality)
82
- else:
83
- pathWriteTarget = pathTempTesting / writeFoldsTarget
84
- filenameFoldsTotalExpected = writeFoldsTarget
85
-
86
- foldsTotalExpected = foldsValue * getLeavesTotal(listDimensionsTestFunctionality)
87
- mock_countFolds = mockFoldingFunction(foldsValue, listDimensionsTestFunctionality)
88
-
89
- with mockDispatcher(mock_countFolds):
90
- returned = countFolds(listDimensionsTestFunctionality, pathLikeWriteFoldsTotal=pathWriteTarget)
91
-
92
- standardizedEqualTo(str(foldsTotalExpected), lambda: (pathTempTesting / filenameFoldsTotalExpected).read_text())
64
+ # TODO fix this mock
65
+ # @pytest.mark.parametrize("foldsValue,writeFoldsTarget", [
66
+ # (756839, "foldsTotalTest.txt"), # Direct file
67
+ # (2640919, "foldsTotalTest.txt"), # Direct file
68
+ # (7715177, None), # Directory, will use default filename
69
+ # ])
70
+ # def test_countFolds_writeFoldsTotal(
71
+ # listDimensionsTestFunctionality: List[int],
72
+ # pathTempTesting: pathlib.Path,
73
+ # mockFoldingFunction: Callable[..., Callable[..., None]],
74
+ # mockDispatcher: Callable[[Callable[..., None]], Any],
75
+ # foldsValue: int,
76
+ # writeFoldsTarget: Optional[str]
77
+ # ) -> None:
78
+ # """Test writing folds total to either a file or directory."""
79
+ # # For directory case, use the directory path directly
80
+ # if writeFoldsTarget is None:
81
+ # pathWriteTarget = pathTempTesting
82
+ # filenameFoldsTotalExpected = getFilenameFoldsTotal(listDimensionsTestFunctionality)
83
+ # else:
84
+ # pathWriteTarget = pathTempTesting / writeFoldsTarget
85
+ # filenameFoldsTotalExpected = writeFoldsTarget
86
+
87
+ # foldsTotalExpected = foldsValue * getLeavesTotal(listDimensionsTestFunctionality)
88
+ # mock_countFolds = mockFoldingFunction(foldsValue, listDimensionsTestFunctionality)
89
+
90
+ # with mockDispatcher(mock_countFolds):
91
+ # returned = countFolds(listDimensionsTestFunctionality, pathLikeWriteFoldsTotal=pathWriteTarget)
92
+
93
+ # standardizedEqualTo(str(foldsTotalExpected), lambda: (pathTempTesting / filenameFoldsTotalExpected).read_text())
93
94
 
94
95
  @pytest.mark.parametrize("nameOfTest,callablePytest", PytestFor_intInnit())
95
96
  def testIntInnit(nameOfTest: str, callablePytest: Callable[[], None]) -> None:
@@ -1,212 +0,0 @@
1
- from mapFolding import getPathFilenameFoldsTotal, indexMy, indexTrack
2
- from mapFolding import setDatatypeElephino, setDatatypeFoldsTotal, setDatatypeLeavesTotal, setDatatypeModule, hackSSOTdatatype
3
- from someAssemblyRequired import makeStateJob
4
- from typing import Optional
5
- import importlib
6
- import importlib.util
7
- import inspect
8
- import more_itertools
9
- import numpy
10
- import pathlib
11
- import python_minifier
12
-
13
- identifierCallableLaunch = "goGoGadgetAbsurdity"
14
-
15
- def makeStrRLEcompacted(arrayTarget: numpy.ndarray, identifierName: str) -> str:
16
- """Converts a NumPy array into a compressed string representation using run-length encoding (RLE).
17
-
18
- This function takes a NumPy array and converts it into an optimized string representation by:
19
- 1. Compressing consecutive sequences of numbers into range objects
20
- 2. Minimizing repeated zeros using array multiplication syntax
21
- 3. Converting the result into a valid Python array initialization statement
22
-
23
- Parameters:
24
- arrayTarget (numpy.ndarray): The input NumPy array to be converted
25
- identifierName (str): The variable name to use in the output string
26
-
27
- Returns:
28
- str: A string containing Python code that recreates the input array in compressed form.
29
- Format: "{identifierName} = numpy.array({compressed_data}, dtype=numpy.{dtype})"
30
-
31
- Example:
32
- >>> arr = numpy.array([[0,0,0,1,2,3,4,0,0]])
33
- >>> print(makeStrRLEcompacted(arr, "myArray"))
34
- "myArray = numpy.array([[0]*3,*range(1,5),[0]*2], dtype=numpy.int64)"
35
-
36
- Notes:
37
- - Sequences of 4 or fewer numbers are kept as individual values
38
- - Sequences longer than 4 numbers are converted to range objects
39
- - Consecutive zeros are compressed using multiplication syntax
40
- - The function preserves the original array's dtype
41
- """
42
-
43
- def compressRangesNDArrayNoFlatten(arraySlice):
44
- if isinstance(arraySlice, numpy.ndarray) and arraySlice.ndim > 1:
45
- return [compressRangesNDArrayNoFlatten(arraySlice[index]) for index in range(arraySlice.shape[0])]
46
- elif isinstance(arraySlice, numpy.ndarray) and arraySlice.ndim == 1:
47
- listWithRanges = []
48
- for group in more_itertools.consecutive_groups(arraySlice.tolist()):
49
- ImaSerious = list(group)
50
- if len(ImaSerious) <= 4:
51
- listWithRanges += ImaSerious
52
- else:
53
- ImaRange = [range(ImaSerious[0], ImaSerious[-1] + 1)]
54
- listWithRanges += ImaRange
55
- return listWithRanges
56
- return arraySlice
57
-
58
- arrayAsNestedLists = compressRangesNDArrayNoFlatten(arrayTarget)
59
-
60
- stringMinimized = python_minifier.minify(str(arrayAsNestedLists))
61
- commaZeroMaximum = arrayTarget.shape[-1] - 1
62
- stringMinimized = stringMinimized.replace('[0' + ',0'*commaZeroMaximum + ']', '[0]*'+str(commaZeroMaximum+1))
63
- for countZeros in range(commaZeroMaximum, 2, -1):
64
- stringMinimized = stringMinimized.replace(',0'*countZeros + ']', ']+[0]*'+str(countZeros))
65
-
66
- stringMinimized = stringMinimized.replace('range', '*range')
67
-
68
- return f"{identifierName} = numpy.array({stringMinimized}, dtype=numpy.{arrayTarget.dtype})"
69
-
70
- def writeModuleWithNumba(listDimensions) -> pathlib.Path:
71
- """
72
- Writes a Numba-optimized Python module for map folding calculations.
73
-
74
- This function takes map dimensions and generates a specialized Python module with Numba
75
- optimizations. It processes a sequential counting algorithm, adds Numba decorators and
76
- necessary data structures, and writes the resulting code to a file.
77
-
78
- Parameters:
79
- listDimensions: List of integers representing the dimensions of the map to be folded.
80
-
81
- Returns:
82
- pathlib.Path: Path to the generated Python module file.
83
-
84
- The generated module includes:
85
- - Numba JIT compilation decorators for performance optimization
86
- - Required numpy and numba imports
87
- - Dynamic and static data structures needed for folding calculations
88
- - Processed algorithm from the original sequential counter
89
- - Launch code for standalone execution
90
- - Code to write the final fold count to a file
91
- The function handles:
92
- - Translation of original code to Numba-compatible syntax
93
- - Insertion of pre-calculated values from the state job
94
- - Management of variable declarations and assignments
95
- - Setup of proper data types for Numba optimization
96
- - Organization of the output file structure
97
-
98
- Note:
99
- The generated module requires Numba and numpy to be installed.
100
- The output file will be placed in the same directory as the folds total file,
101
- with a .py extension.
102
- """
103
- stateJob = makeStateJob(listDimensions, writeJob=False)
104
- pathFilenameFoldsTotal = getPathFilenameFoldsTotal(stateJob['mapShape'])
105
-
106
- from syntheticModules import countSequential
107
- algorithmSource = countSequential
108
- codeSource = inspect.getsource(algorithmSource)
109
-
110
- lineNumba = f"@numba.jit(numba.types.{hackSSOTdatatype('datatypeFoldsTotal')}(), cache=True, nopython=True, fastmath=True, forceinline=True, inline='always', looplift=False, _nrt=True, error_model='numpy', parallel=False, boundscheck=False, no_cfunc_wrapper=False, no_cpython_wrapper=False)"
111
-
112
- linesImport = "\n".join([
113
- "import numpy"
114
- , "import numba"
115
- ])
116
-
117
- ImaIndent = ' '
118
- linesDataDynamic = """"""
119
- linesDataDynamic = "\n".join([linesDataDynamic
120
- , ImaIndent + makeStrRLEcompacted(stateJob['gapsWhere'], 'gapsWhere')
121
- ])
122
-
123
- linesDataStatic = """"""
124
- linesDataStatic = "\n".join([linesDataStatic
125
- , ImaIndent + makeStrRLEcompacted(stateJob['connectionGraph'], 'connectionGraph')
126
- ])
127
-
128
- my = stateJob['my']
129
- track = stateJob['track']
130
- linesAlgorithm = """"""
131
- for lineSource in codeSource.splitlines():
132
- if lineSource.startswith(('#', 'import', 'from', '@numba.jit')):
133
- continue
134
- elif not lineSource:
135
- continue
136
- elif lineSource.startswith('def '):
137
- lineSource = "\n".join([lineNumba
138
- , f"def {identifierCallableLaunch}():"
139
- , linesDataDynamic
140
- , linesDataStatic
141
- ])
142
- elif 'taskIndex' in lineSource:
143
- continue
144
- elif 'my[indexMy.' in lineSource:
145
- if 'dimensionsTotal' in lineSource:
146
- continue
147
- # Statements are in the form: leaf1ndex = my[indexMy.leaf1ndex.value]
148
- identifier, statement = lineSource.split('=')
149
- lineSource = ImaIndent + identifier.strip() + f"=numba.types.{hackSSOTdatatype(identifier.strip())}({str(eval(statement.strip()))})"
150
- elif ': int =' in lineSource or ':int=' in lineSource:
151
- if 'dimensionsTotal' in lineSource:
152
- continue
153
- # Statements are in the form: groupsOfFolds: int = 0
154
- assignment, statement = lineSource.split('=')
155
- identifier = assignment.split(':')[0].strip()
156
- lineSource = ImaIndent + identifier.strip() + f"=numba.types.{hackSSOTdatatype(identifier.strip())}({str(eval(statement.strip()))})"
157
- elif 'track[indexTrack.' in lineSource:
158
- # Statements are in the form: leafAbove = track[indexTrack.leafAbove.value]
159
- identifier, statement = lineSource.split('=')
160
- lineSource = ImaIndent + makeStrRLEcompacted(eval(statement.strip()), identifier.strip())
161
- elif 'foldGroups[-1]' in lineSource:
162
- lineSource = lineSource.replace('foldGroups[-1]', str(stateJob['foldGroups'][-1]))
163
- elif 'dimensionsTotal' in lineSource:
164
- lineSource = lineSource.replace('dimensionsTotal', str(stateJob['my'][indexMy.dimensionsTotal]))
165
-
166
- linesAlgorithm = "\n".join([linesAlgorithm
167
- , lineSource
168
- ])
169
-
170
- linesLaunch = """"""
171
- linesLaunch = linesLaunch + f"""
172
- if __name__ == '__main__':
173
- # import time
174
- # timeStart = time.perf_counter()
175
- {identifierCallableLaunch}()
176
- # print(time.perf_counter() - timeStart)
177
- """
178
-
179
- linesWriteFoldsTotal = """"""
180
- linesWriteFoldsTotal = "\n".join([linesWriteFoldsTotal
181
- , f" groupsOfFolds *= {str(stateJob['foldGroups'][-1])}"
182
- , " print(groupsOfFolds)"
183
- , " with numba.objmode():"
184
- , f" open('{pathFilenameFoldsTotal.as_posix()}', 'w').write(str(groupsOfFolds))"
185
- , " return groupsOfFolds"
186
- ])
187
-
188
- linesAll = "\n".join([
189
- linesImport
190
- , linesAlgorithm
191
- , linesWriteFoldsTotal
192
- , linesLaunch
193
- ])
194
-
195
- pathFilenameDestination = pathFilenameFoldsTotal.with_suffix(".py")
196
- pathFilenameDestination.write_text(linesAll)
197
-
198
- return pathFilenameDestination
199
-
200
- if __name__ == '__main__':
201
- listDimensions = [5,5]
202
- setDatatypeFoldsTotal('int64', sourGrapes=True)
203
- setDatatypeElephino('uint8', sourGrapes=True)
204
- setDatatypeLeavesTotal('int8', sourGrapes=True)
205
- pathFilenameModule = writeModuleWithNumba(listDimensions)
206
-
207
- # Induce numba.jit compilation
208
- moduleSpec = importlib.util.spec_from_file_location(pathFilenameModule.stem, pathFilenameModule)
209
- if moduleSpec is None: raise ImportError(f"Could not load module specification from {pathFilenameModule}")
210
- module = importlib.util.module_from_spec(moduleSpec)
211
- if moduleSpec.loader is None: raise ImportError(f"Could not load module from {moduleSpec}")
212
- moduleSpec.loader.exec_module(module)