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

Implement rand() #112

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.5.12"
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"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

Expand Down
3 changes: 3 additions & 0 deletions src/DomainSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module DomainSets
using StaticArrays
using LinearAlgebra, Statistics
import LinearAlgebra: cross, ×, pinv
import Random
using Random: AbstractRNG

using IntervalSets
using CompositeTypes, CompositeTypes.Display, CompositeTypes.Indexing
Expand Down Expand Up @@ -216,6 +218,7 @@ include("domains/indicator.jl")
include("domains/boundingbox.jl")

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

end # module
18 changes: 18 additions & 0 deletions src/applications/random.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Random.gentype(::Type{<:Domain{T}}) where T = T

# Random.gentype(::Type{<:ProductDomain{T}}) where T = T
Base.rand(rng::AbstractRNG, s::Random.SamplerTrivial{<:ProductDomain}) = map(i->(rand(rng, i)), factors(s[]))
Copy link
Member

Choose a reason for hiding this comment

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

I think here you'd want to put a toexternalpoint(d, outcome_of_map) around it, where d is the product domain


# Random.gentype(::Type{DerivedDomain{T}}) where T = Random.gentype(D)
Base.rand(rng::AbstractRNG, s::Random.SamplerTrivial{<:SimpleLazyDomain}) = rand(rng, superdomain(s[]))

# Ball
# Mapped


# Rectangle
# Wrapped
# Product Domain

# # Maybe
# Sphere
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Test, LinearAlgebra, StaticArrays
using Test, LinearAlgebra, StaticArrays, Random

using DomainSets
using CompositeTypes.Indexing

include("test_common.jl")
# include("test_common.jl")
include("test_maps.jl")
include("test_generic_domain.jl")
include("test_specific_domains.jl")
include("test_canonical.jl")
include("test_setoperations.jl")
# include("test_generic_domain.jl")
# include("test_specific_domains.jl")
# include("test_canonical.jl")
# include("test_setoperations.jl")
include("test_applications.jl")
include("test_readme.jl")
# include("test_readme.jl")
21 changes: 21 additions & 0 deletions test/test_applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,32 @@ function test_cart_polar_map(T)
@test inverse(m2) == m1
end

function test_rand(T)
r = Rectangle(T[-1, 2], T[3, 4])
@test @inferred(Random.gentype(r)) == Vector{T}
@test typeof(rand(r)) == Random.gentype(r)
@test @inferred(rand(r)) in r

r = Rectangle(SA[T(-1), T(2)], SA[T(3), T(4)])
@test @inferred(Random.gentype(r)) == SVector{2, T}
@test typeof(rand(r)) == Random.gentype(r)
@test @inferred(rand(r)) in r

hybrid_product = ProductDomain(["a", "b"], 1.0..2.0)
@test @inferred(Random.gentype(hybrid_product)) == Tuple{String, Float64}
@test typeof(rand(hybrid_product)) == Random.gentype(hybrid_product)
@test @inferred(rand(hybrid_product)) in hybrid_product

# b = Ball(2.0, SA[1.0, 2.0])
# @test @inferred(Random.gentype(r)) == SVector{2, T}
# @test typeof(rand(r)) == Random.gentype(r)
# @test @inferred(rand(r)) in r
end

function test_applications(T)
test_rotation_map(T)
test_cart_polar_map(T)
test_rand(T)
end

@testset "applications" begin
Expand Down