numga 2.0.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.
- numga/__init__.py +71 -0
- numga/algebra/__init__.py +6 -0
- numga/algebra/algebra.py +580 -0
- numga/algebra/bitops.py +88 -0
- numga/algebra/description.py +190 -0
- numga/algebra/self_product.py +58 -0
- numga/algebras.py +120 -0
- numga/backend/__init__.py +7 -0
- numga/backend/context.py +323 -0
- numga/backend/dense.py +183 -0
- numga/backend/exact.py +171 -0
- numga/backend/jax.py +265 -0
- numga/backend/numpy.py +144 -0
- numga/backend/sparse.py +164 -0
- numga/backend/torch.py +286 -0
- numga/binding.py +320 -0
- numga/expression.py +210 -0
- numga/extension.py +230 -0
- numga/extensions/__init__.py +3 -0
- numga/extensions/_linalg.py +63 -0
- numga/extensions/_scalar_functions.py +23 -0
- numga/extensions/arithmetic.py +130 -0
- numga/extensions/coefficients.py +18 -0
- numga/extensions/decompose.py +91 -0
- numga/extensions/fields.py +373 -0
- numga/extensions/forms.py +183 -0
- numga/extensions/grade_transforms.py +50 -0
- numga/extensions/invariant_decomposition.py +243 -0
- numga/extensions/inverse.py +186 -0
- numga/extensions/logexp.py +230 -0
- numga/extensions/norms.py +103 -0
- numga/extensions/optimized.py +162 -0
- numga/extensions/outermorphism.py +86 -0
- numga/extensions/roots.py +114 -0
- numga/extensions/scalar.py +104 -0
- numga/extensions/spectra.py +91 -0
- numga/extensions/systems.py +253 -0
- numga/extensions/trace.py +122 -0
- numga/extensor/__init__.py +4 -0
- numga/extensor/application.py +156 -0
- numga/extensor/extensor.py +979 -0
- numga/extensor/fields.py +320 -0
- numga/extensor/namespaces.py +78 -0
- numga/extensor/operands.py +144 -0
- numga/flyweight.py +39 -0
- numga/gatype/__init__.py +36 -0
- numga/gatype/dispatch.py +480 -0
- numga/gatype/errors.py +19 -0
- numga/gatype/factory.py +181 -0
- numga/gatype/gatype.py +900 -0
- numga/gatype/metric.py +71 -0
- numga/gatype/orientation.py +48 -0
- numga/gatype/pattern.py +155 -0
- numga/gatype/propagation.py +345 -0
- numga/gatype/queries.py +211 -0
- numga/gatype/rules.py +137 -0
- numga/gatype/traits.py +619 -0
- numga/multivector/__init__.py +4 -0
- numga/multivector/factory.py +204 -0
- numga/multivector/subalgebra.py +117 -0
- numga/operator/__init__.py +5 -0
- numga/operator/factory.py +724 -0
- numga/operator/format.py +110 -0
- numga/operator/kernel.py +198 -0
- numga/render/__init__.py +41 -0
- numga/render/camera.py +147 -0
- numga/render/contours.py +141 -0
- numga/render/drawing.py +279 -0
- numga/render/flow.py +323 -0
- numga/render/meshes.py +191 -0
- numga/render/planar.py +12 -0
- numga/render/quadrics.py +163 -0
- numga/render/scene.py +58 -0
- numga/render/simplices.py +399 -0
- numga/render/solids.py +922 -0
- numga/sparse/__init__.py +7 -0
- numga/sparse/extensor.py +534 -0
- numga/sparse/numeric.py +221 -0
- numga/subspace/__init__.py +7 -0
- numga/subspace/factory.py +317 -0
- numga/subspace/subspace.py +274 -0
- numga/topology.py +612 -0
- numga/wgsl/__init__.py +24 -0
- numga/wgsl/dialect.py +1643 -0
- numga/wgsl/library.py +94 -0
- numga/wgsl/page.py +43 -0
- numga/wgsl/runner.py +395 -0
- numga-2.0.0.dist-info/METADATA +113 -0
- numga-2.0.0.dist-info/RECORD +92 -0
- numga-2.0.0.dist-info/WHEEL +5 -0
- numga-2.0.0.dist-info/licenses/LICENSE +21 -0
- numga-2.0.0.dist-info/top_level.txt +1 -0
numga/algebra/bitops.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Basis blades in an orthogonal geometric algebra map to non-negative integer bit masks in which
|
|
2
|
+
bit `i` marks the presence of generator `i` up to 64 dimensions. Scalar and NumPy-array bit
|
|
3
|
+
operations count blade grade via population count, convert inversion parities into `+1` and `-1`
|
|
4
|
+
orientation signs, pack generator index sequences into canonical masks, and select the narrowest
|
|
5
|
+
unsigned integer dtype (`uint8` through `uint64`) able to hold every blade mask of a given
|
|
6
|
+
dimension."""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Iterable
|
|
11
|
+
from operator import index
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
_bit_count_radix = (
|
|
17
|
+
np.unpackbits(np.arange(256, dtype=np.uint8)[:, None], axis=1)
|
|
18
|
+
.sum(axis=1)
|
|
19
|
+
.astype(np.uint8)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def bit_count(masks: int | np.ndarray) -> int | np.ndarray:
|
|
24
|
+
"""Population count gives the grade of a single integer blade mask or an array of blade masks."""
|
|
25
|
+
if isinstance(masks, (int, np.integer)):
|
|
26
|
+
return int(masks).bit_count()
|
|
27
|
+
masks = np.asarray(masks)
|
|
28
|
+
if hasattr(np, "bitwise_count"):
|
|
29
|
+
return np.bitwise_count(masks)
|
|
30
|
+
raw = masks.view(np.uint8).reshape(masks.shape + (-1,))
|
|
31
|
+
return _bit_count_radix[raw].sum(axis=-1).astype(np.uint8)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def parity_to_sign(parity: int | np.ndarray) -> int | np.ndarray:
|
|
35
|
+
"""Even parities map to `+1` and odd parities map to `-1`."""
|
|
36
|
+
if isinstance(parity, (int, np.integer)):
|
|
37
|
+
return 1 if index(parity) % 2 == 0 else -1
|
|
38
|
+
return (1 - (np.asarray(parity) % 2) * 2).astype(np.int8)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
parity_sign = parity_to_sign
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def permutation_sign(entries: Iterable[int]) -> int:
|
|
45
|
+
"""Pairwise inversions of distinct integer entries determine `+1` for even permutations and
|
|
46
|
+
`-1` for odd permutations."""
|
|
47
|
+
items = tuple(index(value) for value in entries)
|
|
48
|
+
if len(set(items)) != len(items):
|
|
49
|
+
raise ValueError("a permutation cannot contain duplicate entries")
|
|
50
|
+
inversions = sum(
|
|
51
|
+
left > right
|
|
52
|
+
for position, left in enumerate(items)
|
|
53
|
+
for right in items[position + 1 :]
|
|
54
|
+
)
|
|
55
|
+
return parity_sign(inversions)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def mask_from_indices(indices: Iterable[int]) -> int:
|
|
59
|
+
"""Distinct non-negative generator indices pack into a canonical bit mask with bit `i` set for
|
|
60
|
+
generator `i`."""
|
|
61
|
+
result = 0
|
|
62
|
+
for value in indices:
|
|
63
|
+
generator = index(value)
|
|
64
|
+
if generator < 0:
|
|
65
|
+
raise ValueError("generator indices must be non-negative")
|
|
66
|
+
bit = 1 << generator
|
|
67
|
+
if result & bit:
|
|
68
|
+
raise ValueError("a basis blade cannot repeat a generator")
|
|
69
|
+
result |= bit
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def unsigned_dtype(dimension: int) -> np.dtype:
|
|
74
|
+
"""An algebra of `dimension` generators fits its canonical blade masks in the narrowest
|
|
75
|
+
unsigned NumPy integer type up to `uint64`."""
|
|
76
|
+
dimension = index(dimension)
|
|
77
|
+
if dimension < 0:
|
|
78
|
+
raise ValueError("dimension must be non-negative")
|
|
79
|
+
if dimension <= 8:
|
|
80
|
+
return np.dtype(np.uint8)
|
|
81
|
+
if dimension <= 16:
|
|
82
|
+
return np.dtype(np.uint16)
|
|
83
|
+
if dimension <= 32:
|
|
84
|
+
return np.dtype(np.uint32)
|
|
85
|
+
if dimension <= 64:
|
|
86
|
+
return np.dtype(np.uint64)
|
|
87
|
+
raise ValueError("NumPy blade-mask arrays support at most 64 generators")
|
|
88
|
+
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""An orthogonal geometric algebra is defined by an ordered tuple of unique generator names and a
|
|
2
|
+
matching tuple of diagonal metric squares in `(+1, -1, 0)`. `AlgebraDescription` validates and
|
|
3
|
+
stores that pair independently of bit-mask encoding or array backends, reserving `"1"` for the unit
|
|
4
|
+
scalar blade and forming orthogonal direct sums under `left * right` whenever generator names are
|
|
5
|
+
disjoint.
|
|
6
|
+
|
|
7
|
+
A compact string such as `"x+y+z+w0"` writes each generator name directly before its metric
|
|
8
|
+
character (`+`, `-`, or `0`), and `to_compact_string` recovers that notation whenever no generator
|
|
9
|
+
name contains `+`, `-`, or `0`. `AlgebraDescription`, `from_signature`, and `from_pqr` take
|
|
10
|
+
generator names and metric signs separately, supplying `a..z` defaults when names are omitted.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from collections.abc import Iterable
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from operator import index
|
|
18
|
+
from types import NotImplementedType
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_CHAR_TO_SIGN = {"+": 1, "-": -1, "0": 0}
|
|
22
|
+
_SIGN_TO_CHAR = {value: key for key, value in _CHAR_TO_SIGN.items()}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _metric_signs(signature: Iterable[int]) -> tuple[int, ...]:
|
|
26
|
+
result = []
|
|
27
|
+
for value in signature:
|
|
28
|
+
try:
|
|
29
|
+
sign = index(value)
|
|
30
|
+
except TypeError as error:
|
|
31
|
+
raise TypeError("metric entries must be integers") from error
|
|
32
|
+
if sign not in (-1, 0, 1):
|
|
33
|
+
raise ValueError("metric entries must be -1, 0, or +1")
|
|
34
|
+
result.append(sign)
|
|
35
|
+
return tuple(result)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _default_basis_names(dimension: int) -> tuple[str, ...]:
|
|
39
|
+
# Bijective base-26 naming produces a..z, aa..az, ba...
|
|
40
|
+
def name(number: int) -> str:
|
|
41
|
+
characters = []
|
|
42
|
+
while True:
|
|
43
|
+
number, remainder = divmod(number, 26)
|
|
44
|
+
characters.append(chr(ord("a") + remainder))
|
|
45
|
+
if number == 0:
|
|
46
|
+
return "".join(reversed(characters))
|
|
47
|
+
number -= 1
|
|
48
|
+
|
|
49
|
+
return tuple(name(i) for i in range(dimension))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def parse_description(specification: str) -> tuple:
|
|
53
|
+
"""Parsing a compact string such as `"x+y+z+w0"` separates each generator name from its
|
|
54
|
+
trailing `+`, `-`, or `0` metric square."""
|
|
55
|
+
if not isinstance(specification, str):
|
|
56
|
+
raise TypeError("an algebra description must be a string")
|
|
57
|
+
if not specification:
|
|
58
|
+
return (), ()
|
|
59
|
+
|
|
60
|
+
names = []
|
|
61
|
+
signs = []
|
|
62
|
+
start = 0
|
|
63
|
+
for position, character in enumerate(specification):
|
|
64
|
+
if character not in _CHAR_TO_SIGN:
|
|
65
|
+
continue
|
|
66
|
+
name = specification[start:position]
|
|
67
|
+
if not name:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f"missing generator name before metric character at index {position}"
|
|
70
|
+
)
|
|
71
|
+
names.append(name)
|
|
72
|
+
signs.append(_CHAR_TO_SIGN[character])
|
|
73
|
+
start = position + 1
|
|
74
|
+
|
|
75
|
+
if start != len(specification):
|
|
76
|
+
raise ValueError("an algebra description must end in '+', '-', or '0'")
|
|
77
|
+
|
|
78
|
+
return tuple(names), tuple(signs)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass(frozen=True, slots=True)
|
|
82
|
+
class AlgebraDescription:
|
|
83
|
+
"""Ordered generator names and diagonal metric squares in `(+1, -1, 0)` specify an orthogonal
|
|
84
|
+
geometric algebra."""
|
|
85
|
+
|
|
86
|
+
basis_names: tuple[str, ...]
|
|
87
|
+
signature: tuple[int, ...]
|
|
88
|
+
|
|
89
|
+
def __post_init__(self) -> None:
|
|
90
|
+
names = tuple(self.basis_names)
|
|
91
|
+
signs = _metric_signs(self.signature)
|
|
92
|
+
object.__setattr__(self, "basis_names", names)
|
|
93
|
+
object.__setattr__(self, "signature", signs)
|
|
94
|
+
|
|
95
|
+
if len(names) != len(signs):
|
|
96
|
+
raise ValueError("basis_names and signature must have the same length")
|
|
97
|
+
if any(not isinstance(name, str) or not name for name in names):
|
|
98
|
+
raise ValueError("basis names must be non-empty strings")
|
|
99
|
+
if len(set(names)) != len(names):
|
|
100
|
+
raise ValueError("basis names must be unique")
|
|
101
|
+
if "1" in names:
|
|
102
|
+
raise ValueError("'1' is reserved as the scalar blade name")
|
|
103
|
+
|
|
104
|
+
@classmethod
|
|
105
|
+
def parse(cls, specification: str) -> AlgebraDescription:
|
|
106
|
+
return cls(*parse_description(specification))
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def from_signature(
|
|
110
|
+
cls,
|
|
111
|
+
signature: Iterable[int],
|
|
112
|
+
basis_names: Iterable[str] | None = None,
|
|
113
|
+
) -> AlgebraDescription:
|
|
114
|
+
"""Per-generator metric squares in `(-1, 0, +1)` pair with explicit generator names or
|
|
115
|
+
deterministic `a..z` defaults."""
|
|
116
|
+
signs = _metric_signs(signature)
|
|
117
|
+
names = (
|
|
118
|
+
_default_basis_names(len(signs))
|
|
119
|
+
if basis_names is None
|
|
120
|
+
else tuple(basis_names)
|
|
121
|
+
)
|
|
122
|
+
return cls(names, signs)
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def from_pqr(
|
|
126
|
+
cls,
|
|
127
|
+
p: int,
|
|
128
|
+
q: int,
|
|
129
|
+
r: int,
|
|
130
|
+
basis_names: Iterable[str] | None = None,
|
|
131
|
+
) -> AlgebraDescription:
|
|
132
|
+
"""Signature counts `(p, q, r)` order `+1` generators first, `-1` second, and `0` last."""
|
|
133
|
+
counts = []
|
|
134
|
+
for value in (p, q, r):
|
|
135
|
+
try:
|
|
136
|
+
count = index(value)
|
|
137
|
+
except TypeError as error:
|
|
138
|
+
raise TypeError("p, q, and r must be integers") from error
|
|
139
|
+
if count < 0:
|
|
140
|
+
raise ValueError("p, q, and r must be non-negative")
|
|
141
|
+
counts.append(count)
|
|
142
|
+
return cls.from_signature(
|
|
143
|
+
(1,) * counts[0] + (-1,) * counts[1] + (0,) * counts[2],
|
|
144
|
+
basis_names=basis_names,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def dimension(self) -> int:
|
|
149
|
+
return len(self.signature)
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def pqr(self) -> tuple[int, int, int]:
|
|
153
|
+
return (
|
|
154
|
+
self.signature.count(1),
|
|
155
|
+
self.signature.count(-1),
|
|
156
|
+
self.signature.count(0),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
@property
|
|
160
|
+
def signature_string(self) -> str:
|
|
161
|
+
return "".join(_SIGN_TO_CHAR[sign] for sign in self.signature)
|
|
162
|
+
|
|
163
|
+
def to_compact_string(self) -> str:
|
|
164
|
+
"""Concatenating each generator name with its metric character produces compact notation
|
|
165
|
+
such as `"x+y+z+w0"` whenever no generator name contains `+`, `-`, or `0`."""
|
|
166
|
+
if any(
|
|
167
|
+
any(character in _CHAR_TO_SIGN for character in name)
|
|
168
|
+
for name in self.basis_names
|
|
169
|
+
):
|
|
170
|
+
raise ValueError(
|
|
171
|
+
"basis names containing '+', '-', or '0' have no compact representation"
|
|
172
|
+
)
|
|
173
|
+
return "".join(
|
|
174
|
+
name + _SIGN_TO_CHAR[sign]
|
|
175
|
+
for name, sign in zip(self.basis_names, self.signature)
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
def __mul__(self, other: object) -> AlgebraDescription | NotImplementedType:
|
|
179
|
+
"""Multiplying two descriptions with disjoint generator names concatenates their generators
|
|
180
|
+
and diagonal metrics into the orthogonal direct-sum description."""
|
|
181
|
+
if not isinstance(other, AlgebraDescription):
|
|
182
|
+
return NotImplemented
|
|
183
|
+
overlap = set(self.basis_names).intersection(other.basis_names)
|
|
184
|
+
if overlap:
|
|
185
|
+
names = ", ".join(sorted(overlap))
|
|
186
|
+
raise ValueError(f"product algebra has duplicate basis names: {names}")
|
|
187
|
+
return AlgebraDescription(
|
|
188
|
+
self.basis_names + other.basis_names,
|
|
189
|
+
self.signature + other.signature,
|
|
190
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Quadratic self-products `x * T(x)` between a multivector `x` and a grade or sign transform `T(x)`
|
|
2
|
+
cancel off-diagonal blade pairs whenever `b_i * T(b_j) + b_j * T(b_i) == 0`, shrinking the static
|
|
3
|
+
output support below the general bilinear product `subspace * subspace`. Vectors under `v * v.reverse()`
|
|
4
|
+
land purely in grade `0` even though `vector * vector` spans grades `0` and `2`, and even elements
|
|
5
|
+
under `r * r.reverse()` land purely in grade `0` up to dimension three while reaching grades `0`
|
|
6
|
+
and `4` in dimension four.
|
|
7
|
+
|
|
8
|
+
Because real or complex scalar coordinates commute (`x_i * x_j == x_j * x_i`), off-diagonal terms
|
|
9
|
+
`(i, j)` and `(j, i)` combine with half their signed sum. Under an orthogonal diagonal metric,
|
|
10
|
+
`b_i * T(b_j)` and `b_j * T(b_i)` always land on the same canonical output mask `b_i ^ b_j` with
|
|
11
|
+
either matching signs, opposite signs, or zeros from a null contraction, so `(c_ij + c_ji) // 2`
|
|
12
|
+
remains an exact integer in `(-1, 0, +1)` with no rounding.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Iterable
|
|
18
|
+
from functools import lru_cache
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from numga.algebra import Algebra
|
|
25
|
+
from numga.subspace import SubSpace
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def grade_transform_signs(algebra: Algebra, transform: str, masks: Iterable[int]) -> np.ndarray:
|
|
29
|
+
"""Named grade transforms (`"identity"`, `"reverse"`, `"clifford_conjugate"`, `"involute"`,
|
|
30
|
+
`"scalar_negation"`, and `"pseudoscalar_negation"`) assign `+1` or `-1` to each canonical blade
|
|
31
|
+
mask."""
|
|
32
|
+
blades = np.asarray(tuple(masks), dtype=np.int64)
|
|
33
|
+
signs = {
|
|
34
|
+
"identity": lambda: np.ones_like(blades),
|
|
35
|
+
"reverse": lambda: algebra.reverse_sign(blades),
|
|
36
|
+
"clifford_conjugate": lambda: algebra.conjugate_sign(blades),
|
|
37
|
+
"involute": lambda: algebra.involute_sign(blades),
|
|
38
|
+
"scalar_negation": lambda: np.where(blades == 0, 1, -1),
|
|
39
|
+
"pseudoscalar_negation": lambda: np.where((blades == 0) | (blades == algebra.pseudoscalar_mask), 1, -1),
|
|
40
|
+
}[transform]()
|
|
41
|
+
return np.asarray(signs, dtype=np.int8)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@lru_cache(maxsize=None)
|
|
45
|
+
def symmetric_product_table(subspace: SubSpace, transform: str = "reverse") -> tuple[np.ndarray, np.ndarray]:
|
|
46
|
+
"""Symmetrizing `x * T(x)` across the `n` blades of `subspace` yields `[n, n]` arrays of
|
|
47
|
+
canonical output masks and exact integer pair coefficients `(c + c.T) // 2`."""
|
|
48
|
+
algebra = subspace.algebra
|
|
49
|
+
table = algebra.geometric_product_table(subspace.masks, subspace.masks)
|
|
50
|
+
coefficients = table.coefficients * grade_transform_signs(algebra, transform, subspace.masks)
|
|
51
|
+
return table.blades, (coefficients + coefficients.T) // 2
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@lru_cache(maxsize=None)
|
|
55
|
+
def symmetric_product_support(subspace: SubSpace, transform: str = "reverse") -> frozenset[int]:
|
|
56
|
+
"""Nonzero pair coefficients determine the canonical blade masks reachable by `x * T(x)`."""
|
|
57
|
+
blades, coefficients = symmetric_product_table(subspace, transform)
|
|
58
|
+
return frozenset(blades[coefficients != 0].tolist())
|
numga/algebras.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Stock geometric algebras pair standard metric signatures with convention-matched basis layouts
|
|
2
|
+
and geometry-specific constructors. Right-handed cyclic bivector bases (`yz`, `zx`, `xy`) and
|
|
3
|
+
homogeneous projective bases (`x+y+w0` for `PGA2D`, `w0x+y+z+` for `PGA3D`) come preconfigured on
|
|
4
|
+
`VGA3D`, `STA`, `PGA2D`, `PGA3D`, and `Spherical3D`, alongside planar vector algebra `VGA2D`
|
|
5
|
+
(`x+y+`), planar spacetime `STA2D` (`x+y+t-`), and 3D conformal space `CGA3D` (`x+y+z+w+e-`).
|
|
6
|
+
Because `Algebra` interns by both description and factory callables, stock algebras carrying custom
|
|
7
|
+
layouts or constructors remain distinct from plain `Algebra(specification)` instances of the same
|
|
8
|
+
signature.
|
|
9
|
+
|
|
10
|
+
Plane-based projective algebras with a single null generator use `ProjectiveMultivectorFactory` to
|
|
11
|
+
construct intrinsic points and ideal directions directly from Euclidean coordinates by dualizing
|
|
12
|
+
offset or origin planes. On the unit sphere in `x+y+z+`, `SphericalSubSpaceFactory` adds `plane`,
|
|
13
|
+
`line`, and intrinsic `point` subspaces so great circles take grade-1 cutting planes and spherical
|
|
14
|
+
points take grade-2 antivectors.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from functools import partial
|
|
20
|
+
|
|
21
|
+
from numga.algebra import Algebra
|
|
22
|
+
from numga.extensor import Extensor
|
|
23
|
+
from numga.multivector import MultivectorFactory
|
|
24
|
+
from numga.subspace import SubSpace, SubSpaceFactory
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ProjectiveMultivectorFactory(MultivectorFactory):
|
|
28
|
+
"""Euclidean coordinate helpers construct intrinsic points and ideal directions in plane-based
|
|
29
|
+
projective algebras with a single null generator."""
|
|
30
|
+
|
|
31
|
+
def point(self, coordinates) -> Extensor:
|
|
32
|
+
"""Dualizing a non-degenerate plane offset by the unit null generator maps Euclidean
|
|
33
|
+
`coordinates` of shape `[..., d]` to intrinsic points of unit weight."""
|
|
34
|
+
if self.algebra.degenerate_mask.bit_count() != 1:
|
|
35
|
+
raise TypeError(f"points of weight one need a single degenerate basis vector; {self.algebra} has none or several")
|
|
36
|
+
planes = self(self.algebra.gatype.vector().derive.nondegenerate, coordinates)
|
|
37
|
+
return (planes + self.blade(self.algebra.degenerate_mask)).dual()
|
|
38
|
+
|
|
39
|
+
def direction(self, coordinates) -> Extensor:
|
|
40
|
+
"""Dualizing a non-degenerate plane through the origin maps Euclidean direction `coordinates`
|
|
41
|
+
of shape `[..., d]` to intrinsic ideal points at infinity."""
|
|
42
|
+
return self(self.algebra.gatype.vector().derive.nondegenerate, coordinates).dual()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
PGA2D = Algebra(
|
|
46
|
+
"x+y+w0",
|
|
47
|
+
subspace_factory=partial(
|
|
48
|
+
SubSpaceFactory,
|
|
49
|
+
default="1 x y w yw wx xy xyw",
|
|
50
|
+
),
|
|
51
|
+
multivector_factory=ProjectiveMultivectorFactory,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
PGA3D = Algebra(
|
|
56
|
+
"w0x+y+z+",
|
|
57
|
+
subspace_factory=partial(
|
|
58
|
+
SubSpaceFactory,
|
|
59
|
+
default="1 x y z w yz zx xy wx wy wz wzy wxz wyx xyz wxyz",
|
|
60
|
+
),
|
|
61
|
+
multivector_factory=ProjectiveMultivectorFactory,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class SphericalSubSpaceFactory(SubSpaceFactory):
|
|
66
|
+
"""On the unit sphere in `x+y+z+`, grade-1 vectors represent cutting planes and great-circle
|
|
67
|
+
lines while intrinsic grade-2 antivectors `(yz, zx, xy)` represent points."""
|
|
68
|
+
|
|
69
|
+
constructor_names = SubSpaceFactory.constructor_names + (
|
|
70
|
+
"plane",
|
|
71
|
+
"point",
|
|
72
|
+
"line",
|
|
73
|
+
)
|
|
74
|
+
intrinsic_constructor_names = SubSpaceFactory.intrinsic_constructor_names + ("point",)
|
|
75
|
+
|
|
76
|
+
def plane(self) -> SubSpace:
|
|
77
|
+
"""Great circles on the sphere correspond to grade-1 cutting planes through the origin."""
|
|
78
|
+
return self.vector()
|
|
79
|
+
|
|
80
|
+
def point(self) -> SubSpace:
|
|
81
|
+
"""Points on the sphere occupy the grade-2 antivector subspace `(yz, zx, xy)`."""
|
|
82
|
+
return self.antivector()
|
|
83
|
+
|
|
84
|
+
def line(self) -> SubSpace:
|
|
85
|
+
"""Geodesic lines on the sphere coincide with great-circle cutting planes."""
|
|
86
|
+
return self.plane()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
Spherical3D = Algebra(
|
|
90
|
+
"x+y+z+",
|
|
91
|
+
subspace_factory=partial(
|
|
92
|
+
SphericalSubSpaceFactory,
|
|
93
|
+
default="1 x y z yz zx xy xyz",
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
STA = Algebra(
|
|
99
|
+
"x+y+z+t-",
|
|
100
|
+
subspace_factory=partial(
|
|
101
|
+
SubSpaceFactory,
|
|
102
|
+
default="1 x y z t yz zx xy xt yt zt xyz yzt zxt xyt xyzt",
|
|
103
|
+
),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
VGA3D = Algebra(
|
|
108
|
+
"x+y+z+",
|
|
109
|
+
subspace_factory=partial(
|
|
110
|
+
SubSpaceFactory,
|
|
111
|
+
default="1 x y z yz zx xy xyz",
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
VGA2D = Algebra("x+y+")
|
|
117
|
+
|
|
118
|
+
CGA3D = Algebra("x+y+z+w+e-")
|
|
119
|
+
|
|
120
|
+
STA2D = Algebra("x+y+t-")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Every `Extensor` pairs a static `GAType` with an immutable `Context` governing coefficient storage
|
|
2
|
+
and contraction execution, with `ExactContext` and `NumpyContext` available directly and optional
|
|
3
|
+
`JaxContext` and `TorchContext` in `numga.backend.jax` and `numga.backend.torch`."""
|
|
4
|
+
|
|
5
|
+
from numga.backend.context import Context
|
|
6
|
+
from numga.backend.exact import ExactContext
|
|
7
|
+
from numga.backend.numpy import NumpyContext
|