From 08644e546b53563799c028c10b417d4d81b5ae8d Mon Sep 17 00:00:00 2001 From: geekyjackson <105396509+the-one-and-only-jackson@users.noreply.github.com> Date: Sun, 28 May 2023 16:56:31 -0600 Subject: [PATCH] Added HybridProductSpaceStyle --- src/CommonRLSpaces.jl | 1 + src/basic.jl | 9 ++++++--- test/product.jl | 11 ++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CommonRLSpaces.jl b/src/CommonRLSpaces.jl index c1c2a19..9802b78 100644 --- a/src/CommonRLSpaces.jl +++ b/src/CommonRLSpaces.jl @@ -15,6 +15,7 @@ export AbstractSpaceStyle, FiniteSpaceStyle, ContinuousSpaceStyle, + HybridSpaceStyle, UnknownSpaceStyle, bounds, elsize diff --git a/src/basic.jl b/src/basic.jl index 79e6697..b0b398e 100644 --- a/src/basic.jl +++ b/src/basic.jl @@ -2,6 +2,7 @@ abstract type AbstractSpaceStyle end struct FiniteSpaceStyle <: AbstractSpaceStyle end struct ContinuousSpaceStyle <: AbstractSpaceStyle end +struct HybridProductSpaceStyle <: AbstractSpaceStyle end struct UnknownSpaceStyle <: AbstractSpaceStyle end """ @@ -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." diff --git a/test/product.jl b/test/product.jl index 0c89c5f..f558a15 100644 --- a/test/product.jl +++ b/test/product.jl @@ -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 +