Skip to content

Commit

Permalink
Added HybridProductSpaceStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
the-one-and-only-jackson committed Jun 2, 2023
1 parent 235fb1c commit 08644e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/CommonRLSpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export
AbstractSpaceStyle,
FiniteSpaceStyle,
ContinuousSpaceStyle,
HybridSpaceStyle,
UnknownSpaceStyle,
bounds,
elsize
Expand Down
9 changes: 6 additions & 3 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ abstract type AbstractSpaceStyle end

struct FiniteSpaceStyle <: AbstractSpaceStyle end
struct ContinuousSpaceStyle <: AbstractSpaceStyle end
struct HybridProductSpaceStyle <: AbstractSpaceStyle end
struct UnknownSpaceStyle <: AbstractSpaceStyle end

"""
Expand All @@ -25,12 +26,14 @@ end

SpaceStyle(::AbstractInterval) = ContinuousSpaceStyle()

promote_spacestyle(::FiniteSpaceStyle, ::FiniteSpaceStyle) = FiniteSpaceStyle()
promote_spacestyle(::ContinuousSpaceStyle, ::ContinuousSpaceStyle) = ContinuousSpaceStyle()
const BASE_SPACE_STYLES = Union{FiniteSpaceStyle, ContinuousSpaceStyle, HybridProductSpaceStyle}
function promote_spacestyle(::T1, ::T2) where {T1 <: BASE_SPACE_STYLES, T2 <: BASE_SPACE_STYLES}
return (T1 == T2) ? T1() : HybridProductSpaceStyle()
end
promote_spacestyle(_, _) = UnknownSpaceStyle()

# handle case of 3 or more
promote_spacestyle(s1, s2, s3, others...) = foldl(promote_spacestyle, (s1, s2, s3, args...))
promote_spacestyle(s1, s2, s3, args...) = foldl(promote_spacestyle, (s1, s2, s3, args...))

"Return the size of the objects in a space. This is guaranteed to be defined if the objects
in the space are arrays, but otherwise it may not be defined."
Expand Down
11 changes: 10 additions & 1 deletion test/product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ end
@test @inferred rand(tp) in tp
@test (1,3) in tp
@test !((1,2) in tp)
@test_broken eltype(tp) == Tuple{Float64, Float64}
@test_broken eltype(tp) == Tuple{Float64, Float64} # IntervalSets eltype -> Int64
@test @inferred SpaceStyle(tp) == ContinuousSpaceStyle()
@test @inferred bounds(tp) == ((1,3), (2,4))
@test @inferred bounds(TupleProduct(1..2, 3..4, 5..6)) == ((1,3,5), (2,4,6))
@test @inferred clamp((0,0), tp) == (1, 3)
end

@testset "TupleProduct hybrid" begin
tp = TupleProduct(1.0..2.0, [3,4])
@test @inferred rand(tp) in tp
@test (1.5,3) in tp
@test !((1.5,3.5) in tp)
@test eltype(tp) == Tuple{Float64, Int64}
@test @inferred SpaceStyle(tp) == HybridSpaceStyle()
end


0 comments on commit 08644e5

Please sign in to comment.