mapFolding 0.3.12__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. mapFolding/__init__.py +40 -38
  2. mapFolding/basecamp.py +50 -50
  3. mapFolding/beDRY.py +336 -336
  4. mapFolding/oeis.py +262 -262
  5. mapFolding/reference/flattened.py +294 -293
  6. mapFolding/reference/hunterNumba.py +126 -126
  7. mapFolding/reference/irvineJavaPort.py +99 -99
  8. mapFolding/reference/jax.py +153 -153
  9. mapFolding/reference/lunnan.py +148 -148
  10. mapFolding/reference/lunnanNumpy.py +115 -115
  11. mapFolding/reference/lunnanWhile.py +114 -114
  12. mapFolding/reference/rotatedEntryPoint.py +183 -183
  13. mapFolding/reference/total_countPlus1vsPlusN.py +203 -203
  14. mapFolding/someAssemblyRequired/__init__.py +5 -1
  15. mapFolding/someAssemblyRequired/getLLVMforNoReason.py +12 -12
  16. mapFolding/someAssemblyRequired/makeJob.py +46 -52
  17. mapFolding/someAssemblyRequired/synthesizeModuleJAX.py +17 -17
  18. mapFolding/someAssemblyRequired/synthesizeNumba.py +343 -633
  19. mapFolding/someAssemblyRequired/synthesizeNumbaGeneralized.py +325 -0
  20. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +173 -0
  21. mapFolding/someAssemblyRequired/synthesizeNumbaModules.py +77 -0
  22. mapFolding/syntheticModules/__init__.py +0 -0
  23. mapFolding/syntheticModules/numba_countInitialize.py +4 -4
  24. mapFolding/syntheticModules/numba_countParallel.py +4 -4
  25. mapFolding/syntheticModules/numba_countSequential.py +4 -4
  26. mapFolding/syntheticModules/numba_doTheNeedful.py +7 -7
  27. mapFolding/theDao.py +165 -165
  28. mapFolding/theSSOT.py +177 -173
  29. mapFolding/theSSOTnumba.py +90 -74
  30. mapFolding-0.4.1.dist-info/METADATA +154 -0
  31. mapFolding-0.4.1.dist-info/RECORD +42 -0
  32. tests/conftest.py +253 -129
  33. tests/test_computations.py +79 -0
  34. tests/test_oeis.py +76 -85
  35. tests/test_other.py +136 -224
  36. tests/test_tasks.py +19 -23
  37. tests/test_types.py +2 -2
  38. mapFolding/someAssemblyRequired/synthesizeNumbaHardcoding.py +0 -188
  39. mapFolding-0.3.12.dist-info/METADATA +0 -155
  40. mapFolding-0.3.12.dist-info/RECORD +0 -40
  41. tests/conftest_tmpRegistry.py +0 -62
  42. tests/conftest_uniformTests.py +0 -53
  43. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/LICENSE +0 -0
  44. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/WHEEL +0 -0
  45. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/entry_points.txt +0 -0
  46. {mapFolding-0.3.12.dist-info → mapFolding-0.4.1.dist-info}/top_level.txt +0 -0
@@ -3,151 +3,151 @@ An unnecessarily literal translation of the original Atlas Autocode code by W. F
3
3
  W. F. Lunnon, Multi-dimensional map-folding, The Computer Journal, Volume 14, Issue 1, 1971, Pages 75-80, https://doi.org/10.1093/comjnl/14.1.75
