Skip to content

Commit d4494f2

Browse files
authored
Remove compatibility with Complex (#113)
* remove compatibility with `Complex` * fix tests for removing compatibility with `Complex`
1 parent 9c62d64 commit d4494f2

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

src/Quaternion.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,9 @@ const QuaternionF32 = Quaternion{Float32}
2020
const QuaternionF64 = Quaternion{Float64}
2121

2222
Quaternion{T}(x::Real) where {T<:Real} = Quaternion(convert(T, x))
23-
function Quaternion{T}(x::Complex) where {T<:Real}
24-
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
25-
Quaternion(convert(Complex{T}, x))
26-
end
2723
Quaternion{T}(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3)
2824
Quaternion(s::Real, v1::Real, v2::Real, v3::Real) = Quaternion(promote(s, v1, v2, v3)...)
2925
Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x))
30-
function Quaternion(z::Complex)
31-
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
32-
Quaternion(z.re, z.im, zero(z.re), zero(z.re))
33-
end
3426
function Quaternion(s::Real, a::AbstractVector)
3527
Base.depwarn("`Quaternion(s::Real, a::AbstractVector)` is deprecated and will be removed in the next breaking release (v0.7.0). Please use `Quaternion(s, a[1], a[2], a[3])` instead.", :Quaternion)
3628
Quaternion(s, a[1], a[2], a[3])
@@ -41,10 +33,6 @@ function Quaternion(a::AbstractVector)
4133
end
4234

4335
Base.promote_rule(::Type{Quaternion{T}}, ::Type{S}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)}
44-
function Base.promote_rule(::Type{Quaternion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real}
45-
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
46-
Quaternion{promote_type(T, S)}
47-
end
4836
Base.promote_rule(::Type{Quaternion{T}}, ::Type{Quaternion{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)}
4937

5038
"""

test/Quaternion.jl

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ struct MyReal <: Real
88
end
99
Base.:(/)(a::MyReal, b::Real) = a.val / b
1010

11+
function _quat(c::Complex{T}) where T
12+
Quaternion(reim(c)...,zero(T),zero(T))
13+
end
14+
function _quat(a::Real)
15+
Quaternion(a)
16+
end
17+
1118
@testset "Quaternion" begin
1219
@testset "type aliases" begin
1320
@test QuaternionF16 === Quaternion{Float16}
@@ -33,16 +40,6 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
3340
@test @inferred(Quaternion(T(x))) === Quaternion{T}(coef...)
3441
end
3542
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)..., 0, 0))
41-
z2 = Complex{T}(z)
42-
@test Quaternion{T}(z) === Quaternion{T}(coef...)
43-
@test @inferred(Quaternion(z2)) === Quaternion{T}(coef...)
44-
end
45-
end
4643
@testset "from quaternion" begin
4744
@testset for q in (Quaternion(1, 2, 3, 4), QuaternionF64(0, 1, 0, 0)),
4845
T in (Float32, Float64)
@@ -70,7 +67,6 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
7067

7168
@testset "convert" begin
7269
@test convert(Quaternion{Float64}, 1) === Quaternion(1.0)
73-
@test convert(Quaternion{Float64}, Complex(1, 2)) === Quaternion(1.0, 2.0, 0.0, 0.0)
7470
@test convert(Quaternion{Float64}, Quaternion(1, 2, 3, 4)) ===
7571
Quaternion(1.0, 2.0, 3.0, 4.0)
7672
@test convert(Quaternion{Float64}, Quaternion(1.0, 2.0, 3.0, 4.0)) ===
@@ -84,13 +80,10 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
8480
(Quaternion(1.0, 2, 3, 4), Quaternion(1.0))
8581
@test promote(Quaternion(1.0f0, 2, 3, 4), 2.0) ===
8682
(Quaternion(1.0, 2, 3, 4), Quaternion(2.0))
87-
@test promote(Quaternion(1.0f0), 2 + 3im) ===
88-
(Quaternion(1.0f0), Quaternion(2.0f0 + 3.0f0im))
8983
@test promote(Quaternion(1.0f0), Quaternion(2.0)) ===
9084
(Quaternion(1.0), Quaternion(2.0))
9185

9286
@test Quaternion(1) == 1.0
93-
@test Quaternion(1, 2, 0, 0) == Complex(1.0, 2.0)
9487
end
9588

9689
@testset "shorthands" begin
@@ -174,20 +167,14 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
174167
for _ in 1:100, T in (Float32, Float64, Int32, Int64)
175168
if T <: Integer
176169
q, q1, q2, q3 = [Quaternion(rand((-T(100)):T(100), 4)...) for _ in 1:4]
177-
c1, c2 = [complex(rand((-T(100)):T(100), 2)...) for _ in 1:2]
178170
else
179171
q, q1, q2, q3 = randn(Quaternion{T}, 4)
180-
c1, c2 = randn(Complex{T}, 2)
181172
end
182173

183174
# skewfield
184175
test_group(q1, q2, q3, +, zero(q), -)
185176
test_group(q1, q2, q3, *, one(q), inv)
186177
test_multiplicative(q1, q2, *, norm)
187-
188-
# complex embedding
189-
test_multiplicative(c1, c2, *, Quaternion)
190-
test_multiplicative(c1, c2, +, Quaternion)
191178
end
192179
end
193180

@@ -271,9 +258,11 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
271258
@test qk * qk == -q1
272259
end
273260

274-
@testset "abs2" for _ in 1:100, T in (Float16, Float32, Float64)
275-
q = rand(Quaternion{T})
276-
@test abs2(q) == q'*q
261+
@testset "abs2 with $(T)" for T in (Float16, Float32, Float64)
262+
for _ in 1:100
263+
q = rand(Quaternion{T})
264+
@test abs2(q) == q'*q
265+
end
277266
end
278267

279268
@testset "/" begin
@@ -320,8 +309,8 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
320309
@testset for fun in unary_funs
321310
for _ in 1:100
322311
c = randn(ComplexF64)
323-
q = quat(c)
324-
@test @inferred(fun(q)) fun(c)
312+
q = _quat(c)
313+
@test @inferred(fun(q)) _quat(fun(c))
325314
@test q2 * fun(q) * inv(q2) fun(q2 * q * inv(q2))
326315
end
327316
end
@@ -343,8 +332,8 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
343332
q, q2 = randn(QuaternionF64, 2)
344333
for _ in 1:100
345334
c = randn(ComplexF64)
346-
q = quat(c)
347-
@test @inferred(fun(q)) fun(c)
335+
q = _quat(c)
336+
@test @inferred(fun(q)) _quat(fun(c))
348337
@test q2 * fun(q) * inv(q2) fun(q2 * q * inv(q2))
349338
end
350339
end

0 commit comments

Comments
 (0)