Skip to content

Commit

Permalink
Improvements to random octonion generation (#19)
Browse files Browse the repository at this point in the history
* Don't use `@irrational`

* Deprecate octorand

* Remove octorand export

* Increment version number
  • Loading branch information
sethaxen authored Jan 25, 2023
1 parent 694e3ca commit d4fdee0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
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

2 comments on commit d4fdee0

@sethaxen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/76373

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.3 -m "<description of version>" d4fdee00c0db786d0afaedc30e4399674d2dfd5a
git push origin v0.2.3

Please sign in to comment.