4
4
  """# NOTE not functional yet
5
5
  def foldings(p, job=None):
6
- """An unnecessarily literal translation of the original Atlas Autocode code."""
7
- p = list(p)
8
- p.append(None) # NOTE mimics Atlas `array` type
9
- p.insert(0, None) # NOTE mimics Atlas `array` type
10
-
11
- if job is None:
12
- global G
13
- G = 0
14
- def job(A, B):
15
- global G
16
- G = G + 1
17
- return foldings(p, job)
18
- # perform job (A, B) on each folding of a p[1] x ... x p[d] map,
19
- # where A and B are the above and below vectors. p[d + 1] < 0 terminates p;
20
-
21
- d: int
22
- n: int
23
- j: int
24
- i: int
25
- m: int
26
- l: int
27
- g: int
28
- gg: int
29
- dd: int
30
-
31
- n = 1
32
- i, d = 0, 0
33
-
34
- while (i := i + 1) and p[i] is not None:
35
- d = i
36
- n = n * p[i]
37
-
38
- # d dimensions and n leaves;
39
-
40
- # A: list[int] = [None] * (n + 1) # type: ignore
41
- # B: list[int] = [None] * (n + 1) # type: ignore
42
- # count: list[int] = [None] * (n + 1) # type: ignore
43
- # gapter: list[int] = [None] * (n + 1) # type: ignore
44
- # gap: list[int] = [None] * (n * n + 1) # type: ignore
45
- A: list[int] = [0] * (n + 1) # type: ignore
46
- B: list[int] = [0] * (n + 1) # type: ignore
47
- count: list[int] = [0] * (n + 1) # type: ignore
48
- gapter: list[int] = [0] * (n + 1) # type: ignore
49
- gap: list[int] = [0] * (n * n + 1) # type: ignore
50
-
51
- # B[m] is the leaf below leaf m in the current folding,
52
- # A[m] the leaf above. count[m] is the no. of sections in which
53
- # there is a gap for the new leaf l below leaf m,
54
- # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
55
- # and later gap[gapter[l]] is the gap where leaf l is currently inserted;
56
-
57
- P: list[int] = [0] * (d + 1) # type: ignore
58
- C: list[list[int]] = [[0] * (n + 1) for dimension1 in range(d + 1)] # type: ignore
59
- # D: list[list[list[int]]] = [[[None] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)] # type: ignore
60
- D: list[list[list[int]]] = [[[0] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)]
61
-
62
- P[0] = 1
63
- for i in range(1, d + 1):
64
- P[i] = P[i - 1] * p[i]
65
-
66
- for i in range(1, d + 1):
67
- for m in range(1, n + 1):
68
- C[i][m] = ((m - 1) // P[i - 1]) - ((m - 1) // P[i]) * p[i] + 1
69
-
70
- for i in range(1, d + 1):
71
- for l in range(1, n + 1):
72
- for m in range(1, l + 1):
73
- D[i][l][m] = (0 if m == 0
74
- else
75
- ((m if C[i][m] == 1
76
- else m - P[i - 1])
77
- if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2
78
- else
79
- (m if C[i][m] == p[i] or m + P[i - 1] > l
80
- else m + P[i - 1])))
81
- # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
82
- # D[i][l][m] = leaf connected to m in section i when inserting l;
83
-
84
- for m in range(n + 1):
85
- count[m] = 0
86
-
87
- A[0], B[0], g, l = 0, 0, 0, 0
88
-
89
- state = 'entry'
90
- while True:
91
- if state == 'entry':
92
- gapter[l] = g
93
- l = l + 1
94
- if l <= n:
95
- state = 'down'
96
- continue
97
- else:
98
- job(A, B)
99
- state = 'up'
100
- continue
101
-
102
- elif state == 'down':
103
- dd = 0
104
- gg = gapter[l - 1]
105
- g = gg
106
- for i in range(1, d + 1):
107
- if D[i][l][l] == l:
108
- dd = dd + 1
109
- else:
110
- m = D[i][l][l]
111
- while m != l:
112
- gap[gg] = m
113
- if count[m] == 0:
114
- gg = gg + 1
115
- count[m] = count[m] + 1
116
- m = D[i][l][B[m]]
117
-
118
- if dd == d:
119
- for m in range(l):
120
- gap[gg] = m
121
- gg = gg + 1
122
-
123
- for j in range(g, gg):
124
- gap[g] = gap[j]
125
- if count[gap[j]] == d - dd:
126
- g = g + 1
127
- count[gap[j]] = 0
128
- state = 'along'
129
- continue
130
-
131
- elif state == 'along':
132
- if g == gapter[l - 1]:
133
- state = 'up'
134
- continue
135
- g = g - 1
136
- A[l] = gap[g]
137
- B[l] = B[A[l]]
138
- B[A[l]] = l
139
- A[B[l]] = l
140
- state = 'entry'
141
- continue
142
-
143
- elif state == 'up':
144
- l = l - 1
145
- B[A[l]] = B[l]
146
- A[B[l]] = A[l]
147
- if l > 0:
148
- state = 'along'
149
- continue
150
- else:
151
- break
152
-
153
- return G #if job.__closure__ else None
6
+ """An unnecessarily literal translation of the original Atlas Autocode code."""
7
+ p = list(p)
8
+ p.append(None) # NOTE mimics Atlas `array` type
9
+ p.insert(0, None) # NOTE mimics Atlas `array` type
10
+
11
+ if job is None:
12
+ global G
13
+ G = 0
14
+ def job(A, B):
15
+ global G
16
+ G = G + 1
17
+ return foldings(p, job)
18
+ # perform job (A, B) on each folding of a p[1] x ... x p[d] map,
19
+ # where A and B are the above and below vectors. p[d + 1] < 0 terminates p;
20
+
21
+ d: int
22
+ n: int
23
+ j: int
24
+ i: int
25
+ m: int
26
+ l: int
27
+ g: int
28
+ gg: int
29
+ dd: int
30
+
31
+ n = 1
32
+ i, d = 0, 0
33
+
34
+ while (i := i + 1) and p[i] is not None:
35
+ d = i
36
+ n = n * p[i]
37
+
38
+ # d dimensions and n leaves;
39
+
40
+ # A: list[int] = [None] * (n + 1) # type: ignore
41
+ # B: list[int] = [None] * (n + 1) # type: ignore
42
+ # count: list[int] = [None] * (n + 1) # type: ignore
43
+ # gapter: list[int] = [None] * (n + 1) # type: ignore
44
+ # gap: list[int] = [None] * (n * n + 1) # type: ignore
45
+ A: list[int] = [0] * (n + 1) # type: ignore
46
+ B: list[int] = [0] * (n + 1) # type: ignore
47
+ count: list[int] = [0] * (n + 1) # type: ignore
48
+ gapter: list[int] = [0] * (n + 1) # type: ignore
49
+ gap: list[int] = [0] * (n * n + 1) # type: ignore
50
+
51
+ # B[m] is the leaf below leaf m in the current folding,
52
+ # A[m] the leaf above. count[m] is the no. of sections in which
53
+ # there is a gap for the new leaf l below leaf m,
54
+ # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
55
+ # and later gap[gapter[l]] is the gap where leaf l is currently inserted;
56
+
57
+ P: list[int] = [0] * (d + 1) # type: ignore
58
+ C: list[list[int]] = [[0] * (n + 1) for dimension1 in range(d + 1)] # type: ignore
59
+ # D: list[list[list[int]]] = [[[None] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)] # type: ignore
60
+ D: list[list[list[int]]] = [[[0] * (n + 1) for dimension2 in range(n + 1)] for dimension1 in range(d + 1)]
61
+
62
+ P[0] = 1
63
+ for i in range(1, d + 1):
64
+ P[i] = P[i - 1] * p[i]
65
+
66
+ for i in range(1, d + 1):
67
+ for m in range(1, n + 1):
68
+ C[i][m] = ((m - 1) // P[i - 1]) - ((m - 1) // P[i]) * p[i] + 1
69
+
70
+ for i in range(1, d + 1):
71
+ for l in range(1, n + 1):
72
+ for m in range(1, l + 1):
73
+ D[i][l][m] = (0 if m == 0
74
+ else
75
+ ((m if C[i][m] == 1
76
+ else m - P[i - 1])
77
+ if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2
78
+ else
79
+ (m if C[i][m] == p[i] or m + P[i - 1] > l
80
+ else m + P[i - 1])))
81
+ # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
82
+ # D[i][l][m] = leaf connected to m in section i when inserting l;
83
+
84
+ for m in range(n + 1):
85
+ count[m] = 0
86
+
87
+ A[0], B[0], g, l = 0, 0, 0, 0
88
+
89
+ state = 'entry'
90
+ while True:
91
+ if state == 'entry':
92
+ gapter[l] = g
93
+ l = l + 1
94
+ if l <= n:
95
+ state = 'down'
96
+ continue
97
+ else:
98
+ job(A, B)
99
+ state = 'up'
100
+ continue
101
+
102
+ elif state == 'down':
103
+ dd = 0
104
+ gg = gapter[l - 1]
105
+ g = gg
106
+ for i in range(1, d + 1):
107
+ if D[i][l][l] == l:
108
+ dd = dd + 1
109
+ else:
110
+ m = D[i][l][l]
111
+ while m != l:
112
+ gap[gg] = m
113
+ if count[m] == 0:
114
+ gg = gg + 1
115
+ count[m] = count[m] + 1
116
+ m = D[i][l][B[m]]
117
+
118
+ if dd == d:
119
+ for m in range(l):
120
+ gap[gg] = m
121
+ gg = gg + 1
122
+
123
+ for j in range(g, gg):
124
+ gap[g] = gap[j]
125
+ if count[gap[j]] == d - dd:
126
+ g = g + 1
127
+ count[gap[j]] = 0
128
+ state = 'along'
129
+ continue
130
+
131
+ elif state == 'along':
132
+ if g == gapter[l - 1]:
133
+ state = 'up'
134
+ continue
135
+ g = g - 1
136
+ A[l] = gap[g]
137
+ B[l] = B[A[l]]
138
+ B[A[l]] = l
139
+ A[B[l]] = l
140
+ state = 'entry'
141
+ continue
142
+
143
+ elif state == 'up':
144
+ l = l - 1
145
+ B[A[l]] = B[l]
146
+ A[B[l]] = A[l]
147
+ if l > 0:
148
+ state = 'along'
149
+ continue
150
+ else:
151
+ break
152
+
153
+ return G #if job.__closure__ else None
@@ -6,118 +6,118 @@ from typing import List
6
6
  import numpy
7
7
 
8
8
  def foldings(p: List[int]) -> int:
9
- """
10
- Run loop with (A, B) on each folding of a p[1] x ... x p[d] map, where A and B are the above and below vectors.
11
-
12
- Parameters:
13
- p: A list of integers representing the dimensions of the map.
14
-
15
- Returns:
16
- G: The number of distinct foldings for the given map dimensions.
17
-
18
- NOTE If there are fewer than two dimensions, any dimensions are not positive, or any dimensions are not integers, the output will be unreliable.
19
- """
20
-
21
- g: int = 0
22
- d: int = len(p)
23
- n: int = 1
24
- for i in range(d):
25
- n = n * p[i]
26
-
27
- # d dimensions and n leaves
28
-
29
- A = numpy.zeros(n + 1, dtype=int)
30
- B = numpy.zeros(n + 1, dtype=int)
31
- count = numpy.zeros(n + 1, dtype=int)
32
- gapter = numpy.zeros(n + 1, dtype=int)
33
- gap = numpy.zeros(n * n + 1, dtype=int)
34
-
35
- # B[m] is the leaf below leaf m in the current folding,
36
- # A[m] the leaf above. count[m] is the no. of sections in which
37
- # there is a gap for the new leaf l below leaf m,
38
- # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
39
- # and later gap[gapter[l]] is the gap where leaf l is currently inserted
40
-
41
- P = numpy.ones(d + 1, dtype=int)
42
- C = numpy.zeros((d + 1, n + 1), dtype=int)
43
- D = numpy.zeros((d + 1, n + 1, n + 1), dtype=int)
44
-
45
- for i in range(1, d + 1):
46
- P[i] = P[i - 1] * p[i - 1]
47
-
48
- for i in range(1, d + 1):
49
- for m in range(1, n + 1):
50
- C[i][m] = ((m - 1) // P[i - 1]) % p[i - 1] + 1 # NOTE Because modulo is available, this statement is simpler.
51
-
52
- for i in range(1, d + 1):
53
- for l in range(1, n + 1):
54
- for m in range(1, l + 1):
55
- if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2:
56
- if C[i][m] == 1:
57
- D[i][l][m] = m
58
- else:
59
- D[i][l][m] = m - P[i - 1]
60
- else:
61
- if C[i][m] == p[i - 1] or m + P[i - 1] > l:
62
- D[i][l][m] = m
63
- else:
64
- D[i][l][m] = m + P[i - 1]
65
- # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
66
- # D[i][l][m] = leaf connected to m in section i when inserting l;
67
-
68
- G: int = 0
69
- l: int = 1
70
-
71
- # kick off with null folding
72
- while l > 0:
73
- if l <= 1 or B[0] == 1: # NOTE This statement is part of a significant divergence from the 1971 paper. As a result, this version is greater than one order of magnitude faster.
74
- if l > n:
75
- G = G + n # NOTE Due to `B[0] == 1`, this implementation increments the counted foldings in batches of `n`-many foldings, rather than immediately incrementing when a folding is found, i.e. `G = G + 1`
76
- else:
77
- dd: int = 0
78
- gg: int = gapter[l - 1]
79
- g = gg
80
- # dd is the no. of sections in which l is unconstrained,
81
- # gg the no. of possible and g the no. of actual gaps for l, + gapter[l - 1]
82
-
83
- # find the possible gaps for leaf l in each section,
84
- # then discard those not common to all. All possible if dd = d
85
- for i in range(1, d + 1):
86
- if D[i][l][l] == l:
87
- dd = dd + 1
88
- else:
89
- m: int = D[i][l][l]
90
- while m != l:
91
- gap[gg] = m
92
- if count[m] == 0:
93
- gg = gg + 1
94
- count[m] += 1
95
- m = D[i][l][B[m]]
96
-
97
- if dd == d:
98
- for m in range(l):
99
- gap[gg] = m
100
- gg = gg + 1
101
-
102
- for j in range(g, gg):
103
- gap[g] = gap[j]
104
- if count[gap[j]] == d - dd:
105
- g = g + 1
106
- count[gap[j]] = 0
107
-
108
- # for each gap insert leaf l, [the main while loop shall progress],
109
- # remove leaf l
110
- while l > 0 and g == gapter[l - 1]:
111
- l = l - 1
112
- B[A[l]] = B[l]
113
- A[B[l]] = A[l]
114
-
115
- if l > 0:
116
- g = g - 1
117
- A[l] = gap[g]
118
- B[l] = B[A[l]]
119
- B[A[l]] = l
120
- A[B[l]] = l
121
- gapter[l] = g
122
- l = l + 1
123
- return G
9
+ """
10
+ Run loop with (A, B) on each folding of a p[1] x ... x p[d] map, where A and B are the above and below vectors.
11
+
12
+ Parameters:
13
+ p: A list of integers representing the dimensions of the map.
14
+
15
+ Returns:
16
+ G: The number of distinct foldings for the given map dimensions.
17
+
18
+ NOTE If there are fewer than two dimensions, any dimensions are not positive, or any dimensions are not integers, the output will be unreliable.
19
+ """
20
+
21
+ g: int = 0
22
+ d: int = len(p)
23
+ n: int = 1
24
+ for i in range(d):
25
+ n = n * p[i]
26
+
27
+ # d dimensions and n leaves
28
+
29
+ A = numpy.zeros(n + 1, dtype=int)
30
+ B = numpy.zeros(n + 1, dtype=int)
31
+ count = numpy.zeros(n + 1, dtype=int)
32
+ gapter = numpy.zeros(n + 1, dtype=int)
33
+ gap = numpy.zeros(n * n + 1, dtype=int)
34
+
35
+ # B[m] is the leaf below leaf m in the current folding,
36
+ # A[m] the leaf above. count[m] is the no. of sections in which
37
+ # there is a gap for the new leaf l below leaf m,
38
+ # gap[gapter[l - 1] + j] is the j-th (possible or actual) gap for leaf l,
39
+ # and later gap[gapter[l]] is the gap where leaf l is currently inserted
40
+
41
+ P = numpy.ones(d + 1, dtype=int)
42
+ C = numpy.zeros((d + 1, n + 1), dtype=int)
43
+ D = numpy.zeros((d + 1, n + 1, n + 1), dtype=int)
44
+
45
+ for i in range(1, d + 1):
46
+ P[i] = P[i - 1] * p[i - 1]
47
+
48
+ for i in range(1, d + 1):
49
+ for m in range(1, n + 1):
50
+ C[i][m] = ((m - 1) // P[i - 1]) % p[i - 1] + 1 # NOTE Because modulo is available, this statement is simpler.
51
+
52
+ for i in range(1, d + 1):
53
+ for l in range(1, n + 1):
54
+ for m in range(1, l + 1):
55
+ if C[i][l] - C[i][m] == (C[i][l] - C[i][m]) // 2 * 2:
56
+ if C[i][m] == 1:
57
+ D[i][l][m] = m
58
+ else:
59
+ D[i][l][m] = m - P[i - 1]
60
+ else:
61
+ if C[i][m] == p[i - 1] or m + P[i - 1] > l:
62
+ D[i][l][m] = m
63
+ else:
64
+ D[i][l][m] = m + P[i - 1]
65
+ # P[i] = p[1] x ... x p[i], C[i][m] = i-th co-ordinate of leaf m,
66
+ # D[i][l][m] = leaf connected to m in section i when inserting l;
67
+
68
+ G: int = 0
69
+ l: int = 1
70
+
71
+ # kick off with null folding
72
+ while l > 0:
73
+ if l <= 1 or B[0] == 1: # NOTE This statement is part of a significant divergence from the 1971 paper. As a result, this version is greater than one order of magnitude faster.
74
+ if l > n:
75
+ G = G + n # NOTE Due to `B[0] == 1`, this implementation increments the counted foldings in batches of `n`-many foldings, rather than immediately incrementing when a folding is found, i.e. `G = G + 1`
76
+ else:
77
+ dd: int = 0
78
+ gg: int = gapter[l - 1]
79
+ g = gg
80
+ # dd is the no. of sections in which l is unconstrained,
81
+ # gg the no. of possible and g the no. of actual gaps for l, + gapter[l - 1]
82
+
83
+ # find the possible gaps for leaf l in each section,
84
+ # then discard those not common to all. All possible if dd = d
85
+ for i in range(1, d + 1):
86
+ if D[i][l][l] == l:
87
+ dd = dd + 1
88
+ else:
89
+ m: int = D[i][l][l]
90
+ while m != l:
91
+ gap[gg] = m
92
+ if count[m] == 0:
93
+ gg = gg + 1
94
+ count[m] += 1
95
+ m = D[i][l][B[m]]
96
+
97
+ if dd == d:
98
+ for m in range(l):
99
+ gap[gg] = m
100
+ gg = gg + 1
101
+
102
+ for j in range(g, gg):
103
+ gap[g] = gap[j]
104
+ if count[gap[j]] == d - dd:
105
+ g = g + 1
106
+ count[gap[j]] = 0
107
+
108
+ # for each gap insert leaf l, [the main while loop shall progress],
109
+ # remove leaf l
110
+ while l > 0 and g == gapter[l - 1]:
111
+ l = l - 1
112
+ B[A[l]] = B[l]
113
+ A[B[l]] = A[l]
114
+
115
+ if l > 0:
116
+ g = g - 1
117
+ A[l] = gap[g]
118
+ B[l] = B[A[l]]
119
+ B[A[l]] = l
120
+ A[B[l]] = l
121
+ gapter[l] = g
122
+ l = l + 1
123
+ return G