Skip to content

Commit

Permalink
add @declare_array_version
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Feb 12, 2018
1 parent 7b12631 commit 25338d6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ end
# EmptySet is the absorbing element for CartesianProductArray
@absorbing(CartesianProductArray, EmptySet)

# add functions connecting CartesianProduct and CartesianProductArray
@declare_array_version(CartesianProduct, CartesianProductArray)

"""
array(cpa::CartesianProductArray{N, S})::Vector{S} where {N<:Real, S<:LazySet{N}}
Expand Down
3 changes: 3 additions & 0 deletions src/ConvexHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ end
# EmptySet is the neutral element for ConvexHullArray
@neutral(ConvexHullArray, EmptySet)

# add functions connecting ConvexHull and ConvexHullArray
@declare_array_version(ConvexHull, ConvexHullArray)

"""
CHArray
Expand Down
3 changes: 3 additions & 0 deletions src/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ end
# EmptySet is the absorbing element for MinkowskiSumArray
@absorbing(MinkowskiSumArray, EmptySet)

# add functions connecting MinkowskiSum and MinkowskiSumArray
@declare_array_version(MinkowskiSum, MinkowskiSumArray)

"""
array(msa::MinkowskiSumArray{N, S})::Vector{S} where {N<:Real, S<:LazySet{N}}
Expand Down
79 changes: 79 additions & 0 deletions src/helper_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,82 @@ macro absorbing(SET, ABS)
end
return nothing
end

# TODO document
#
# TODO add ambiguity functions also to the other macros such that the order of
# calling the macros does not matter
#
# TODO remove now redundant function from the three set files
macro declare_array_version(SET, SETARR)
@eval begin
# create function to obtain the array version
function array_constructor(::Type{$SET})
return $SETARR
end

# create functions to use the array version functions
function $SET(X::LazySet{N}, arr::$SETARR{N}) where {N<:Real}
return $SETARR(arr, X)
end
function $SET(arr::$SETARR{N}, X::LazySet{N}) where {N<:Real}
return $SETARR(arr, X)
end
function $SET(arr1::$SETARR{N}, arr2::$SETARR{N}) where {N<:Real}
return $SETARR(arr1, arr2)
end

# create functions for array version
function $SETARR(X::LazySet{N}, arr::$SETARR{N}) where {N<:Real}
push!(array(arr), X)
return arr
end
function $SETARR(arr::$SETARR{N}, X::LazySet{N}) where {N<:Real}
push!(array(arr), X)
return arr
end
function $SETARR(arr1::$SETARR{N}, arr2::$SETARR{N}) where {N<:Real}
append!(array(arr1), array(arr2))
return arr1
end

# handle method ambiguities with neutral elements
if isdefined(:neutral) && method_exists(neutral, (Type{$SET},))
NEUT = neutral($SET)
function $SET(::NEUT{N}, X::$SETARR{N}) where {N<:Real}
return X
end
function $SET(X::$SETARR{N}, ::NEUT{N}) where {N<:Real}
return X
end
end
if isdefined(:neutral) && method_exists(neutral, (Type{$SETARR},))
NEUT = neutral($SETARR)
function $SETARR(::NEUT{N}, X::$SETARR{N}) where {N<:Real}
return X
end
function $SETARR(X::$SETARR{N}, ::NEUT{N}) where {N<:Real}
return X
end
end
# handle method ambiguities with absorbing elements
if isdefined(:absorbing) && method_exists(absorbing, (Type{$SET},))
ABS = absorbing($SET)
function $SET(Y::ABS{N}, ::$SETARR{N}) where {N<:Real}
return Y
end
function $SET(::$SETARR{N}, Y::ABS{N}) where {N<:Real}
return Y
end
end
if isdefined(:absorbing) && method_exists(absorbing, (Type{$SETARR},))
ABS = absorbing($SETARR)
function $SETARR(Y::ABS{N}, ::$SETARR{N}) where {N<:Real}
return Y
end
function $SETARR(::$SETARR{N}, Y::ABS{N}) where {N<:Real}
return Y
end
end
end
end

0 comments on commit 25338d6

Please sign in to comment.