numpy-algebras 0.1.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.
- numpy_algebras-0.1.0/LICENSE +21 -0
- numpy_algebras-0.1.0/PKG-INFO +8 -0
- numpy_algebras-0.1.0/README.md +65 -0
- numpy_algebras-0.1.0/pyproject.toml +13 -0
- numpy_algebras-0.1.0/setup.cfg +4 -0
- numpy_algebras-0.1.0/setup.py +194 -0
- numpy_algebras-0.1.0/src/algpy/__init__.py +0 -0
- numpy_algebras-0.1.0/src/algpy/algebras/__init__.py +34 -0
- numpy_algebras-0.1.0/src/algpy/algebras/_conversions.py +19 -0
- numpy_algebras-0.1.0/src/algpy/algebras/complex/__init__.py +7 -0
- numpy_algebras-0.1.0/src/algpy/algebras/complex/_complex1.c +734 -0
- numpy_algebras-0.1.0/src/algpy/algebras/complex/complex1.h +191 -0
- numpy_algebras-0.1.0/src/algpy/algebras/dual/__init__.py +7 -0
- numpy_algebras-0.1.0/src/algpy/algebras/dual/_dual1.c +734 -0
- numpy_algebras-0.1.0/src/algpy/algebras/dual/dual1.h +173 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/__init__.py +32 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/_cayleydickson1.c +12 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/_cayleydickson2.c +958 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/_cayleydickson3.c +967 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/_cayleydickson4.c +981 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/cayleydickson1.h +22 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/cayleydickson2.h +134 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/cayleydickson3.h +166 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/cayleydickson/cayleydickson4.h +178 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/clifford/__init__.py +26 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/clifford/_clifford1.c +12 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/clifford/_clifford2.c +958 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/clifford/clifford1.h +22 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/clifford/clifford2.h +22 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/__init__.py +28 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/_multicomplex1.c +980 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/_multicomplex2.c +958 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/_multicomplex3.c +967 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/_multicomplex4.c +982 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/multicomplex1.h +142 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/multicomplex2.h +177 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/multicomplex3.h +204 -0
- numpy_algebras-0.1.0/src/algpy/algebras/general/multicomplex/multicomplex4.h +238 -0
- numpy_algebras-0.1.0/src/algpy/algebras/quaternion/__init__.py +11 -0
- numpy_algebras-0.1.0/src/algpy/algebras/quaternion/_quaternion.c +752 -0
- numpy_algebras-0.1.0/src/algpy/algebras/quaternion/quaternion.h +177 -0
- numpy_algebras-0.1.0/src/algpy/algebras/splitcomplex/__init__.py +7 -0
- numpy_algebras-0.1.0/src/algpy/algebras/splitcomplex/_splitcomplex1.c +734 -0
- numpy_algebras-0.1.0/src/algpy/algebras/splitcomplex/splitcomplex1.h +189 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/operations.h +104 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec1.h +14 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec16.h +14 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec2.h +14 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec3.h +14 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec4.h +14 -0
- numpy_algebras-0.1.0/src/algpy/vectorspaces/vec8.h +14 -0
- numpy_algebras-0.1.0/src/numpy_algebras.egg-info/PKG-INFO +8 -0
- numpy_algebras-0.1.0/src/numpy_algebras.egg-info/SOURCES.txt +54 -0
- numpy_algebras-0.1.0/src/numpy_algebras.egg-info/dependency_links.txt +1 -0
- numpy_algebras-0.1.0/src/numpy_algebras.egg-info/requires.txt +1 -0
- numpy_algebras-0.1.0/src/numpy_algebras.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Filonik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# algpy
|
|
2
|
+
|
|
3
|
+
## Build
|
|
4
|
+
|
|
5
|
+
pip install .
|
|
6
|
+
|
|
7
|
+
For development use `pip install -e .`.
|
|
8
|
+
|
|
9
|
+
## Algebras
|
|
10
|
+
|
|
11
|
+
The algebra constructors create scalar types that can also be used as NumPy
|
|
12
|
+
dtypes. Parameters specify the squares of the algebra's generators.
|
|
13
|
+
|
|
14
|
+
### Multicomplex
|
|
15
|
+
|
|
16
|
+
The multicomplex algebra with parameters `k0, ..., k(n-1)` is generated over
|
|
17
|
+
the reals by commuting elements `e_i` satisfying `e_i² = k_i`. Its basis
|
|
18
|
+
consists of products of distinct generators, giving `2ⁿ` real components.
|
|
19
|
+
`multicomplex` accepts one to four parameters; the numbered
|
|
20
|
+
`multicomplex1`–`multicomplex4` constructors are also available.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from algpy.algebras import multicomplex
|
|
24
|
+
|
|
25
|
+
mc = multicomplex(-1, 1)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The two-component specializations are `complex1`, given by
|
|
29
|
+
`multicomplex1(-1)`, `dual1`, given by `multicomplex1(0)`, and `splitcomplex1`,
|
|
30
|
+
given by `multicomplex1(+1)`.
|
|
31
|
+
|
|
32
|
+
### Cayley-Dickson
|
|
33
|
+
|
|
34
|
+
The Cayley-Dickson construction builds successively doubled real algebras.
|
|
35
|
+
At each step it adjoins a new generator whose square is set by the next
|
|
36
|
+
parameter; the multiplication uses the Cayley-Dickson conjugation rule and is
|
|
37
|
+
generally noncommutative (and, at higher dimensions, may be nonassociative).
|
|
38
|
+
`cayleydickson` accepts one to four parameters, with numbered
|
|
39
|
+
`cayleydickson1`–`cayleydickson4` constructors for the corresponding
|
|
40
|
+
dimensions.
|
|
41
|
+
|
|
42
|
+
The `quaternion` type is the Hamilton quaternion specialization
|
|
43
|
+
`cayleydickson2(-1, -1)`. Its components are ordered `(w, x, y, z)`. It
|
|
44
|
+
supports arithmetic, `exp`, `log`, `norm2`, and equality for scalars and NumPy
|
|
45
|
+
arrays.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from algpy.algebras import cayleydickson, quaternion
|
|
49
|
+
|
|
50
|
+
cd = cayleydickson(-1, -1)
|
|
51
|
+
q = quaternion(1, 2, 3, 4)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Clifford
|
|
55
|
+
|
|
56
|
+
The Clifford algebra with parameters `k0, ..., k(n-1)` is generated by elements
|
|
57
|
+
`e_i` with `e_i² = k_i` and `e_i e_j = -e_j e_i` for distinct generators.
|
|
58
|
+
Products of distinct generators form a `2ⁿ`-element basis. `clifford` accepts
|
|
59
|
+
one or two parameters; `clifford1` and `clifford2` are also available.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from algpy.algebras import clifford
|
|
63
|
+
|
|
64
|
+
cl = clifford(-1, 1)
|
|
65
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "numpy"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "numpy-algebras"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Custom number types for numpy."
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = ["numpy"]
|
|
11
|
+
|
|
12
|
+
[tool.setuptools.packages.find]
|
|
13
|
+
where = ["src"]
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import numpy
|
|
2
|
+
from setuptools import Extension, setup
|
|
3
|
+
|
|
4
|
+
extensions = [
|
|
5
|
+
Extension(
|
|
6
|
+
"algpy.algebras.quaternion._quaternion",
|
|
7
|
+
["src/algpy/algebras/quaternion/_quaternion.c"],
|
|
8
|
+
depends=[
|
|
9
|
+
"src/algpy/algebras/quaternion/quaternion.h",
|
|
10
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
11
|
+
"src/algpy/vectorspaces/operations.h",
|
|
12
|
+
],
|
|
13
|
+
include_dirs=[numpy.get_include()],
|
|
14
|
+
),
|
|
15
|
+
Extension(
|
|
16
|
+
"algpy.algebras.complex._complex1",
|
|
17
|
+
["src/algpy/algebras/complex/_complex1.c"],
|
|
18
|
+
depends=[
|
|
19
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
20
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
21
|
+
"src/algpy/vectorspaces/operations.h",
|
|
22
|
+
],
|
|
23
|
+
include_dirs=[numpy.get_include()],
|
|
24
|
+
),
|
|
25
|
+
Extension(
|
|
26
|
+
"algpy.algebras.dual._dual1",
|
|
27
|
+
["src/algpy/algebras/dual/_dual1.c"],
|
|
28
|
+
depends=[
|
|
29
|
+
"src/algpy/algebras/dual/dual1.h",
|
|
30
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
31
|
+
"src/algpy/vectorspaces/operations.h",
|
|
32
|
+
],
|
|
33
|
+
include_dirs=[numpy.get_include()],
|
|
34
|
+
),
|
|
35
|
+
Extension(
|
|
36
|
+
"algpy.algebras.splitcomplex._splitcomplex1",
|
|
37
|
+
["src/algpy/algebras/splitcomplex/_splitcomplex1.c"],
|
|
38
|
+
depends=[
|
|
39
|
+
"src/algpy/algebras/splitcomplex/splitcomplex1.h",
|
|
40
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
41
|
+
"src/algpy/vectorspaces/operations.h",
|
|
42
|
+
],
|
|
43
|
+
include_dirs=[numpy.get_include()],
|
|
44
|
+
),
|
|
45
|
+
Extension(
|
|
46
|
+
"algpy.algebras.general.multicomplex._multicomplex1",
|
|
47
|
+
["src/algpy/algebras/general/multicomplex/_multicomplex1.c"],
|
|
48
|
+
depends=[
|
|
49
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
50
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
51
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
52
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
53
|
+
"src/algpy/vectorspaces/operations.h",
|
|
54
|
+
],
|
|
55
|
+
include_dirs=[numpy.get_include()],
|
|
56
|
+
),
|
|
57
|
+
Extension(
|
|
58
|
+
"algpy.algebras.general.clifford._clifford1",
|
|
59
|
+
["src/algpy/algebras/general/clifford/_clifford1.c"],
|
|
60
|
+
depends=[
|
|
61
|
+
"src/algpy/algebras/general/clifford/clifford1.h",
|
|
62
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
63
|
+
"src/algpy/algebras/general/multicomplex/_multicomplex1.c",
|
|
64
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
65
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
66
|
+
"src/algpy/vectorspaces/operations.h",
|
|
67
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
68
|
+
],
|
|
69
|
+
include_dirs=[numpy.get_include()],
|
|
70
|
+
),
|
|
71
|
+
Extension(
|
|
72
|
+
"algpy.algebras.general.clifford._clifford2",
|
|
73
|
+
["src/algpy/algebras/general/clifford/_clifford2.c"],
|
|
74
|
+
depends=[
|
|
75
|
+
"src/algpy/algebras/general/clifford/clifford2.h",
|
|
76
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson2.h",
|
|
77
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
78
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
79
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
80
|
+
"src/algpy/vectorspaces/operations.h",
|
|
81
|
+
],
|
|
82
|
+
include_dirs=[numpy.get_include()],
|
|
83
|
+
),
|
|
84
|
+
Extension(
|
|
85
|
+
"algpy.algebras.general.cayleydickson._cayleydickson1",
|
|
86
|
+
["src/algpy/algebras/general/cayleydickson/_cayleydickson1.c"],
|
|
87
|
+
depends=[
|
|
88
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson1.h",
|
|
89
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
90
|
+
"src/algpy/algebras/general/multicomplex/_multicomplex1.c",
|
|
91
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
92
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
93
|
+
"src/algpy/vectorspaces/operations.h",
|
|
94
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
95
|
+
],
|
|
96
|
+
include_dirs=[numpy.get_include()],
|
|
97
|
+
),
|
|
98
|
+
Extension(
|
|
99
|
+
"algpy.algebras.general.cayleydickson._cayleydickson2",
|
|
100
|
+
["src/algpy/algebras/general/cayleydickson/_cayleydickson2.c"],
|
|
101
|
+
depends=[
|
|
102
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson2.h",
|
|
103
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
104
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
105
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
106
|
+
"src/algpy/vectorspaces/operations.h",
|
|
107
|
+
],
|
|
108
|
+
include_dirs=[numpy.get_include()],
|
|
109
|
+
),
|
|
110
|
+
Extension(
|
|
111
|
+
"algpy.algebras.general.cayleydickson._cayleydickson3",
|
|
112
|
+
["src/algpy/algebras/general/cayleydickson/_cayleydickson3.c"],
|
|
113
|
+
depends=[
|
|
114
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson3.h",
|
|
115
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson2.h",
|
|
116
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
117
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
118
|
+
"src/algpy/vectorspaces/vec3.h",
|
|
119
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
120
|
+
"src/algpy/vectorspaces/vec8.h",
|
|
121
|
+
"src/algpy/vectorspaces/operations.h",
|
|
122
|
+
],
|
|
123
|
+
include_dirs=[numpy.get_include()],
|
|
124
|
+
),
|
|
125
|
+
Extension(
|
|
126
|
+
"algpy.algebras.general.cayleydickson._cayleydickson4",
|
|
127
|
+
["src/algpy/algebras/general/cayleydickson/_cayleydickson4.c"],
|
|
128
|
+
depends=[
|
|
129
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson4.h",
|
|
130
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson3.h",
|
|
131
|
+
"src/algpy/algebras/general/cayleydickson/cayleydickson2.h",
|
|
132
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
133
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
134
|
+
"src/algpy/vectorspaces/vec3.h",
|
|
135
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
136
|
+
"src/algpy/vectorspaces/vec8.h",
|
|
137
|
+
"src/algpy/vectorspaces/vec16.h",
|
|
138
|
+
"src/algpy/vectorspaces/operations.h",
|
|
139
|
+
],
|
|
140
|
+
include_dirs=[numpy.get_include()],
|
|
141
|
+
),
|
|
142
|
+
Extension(
|
|
143
|
+
"algpy.algebras.general.multicomplex._multicomplex2",
|
|
144
|
+
["src/algpy/algebras/general/multicomplex/_multicomplex2.c"],
|
|
145
|
+
depends=[
|
|
146
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
147
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
148
|
+
"src/algpy/algebras/general/multicomplex/multicomplex2.h",
|
|
149
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
150
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
151
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
152
|
+
"src/algpy/vectorspaces/operations.h",
|
|
153
|
+
],
|
|
154
|
+
include_dirs=[numpy.get_include()],
|
|
155
|
+
),
|
|
156
|
+
Extension(
|
|
157
|
+
"algpy.algebras.general.multicomplex._multicomplex3",
|
|
158
|
+
["src/algpy/algebras/general/multicomplex/_multicomplex3.c"],
|
|
159
|
+
depends=[
|
|
160
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
161
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
162
|
+
"src/algpy/algebras/general/multicomplex/multicomplex2.h",
|
|
163
|
+
"src/algpy/algebras/general/multicomplex/multicomplex3.h",
|
|
164
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
165
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
166
|
+
"src/algpy/vectorspaces/vec3.h",
|
|
167
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
168
|
+
"src/algpy/vectorspaces/vec8.h",
|
|
169
|
+
"src/algpy/vectorspaces/operations.h",
|
|
170
|
+
],
|
|
171
|
+
include_dirs=[numpy.get_include()],
|
|
172
|
+
),
|
|
173
|
+
Extension(
|
|
174
|
+
"algpy.algebras.general.multicomplex._multicomplex4",
|
|
175
|
+
["src/algpy/algebras/general/multicomplex/_multicomplex4.c"],
|
|
176
|
+
depends=[
|
|
177
|
+
"src/algpy/algebras/complex/complex1.h",
|
|
178
|
+
"src/algpy/algebras/general/multicomplex/multicomplex1.h",
|
|
179
|
+
"src/algpy/algebras/general/multicomplex/multicomplex2.h",
|
|
180
|
+
"src/algpy/algebras/general/multicomplex/multicomplex3.h",
|
|
181
|
+
"src/algpy/algebras/general/multicomplex/multicomplex4.h",
|
|
182
|
+
"src/algpy/vectorspaces/vec1.h",
|
|
183
|
+
"src/algpy/vectorspaces/vec2.h",
|
|
184
|
+
"src/algpy/vectorspaces/vec3.h",
|
|
185
|
+
"src/algpy/vectorspaces/vec4.h",
|
|
186
|
+
"src/algpy/vectorspaces/vec8.h",
|
|
187
|
+
"src/algpy/vectorspaces/vec16.h",
|
|
188
|
+
"src/algpy/vectorspaces/operations.h",
|
|
189
|
+
],
|
|
190
|
+
include_dirs=[numpy.get_include()],
|
|
191
|
+
),
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
setup(ext_modules=extensions)
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Custom number types for numpy, implemented in Cython."""
|
|
2
|
+
from .general.multicomplex import multicomplex, multicomplex1, multicomplex2, multicomplex3, multicomplex4
|
|
3
|
+
from .general.clifford import clifford, clifford1, clifford2
|
|
4
|
+
from .general.cayleydickson import (
|
|
5
|
+
cayleydickson,
|
|
6
|
+
cayleydickson1,
|
|
7
|
+
cayleydickson2,
|
|
8
|
+
cayleydickson3,
|
|
9
|
+
cayleydickson4,
|
|
10
|
+
)
|
|
11
|
+
from .quaternion import quaternion
|
|
12
|
+
from .complex import complex1
|
|
13
|
+
from .dual import dual1
|
|
14
|
+
from .splitcomplex import splitcomplex1
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"multicomplex",
|
|
18
|
+
"multicomplex1",
|
|
19
|
+
"multicomplex2",
|
|
20
|
+
"multicomplex3",
|
|
21
|
+
"multicomplex4",
|
|
22
|
+
"clifford",
|
|
23
|
+
"clifford1",
|
|
24
|
+
"clifford2",
|
|
25
|
+
"cayleydickson",
|
|
26
|
+
"cayleydickson1",
|
|
27
|
+
"cayleydickson2",
|
|
28
|
+
"cayleydickson3",
|
|
29
|
+
"cayleydickson4",
|
|
30
|
+
"quaternion",
|
|
31
|
+
"complex1",
|
|
32
|
+
"dual1",
|
|
33
|
+
"splitcomplex1",
|
|
34
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import numpy as _np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def attach(scalar_type, n):
|
|
5
|
+
def _to_float(a, dtype=float):
|
|
6
|
+
a = _np.asarray(a, dtype=scalar_type)
|
|
7
|
+
flat = _np.ascontiguousarray(a.reshape(-1))
|
|
8
|
+
return flat.view(float).reshape(a.shape + (n,)).astype(dtype, copy=False)
|
|
9
|
+
|
|
10
|
+
def _from_float(a):
|
|
11
|
+
a = _np.asarray(a, dtype=float)
|
|
12
|
+
if a.ndim == 0 or a.shape[-1] != n:
|
|
13
|
+
raise ValueError(f"last axis must have length {n}")
|
|
14
|
+
flat = _np.ascontiguousarray(a.reshape(-1))
|
|
15
|
+
return flat.view(scalar_type).reshape(a.shape[:-1])
|
|
16
|
+
|
|
17
|
+
scalar_type.N = n
|
|
18
|
+
scalar_type.to_float = staticmethod(_to_float)
|
|
19
|
+
scalar_type.from_float = staticmethod(_from_float)
|