Skip to content

Commit

Permalink
Add imag_part which returns Tuple (#77)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hyrodium and sethaxen authored Mar 7, 2022
1 parent ffe1bf8 commit 7030d39
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Quaternions"
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
version = "0.5.2"
version = "0.5.3"

[deps]
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Implemented functions are:

+-*/^
real
imag (a vector)
imag_part (tuple)
conj
abs
abs2
Expand Down Expand Up @@ -95,7 +95,7 @@ They play a role, for instance, in the mathematical foundation of String theory.

+-*/^
real
imag (a vector)
imag_part (tuple)
conj
abs
abs2
Expand Down
2 changes: 1 addition & 1 deletion src/DualQuaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end
function exp(dq::DualQuaternion)
se = dual(dq.q0.s, dq.qe.s)
se = exp(se)
dq = dualquat(quat(0.0, imag(dq.q0)), quat(0.0, imag(dq.qe)))
dq = dualquat(quat(0.0, imag_part(dq.q0)...), quat(0.0, imag_part(dq.qe)...))
dq, th = normalizea(dq)
if dq.norm
dualquat(se) * (dualquat(cos(th)) + dq * dualquat(sin(th)))
Expand Down
3 changes: 2 additions & 1 deletion src/Octonion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function show(io::IO, o::Octonion)
end

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

(/)(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)

Expand Down
3 changes: 2 additions & 1 deletion src/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ end

real(::Type{Quaternion{T}}) where {T} = T
real(q::Quaternion) = q.s
imag(q::Quaternion) = [q.v1, q.v2, q.v3]
imag_part(q::Quaternion) = (q.v1, q.v2, q.v3)
@deprecate imag(q::Quaternion) collect(imag_part(q)) false

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

Expand Down
1 change: 1 addition & 0 deletions src/Quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Quaternions
DualQuaternionF64
export quat
export octo
export imag_part
export dualquat
export angleaxis
export angle
Expand Down
6 changes: 4 additions & 2 deletions test/DualQuaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ end
xs = map(dqs) do dq
return [
real(dq.q0)
Quaternions.imag(dq.q0)
imag_part(dq.q0)...
real(dq.qe)
Quaternions.imag(dq.qe)
imag_part(dq.qe)...
]
end
xs_mean = sum(xs) / length(xs)
Expand All @@ -200,6 +200,8 @@ end
q = rand(DualQuaternionF64)
qnorm = normalize(q)
@test_throws MethodError imag(q)
@test_throws MethodError Quaternions.imag(q)
@test_throws MethodError imag_part(q)
@test conj(q) === dualquat(conj(q.q0), conj(q.qe), q.norm)
@test conj(qnorm) === dualquat(conj(qnorm.q0), conj(qnorm.qe), qnorm.norm)
@test conj(conj(q)) === q
Expand Down
7 changes: 4 additions & 3 deletions test/Octonion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ using Test
@test eltype(os) === H
@test length(os) == 1000
xs = map(os) do o
return [real(o); Quaternions.imag(o)]
return [real(o); imag_part(o)...]
end
xs_mean = sum(xs) / length(xs)
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
Expand All @@ -154,7 +154,7 @@ using Test
@test eltype(os) === H
@test length(os) == 10000
xs = map(os) do o
return [real(o); Quaternions.imag(o)]
return [real(o); imag_part(o)...]
end
xs_mean = sum(xs) / length(xs)
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
Expand All @@ -168,7 +168,8 @@ using Test
qnorm = normalize(q)
@test real(q) === q.s
@test_throws MethodError imag(q)
@test Quaternions.imag(q) == [q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7]
@test @test_deprecated(Quaternions.imag(q)) == [q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7]
@test imag_part(q) === (q.v1, q.v2, q.v3, q.v4, q.v5, q.v6, q.v7)
@test conj(q) ===
Octonion(q.s, -q.v1, -q.v2, -q.v3, -q.v4, -q.v5, -q.v6, -q.v7, q.norm)
@test conj(qnorm) === Octonion(
Expand Down
7 changes: 4 additions & 3 deletions test/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
@test eltype(qs) === H
@test length(qs) == 1000
xs = map(qs) do q
return [real(q); Quaternions.imag(q)]
return [real(q); imag_part(q)...]
end
xs_mean = sum(xs) / length(xs)
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
Expand All @@ -164,7 +164,7 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
@test eltype(qs) === H
@test length(qs) == 10000
xs = map(qs) do q
return [real(q); Quaternions.imag(q)]
return [real(q); imag_part(q)...]
end
xs_mean = sum(xs) / length(xs)
xs_var = sum(x -> abs2.(x .- xs_mean), xs) / (length(xs) - 1)
Expand All @@ -178,7 +178,8 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b
qnorm = normalize(q)
@test real(q) === q.s
@test_throws MethodError imag(q)
@test Quaternions.imag(q) == [q.v1, q.v2, q.v3]
@test @test_deprecated(Quaternions.imag(q)) == [q.v1, q.v2, q.v3]
@test imag_part(q) === (q.v1, q.v2, q.v3)
@test conj(q) === Quaternion(q.s, -q.v1, -q.v2, -q.v3, q.norm)
@test conj(qnorm) === Quaternion(qnorm.s, -qnorm.v1, -qnorm.v2, -qnorm.v3, true)
@test conj(conj(q)) === q
Expand Down

2 comments on commit 7030d39

@hyrodium
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56130

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.3 -m "<description of version>" 7030d39a9e5a67c9f22d06a9a3e1a97ee66b9c52
git push origin v0.5.3

Please sign in to comment.