From f52cfdc596ed7245d90dcba3d7dd4bfbb04f7aa6 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 12 Jul 2018 21:18:18 +0200 Subject: [PATCH 1/3] Bump requirement to Julia 0.7-beta --- .travis.yml | 2 +- REQUIRE | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a12fc41..bb329ba3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ os: - linux - osx julia: - - 0.6 + - 0.7 - nightly matrix: diff --git a/REQUIRE b/REQUIRE index fc8e66e3..77cefff5 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ -julia 0.6 +julia 0.7-beta DualNumbers From d94f49a0a906b8a27eb72b695623147ce8c12bb9 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Thu, 12 Jul 2018 22:03:21 +0200 Subject: [PATCH 2/3] Update syntax to Julia 0.7 --- src/Octonion.jl | 2 +- src/Quaternion.jl | 11 +++++++---- src/Quaternions.jl | 6 +++++- test/runtests.jl | 2 +- test/test_Quaternion.jl | 3 ++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Octonion.jl b/src/Octonion.jl index 0265292a..64b4a5c2 100644 --- a/src/Octonion.jl +++ b/src/Octonion.jl @@ -135,7 +135,7 @@ function log(o::Octonion) o, a = normalizea(o) s = o.s M = abs(Octonion(imag(o))) - th = atan2(M, s) + th = atan(M, s) if M > 0 M = th / M return Octonion(log(a), diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 8cdd2acd..048705fc 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -6,6 +6,9 @@ struct Quaternion{T<:Real} <: Number norm::Bool end +(::Type{Quaternion{T}})(x::Real) where {T} = Quaternion{T}(x, 0, 0, 0, false) +(::Type{Quaternion{T}})(q::Quaternion{T}) where {T<:Real} = q +(::Type{Quaternion{T}})(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3, q.norm) Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false) = Quaternion(promote(s, v1, v2, v3)..., n) Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x), abs(x) == one(x)) @@ -94,7 +97,7 @@ end angleaxis(q::Quaternion) = angle(q), axis(q) -angle(q::Quaternion) = 2 * atan2(√(q.v1^2 + q.v2^2 + q.v3^2), q.s) +angle(q::Quaternion) = 2 * atan(√(q.v1^2 + q.v2^2 + q.v3^2), q.s) function axis(q::Quaternion) q = normalize(q) @@ -121,7 +124,7 @@ function log(q::Quaternion) q, a = normalizea(q) s = q.s M = abs_imag(q) - th = atan2(M, s) + th = atan(M, s) if M > 0 M = th / M return Quaternion(log(a), q.v1 * M, q.v2 * M, q.v3 * M) @@ -208,7 +211,7 @@ function qrotation(rotvec::Vector{T}) where {T <: Real} Quaternion(one(T), zero(T), zero(T), zero(T), true) end -function qrotation{T<:Real}(dcm::Matrix{T}) +function qrotation(dcm::Matrix{T}) where {T<:Real} # See https://arxiv.org/pdf/math/0701759.pdf a2 = 1 + dcm[1,1] + dcm[2,2] + dcm[3,3] b2 = 1 + dcm[1,1] - dcm[2,2] - dcm[3,3] @@ -230,7 +233,7 @@ function qrotation{T<:Real}(dcm::Matrix{T}) end end -function qrotation{T<:Real}(dcm::Matrix{T}, qa::Quaternion) +function qrotation(dcm::Matrix{T}, qa::Quaternion) where {T<:Real} q = qrotation(dcm) abs(q-qa) < abs(q+qa) ? q : -q end diff --git a/src/Quaternions.jl b/src/Quaternions.jl index 4d934ce3..ccd8aa16 100644 --- a/src/Quaternions.jl +++ b/src/Quaternions.jl @@ -1,7 +1,11 @@ __precompile__() module Quaternions - importall Base + + import Base: +, -, *, /, ^ + import Base: abs, abs2, angle, conj, cos, exp, inv, isfinite, log, real, sin, sqrt + import Base: convert, promote_rule + import LinearAlgebra: norm, normalize include("Quaternion.jl") include("Octonion.jl") diff --git a/test/runtests.jl b/test/runtests.jl index a4eb73ca..7efdeb78 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Base.Test +using Test using Quaternions test_associative(x, y, z, ⊗) = @test (x ⊗ y) ⊗ z ≈ x ⊗ (y ⊗ z) diff --git a/test/test_Quaternion.jl b/test/test_Quaternion.jl index 648df908..d0635f2e 100644 --- a/test/test_Quaternion.jl +++ b/test/test_Quaternion.jl @@ -1,5 +1,6 @@ -import Quaternions.argq +using Quaternions: argq +using LinearAlgebra # creating random examples sample(QT::Type{Quaternion{T}}) where {T <: Integer} = QT(rand(-100:100, 4)..., false) From acb8c24a9cfb8f408553d3ae0a1d6332c6d08411 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Sat, 14 Jul 2018 08:48:08 +0200 Subject: [PATCH 3/3] Make it work on 0.6 --- .travis.yml | 1 + REQUIRE | 3 ++- src/Quaternions.jl | 4 +++- test/runtests.jl | 2 +- test/test_Quaternion.jl | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb329ba3..acea1217 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ os: - linux - osx julia: + - 0.6 - 0.7 - nightly diff --git a/REQUIRE b/REQUIRE index 77cefff5..b1e4e3ed 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ -julia 0.7-beta +julia 0.6 +Compat 0.48 DualNumbers diff --git a/src/Quaternions.jl b/src/Quaternions.jl index ccd8aa16..7422db46 100644 --- a/src/Quaternions.jl +++ b/src/Quaternions.jl @@ -2,10 +2,12 @@ __precompile__() module Quaternions + using Compat + import Base: +, -, *, /, ^ import Base: abs, abs2, angle, conj, cos, exp, inv, isfinite, log, real, sin, sqrt import Base: convert, promote_rule - import LinearAlgebra: norm, normalize + import Compat.LinearAlgebra: norm, normalize include("Quaternion.jl") include("Octonion.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 7efdeb78..a11cf76e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Test +using Compat.Test using Quaternions test_associative(x, y, z, ⊗) = @test (x ⊗ y) ⊗ z ≈ x ⊗ (y ⊗ z) diff --git a/test/test_Quaternion.jl b/test/test_Quaternion.jl index d0635f2e..a27878fe 100644 --- a/test/test_Quaternion.jl +++ b/test/test_Quaternion.jl @@ -1,6 +1,7 @@ using Quaternions: argq -using LinearAlgebra +using Compat +using Compat.LinearAlgebra # creating random examples sample(QT::Type{Quaternion{T}}) where {T <: Integer} = QT(rand(-100:100, 4)..., false)