Skip to content

Commit 7030d39

Browse files
hyrodiumsethaxen
andauthored
Add imag_part which returns Tuple (#77)
* update README * replace imag with imag_part * add export imag_part * Update imag with @deprecate Co-authored-by: Seth Axen <seth.axen@gmail.com> * update imag(o::Octonion) with @deprecate * Update src/Octonion.jl Co-authored-by: Seth Axen <seth.axen@gmail.com> * update tests * add imag tests for DualQuaternion * Replace `@test` with `@test_deprecated` for `imag` test Co-authored-by: Seth Axen <seth.axen@gmail.com> * Replace `@test` with `@test_deprecated` for `imag` test Co-authored-by: Seth Axen <seth.axen@gmail.com> * bump version to v0.5.3 Co-authored-by: Seth Axen <seth.axen@gmail.com>
1 parent ffe1bf8 commit 7030d39

File tree

9 files changed

+21
-14
lines changed

9 files changed

+21
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Quaternions"
22
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
3-
version = "0.5.2"
3+
version = "0.5.3"
44

55
[deps]
66
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Implemented functions are:
1313

1414
+-*/^
1515
real
16-
imag (a vector)
16+
imag_part (tuple)
1717
conj
1818
abs
1919
abs2
@@ -95,7 +95,7 @@ They play a role, for instance, in the mathematical foundation of String theory.
9595

9696
+-*/^
9797
real
98-
imag (a vector)
98+
imag_part (tuple)
9999
conj
100100
abs
101101
abs2

src/DualQuaternion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ end
154154
function exp(dq::DualQuaternion)
155155
se = dual(dq.q0.s, dq.qe.s)
156156
se = exp(se)
157-
dq = dualquat(quat(0.0, imag(dq.q0)), quat(0.0, imag(dq.qe)))
157+
dq = dualquat(quat(0.0, imag_part(dq.q0)...), quat(0.0, imag_part(dq.qe)...))
158158
dq, th = normalizea(dq)
159159
if dq.norm
160160
dualquat(se) * (dualquat(cos(th)) + dq * dualquat(sin(th)))

src/Octonion.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function show(io::IO, o::Octonion)
4444
end
4545

4646
real(o::Octonion) = o.s
47-
imag(o::Octonion) = [o.v1, o.v2, o.v3, o.v4, o.v5, o.v6, o.v7]
47+
imag_part(o::Octonion) = (o.v1, o.v2, o.v3, o.v4, o.v5, o.v6, o.v7)
48+
@deprecate imag(o::Octonion) collect(imag_part(o)) false
4849

4950
(/)(o::Octonion, x::Real) = Octonion(o.s / x, o.v1 / x, o.v2 / x, o.v3 / x, o.v4 / x, o.v5 / x, o.v6 / x, o.v7 / x)
5051

src/Quaternion.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ end
3636

3737
real(::Type{Quaternion{T}}) where {T} = T
3838
real(q::Quaternion) = q.s
39-
imag(q::Quaternion) = [q.v1, q.v2, q.v3]
39+
imag_part(q::Quaternion) = (q.v1, q.v2, q.v3)
40+
@deprecate imag(q::Quaternion) collect(imag_part(q)) false
4041

4142
(/)(q::Quaternion, x::Real) = Quaternion(q.s / x, q.v1 / x, q.v2 / x, q.v3 / x)
4243

src/Quaternions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Quaternions
3030
DualQuaternionF64
3131
export quat
3232
export octo
33+
export imag_part
3334
export dualquat
3435
export angleaxis
3536
export angle

test/DualQuaternion.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ end
184184
xs = map(dqs) do dq
185185
return [
186186
real(dq.q0)
187-
Quaternions.imag(dq.q0)
187+
imag_part(dq.q0)...
188188
real(dq.qe)
189-
Quaternions.imag(dq.qe)
189+
imag_part(dq.qe)...
190190
]
191191
end
192192
xs_mean = sum(xs) / length(xs)
@@ -200,6 +200,8 @@ end
200200
q = rand(DualQuaternionF64)
201201
qnorm = normalize(q)
202202
@test_throws MethodError imag(q)
203+
@test_throws MethodError Quaternions.imag(q)
204+
@test_throws MethodError imag_part(q)
203205
@test conj(q) === dualquat(conj(q.q0), conj(q.qe), q.norm)
204206
@test conj(qnorm) === dualquat(conj(qnorm.q0), conj(qnorm.qe), qnorm.norm)
205207
@test conj(conj(q)) === q

test/Octonion.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ using Test
136136
@test eltype(os) === H
137137
@test length(os) == 1000
138138
xs = map(os) do o
139-
return [real(o); Quaternions.imag(o)]
139+
return [real(o); imag_part(o)...]
140140
end
141141
xs_mean = sum(xs) / length(xs)
142142
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
@@ -154,7 +154,7 @@ using Test
154154
@test eltype(os) === H
155155
@test length(os) == 10000
156156
xs = map(os) do o
157-
return [real(o); Quaternions.imag(o)]
157+
return [real(o); imag_part(o)...]
158158
end
159159
xs_mean = sum(xs) / length(xs)
160160
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
@@ -168,7 +168,8 @@ using Test
168168
qnorm = normalize(q)
169169
@test real(q) === q.s
170170
@test_throws MethodError imag(q)
171-
@test Quaternions.imag(q) == [q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7]
171+
@test @test_deprecated(Quaternions.imag(q)) == [q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7]
172+
@test imag_part(q) === (q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7)
172173
@test conj(q) ===
173174
Octonion(q.s, -q.v1, -q.v2, -q.v3, -q.v4, -q.v5, -q.v6, -q.v7, q.norm)
174175
@test conj(qnorm) === Octonion(

test/Quaternion.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
146146
@test eltype(qs) === H
147147
@test length(qs) == 1000
148148
xs = map(qs) do q
149-
return [real(q); Quaternions.imag(q)]
149+
return [real(q); imag_part(q)...]
150150
end
151151
xs_mean = sum(xs) / length(xs)
152152
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
@@ -164,7 +164,7 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
164164
@test eltype(qs) === H
165165
@test length(qs) == 10000
166166
xs = map(qs) do q
167-
return [real(q); Quaternions.imag(q)]
167+
return [real(q); imag_part(q)...]
168168
end
169169
xs_mean = sum(xs) / length(xs)
170170
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
@@ -178,7 +178,8 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
178178
qnorm = normalize(q)
179179
@test real(q) === q.s
180180
@test_throws MethodError imag(q)
181-
@test Quaternions.imag(q) == [q.v1, q.v2, q.v3]
181+
@test @test_deprecated(Quaternions.imag(q)) == [q.v1, q.v2, q.v3]
182+
@test imag_part(q) === (q.v1, q.v2, q.v3)
182183
@test conj(q) === Quaternion(q.s, -q.v1, -q.v2, -q.v3, q.norm)
183184
@test conj(qnorm) === Quaternion(qnorm.s, -qnorm.v1, -qnorm.v2, -qnorm.v3, true)
184185
@test conj(conj(q)) === q

0 commit comments

Comments
 (0)