11using LinearAlgebra
22using Octonions
3- using Quaternions: Quaternion, QuaternionF64
3+ using Quaternions: Quaternions, Quaternion, QuaternionF64
44using Random
55using 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