From d4fdee00c0db786d0afaedc30e4399674d2dfd5a Mon Sep 17 00:00:00 2001 From: Seth Axen Date: Wed, 25 Jan 2023 20:17:37 +0100 Subject: [PATCH] Improvements to random octonion generation (#19) * Don't use `@irrational` * Deprecate octorand * Remove octorand export * Increment version number --- Project.toml | 2 +- src/Octonions.jl | 4 +--- src/octonion.jl | 19 ++++++++++--------- test/octonion.jl | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index ce3e81f..5652b05 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Octonions" uuid = "d00ba074-1e29-4f5e-9fd4-d67071d6a14d" -version = "0.2.2" +version = "0.2.3" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/Octonions.jl b/src/Octonions.jl index 9e39f76..55c5dac 100644 --- a/src/Octonions.jl +++ b/src/Octonions.jl @@ -3,11 +3,9 @@ module Octonions using Random using RealDot: RealDot -Base.@irrational INV_SQRT_EIGHT 0.3535533905932737622004 sqrt(big(0.125)) - include("octonion.jl") export Octonion, OctonionF16, OctonionF32, OctonionF64 -export imag_part, octo, octorand +export imag_part, octo end # module diff --git a/src/octonion.jl b/src/octonion.jl index 0a59681..a3492da 100644 --- a/src/octonion.jl +++ b/src/octonion.jl @@ -205,7 +205,7 @@ end Base.:^(o::Octonion, w::Octonion) = exp(w * log(o)) -octorand(rng::AbstractRNG = Random.GLOBAL_RNG) = octo(randn(rng), randn(rng), randn(rng), randn(rng), randn(rng), randn(rng), randn(rng), randn(rng)) +Base.@deprecate octorand(rng::AbstractRNG=Random.GLOBAL_RNG) randn(rng, OctonionF64)*sqrt(8) function Base.rand(rng::AbstractRNG, ::Random.SamplerType{Octonion{T}}) where {T<:Real} Octonion{T}(rand(rng, T), rand(rng, T), rand(rng, T), rand(rng, T), @@ -213,15 +213,16 @@ function Base.rand(rng::AbstractRNG, ::Random.SamplerType{Octonion{T}}) where {T end function Base.randn(rng::AbstractRNG, ::Type{Octonion{T}}) where {T<:AbstractFloat} + scale = inv(sqrt(T(8))) Octonion{T}( - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, - randn(rng, T) * INV_SQRT_EIGHT, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, + randn(rng, T) * scale, ) end diff --git a/test/octonion.jl b/test/octonion.jl index 7e5a28c..86f9591 100644 --- a/test/octonion.jl +++ b/test/octonion.jl @@ -97,6 +97,7 @@ end @testset "random generation" begin @testset "octorand" begin + @test_deprecated octorand() o = octorand() @test o isa Octonion end