Skip to content

Commit

Permalink
Merge pull request #236 from JuliaReach/schillic/162
Browse files Browse the repository at this point in the history
#162 #145 #165 - add macro to restore old array type behavior
  • Loading branch information
schillic authored Feb 24, 2018
2 parents d4d8f8e + 64ccce0 commit debde7d
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 161 deletions.
9 changes: 9 additions & 0 deletions docs/src/lib/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ end
sign_cadlag
@neutral
@absorbing
@declare_array_version
```

## Helper functions for internal use only

```@docs
@neutral_absorbing
@array_neutral
@array_absorbing
```
80 changes: 7 additions & 73 deletions src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,82 +174,15 @@ function CartesianProductArray(n::Int=0, N::Type=Float64)::CartesianProductArray
return CartesianProductArray(arr)
end

"""
```
CartesianProductArray(cpa::CartesianProductArray,
S::LazySet)::CartesianProductArray
```
Multiply a convex set to a Cartesian product of a finite number of convex sets
from the right.
### Input
- `cpa` -- Cartesian product array (is modified)
- `S` -- convex set
### Output
The modified Cartesian product of a finite number of convex sets.
"""
function CartesianProductArray(cpa::CartesianProductArray,
S::LazySet)::CartesianProductArray
push!(cpa.array, S)
return cpa
end

"""
```
CartesianProductArray(S::LazySet,
cpa::CartesianProductArray)::CartesianProductArray
```
Multiply a convex set to a Cartesian product of a finite number of convex sets
from the left.
### Input
- `S` -- convex set
- `cpa` -- Cartesian product array (is modified)
### Output
The modified Cartesian product of a finite number of convex sets.
"""
function CartesianProductArray(S::LazySet,
cpa::CartesianProductArray)::CartesianProductArray
return CartesianProductArray(cpa, S)
end

"""
```
CartesianProductArray(cpa1::CartesianProductArray,
cpa2::CartesianProductArray)::CartesianProductArray
```
Multiply a finite Cartesian product of convex sets to another finite Cartesian
product.
### Input
- `cpa1` -- first Cartesian product array (is modified)
- `cpa2` -- second Cartesian product array
### Output
The modified first Cartesian product.
"""
function CartesianProductArray(cpa1::CartesianProductArray,
cpa2::CartesianProductArray)::CartesianProductArray
append!(cpa1.array, cpa2.array)
return cpa1
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}}
array(cpa::CartesianProductArray{N, S}
)::Vector{S} where {N<:Real, S<:LazySet{N}}
Return the array of a Cartesian product of a finite number of convex sets.
Expand All @@ -261,7 +194,8 @@ Return the array of a Cartesian product of a finite number of convex sets.
The array of a Cartesian product of a finite number of convex sets.
"""
function array(cpa::CartesianProductArray{N, S})::Vector{S} where {N<:Real, S<:LazySet{N}}
function array(cpa::CartesianProductArray{N, S}
)::Vector{S} where {N<:Real, S<:LazySet{N}}
return cpa.array
end

Expand Down
5 changes: 3 additions & 2 deletions src/ConvexHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ end
# EmptySet is the neutral element for ConvexHullArray
@neutral(ConvexHullArray, EmptySet)

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

"""
CHArray
Alias for `ConvexHullArray`.
"""
const CHArray = ConvexHullArray

CH(cha1::ConvexHullArray, cha2::ConvexHullArray) = ConvexHullArray(vcat(cha1.array, cha2.array))

"""
array(cha::ConvexHullArray{N, S})::Vector{S} where {N<:Real, S<:LazySet{N}}
Expand Down
66 changes: 3 additions & 63 deletions src/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,75 +139,15 @@ function MinkowskiSumArray(n::Int=0, N::Type=Float64)::MinkowskiSumArray
return MinkowskiSumArray(arr)
end

"""
MinkowskiSumArray(msa::MinkowskiSumArray, S::LazySet)::MinkowskiSumArray
Add a convex set to a Minkowski sum of a finite number of convex sets from the
right.
### Input
- `msa` -- Minkowski sum array (is modified)
- `S` -- convex set
### Output
The modified Minkowski sum of a finite number of convex sets.
"""
function MinkowskiSumArray(msa::MinkowskiSumArray,
S::LazySet)::MinkowskiSumArray
push!(msa.array, S)
return msa
end

"""
MinkowskiSumArray(S::LazySet, msa::MinkowskiSumArray)::MinkowskiSumArray
Add a convex set to a Minkowski sum of a finite number of convex sets from the
left.
### Input
- `S` -- convex set
- `msa` -- Minkowski sum array (is modified)
### Output
The modified Minkowski sum of a finite number of convex sets.
"""
function MinkowskiSumArray(S::LazySet,
msa::MinkowskiSumArray)::MinkowskiSumArray
return MinkowskiSumArray(msa, S)
end

"""
MinkowskiSumArray(msa1::MinkowskiSumArray,
msa2::MinkowskiSumArray)::MinkowskiSumArray
Add the elements of a finite Minkowski sum of convex sets to another finite
Minkowski sum.
### Input
- `msa1` -- first Minkowski sum array (is modified)
- `msa2` -- second Minkowski sum array
### Output
The modified first Minkowski sum of a finite number of convex sets.
"""
function MinkowskiSumArray(msa1::MinkowskiSumArray,
msa2::MinkowskiSumArray)::MinkowskiSumArray
append!(msa1.array, msa2.array)
return msa1
end

# ZeroSet is the neutral element for MinkowskiSumArray
@neutral(MinkowskiSumArray, ZeroSet)

# 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
Loading

0 comments on commit debde7d

Please sign in to comment.