Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to random octonion generation #19

Merged
merged 5 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 1 addition & 3 deletions src/Octonions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 10 additions & 9 deletions src/octonion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,24 @@ 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),
rand(rng, T), rand(rng, T), rand(rng, T), rand(rng, 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

Expand Down
1 change: 1 addition & 0 deletions test/octonion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ end

@testset "random generation" begin
@testset "octorand" begin
@test_deprecated octorand()
o = octorand()
@test o isa Octonion
end
Expand Down