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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DomainSets"
uuid = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
version = "0.8.1"
version = "0.8.2"

[deps]
CompositeTypes = "b152e2b5-7a66-4b01-a709-34e65c35f657"
Expand Down
2 changes: 2 additions & 0 deletions src/domains/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ in(x::Complex{T}, d::ComplexNumbers) where {T<:Real} = true
in(x, d::ComplexNumbers) = x ∈ RealNumbers()


choice(d::Union{RealNumbers,Rationals,ComplexNumbers,NaturalNumbers,Integers}) = zero(eltype(d))

"The set of natural numbers."
const ℕ = NaturalNumbers()
"The set of integers."
Expand Down
3 changes: 2 additions & 1 deletion src/generic/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ isapprox(d1::Domain, d2::Domain; kwds...) = d1 == d2
isrealdomain(d::Domain) = isrealtype(domaineltype(d))

"Return a point from the given domain."
function choice(d) end
choice(d) = error("Overload choice(::$(typeof(d)))")

choice(d::AbstractSet) = first(d)
choice(d::AbstractArray) = first(d)
choice(d::Number) = d
2 changes: 1 addition & 1 deletion test/test_applications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ end
m2 = CartToPolarMap()
cmap = m1 ∘ m2 ∘ m1
x = rand(2)
@test cmap(x) == m1(m2(m1(x)))
@test cmap(x) ≈ m1(m2(m1(x)))
end
1 change: 1 addition & 0 deletions test/test_domain_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using DomainSets: unionbox, intersectbox
function test_product_domains()
@test productdomain() == ()
@test productdomain(2) == 2
@test choice(productdomain(2)) ≡ 2

@testset "VcatDomain" begin
d1 = VcatDomain(-1.0..1.0, -1.0..1.0)
Expand Down
1 change: 1 addition & 0 deletions test/test_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct NonDomain end
@test !(d3 isa Domain)
@test DomainStyle(d3) == NotDomain()
@test_throws ErrorException checkdomain(d3)
@test_throws ErrorException choice(d3)

@test DomainStyle(2.0) == IsDomain()
@test DomainStyle([1,2]) == IsDomain()
Expand Down
7 changes: 7 additions & 0 deletions test/test_specific_domains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,13 @@ include("test_domain_simplex.jl")
@test (SVector(0.1,0.2),0.3) ∉ d7
@test (SVector(1,2),3) ∉ d7
end

@testset "choice" begin
@test choice(ℕ) ≡ 0
@test choice(ℝ) ≡ 0.0
@test choice(ℚ) ≡ 0//1
@test choice(ℂ) ≡ 0.0+0.0im
end
end

@testset "cartesian product" begin
Expand Down
Loading