Skip to content
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
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name = "DomainSets"
uuid = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
version = "0.7.15"
version = "0.7.16"

[deps]
CompositeTypes = "b152e2b5-7a66-4b01-a709-34e65c35f657"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[extensions]
DomainSetsMakieExt = "Makie"
DomainSetsRandomExt = "Random"

[compat]
Aqua = "0.8"
Expand All @@ -30,8 +31,9 @@ julia = "1.6"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "Makie", "StableRNGs"]
test = ["Test", "Aqua", "Makie", "Random", "StableRNGs"]
26 changes: 19 additions & 7 deletions src/applications/random.jl → ext/DomainSetsRandomExt.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
Random.gentype(::Type{<:Domain{T}}) where T = T
module DomainSetsRandomExt

Base.rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:ProductDomain}) =
toexternalpoint(s[], map(i->(rand(rng, i)), factors(s[])))
using DomainSets
using Random

Base.rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:SimpleLazyDomain}) =
toexternalpoint(s[], rand(rng, superdomain(s[])))
using LinearAlgebra, StaticArrays

function Base.rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:Ball})
import Random:
gentype,
rand

gentype(::Type{<:Domain{T}}) where T = T

rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:ProductDomain}) =
DomainSets.toexternalpoint(s[], map(i->(rand(rng, i)), factors(s[])))

rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:DomainSets.SimpleLazyDomain}) =
DomainSets.toexternalpoint(s[], rand(rng, superdomain(s[])))

function rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:Ball})
# Technical details: http://extremelearning.com.au/how-to-generate-uniformly-random-points-on-n-spheres-and-n-balls/

b = s[]
Expand All @@ -20,7 +31,6 @@ function Base.rand(rng::Random.AbstractRNG, s::Random.SamplerTrivial{<:Ball})
return r
end
end

# for higher dimensional balls, use the "Mueller" method
else
u = randn_dimension(rng, eltype(b), dimension(b))
Expand All @@ -39,3 +49,5 @@ randn_dimension(rng::Random.AbstractRNG, t::Type{<:Vector}, d) = randn(rng, elty
# Unions and intersections could be implemented with rejection sampling, but it might be inefficient
# Sphere will require some decisions because `rand(sphere) in sphere` will usually only be approximately satisfied
# Maps may be difficult because the map could distort the distribution so that it is not uniform.

end # module
2 changes: 0 additions & 2 deletions src/DomainSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module DomainSets
using CompositeTypes, CompositeTypes.Display, CompositeTypes.Indexing
using IntervalSets
using LinearAlgebra
using Random
using StaticArrays

include("../FunctionMaps/src/FunctionMaps.jl")
Expand Down Expand Up @@ -205,7 +204,6 @@ include("domains/boundingbox.jl")
include("generic/generator.jl")

include("applications/coordinates.jl")
include("applications/random.jl")
include("applications/rotation.jl")

include("deprecated.jl")
Expand Down
Loading