diff --git a/Project.toml b/Project.toml index 13b2638..cad6e61 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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"] diff --git a/src/applications/random.jl b/ext/DomainSetsRandomExt.jl similarity index 68% rename from src/applications/random.jl rename to ext/DomainSetsRandomExt.jl index 39d4982..03948bc 100644 --- a/src/applications/random.jl +++ b/ext/DomainSetsRandomExt.jl @@ -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[] @@ -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)) @@ -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 \ No newline at end of file diff --git a/src/DomainSets.jl b/src/DomainSets.jl index 557ddaf..4b45100 100644 --- a/src/DomainSets.jl +++ b/src/DomainSets.jl @@ -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") @@ -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")