hypercomplex-engine 0.4.0__tar.gz → 0.4.1__tar.gz
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.
- {hypercomplex_engine-0.4.0/hypercomplex_engine.egg-info → hypercomplex_engine-0.4.1}/PKG-INFO +1 -1
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_dual.py +12 -6
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_standard.py +2 -2
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/dual.py +4 -3
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/validation.py +1 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/facade.py +5 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1/hypercomplex_engine.egg-info}/PKG-INFO +1 -1
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/SOURCES.txt +1 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/pyproject.toml +1 -1
- hypercomplex_engine-0.4.1/tests/test_dual_tuple_regression.py +90 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/LICENSE +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/README.md +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/basis_element.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/basis_notation.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/bit_utils.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_split.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/split.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/standard.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/common.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/dual.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/split.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/standard.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/printer/__init__.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/printer/cd_format.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/printer/cd_table_printer.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/dependency_links.txt +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/requires.txt +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/top_level.txt +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/setup.cfg +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/tests/test_fast_mode.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/tests/test_fixes_0_4.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/tests/test_mega_mother.py +0 -0
- {hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/tests/test_split_dim.py +0 -0
{hypercomplex_engine-0.4.0/hypercomplex_engine.egg-info → hypercomplex_engine-0.4.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hypercomplex-engine
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Fast O(1)/O(n) multiplication engine and table generator for ordinary, split, and dual Cayley-Dickson algebras.
|
|
5
5
|
Author-email: Maher Ben Abdessalem <ba.maher94@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -125,18 +125,24 @@ class FastDual:
|
|
|
125
125
|
(final_sign, local_index, eps_flag)
|
|
126
126
|
"""
|
|
127
127
|
dim = Validation.dimension(dim)
|
|
128
|
+
Validation.basis_tuple(t1, allow_zero=True, allow_eps=True)
|
|
129
|
+
Validation.basis_tuple(t2, allow_zero=True, allow_eps=True)
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
s1, i = int(t1[0]), int(t1[1])
|
|
134
|
+
s2, j = int(t2[0]), int(t2[1])
|
|
135
|
+
i_eps_flag = int(t1[2]) if len(t1) == 3 else 0
|
|
136
|
+
j_eps_flag = int(t2[2]) if len(t2) == 3 else 0
|
|
131
137
|
|
|
132
138
|
if s1 == 0 or s2 == 0:
|
|
133
139
|
return (0, 0, 0)
|
|
134
140
|
|
|
135
|
-
sign, idx, eps = self.multiply_indices(i, j,
|
|
141
|
+
sign, idx, eps = self.multiply_indices(i, j,dim,i_eps_flag,j_eps_flag)
|
|
136
142
|
|
|
137
143
|
return (s1 * s2 * sign, idx, eps)
|
|
138
144
|
|
|
139
|
-
def multiply_indices(self, i: int, j: int,
|
|
145
|
+
def multiply_indices(self, i: int, j: int,dim:int, i_eps_flag=0 ,j_eps_flag=0) -> tuple:
|
|
140
146
|
"""
|
|
141
147
|
Core dual O(1) multiplication using global indices.
|
|
142
148
|
|
|
@@ -156,8 +162,8 @@ class FastDual:
|
|
|
156
162
|
if j < 0 or j >= total:
|
|
157
163
|
raise ValueError(f"index must be in [0, {total - 1}] for dual dim={dim}, got {j}")
|
|
158
164
|
|
|
159
|
-
i_eps = i >= half
|
|
160
|
-
j_eps = j >= half
|
|
165
|
+
i_eps = i >= half or i_eps_flag
|
|
166
|
+
j_eps = j >= half or j_eps_flag
|
|
161
167
|
|
|
162
168
|
i_loc = i & (half - 1)
|
|
163
169
|
j_loc = j & (half - 1)
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_standard.py
RENAMED
|
@@ -28,8 +28,8 @@ class FastStandard:
|
|
|
28
28
|
Returns:
|
|
29
29
|
(final_sign, index1 XOR index2)
|
|
30
30
|
"""
|
|
31
|
-
Validation.basis_tuple(t1, allow_zero=
|
|
32
|
-
Validation.basis_tuple(t2, allow_zero=
|
|
31
|
+
Validation.basis_tuple(t1, allow_zero=False, allow_eps=False)
|
|
32
|
+
Validation.basis_tuple(t2, allow_zero=False, allow_eps=False)
|
|
33
33
|
|
|
34
34
|
s1, i = int(t1[0]), int(t1[1])
|
|
35
35
|
s2, j = int(t2[0]), int(t2[1])
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/dual.py
RENAMED
|
@@ -48,7 +48,8 @@ class DualHolographic:
|
|
|
48
48
|
|
|
49
49
|
s1, i = int(t1[0]), int(t1[1])
|
|
50
50
|
s2, j = int(t2[0]), int(t2[1])
|
|
51
|
-
|
|
51
|
+
i_eps_flag = int(t1[2]) if len(t1) == 3 else 0
|
|
52
|
+
j_eps_flag = int(t2[2]) if len(t2) == 3 else 0
|
|
52
53
|
# Zero propagates.
|
|
53
54
|
if s1 == 0 or s2 == 0:
|
|
54
55
|
return (0, 0, 0)
|
|
@@ -63,8 +64,8 @@ class DualHolographic:
|
|
|
63
64
|
|
|
64
65
|
half = 1 << dim
|
|
65
66
|
|
|
66
|
-
i_eps = i >= half
|
|
67
|
-
j_eps = j >= half
|
|
67
|
+
i_eps = i >= half or i_eps_flag
|
|
68
|
+
j_eps = j >= half or j_eps_flag
|
|
68
69
|
|
|
69
70
|
i_loc = i & (half - 1)
|
|
70
71
|
j_loc = j & (half - 1)
|
|
@@ -264,6 +264,11 @@ def multiply(
|
|
|
264
264
|
# required, never inferred. Validate before anything else.
|
|
265
265
|
if kind in ("split", "dual", "dual_split") and dim is None:
|
|
266
266
|
raise ValueError(f"dim is required for {kind} multiplication")
|
|
267
|
+
# Validate inputs before any early return, so malformed data always
|
|
268
|
+
# raises ValidationError instead of leaking TypeError/IndexError.
|
|
269
|
+
allow_eps = kind in ("dual", "dual_split")
|
|
270
|
+
Validation.basis_tuple(a, allow_zero=True, allow_eps=allow_eps)
|
|
271
|
+
Validation.basis_tuple(b, allow_zero=True, allow_eps=allow_eps)
|
|
267
272
|
|
|
268
273
|
# Zero propagation
|
|
269
274
|
if int(a[0]) == 0 or int(b[0]) == 0:
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1/hypercomplex_engine.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hypercomplex-engine
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Fast O(1)/O(n) multiplication engine and table generator for ordinary, split, and dual Cayley-Dickson algebras.
|
|
5
5
|
Author-email: Maher Ben Abdessalem <ba.maher94@gmail.com>
|
|
6
6
|
License: MIT License
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/SOURCES.txt
RENAMED
|
@@ -29,6 +29,7 @@ hypercomplex_engine.egg-info/SOURCES.txt
|
|
|
29
29
|
hypercomplex_engine.egg-info/dependency_links.txt
|
|
30
30
|
hypercomplex_engine.egg-info/requires.txt
|
|
31
31
|
hypercomplex_engine.egg-info/top_level.txt
|
|
32
|
+
tests/test_dual_tuple_regression.py
|
|
32
33
|
tests/test_fast_mode.py
|
|
33
34
|
tests/test_fixes_0_4.py
|
|
34
35
|
tests/test_mega_mother.py
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Regression tests for dual-engine tuple normalization and facade zero handling.
|
|
2
|
+
|
|
3
|
+
History:
|
|
4
|
+
- 0.4.0: DualHolographic ignored the eps flag while FastDual promoted it
|
|
5
|
+
(engines diverged on identical 3-tuple input).
|
|
6
|
+
- 0.4.0 hotfix attempt: DualHolographic read t[2] unconditionally, crashing
|
|
7
|
+
with IndexError on documented 2-tuple input and breaking the facade's
|
|
8
|
+
engine="holographic" dual path (which normalizes to 2-tuples).
|
|
9
|
+
- 0.4.1: both fixed; facade validates before zero-propagation.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
# Adjust these imports to whatever hypercomplex/__init__.py exports.
|
|
15
|
+
from hypercomplex import multiply, FastDual, DualHolographic
|
|
16
|
+
from hypercomplex.core.validation import Validation
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ---------- tuple normalization: engines must agree on identical input ----------
|
|
20
|
+
|
|
21
|
+
def _all_global_pairs(dim):
|
|
22
|
+
half = 1 << dim
|
|
23
|
+
for i in range(half << 1):
|
|
24
|
+
for j in range(half << 1):
|
|
25
|
+
yield (1, i, 1 if i >= half else 0), (1, j, 1 if j >= half else 0)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize("dim", [0, 1, 2, 3])
|
|
29
|
+
def test_engines_agree_global_3tuples(dim):
|
|
30
|
+
fast, holo = FastDual(), DualHolographic()
|
|
31
|
+
for a, b in _all_global_pairs(dim):
|
|
32
|
+
assert fast.multiply(a, b, dim) == holo.multiply(a, b, dim)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("dim", [1, 2, 3])
|
|
36
|
+
def test_engines_agree_on_2tuples(dim):
|
|
37
|
+
"""2-tuples are documented input; must not raise (the 0.4.0 regression)."""
|
|
38
|
+
fast, holo = FastDual(), DualHolographic()
|
|
39
|
+
for a, b in _all_global_pairs(dim):
|
|
40
|
+
a2, b2 = a[:2], b[:2] # strip the eps flag
|
|
41
|
+
assert fast.multiply(a2, b2, dim) == holo.multiply(a2, b2, dim)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.parametrize("dim", [1, 2, 3])
|
|
45
|
+
def test_local_3tuple_matches_promoted_global(dim):
|
|
46
|
+
"""(sign, local_index, eps=1) must equal (sign, local_index + half)."""
|
|
47
|
+
fast, holo = FastDual(), DualHolographic()
|
|
48
|
+
half = 1 << dim
|
|
49
|
+
for loc in range(half):
|
|
50
|
+
for j in range(half << 1):
|
|
51
|
+
for engine in (fast, holo):
|
|
52
|
+
assert engine.multiply((1, loc, 1), (1, j), dim) == \
|
|
53
|
+
engine.multiply((1, loc + half), (1, j), dim)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# ---------- facade routes, including the path that crashed ----------
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize("engine", ["fast", "holographic"])
|
|
59
|
+
def test_facade_dual_both_engines(engine):
|
|
60
|
+
assert multiply("dual", (1, 3), (1, 5), dim=3, engine=engine) == \
|
|
61
|
+
multiply("dual", (1, 3), (1, 5), dim=3, engine="fast")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_facade_dual_3tuple_promotion():
|
|
65
|
+
half = 1 << 3
|
|
66
|
+
for engine in ("fast", "holographic"):
|
|
67
|
+
assert multiply("dual", (1, 2, 1), (1, 1), dim=3, engine=engine) == \
|
|
68
|
+
multiply("dual", (1, 2 + half), (1, 1), dim=3, engine=engine)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# ---------- zero handling: validated, shape-correct, convention documented ----------
|
|
72
|
+
|
|
73
|
+
def test_facade_zero_shapes():
|
|
74
|
+
assert multiply("dual", (0, 2), (1, 3), dim=2) == (0, 0, 0)
|
|
75
|
+
assert multiply("dual_split", (1, 2), (0, 3), dim=2) == (0, 0, 0)
|
|
76
|
+
assert multiply("standard", (0, 2), (1, 3), dim=2) == (0, 0) # formal zero
|
|
77
|
+
assert multiply("split", (0, 2), (1, 3), dim=2) == (0, 0)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_facade_malformed_raises_validation_error():
|
|
81
|
+
with pytest.raises((TypeError, ValueError)):
|
|
82
|
+
multiply("dual", 5, (1, 1), dim=2) # not a tuple
|
|
83
|
+
with pytest.raises((TypeError, ValueError)):
|
|
84
|
+
multiply("standard", (1, 2, 3, 4), (1, 1)) # wrong arity
|
|
85
|
+
|
|
86
|
+
# ---------- nilpotency still intact ----------
|
|
87
|
+
|
|
88
|
+
@pytest.mark.parametrize("engine", ["fast", "holographic"])
|
|
89
|
+
def test_nilpotency(engine):
|
|
90
|
+
assert multiply("dual", (1, 1), (1, 1), dim=0, engine=engine) == (0, 0, 0)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/fast/fast_split.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/__init__.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/split.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/holographic/standard.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/__init__.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/common.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/dual.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/split.py
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/core/table_builder/standard.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex/printer/cd_table_printer.py
RENAMED
|
File without changes
|
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/requires.txt
RENAMED
|
File without changes
|
{hypercomplex_engine-0.4.0 → hypercomplex_engine-0.4.1}/hypercomplex_engine.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|