Skip to content

Commit 08644e5

Browse files
Added HybridProductSpaceStyle
1 parent 235fb1c commit 08644e5

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/CommonRLSpaces.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export
1515
AbstractSpaceStyle,
1616
FiniteSpaceStyle,
1717
ContinuousSpaceStyle,
18+
HybridSpaceStyle,
1819
UnknownSpaceStyle,
1920
bounds,
2021
elsize

src/basic.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ abstract type AbstractSpaceStyle end
22

33
struct FiniteSpaceStyle <: AbstractSpaceStyle end
44
struct ContinuousSpaceStyle <: AbstractSpaceStyle end
5+
struct HybridProductSpaceStyle <: AbstractSpaceStyle end
56
struct UnknownSpaceStyle <: AbstractSpaceStyle end
67

78
"""
@@ -25,12 +26,14 @@ end
2526

2627
SpaceStyle(::AbstractInterval) = ContinuousSpaceStyle()
2728

28-
promote_spacestyle(::FiniteSpaceStyle, ::FiniteSpaceStyle) = FiniteSpaceStyle()
29-
promote_spacestyle(::ContinuousSpaceStyle, ::ContinuousSpaceStyle) = ContinuousSpaceStyle()
29+
const BASE_SPACE_STYLES = Union{FiniteSpaceStyle, ContinuousSpaceStyle, HybridProductSpaceStyle}
30+
function promote_spacestyle(::T1, ::T2) where {T1 <: BASE_SPACE_STYLES, T2 <: BASE_SPACE_STYLES}
31+
return (T1 == T2) ? T1() : HybridProductSpaceStyle()
32+
end
3033
promote_spacestyle(_, _) = UnknownSpaceStyle()
3134

3235
# handle case of 3 or more
33-
promote_spacestyle(s1, s2, s3, others...) = foldl(promote_spacestyle, (s1, s2, s3, args...))
36+
promote_spacestyle(s1, s2, s3, args...) = foldl(promote_spacestyle, (s1, s2, s3, args...))
3437

3538
"Return the size of the objects in a space. This is guaranteed to be defined if the objects
3639
in the space are arrays, but otherwise it may not be defined."

test/product.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@ end
3131
@test @inferred rand(tp) in tp
3232
@test (1,3) in tp
3333
@test !((1,2) in tp)
34-
@test_broken eltype(tp) == Tuple{Float64, Float64}
34+
@test_broken eltype(tp) == Tuple{Float64, Float64} # IntervalSets eltype -> Int64
3535
@test @inferred SpaceStyle(tp) == ContinuousSpaceStyle()
3636
@test @inferred bounds(tp) == ((1,3), (2,4))
3737
@test @inferred bounds(TupleProduct(1..2, 3..4, 5..6)) == ((1,3,5), (2,4,6))
3838
@test @inferred clamp((0,0), tp) == (1, 3)
3939
end
4040

41+
@testset "TupleProduct hybrid" begin
42+
tp = TupleProduct(1.0..2.0, [3,4])
43+
@test @inferred rand(tp) in tp
44+
@test (1.5,3) in tp
45+
@test !((1.5,3.5) in tp)
46+
@test eltype(tp) == Tuple{Float64, Int64}
47+
@test @inferred SpaceStyle(tp) == HybridSpaceStyle()
48+
end
49+
4150

0 commit comments

Comments
 (0)