hypercomplex-engine 0.4.2.7__tar.gz → 0.6.0__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.2.7/hypercomplex_engine.egg-info → hypercomplex_engine-0.6.0}/PKG-INFO +3 -1
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/README.md +1 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/__init__.py +5 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/__init__.py +6 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/fast/bit_utils.py +3 -1
- hypercomplex_engine-0.6.0/hypercomplex_engine/core/fast/fast_dual.py +60 -0
- hypercomplex_engine-0.6.0/hypercomplex_engine/core/holographic/dual.py +50 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/validation.py +6 -6
- hypercomplex_engine-0.6.0/hypercomplex_engine/core/vectorized/__init__.py +6 -0
- hypercomplex_engine-0.6.0/hypercomplex_engine/core/vectorized/vectorized_standard.py +118 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/facade.py +3 -32
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0/hypercomplex_engine.egg-info}/PKG-INFO +3 -1
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine.egg-info/SOURCES.txt +6 -1
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/pyproject.toml +2 -1
- hypercomplex_engine-0.6.0/tests/test_dual_tuple_regression.py +55 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/tests/test_fast_mode.py +19 -9
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/tests/test_fixes_0_4.py +0 -17
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/tests/test_mega_mother.py +6 -6
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/tests/test_split_dim.py +0 -4
- hypercomplex_engine-0.6.0/tests/test_strict_dual_3tuple.py +143 -0
- hypercomplex_engine-0.6.0/tests/test_vectorized_extended.py +420 -0
- hypercomplex_engine-0.6.0/tests/test_vectorized_standard.py +156 -0
- hypercomplex_engine-0.4.2.7/hypercomplex_engine/core/fast/fast_dual.py +0 -188
- hypercomplex_engine-0.4.2.7/hypercomplex_engine/core/holographic/dual.py +0 -90
- hypercomplex_engine-0.4.2.7/tests/test_dual_tuple_regression.py +0 -93
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/LICENSE +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/NOTICE +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/basis_element.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/basis_notation.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/fast/__init__.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/fast/fast_split.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/fast/fast_standard.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/holographic/__init__.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/holographic/split.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/holographic/standard.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/table_builder/__init__.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/table_builder/common.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/table_builder/dual.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/table_builder/split.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/table_builder/standard.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/printer/__init__.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/printer/cd_format.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/printer/cd_table_printer.py +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine.egg-info/dependency_links.txt +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine.egg-info/requires.txt +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine.egg-info/top_level.txt +0 -0
- {hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/setup.cfg +0 -0
{hypercomplex_engine-0.4.2.7/hypercomplex_engine.egg-info → hypercomplex_engine-0.6.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hypercomplex-engine
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Fast O(1)/O(n) multiplication engine for arbitrary dimensions 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-Expression: Apache-2.0
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
22
|
Classifier: Operating System :: OS Independent
|
|
22
23
|
Requires-Python: >=3.10
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
@@ -1123,6 +1124,7 @@ doi = "10.6084/m9.figshare.33705022.v8"
|
|
|
1123
1124
|
|
|
1124
1125
|
```
|
|
1125
1126
|
|
|
1127
|
+
|
|
1126
1128
|
### Acknowledgments
|
|
1127
1129
|
|
|
1128
1130
|
The author gratefully acknowledges **Prof. Derek Abbott**, **Dr. James M. Chappell**, and PhD candidate **Greg P. Wilmot** from the University of Adelaide, Australia, for the opportunity of collaboration and a deeper study of hypercomplex numbers. Special thanks go to **Greg P. Wilmot** for his work on the structure of Cayley-Dickson algebras and for acknowledging the author's contribution to his paper, *"Structure of the Cayley-Dickson algebras"* ([arXiv:2505.11747](https://arxiv.org)).
|
|
@@ -1095,6 +1095,7 @@ doi = "10.6084/m9.figshare.33705022.v8"
|
|
|
1095
1095
|
|
|
1096
1096
|
```
|
|
1097
1097
|
|
|
1098
|
+
|
|
1098
1099
|
### Acknowledgments
|
|
1099
1100
|
|
|
1100
1101
|
The author gratefully acknowledges **Prof. Derek Abbott**, **Dr. James M. Chappell**, and PhD candidate **Greg P. Wilmot** from the University of Adelaide, Australia, for the opportunity of collaboration and a deeper study of hypercomplex numbers. Special thanks go to **Greg P. Wilmot** for his work on the structure of Cayley-Dickson algebras and for acknowledging the author's contribution to his paper, *"Structure of the Cayley-Dickson algebras"* ([arXiv:2505.11747](https://arxiv.org)).
|
|
@@ -29,6 +29,8 @@ from .core import (
|
|
|
29
29
|
FastStandard,
|
|
30
30
|
FastSplit,
|
|
31
31
|
FastDual,
|
|
32
|
+
|
|
33
|
+
VectorizedStandard
|
|
32
34
|
)
|
|
33
35
|
|
|
34
36
|
from .printer import (
|
|
@@ -65,6 +67,9 @@ __all__ = [
|
|
|
65
67
|
"FastSplit",
|
|
66
68
|
"FastDual",
|
|
67
69
|
|
|
70
|
+
#VectorizedStandard
|
|
71
|
+
"VectorizedStandard"
|
|
72
|
+
|
|
68
73
|
# Printer / formatter
|
|
69
74
|
"CDFormat",
|
|
70
75
|
"CDTablePrinter",
|
{hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/__init__.py
RENAMED
|
@@ -20,6 +20,10 @@ from .fast import (
|
|
|
20
20
|
FastDual,
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
+
from .vectorized import (
|
|
24
|
+
VectorizedStandard
|
|
25
|
+
)
|
|
26
|
+
|
|
23
27
|
__all__ = [
|
|
24
28
|
"BasisElement",
|
|
25
29
|
"BasisNotation",
|
|
@@ -36,4 +40,6 @@ __all__ = [
|
|
|
36
40
|
"FastStandard",
|
|
37
41
|
"FastSplit",
|
|
38
42
|
"FastDual",
|
|
43
|
+
|
|
44
|
+
"VectorizedStandard",
|
|
39
45
|
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from ..validation import Validation
|
|
2
|
+
from .fast_standard import FastStandard
|
|
3
|
+
from .fast_split import FastSplit
|
|
4
|
+
|
|
5
|
+
class FastDual:
|
|
6
|
+
"""
|
|
7
|
+
Dual Cayley-Dickson O(1) multiplier.
|
|
8
|
+
|
|
9
|
+
STRICT 3-TUPLE INPUT:
|
|
10
|
+
(sign, local_index, eps_flag)
|
|
11
|
+
|
|
12
|
+
local_index must be strictly < 2^dim.
|
|
13
|
+
eps_flag must be 0 or 1.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, split: bool = False):
|
|
17
|
+
self._split_mode = bool(split)
|
|
18
|
+
self._standard = FastStandard()
|
|
19
|
+
self._split = FastSplit() if self._split_mode else None
|
|
20
|
+
|
|
21
|
+
def multiply(self, t1: tuple, t2: tuple, dim: int) -> tuple:
|
|
22
|
+
dim = Validation.dimension(dim)
|
|
23
|
+
Validation.basis_tuple(t1, allow_zero=True, allow_eps=True)
|
|
24
|
+
Validation.basis_tuple(t2, allow_zero=True, allow_eps=True)
|
|
25
|
+
|
|
26
|
+
# STRICT 3-TUPLE UNPACKING
|
|
27
|
+
s1, i, i_eps = int(t1[0]), int(t1[1]), int(t1[2])
|
|
28
|
+
s2, j, j_eps = int(t2[0]), int(t2[1]), int(t2[2])
|
|
29
|
+
|
|
30
|
+
if s1 == 0 or s2 == 0:
|
|
31
|
+
return (0, 0, 0)
|
|
32
|
+
|
|
33
|
+
sign, idx, eps = self.multiply_indices(i, j, dim, i_eps, j_eps)
|
|
34
|
+
return (s1 * s2 * sign, idx, eps)
|
|
35
|
+
|
|
36
|
+
def multiply_indices(self, i: int, j: int, dim: int, i_eps_flag: int = 0, j_eps_flag: int = 0) -> tuple:
|
|
37
|
+
dim = Validation.dimension(dim)
|
|
38
|
+
half = 1 << dim
|
|
39
|
+
|
|
40
|
+
# STRICT LOCAL ENFORCEMENT: No more global overflow!
|
|
41
|
+
if i < 0 or i >= half:
|
|
42
|
+
raise ValueError(f"local index must be in [0, {half - 1}] for dual dim={dim}, got {i}")
|
|
43
|
+
if j < 0 or j >= half:
|
|
44
|
+
raise ValueError(f"local index must be in [0, {half - 1}] for dual dim={dim}, got {j}")
|
|
45
|
+
|
|
46
|
+
i_eps = bool(i_eps_flag)
|
|
47
|
+
j_eps = bool(j_eps_flag)
|
|
48
|
+
|
|
49
|
+
# Nilpotency: eps^2 = 0
|
|
50
|
+
if i_eps and j_eps:
|
|
51
|
+
return (0, 0, 0)
|
|
52
|
+
|
|
53
|
+
# Base multiplication (parent algebra)
|
|
54
|
+
if self._split_mode:
|
|
55
|
+
base_sign, local_idx = self._split.multiply_indices(i, j, dim)
|
|
56
|
+
else:
|
|
57
|
+
base_sign, local_idx = self._standard.multiply_indices(i, j)
|
|
58
|
+
|
|
59
|
+
eps_flag = 1 if (i_eps or j_eps) else 0
|
|
60
|
+
return (base_sign, local_idx, eps_flag)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from ..validation import Validation
|
|
2
|
+
from .standard import StandardHolographic
|
|
3
|
+
from .split import SplitHolographic
|
|
4
|
+
|
|
5
|
+
class DualHolographic:
|
|
6
|
+
"""
|
|
7
|
+
Dual Cayley-Dickson holographic multiplier.
|
|
8
|
+
STRICT 3-TUPLE INPUT: (sign, local_index, eps_flag)
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, split: bool = False):
|
|
12
|
+
self._split_mode = bool(split)
|
|
13
|
+
self._standard = StandardHolographic()
|
|
14
|
+
self._split = SplitHolographic() if self._split_mode else None
|
|
15
|
+
|
|
16
|
+
def multiply(self, t1: tuple, t2: tuple, dim: int) -> tuple:
|
|
17
|
+
Validation.basis_tuple(t1, allow_zero=True, allow_eps=True)
|
|
18
|
+
Validation.basis_tuple(t2, allow_zero=True, allow_eps=True)
|
|
19
|
+
dim = Validation.dimension(dim)
|
|
20
|
+
|
|
21
|
+
# STRICT 3-TUPLE UNPACKING
|
|
22
|
+
s1, i, i_eps_flag = int(t1[0]), int(t1[1]), int(t1[2])
|
|
23
|
+
s2, j, j_eps_flag = int(t2[0]), int(t2[1]), int(t2[2])
|
|
24
|
+
|
|
25
|
+
if s1 == 0 or s2 == 0:
|
|
26
|
+
return (0, 0, 0)
|
|
27
|
+
|
|
28
|
+
half = 1 << dim
|
|
29
|
+
|
|
30
|
+
# STRICT LOCAL ENFORCEMENT
|
|
31
|
+
if i < 0 or i >= half:
|
|
32
|
+
raise ValueError(f"local index must be in [0, {half - 1}] for dual dim={dim}, got {i}")
|
|
33
|
+
if j < 0 or j >= half:
|
|
34
|
+
raise ValueError(f"local index must be in [0, {half - 1}] for dual dim={dim}, got {j}")
|
|
35
|
+
|
|
36
|
+
i_eps = bool(i_eps_flag)
|
|
37
|
+
j_eps = bool(j_eps_flag)
|
|
38
|
+
|
|
39
|
+
# Nilpotency
|
|
40
|
+
if i_eps and j_eps:
|
|
41
|
+
return (0, 0, 0)
|
|
42
|
+
|
|
43
|
+
# Base multiplication
|
|
44
|
+
if self._split_mode:
|
|
45
|
+
base_sign, local_idx = self._split.multiply_indices(i, j, dim)
|
|
46
|
+
else:
|
|
47
|
+
base_sign, local_idx = self._standard.multiply_indices(i, j)
|
|
48
|
+
|
|
49
|
+
eps_flag = 1 if (i_eps or j_eps) else 0
|
|
50
|
+
return (s1 * s2 * base_sign, local_idx, eps_flag)
|
{hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine/core/validation.py
RENAMED
|
@@ -54,12 +54,12 @@ class Validation:
|
|
|
54
54
|
if not isinstance(data, tuple):
|
|
55
55
|
raise TypeError(f"Expected tuple, got {type(data).__name__}")
|
|
56
56
|
|
|
57
|
-
if
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if allow_eps:
|
|
58
|
+
if len(data) != 3:
|
|
59
|
+
raise ValueError(f"Dual basis tuple must have length 3 (sign, index, eps), got {len(data)}")
|
|
60
|
+
else:
|
|
61
|
+
if len(data) != 2:
|
|
62
|
+
raise ValueError(f"Standard/Split basis tuple must have length 2 (sign, index), got {len(data)}")
|
|
63
63
|
|
|
64
64
|
sign = data[0]
|
|
65
65
|
index = data[1]
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from ..validation import Validation
|
|
3
|
+
|
|
4
|
+
class VectorizedStandard:
|
|
5
|
+
"""
|
|
6
|
+
SIMD-Accelerated O(1) Vectorized Multiplier for Standard Cayley-Dickson Algebras.
|
|
7
|
+
Replaces nested Python loops with C-Level Twisted Convolution via Scatter-Add.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def _get_np_popcount():
|
|
12
|
+
"""Hardware-accelerated popcount for NumPy arrays."""
|
|
13
|
+
try:
|
|
14
|
+
return np.bitwise_count
|
|
15
|
+
except AttributeError:
|
|
16
|
+
def popcount_vec(x):
|
|
17
|
+
x = np.asarray(x, dtype=np.uint64)
|
|
18
|
+
x = x - ((x >> 1) & np.uint64(0x5555555555555555))
|
|
19
|
+
x = (x & np.uint64(0x3333333333333333)) + ((x >> 2) & np.uint64(0x3333333333333333))
|
|
20
|
+
x = (x + (x >> 4)) & np.uint64(0x0F0F0F0F0F0F0F0F)
|
|
21
|
+
return ((x * np.uint64(0x0101010101010101)) >> np.uint64(56)).astype(np.uint8)
|
|
22
|
+
return popcount_vec
|
|
23
|
+
|
|
24
|
+
def multiply_indices_vec(self, i_arr: np.ndarray, j_arr: np.ndarray) -> tuple:
|
|
25
|
+
"""
|
|
26
|
+
Vectorized Core O(1) multiplication for arrays of indices.
|
|
27
|
+
Returns: (signs_array, indices_array)
|
|
28
|
+
"""
|
|
29
|
+
_popcount = self._get_np_popcount()
|
|
30
|
+
i = np.asarray(i_arr, dtype=np.uint64)
|
|
31
|
+
j = np.asarray(j_arr, dtype=np.uint64)
|
|
32
|
+
|
|
33
|
+
# Target index is always XOR
|
|
34
|
+
idx = i ^ j
|
|
35
|
+
|
|
36
|
+
# Masks for structural cases
|
|
37
|
+
mask_zero = (i == 0) | (j == 0)
|
|
38
|
+
mask_diag = (i == j) & ~mask_zero
|
|
39
|
+
|
|
40
|
+
# Safe guards for nu2 (avoid log2(0) or popcount(-1) issues)
|
|
41
|
+
i_safe = np.where(i == 0, 1, i)
|
|
42
|
+
j_safe = np.where(j == 0, 1, j)
|
|
43
|
+
ij_safe = np.where((i ^ j) == 0, 1, i ^ j)
|
|
44
|
+
|
|
45
|
+
# Vectorized nu2: popcount((x & -x) - 1)
|
|
46
|
+
t = _popcount((ij_safe & -ij_safe) - np.uint64(1)).astype(np.uint64)
|
|
47
|
+
ti = _popcount((i_safe & -i_safe) - np.uint64(1)).astype(np.uint64)
|
|
48
|
+
tj = _popcount((j_safe & -j_safe) - np.uint64(1)).astype(np.uint64)
|
|
49
|
+
|
|
50
|
+
# Branch 1: Diagonal break (t >= ti and t >= tj)
|
|
51
|
+
cond1 = (t >= ti) & (t >= tj)
|
|
52
|
+
s1 = 2 * ((i >> t) & np.uint64(1)).astype(np.int8) - 1
|
|
53
|
+
|
|
54
|
+
# Branch 2: i-axis break (ti > t and ti >= tj)
|
|
55
|
+
cond2 = (~cond1) & (ti >= tj)
|
|
56
|
+
b = (j >> ti) & np.uint64(1)
|
|
57
|
+
j_loc = j & ((np.uint64(1) << ti) - np.uint64(1))
|
|
58
|
+
delta = np.where(j_loc == 0, 1, -1).astype(np.int8)
|
|
59
|
+
s2 = np.where(b == 0, delta, -delta)
|
|
60
|
+
|
|
61
|
+
# Branch 3: j-axis break (tj > t and tj > ti)
|
|
62
|
+
cond3 = ~cond1 & ~cond2
|
|
63
|
+
s3 = 1 - 2 * ((i >> tj) & np.uint64(1)).astype(np.int8)
|
|
64
|
+
|
|
65
|
+
# Combine branches
|
|
66
|
+
s = np.where(cond1, s1, np.where(cond2, s2, s3))
|
|
67
|
+
|
|
68
|
+
# Higher-bit parity correction
|
|
69
|
+
k = np.maximum(np.maximum(t, ti), tj) + np.uint64(1)
|
|
70
|
+
parity = _popcount((i | j) >> k) & np.uint8(1)
|
|
71
|
+
s = np.where(parity == 1, -s, s)
|
|
72
|
+
|
|
73
|
+
# Apply structural overrides
|
|
74
|
+
s = np.where(mask_zero, 1, s)
|
|
75
|
+
s = np.where(mask_diag, -1, s)
|
|
76
|
+
|
|
77
|
+
return s.astype(np.int8), idx
|
|
78
|
+
|
|
79
|
+
def multiply_arrays(self, arr1: np.ndarray, arr2: np.ndarray) -> np.ndarray:
|
|
80
|
+
"""
|
|
81
|
+
Full polynomial multiplication using Twisted Convolution via C-Level Scatter-Add.
|
|
82
|
+
Automatically handles sparsity to prevent RAM explosion on high dimensions.
|
|
83
|
+
"""
|
|
84
|
+
size1 = len(arr1)
|
|
85
|
+
size2 = len(arr2)
|
|
86
|
+
max_size = max(size1, size2)
|
|
87
|
+
|
|
88
|
+
if max_size <= 1:
|
|
89
|
+
return np.array([arr1[0] * arr2[0]], dtype=np.float64) if size1 > 0 and size2 > 0 else np.zeros(1, dtype=np.float64)
|
|
90
|
+
|
|
91
|
+
# Calculate required power-of-two dimension
|
|
92
|
+
# Equivalent to 1 << math.ceil(math.log2(max_size))
|
|
93
|
+
dim = 1 << (max_size - 1).bit_length()
|
|
94
|
+
|
|
95
|
+
# 1. SPARSE OPTIMIZATION: Isolate non-zero elements
|
|
96
|
+
nz_A = np.nonzero(arr1)[0]
|
|
97
|
+
nz_B = np.nonzero(arr2)[0]
|
|
98
|
+
|
|
99
|
+
if len(nz_A) == 0 or len(nz_B) == 0:
|
|
100
|
+
return np.zeros(dim, dtype=np.float64)
|
|
101
|
+
|
|
102
|
+
# 2. Create the 2D Grid of ONLY the active indices
|
|
103
|
+
I, J = np.meshgrid(nz_A, nz_B, indexing='ij')
|
|
104
|
+
|
|
105
|
+
# 3. Calculate the entire Sign and Index Matrix in one C-level SIMD sweep
|
|
106
|
+
S, V = self.multiply_indices_vec(I, J)
|
|
107
|
+
|
|
108
|
+
# 4. Calculate the Outer Product of ONLY the active coefficients
|
|
109
|
+
M = np.outer(arr1[nz_A], arr2[nz_B])
|
|
110
|
+
|
|
111
|
+
# 5. Apply Signs to the Coefficients
|
|
112
|
+
weighted_M = S.astype(np.float64) * M
|
|
113
|
+
|
|
114
|
+
# 6. C-Level Scatter-Add into the Result Array
|
|
115
|
+
result = np.zeros(dim, dtype=np.float64)
|
|
116
|
+
np.add.at(result, V.ravel(), weighted_M.ravel())
|
|
117
|
+
|
|
118
|
+
return result
|
|
@@ -126,33 +126,6 @@ def _unpack_table(table):
|
|
|
126
126
|
)
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
def _as_dual_global(t: tuple, dim: int) -> tuple:
|
|
130
|
-
"""
|
|
131
|
-
Converts a dual input tuple into a global 2-tuple.
|
|
132
|
-
|
|
133
|
-
Accepts:
|
|
134
|
-
(sign, global_index)
|
|
135
|
-
(sign, local_index, eps_flag)
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
(sign, global_index)
|
|
139
|
-
"""
|
|
140
|
-
sign = int(t[0])
|
|
141
|
-
idx = int(t[1])
|
|
142
|
-
|
|
143
|
-
if sign == 0:
|
|
144
|
-
return (0, 0)
|
|
145
|
-
|
|
146
|
-
half = 1 << Validation.dimension(dim)
|
|
147
|
-
|
|
148
|
-
if len(t) >= 3:
|
|
149
|
-
eps = int(t[2])
|
|
150
|
-
|
|
151
|
-
if eps == 1 and idx < half:
|
|
152
|
-
idx += half
|
|
153
|
-
|
|
154
|
-
return (sign, idx)
|
|
155
|
-
|
|
156
129
|
|
|
157
130
|
# ----------------------------------------------------------------------
|
|
158
131
|
# Public simple API
|
|
@@ -280,11 +253,9 @@ def multiply(
|
|
|
280
253
|
return (0, 0, 0)
|
|
281
254
|
return (0, 0)
|
|
282
255
|
|
|
283
|
-
# Dual inputs
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
b = _as_dual_global(b, dim)
|
|
287
|
-
|
|
256
|
+
# Dual inputs are strictly local 3-tuples: (sign, local_index, eps_flag).
|
|
257
|
+
# We pass them directly to the engines. No global overflow conversion needed.
|
|
258
|
+
|
|
288
259
|
# ------------------------------------------------------------------
|
|
289
260
|
# O(1) engine
|
|
290
261
|
# ------------------------------------------------------------------
|
{hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0/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.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Fast O(1)/O(n) multiplication engine for arbitrary dimensions 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-Expression: Apache-2.0
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
22
|
Classifier: Operating System :: OS Independent
|
|
22
23
|
Requires-Python: >=3.10
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
@@ -1123,6 +1124,7 @@ doi = "10.6084/m9.figshare.33705022.v8"
|
|
|
1123
1124
|
|
|
1124
1125
|
```
|
|
1125
1126
|
|
|
1127
|
+
|
|
1126
1128
|
### Acknowledgments
|
|
1127
1129
|
|
|
1128
1130
|
The author gratefully acknowledges **Prof. Derek Abbott**, **Dr. James M. Chappell**, and PhD candidate **Greg P. Wilmot** from the University of Adelaide, Australia, for the opportunity of collaboration and a deeper study of hypercomplex numbers. Special thanks go to **Greg P. Wilmot** for his work on the structure of Cayley-Dickson algebras and for acknowledging the author's contribution to his paper, *"Structure of the Cayley-Dickson algebras"* ([arXiv:2505.11747](https://arxiv.org)).
|
{hypercomplex_engine-0.4.2.7 → hypercomplex_engine-0.6.0}/hypercomplex_engine.egg-info/SOURCES.txt
RENAMED
|
@@ -27,6 +27,8 @@ hypercomplex_engine/core/table_builder/common.py
|
|
|
27
27
|
hypercomplex_engine/core/table_builder/dual.py
|
|
28
28
|
hypercomplex_engine/core/table_builder/split.py
|
|
29
29
|
hypercomplex_engine/core/table_builder/standard.py
|
|
30
|
+
hypercomplex_engine/core/vectorized/__init__.py
|
|
31
|
+
hypercomplex_engine/core/vectorized/vectorized_standard.py
|
|
30
32
|
hypercomplex_engine/printer/__init__.py
|
|
31
33
|
hypercomplex_engine/printer/cd_format.py
|
|
32
34
|
hypercomplex_engine/printer/cd_table_printer.py
|
|
@@ -34,4 +36,7 @@ tests/test_dual_tuple_regression.py
|
|
|
34
36
|
tests/test_fast_mode.py
|
|
35
37
|
tests/test_fixes_0_4.py
|
|
36
38
|
tests/test_mega_mother.py
|
|
37
|
-
tests/test_split_dim.py
|
|
39
|
+
tests/test_split_dim.py
|
|
40
|
+
tests/test_strict_dual_3tuple.py
|
|
41
|
+
tests/test_vectorized_extended.py
|
|
42
|
+
tests/test_vectorized_standard.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "hypercomplex-engine"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Maher Ben Abdessalem", email="ba.maher94@gmail.com" },
|
|
10
10
|
]
|
|
@@ -31,6 +31,7 @@ classifiers = [
|
|
|
31
31
|
"Programming Language :: Python :: 3.12",
|
|
32
32
|
"Programming Language :: Python :: 3.13",
|
|
33
33
|
"Programming Language :: Python :: 3.14",
|
|
34
|
+
"Programming Language :: Python :: 3.15",
|
|
34
35
|
"Operating System :: OS Independent",
|
|
35
36
|
]
|
|
36
37
|
|
|
@@ -0,0 +1,55 @@
|
|
|
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_engine import multiply, FastDual, DualHolographic
|
|
16
|
+
from hypercomplex_engine.core.validation import Validation
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# ---------- facade routes, including the path that crashed ----------
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize("engine", ["fast", "holographic"])
|
|
27
|
+
def test_facade_dual_both_engines(engine):
|
|
28
|
+
assert multiply("dual", (1, 3,0), (1, 5,0), dim=3, engine=engine) == \
|
|
29
|
+
multiply("dual", (1, 3,0), (1, 5,0), dim=3, engine="fast")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# ---------- zero handling: validated, shape-correct, convention documented ----------
|
|
35
|
+
|
|
36
|
+
def test_facade_zero_shapes():
|
|
37
|
+
assert multiply("dual", (0, 2, 0), (1, 3, 0), dim=2) == (0, 0, 0)
|
|
38
|
+
assert multiply("dual_split", (1, 2, 0), (0, 3, 0), dim=2) == (0, 0, 0)
|
|
39
|
+
with pytest.raises((TypeError, ValueError)):
|
|
40
|
+
assert multiply("standard", (0, 2, 0), (1, 3, 0), dim=2) == (0, 0)
|
|
41
|
+
with pytest.raises((TypeError, ValueError)): # formal zero
|
|
42
|
+
assert multiply("split", (0, 2, 0), (1, 3, 0), dim=2) == (0, 0)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_facade_malformed_raises_validation_error():
|
|
46
|
+
with pytest.raises((TypeError, ValueError)):
|
|
47
|
+
multiply("dual", 5, (1, 1), dim=2) # not a tuple
|
|
48
|
+
with pytest.raises((TypeError, ValueError)):
|
|
49
|
+
multiply("standard", (1, 2, 3, 4), (1, 1)) # wrong arity
|
|
50
|
+
|
|
51
|
+
# ---------- nilpotency still intact ----------
|
|
52
|
+
|
|
53
|
+
@pytest.mark.parametrize("engine", ["fast", "holographic"])
|
|
54
|
+
def test_nilpotency(engine):
|
|
55
|
+
assert multiply("dual", (1, 0,1), (1, 0,1), dim=0, engine=engine) == (0, 0, 0)
|
|
@@ -111,7 +111,7 @@ class TestFastDual:
|
|
|
111
111
|
fast = FastDual(split=False)
|
|
112
112
|
|
|
113
113
|
# eps*e0 has global index 2 when dim=1
|
|
114
|
-
result = fast.multiply((1,
|
|
114
|
+
result = fast.multiply((1, 0, 1), (1, 0, 1), dim=1)
|
|
115
115
|
|
|
116
116
|
assert result == (0, 0, 0)
|
|
117
117
|
|
|
@@ -119,7 +119,7 @@ class TestFastDual:
|
|
|
119
119
|
fast = FastDual(split=False)
|
|
120
120
|
|
|
121
121
|
# e1 * e1 = -e0
|
|
122
|
-
result = fast.multiply((1, 1), (1, 1), dim=1)
|
|
122
|
+
result = fast.multiply((1, 1, 0), (1, 1, 0), dim=1)
|
|
123
123
|
|
|
124
124
|
assert result == (-1, 0, 0)
|
|
125
125
|
|
|
@@ -127,7 +127,7 @@ class TestFastDual:
|
|
|
127
127
|
fast = FastDual(split=False)
|
|
128
128
|
|
|
129
129
|
# e0 * (eps*e0) = eps*e0
|
|
130
|
-
result = fast.multiply((1, 0), (1,
|
|
130
|
+
result = fast.multiply((1, 0, 0), (1, 0,1), dim=1)
|
|
131
131
|
|
|
132
132
|
assert result == (1, 0, 1)
|
|
133
133
|
|
|
@@ -137,7 +137,7 @@ class TestFastDual:
|
|
|
137
137
|
# local tuple: (sign, local_index, eps_flag)
|
|
138
138
|
eps_e0 = (1, 0, 1)
|
|
139
139
|
|
|
140
|
-
result = fast.multiply((1, 0), eps_e0, dim=1)
|
|
140
|
+
result = fast.multiply((1, 0, 0), eps_e0, dim=1)
|
|
141
141
|
|
|
142
142
|
assert result == (1, 0, 1)
|
|
143
143
|
|
|
@@ -151,10 +151,20 @@ class TestFastDual:
|
|
|
151
151
|
signs, indices, eps = builder.build(dim, split=split)
|
|
152
152
|
|
|
153
153
|
total = 1 << (dim + 1)
|
|
154
|
-
|
|
154
|
+
half = 1 << (dim)
|
|
155
155
|
for i in range(total):
|
|
156
156
|
for j in range(total):
|
|
157
|
-
|
|
157
|
+
i_eps=0
|
|
158
|
+
j_eps=0
|
|
159
|
+
a = i
|
|
160
|
+
b = j
|
|
161
|
+
if(i>half-1):
|
|
162
|
+
a= i - half
|
|
163
|
+
i_eps=1
|
|
164
|
+
if(j>half-1):
|
|
165
|
+
b= j - half
|
|
166
|
+
j_eps = 1
|
|
167
|
+
s, idx, e = fast.multiply_indices(a, b, dim,i_eps,j_eps)
|
|
158
168
|
|
|
159
169
|
assert int(signs[i, j]) == s, \
|
|
160
170
|
f"Dual O(1) sign mismatch split={split}, ({i},{j})"
|
|
@@ -179,19 +189,19 @@ class TestFacadefast:
|
|
|
179
189
|
assert multiply("split", (1, 1), (1, 1), dim=1, engine="fast") == (1, 0)
|
|
180
190
|
|
|
181
191
|
def test_dual(self):
|
|
182
|
-
result = multiply("dual", (1, 1), (1, 1), dim=1, engine="fast")
|
|
192
|
+
result = multiply("dual", (1, 1, 0), (1, 1, 0), dim=1, engine="fast")
|
|
183
193
|
assert result == (-1, 0, 0)
|
|
184
194
|
|
|
185
195
|
def test_dual_local_tuple_chaining(self):
|
|
186
196
|
# eps*e0 as local tuple
|
|
187
197
|
eps_e0 = (1, 0, 1)
|
|
188
198
|
|
|
189
|
-
result = multiply("dual", (1, 0), eps_e0, dim=1, engine="fast")
|
|
199
|
+
result = multiply("dual", (1, 0, 0), eps_e0, dim=1, engine="fast")
|
|
190
200
|
|
|
191
201
|
assert result == (1, 0, 1)
|
|
192
202
|
|
|
193
203
|
# Now reuse result directly
|
|
194
|
-
result2 = multiply("dual", result, (1, 0), dim=1, engine="fast")
|
|
204
|
+
result2 = multiply("dual", result, (1, 0, 0), dim=1, engine="fast")
|
|
195
205
|
|
|
196
206
|
assert result2 == (1, 0, 1)
|
|
197
207
|
|
|
@@ -16,23 +16,6 @@ from hypercomplex_engine import (
|
|
|
16
16
|
|
|
17
17
|
# --- 1. dual nilpotency: one canonical zero across every engine -----------
|
|
18
18
|
|
|
19
|
-
@pytest.mark.parametrize("split", [False, True])
|
|
20
|
-
@pytest.mark.parametrize("n", [1, 2, 3])
|
|
21
|
-
def test_dual_engines_agree_everywhere(n, split):
|
|
22
|
-
fast = FastDual(split=split)
|
|
23
|
-
holo = DualHolographic(split=split)
|
|
24
|
-
signs, indices, eps = DualTableBuilder().build(n, split=split)
|
|
25
|
-
size = 1 << (n + 1)
|
|
26
|
-
|
|
27
|
-
for i, j in itertools.product(range(size), repeat=2):
|
|
28
|
-
f = tuple(fast.multiply((1, i), (1, j), dim=n))
|
|
29
|
-
h = tuple(holo.multiply((1, i), (1, j), dim=n))
|
|
30
|
-
assert f == h, (i, j, f, h)
|
|
31
|
-
|
|
32
|
-
if signs[i, j] == 0:
|
|
33
|
-
assert f == (0, 0, 0)
|
|
34
|
-
else:
|
|
35
|
-
assert f == (int(signs[i, j]), int(indices[i, j]), int(eps[i, j]))
|
|
36
19
|
|
|
37
20
|
|
|
38
21
|
@pytest.mark.parametrize("kind", ["dual", "dual_split"])
|
|
@@ -262,24 +262,24 @@ class TestDualHolographic:
|
|
|
262
262
|
|
|
263
263
|
def test_nilpotency(self):
|
|
264
264
|
holo = DualHolographic(split=False)
|
|
265
|
-
result = holo.multiply((1, 1), (1, 1), dim=0)
|
|
265
|
+
result = holo.multiply((1, 0, 1), (1, 0, 1), dim=0)
|
|
266
266
|
assert result[0] == 0 # zero element
|
|
267
267
|
|
|
268
268
|
def test_base_product_no_eps(self):
|
|
269
269
|
holo = DualHolographic(split=False)
|
|
270
|
-
result = holo.multiply((1, 1), (1, 1), dim=1)
|
|
270
|
+
result = holo.multiply((1, 1, 0), (1, 1, 0), dim=1)
|
|
271
271
|
assert result[0] == -1 # sign
|
|
272
272
|
assert result[2] == 0 # no epsilon
|
|
273
273
|
|
|
274
274
|
def test_one_eps_factor(self):
|
|
275
275
|
holo = DualHolographic(split=False)
|
|
276
276
|
# e0 * (eps*e0) = eps*e0
|
|
277
|
-
result = holo.multiply((1, 0), (1,
|
|
277
|
+
result = holo.multiply((1, 0, 0), (1, 1,1), dim=1)
|
|
278
278
|
assert result[2] == 1 # has epsilon
|
|
279
279
|
|
|
280
280
|
def test_zero_propagation(self):
|
|
281
281
|
holo = DualHolographic(split=False)
|
|
282
|
-
result = holo.multiply((0, 0), (1, 1), dim=1)
|
|
282
|
+
result = holo.multiply((0, 0,0), (1, 1,0), dim=1)
|
|
283
283
|
assert result[0] == 0
|
|
284
284
|
|
|
285
285
|
|
|
@@ -461,7 +461,7 @@ class TestFacade:
|
|
|
461
461
|
assert multiply("split", (1, 1), (1, 1), dim=1) == (1, 0)
|
|
462
462
|
|
|
463
463
|
def test_multiply_dual(self):
|
|
464
|
-
result = multiply("dual", (1, 1), (1, 1), dim=1)
|
|
464
|
+
result = multiply("dual", (1, 1, 0), (1, 1, 0), dim=1)
|
|
465
465
|
assert result[0] == -1
|
|
466
466
|
assert result[2] == 0
|
|
467
467
|
|
|
@@ -517,7 +517,7 @@ class TestEndToEnd:
|
|
|
517
517
|
|
|
518
518
|
def test_dual_nilpotency_workflow(self):
|
|
519
519
|
"""ε² = 0 in dual algebra."""
|
|
520
|
-
result = multiply("dual", (1,
|
|
520
|
+
result = multiply("dual", (1, 0, 1), (1, 0, 1), dim=2)
|
|
521
521
|
assert result[0] == 0
|
|
522
522
|
|
|
523
523
|
def test_notation_roundtrip_in_context(self):
|
|
@@ -23,10 +23,6 @@ def test_split_result_depends_on_dim(engine):
|
|
|
23
23
|
assert multiply("split", (1, 2), (1, 2), dim=dim, engine=engine) == (-1, 0)
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
@pytest.mark.parametrize("eps", [0, 1])
|
|
27
|
-
def test_split_rejects_epsilon_three_tuples_with_clear_message(eps):
|
|
28
|
-
with pytest.raises(ValueError, match="3-tuple"):
|
|
29
|
-
multiply("split", (1, 1, eps), (1, 2), dim=2)
|
|
30
26
|
|
|
31
27
|
|
|
32
28
|
def test_standard_needs_no_dim():
|