Skip to content

Commit

Permalink
Deprecate quatrand and nquatrand (#125)
Browse files Browse the repository at this point in the history
* remove Rational in randn

* deprecate quatrand and nquatrand

* remove exports, quatrand and nquatrand

* add `@test_deprecated` for quatrand and nquatrand
  • Loading branch information
hyrodium authored Jan 25, 2023
1 parent 6cba417 commit a4d227c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,19 @@ end

Base.:^(q::Quaternion, w::Quaternion) = exp(w * log(q))

quatrand(rng = Random.GLOBAL_RNG) = quat(randn(rng), randn(rng), randn(rng), randn(rng))
nquatrand(rng = Random.GLOBAL_RNG) = sign(quatrand(rng))
Base.@deprecate quatrand(rng::AbstractRNG=Random.GLOBAL_RNG) randn(rng, QuaternionF64) * 2
Base.@deprecate nquatrand(rng = Random.GLOBAL_RNG) sign(randn(rng, QuaternionF64))

function Base.rand(rng::AbstractRNG, ::Random.SamplerType{Quaternion{T}}) where {T<:Real}
Quaternion{T}(rand(rng, T), rand(rng, T), rand(rng, T), rand(rng, T))
end

function Base.randn(rng::AbstractRNG, ::Type{Quaternion{T}}) where {T<:AbstractFloat}
Quaternion{T}(
randn(rng, T) * 1//2,
randn(rng, T) * 1//2,
randn(rng, T) * 1//2,
randn(rng, T) * 1//2,
randn(rng, T) / 2,
randn(rng, T) / 2,
randn(rng, T) / 2,
randn(rng, T) / 2,
)
end

Expand Down
2 changes: 0 additions & 2 deletions src/Quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export Quaternion
export QuaternionF16, QuaternionF32, QuaternionF64
export quat
export imag_part
export quatrand
export nquatrand
export slerp

end # module
2 changes: 2 additions & 0 deletions test/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ end

@testset "random generation" begin
@testset "quatrand" begin
@test_deprecated quatrand()
rng = Random.MersenneTwister(42)
q1 = quatrand(rng)
@test q1 isa Quaternion
Expand All @@ -106,6 +107,7 @@ end
end

@testset "nquatrand" begin
@test_deprecated nquatrand()
rng = Random.MersenneTwister(42)
q1 = nquatrand(rng)
@test q1 isa Quaternion
Expand Down

0 comments on commit a4d227c

Please sign in to comment.