Skip to content

Commit 06af9a8

Browse files
authored
Remove Complex and Quaternion embeddings (#6)
* Remove complex and quaternion embeddings * Remove complex and quaternion embedding tests * Increment version number
1 parent fe97464 commit 06af9a8

File tree

4 files changed

+24
-54
lines changed

4 files changed

+24
-54
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name = "Octonions"
22
uuid = "d00ba074-1e29-4f5e-9fd4-d67071d6a14d"
3-
version = "0.1.0"
3+
version = "0.2.0-DEV"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7-
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
87
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
98

109
[compat]
11-
Quaternions = "0.5.6"
10+
Quaternions = "0.7"
1211
julia = "1"
1312

1413
[extras]
14+
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
1515
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1616

1717
[targets]
18-
test = ["Test"]
18+
test = ["Quaternions", "Test"]

src/Octonions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Base: abs, abs2, conj, exp, inv, isreal, isfinite, isinf, iszero, isnan,
55
import Base: promote_rule, float
66
import Base: rand, randn
77
import LinearAlgebra: normalize
8-
using Quaternions: Quaternion
98
using Random
109

1110
Base.@irrational INV_SQRT_EIGHT 0.3535533905932737622004 sqrt(big(0.125))

src/octonion.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ struct Octonion{T<:Real} <: Number
1111
end
1212

1313
Octonion{T}(x::Real) where {T<:Real} = Octonion(convert(T, x))
14-
Octonion{T}(x::Complex) where {T<:Real} = Octonion(convert(Complex{T}, x))
15-
Octonion{T}(q::Quaternion) where {T<:Real} = Octonion(convert(Quaternion{T}, q))
1614
Octonion{T}(o::Octonion) where {T<:Real} =
1715
Octonion{T}(o.s, o.v1, o.v2, o.v3, o.v4, o.v5, o.v6, o.v7, o.norm)
1816

1917
Octonion(s::Real, v1::Real, v2::Real, v3::Real, v4::Real, v5::Real, v6::Real, v7::Real, n::Bool = false) =
2018
Octonion(promote(s, v1, v2, v3, v4, v5, v6, v7)..., n)
2119
Octonion(x::Real) = Octonion(x, zero(x), zero(x), zero(x), zero(x), zero(x), zero(x), zero(x), abs(x) == one(x))
22-
Octonion(z::Complex) = Octonion(z.re, z.im, zero(z.re), zero(z.re), zero(z.re), zero(z.re), zero(z.re), zero(z.re), abs(z) == one(z.re))
23-
Octonion(q::Quaternion) = Octonion(q.s, q.v1, q.v2, q.v3, zero(q.s), zero(q.s), zero(q.s), zero(q.s), q.norm)
2420
Octonion(s::Real, a::Vector) = Octonion(s, a[1], a[2], a[3], a[4], a[5], a[6], a[7])
2521
Octonion(a::Vector) = Octonion(0, a[1], a[2], a[3], a[4], a[5], a[6], a[7])
2622

@@ -29,8 +25,6 @@ const OctonionF32 = Octonion{Float32}
2925
const OctonionF64 = Octonion{Float64}
3026

3127
promote_rule(::Type{Octonion{T}}, ::Type{S}) where {T <: Real, S <: Real} = Octonion{promote_type(T, S)}
32-
promote_rule(::Type{Octonion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real} = Octonion{promote_type(T, S)}
33-
promote_rule(::Type{Octonion{T}}, ::Type{Quaternion{S}}) where {T <: Real, S <: Real} = Octonion{promote_type(T, S)}
3428
promote_rule(::Type{Octonion{T}}, ::Type{Octonion{S}}) where {T <: Real, S <: Real} = Octonion{promote_type(T, S)}
3529

3630
octo(p, v1, v2, v3, v4, v5, v6, v7) = Octonion(p, v1, v2, v3, v4, v5, v6, v7)
@@ -148,7 +142,8 @@ function log(o::Octonion)
148142
o.v6 * M,
149143
o.v7 * M)
150144
else
151-
return Octonion(complex(log(a), ifelse(iszero(a), zero(th), th)))
145+
z = zero(th)
146+
return Octonion(log(a), ifelse(iszero(a), z, th), z, z, z, z, z, z)
152147
end
153148
end
154149

test/octonion.jl

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
using LinearAlgebra
22
using Octonions
3-
using Quaternions: Quaternion, QuaternionF64
3+
using Quaternions: Quaternions, Quaternion, QuaternionF64
44
using Random
55
using Test
66

7+
_octo(a::Real) = octo(a)
8+
function _octo(c::Complex{T}) where T
9+
z = zero(T)
10+
return octo(reim(c)..., z, z, z, z, z, z)
11+
end
12+
function _octo(q::Quaternion{T}) where T
13+
z = zero(T)
14+
return octo(real(q), Quaternions.imag_part(q)..., z, z, z, z)
15+
end
16+
717
@testset "Octonion" begin
818
@testset "type aliases" begin
919
@test OctonionF16 === Octonion{Float16}
@@ -33,26 +43,6 @@ using Test
3343
@test @inferred(Octonion(T(x))) === Octonion{T}(coef..., isone(abs(x)))
3444
end
3545
end
36-
@testset "from complex" begin
37-
@testset for z in (1 + 0im, -im, 1 + 2im),
38-
T in (Float32, Float64, Int, Rational{Int})
39-
40-
coef = T.((reim(z)..., zeros(6)...))
41-
z2 = Complex{T}(z)
42-
norm = isone(abs(z))
43-
@test Octonion{T}(z) === Octonion{T}(coef..., norm)
44-
@test @inferred(Octonion(z2)) === Octonion{T}(coef..., norm)
45-
end
46-
end
47-
@testset "from quaternion" begin
48-
qs = (Quaternion(1, 2, 3, 4), QuaternionF64(0, 1, 0, 0, true))
49-
@testset for q in qs, T in (Float32, Float64)
50-
coef = T.((q.s, q.v1, q.v2, q.v3, zeros(4)...))
51-
q2 = Quaternion{T}(q)
52-
@test @inferred(Octonion{T}(q)) === Octonion{T}(coef..., q.norm)
53-
@test @inferred(Octonion(q2)) === Octonion{T}(coef..., q.norm)
54-
end
55-
end
5646
@testset "from octonion" begin
5747
os = (
5848
Octonion(1, 2, 3, 4, 5, 6, 7, 8), OctonionF64(0, 1, 0, 0, 0, 0, 0, 0, true)
@@ -80,12 +70,6 @@ using Test
8070

8171
@testset "convert" begin
8272
@test convert(Octonion{Float64}, 1) === Octonion(1.0)
83-
@test convert(Octonion{Float64}, Complex(1, 2)) ===
84-
Octonion(1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
85-
@test convert(Octonion{Float64}, Quaternion(1, 2, 3, 4)) ===
86-
Octonion(1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0, 0.0)
87-
@test convert(Octonion{Float64}, Quaternion(0, 1, 0, 0, true)) ===
88-
Octonion(0.0, 1.0, 0.0, 0.0, 0, 0, 0, 0, true)
8973
@test convert(Octonion{Float64}, Octonion(1, 2, 3, 4, 5, 6, 7, 8)) ===
9074
Octonion(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
9175
@test convert(Octonion{Float64}, Octonion(0, 0, 0, 0, 1, 0, 0, 0, true)) ===
@@ -96,16 +80,9 @@ using Test
9680
@test promote(Octonion(1.0, 2:8...), 1.0) === (Octonion(1.0, 2:8...), Octonion(1.0))
9781
@test promote(Octonion(1.0f0, 2:8...), 2.0) ===
9882
(Octonion(1.0, 2:8...), Octonion(2.0))
99-
@test promote(Octonion(1.0f0), 2 + 3im) ===
100-
(Octonion(1.0f0), Octonion(2.0f0 + 3.0f0im))
101-
@test promote(Octonion(1.0f0), Quaternion(1, 2, 3, 4)) ===
102-
(Octonion(1.0f0), Octonion(1.0f0:4.0f0..., fill(0, 4)...))
10383
@test promote(Octonion(1.0f0), Octonion(2.0)) === (Octonion(1.0), Octonion(2.0))
10484

10585
@test Octonion(1) == 1.0
106-
@test Octonion(1, 2, fill(0, 6)...) == Complex(1.0, 2.0)
107-
@test Octonion(1) == 1.0
108-
@test Octonion(1:4..., fill(0, 4)...) == Quaternion(1.0:4.0...)
10986
end
11087

11188
@testset "shorthands" begin
@@ -209,8 +186,8 @@ using Test
209186
test_multiplicative(q1, q2, *, norm)
210187

211188
# complex embedding
212-
test_multiplicative(c1, c2, *, Octonion)
213-
test_multiplicative(c1, c2, +, Octonion)
189+
test_multiplicative(c1, c2, *, _octo)
190+
test_multiplicative(c1, c2, +, _octo)
214191
end
215192
end
216193

@@ -371,8 +348,7 @@ using Test
371348
@test q7 * q6 == q3
372349
@test q7 * q7 == -q0
373350

374-
@testset "* same between Quaternions and Octonion" begin
375-
# make sure this tracks the `*` tests for Quaternions
351+
@testset "* same between quaternion and Octonion" begin
376352
q1 = Octonion(1,0,0,0,0,0,0,0)
377353
qi = Octonion(0,1,0,0,0,0,0,0)
378354
qj = Octonion(0,0,1,0,0,0,0,0)
@@ -446,8 +422,8 @@ using Test
446422
for _ in 1:100
447423
o1, o2 = randn(OctonionF64, 2)
448424
q = randn(QuaternionF64)
449-
o = octo(q)
450-
@test @inferred(fun(o)) fun(q)
425+
o = _octo(q)
426+
@test @inferred(fun(o)) _octo(fun(q))
451427
@test o2 * fun(o1) * inv(o2) fun(o2 * o1 * inv(o2))
452428
end
453429
end
@@ -461,8 +437,8 @@ using Test
461437
for _ in 1:100
462438
o1, o2 = randn(OctonionF64, 2)
463439
q = randn(QuaternionF64)
464-
o = octo(q)
465-
@test @inferred(fun(o)) fun(q)
440+
o = _octo(q)
441+
@test @inferred(fun(o)) _octo(fun(q))
466442
@test o2 * fun(o1) * inv(o2) fun(o2 * o1 * inv(o2))
467443
end
468444
end

0 commit comments

Comments
 (0)