From 7030d39a9e5a67c9f22d06a9a3e1a97ee66b9c52 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 7 Mar 2022 21:29:31 +0900 Subject: [PATCH] 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 * update imag(o::Octonion) with @deprecate * Update src/Octonion.jl Co-authored-by: Seth Axen * update tests * add imag tests for DualQuaternion * Replace `@test` with `@test_deprecated` for `imag` test Co-authored-by: Seth Axen * Replace `@test` with `@test_deprecated` for `imag` test Co-authored-by: Seth Axen * bump version to v0.5.3 Co-authored-by: Seth Axen --- Project.toml | 2 +- README.md | 4 ++-- src/DualQuaternion.jl | 2 +- src/Octonion.jl | 3 ++- src/Quaternion.jl | 3 ++- src/Quaternions.jl | 1 + test/DualQuaternion.jl | 6 ++++-- test/Octonion.jl | 7 ++++--- test/Quaternion.jl | 7 ++++--- 9 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index fb2f6b81..be94c11b 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/README.md b/README.md index 3d9681a5..b033773e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Implemented functions are: +-*/^ real - imag (a vector) + imag_part (tuple) conj abs abs2 @@ -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 diff --git a/src/DualQuaternion.jl b/src/DualQuaternion.jl index 82ef5100..e39ba8a7 100644 --- a/src/DualQuaternion.jl +++ b/src/DualQuaternion.jl @@ -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))) diff --git a/src/Octonion.jl b/src/Octonion.jl index a3f0c2bd..52536e55 100644 --- a/src/Octonion.jl +++ b/src/Octonion.jl @@ -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) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 65ca33d9..990bc3a0 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -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) diff --git a/src/Quaternions.jl b/src/Quaternions.jl index 4c32c7f4..6eeed774 100644 --- a/src/Quaternions.jl +++ b/src/Quaternions.jl @@ -30,6 +30,7 @@ module Quaternions DualQuaternionF64 export quat export octo + export imag_part export dualquat export angleaxis export angle diff --git a/test/DualQuaternion.jl b/test/DualQuaternion.jl index e438d6e3..d731b4ac 100644 --- a/test/DualQuaternion.jl +++ b/test/DualQuaternion.jl @@ -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) @@ -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 diff --git a/test/Octonion.jl b/test/Octonion.jl index e5065ba9..84bd536d 100644 --- a/test/Octonion.jl +++ b/test/Octonion.jl @@ -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) @@ -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) @@ -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( diff --git a/test/Quaternion.jl b/test/Quaternion.jl index c9f4d3ed..a03d4ab0 100644 --- a/test/Quaternion.jl +++ b/test/Quaternion.jl @@ -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) @@ -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) @@ -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