hypercomplex-engine 0.5.0__py3-none-any.whl → 0.6.0__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.
@@ -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",
@@ -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
  ]
@@ -17,4 +17,6 @@ def popcount(x: int) -> int:
17
17
  """
18
18
  Number of set bits.
19
19
  """
20
- return int(x).bit_count()
20
+ x=int(x)
21
+ return x.bit_count() if hasattr(x, "bit_count") else bin(x).count("1")
22
+
@@ -0,0 +1,6 @@
1
+ from .vectorized_standard import VectorizedStandard
2
+
3
+
4
+ __all__ = [
5
+ "VectorizedStandard"
6
+ ]
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypercomplex-engine
3
- Version: 0.5.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
@@ -1,11 +1,11 @@
1
- hypercomplex_engine/__init__.py,sha256=pwDbzzCLFaSqD_rsNVmgdZhylolIcEkDBJFEVstLMYE,1247
1
+ hypercomplex_engine/__init__.py,sha256=DWb_oW6Qvr3Js-1wvdTW7ox7aJP1ci_LPDZ5vK95VNM,1321
2
2
  hypercomplex_engine/facade.py,sha256=Rw0GyrZJMs1fkdZzLwwjIdZAvid4XmDGJEM-G7fOG_k,9192
3
- hypercomplex_engine/core/__init__.py,sha256=7cD5SJFbAewuVMIvKnQ6tb7JwcmpGQktSvGbN5n8dIM,668
3
+ hypercomplex_engine/core/__init__.py,sha256=VMszCgYLjMFSzcsdTPGnkJusM12iVow4aeazsPklWjU,747
4
4
  hypercomplex_engine/core/basis_element.py,sha256=TnPb1xLICv0TK0AfTW_I8_8T2TavktKTq4MEPLWnyU8,1402
5
5
  hypercomplex_engine/core/basis_notation.py,sha256=K17IUXEio7KmY3pvpFdDFI2MsLs11-E5Z5Cp10CS84Y,4887
6
6
  hypercomplex_engine/core/validation.py,sha256=VThGdXzESoiOO1y6Ios-GcEyHGdbi8V9_fMmEEExkqw,3245
7
7
  hypercomplex_engine/core/fast/__init__.py,sha256=6KsWo1dhNlT69jT_Bi8-khOrNFX9cDs98987TGTXo4w,173
8
- hypercomplex_engine/core/fast/bit_utils.py,sha256=aqBjPX2srWym6AjxZqTzt998-in_-5VAxNUiQXUFAVw,385
8
+ hypercomplex_engine/core/fast/bit_utils.py,sha256=U8jmGRKB8tymSyyhCMMwEL5Ap2vUfrZTDyrTutVrB8k,448
9
9
  hypercomplex_engine/core/fast/fast_dual.py,sha256=zQSMvXCNQgI_ZhmNEkds0_VbpNzFxS0476NfH2Qyfro,2098
10
10
  hypercomplex_engine/core/fast/fast_split.py,sha256=Wdr9pd9zXA_mFzlMxVv8LpPwDZJFP-XPVa0uQIEs3jA,3037
11
11
  hypercomplex_engine/core/fast/fast_standard.py,sha256=JQ7Mxb4qQTH6EuWQjpTtbxwb4rVI0Iu-jggHiwmEj1I,3250
@@ -18,12 +18,14 @@ hypercomplex_engine/core/table_builder/common.py,sha256=PEY_Vd0_tYrDJt5IOqEvrex3
18
18
  hypercomplex_engine/core/table_builder/dual.py,sha256=9flbYGsCnZeKMirS3JlDg__EqSv_LBA1M_JhWPQEWxw,2888
19
19
  hypercomplex_engine/core/table_builder/split.py,sha256=OUBNKT_-L6BMlCxiSYWzAOGSOdYGJZzLOR0Zo6R5Ubw,2923
20
20
  hypercomplex_engine/core/table_builder/standard.py,sha256=3kyg4TLCG_LKhC8lT95hZBFmOee0Wg39T7CDIhayVUs,2820
21
+ hypercomplex_engine/core/vectorized/__init__.py,sha256=NfwXNqe9n8acZaMTquuXH5BLB-fbmCUDvKAB5rcWrOE,92
22
+ hypercomplex_engine/core/vectorized/vectorized_standard.py,sha256=yCV48LvwrMZxg8Rc4UYLejg7uZxhoyjfknWxqfL3rwo,4656
21
23
  hypercomplex_engine/printer/__init__.py,sha256=6EZOUBYb9TDgfqrFpnIfPS1bbPFZ0dMX6RCPDZepL6M,129
22
24
  hypercomplex_engine/printer/cd_format.py,sha256=X_cotGumJlRMuJO5cbsnI8FA9Py12TGYftPlUdx-9xg,5731
23
25
  hypercomplex_engine/printer/cd_table_printer.py,sha256=Ny1g5osDwttI5I8-KV4DzhVhWp_7fP-R5lYyC9sEhKE,4973
24
- hypercomplex_engine-0.5.0.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
25
- hypercomplex_engine-0.5.0.dist-info/licenses/NOTICE,sha256=WRgJ9Hv74Vke3ByFbvR6sqdlinPx4rCWDc0-7Iyh9VI,745
26
- hypercomplex_engine-0.5.0.dist-info/METADATA,sha256=pmB0Ja-z1sEzwvYYNGYlSlYXpdf02QKvu221h7mZkiQ,26238
27
- hypercomplex_engine-0.5.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
28
- hypercomplex_engine-0.5.0.dist-info/top_level.txt,sha256=654ACRoo9vk38vKW7kVBfgD-IjIADgVmh75smmXBZ88,20
29
- hypercomplex_engine-0.5.0.dist-info/RECORD,,
26
+ hypercomplex_engine-0.6.0.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
27
+ hypercomplex_engine-0.6.0.dist-info/licenses/NOTICE,sha256=WRgJ9Hv74Vke3ByFbvR6sqdlinPx4rCWDc0-7Iyh9VI,745
28
+ hypercomplex_engine-0.6.0.dist-info/METADATA,sha256=-xOkrkRP_H__kmTQ3BLBl_t8SghUkReStNVHtcweCaY,26289
29
+ hypercomplex_engine-0.6.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
30
+ hypercomplex_engine-0.6.0.dist-info/top_level.txt,sha256=654ACRoo9vk38vKW7kVBfgD-IjIADgVmh75smmXBZ88,20
31
+ hypercomplex_engine-0.6.0.dist-info/RECORD,,