Skip to content

Commit

Permalink
add version without kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Oct 13, 2018
1 parent b2cf366 commit 3fbf13a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
11 changes: 4 additions & 7 deletions src/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ end

@inline function ρ_helper(d::AbstractVector{N},
cp::CartesianProduct{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
ρ_rec::Function) where {N<:Real}
n1 = dim(cp.X)
return ρ_rec(d[1:n1], cp.X; kwargs...) +
ρ_rec(d[n1+1:length(d)], cp.Y; kwargs...)
return ρ_rec(d[1:n1], cp.X) + ρ_rec(d[n1+1:length(d)], cp.Y)
end

"""
Expand Down Expand Up @@ -348,13 +346,12 @@ end

@inline function ρ_helper(d::AbstractVector{N},
cpa::CartesianProductArray{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
ρ_rec::Function) where {N<:Real}
sfun = zero(N)
i0 = 1
for Xi in cpa.array
i1 = i0 + dim(Xi) - 1
sfun += ρ_rec(d[i0:i1], Xi; kwargs...)
sfun += ρ_rec(d[i0:i1], Xi)
i0 = i1 + 1
end
return sfun
Expand Down
10 changes: 4 additions & 6 deletions src/ConvexHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ end

@inline function ρ_helper(d::AbstractVector{N},
ch::ConvexHull{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
return max(ρ_rec(d, ch.X; kwargs...), ρ_rec(d, ch.Y; kwargs...))
ρ_rec::Function) where {N<:Real}
return max(ρ_rec(d, ch.X), ρ_rec(d, ch.Y))
end

"""
Expand Down Expand Up @@ -277,9 +276,8 @@ end

@inline function ρ_helper(d::AbstractVector{N},
cha::ConvexHullArray{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
return maximum([ρ_rec(d, Xi; kwargs...) for Xi in array(cha)])
ρ_rec::Function) where {N<:Real}
return maximum([ρ_rec(d, Xi) for Xi in array(cha)])
end

"""
Expand Down
5 changes: 2 additions & 3 deletions src/ExponentialMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ end

@inline function ρ_helper(d::AbstractVector{N},
em::ExponentialMap{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
ρ_rec::Function) where {N<:Real}
d_dense = d isa Vector ? d : Vector(d)
v = expmv(one(N), transpose(em.spmexp.M), d_dense) # v <- exp(M^T) * d
return ρ_rec(v, em.X; kwargs...)
return ρ_rec(v, em.X)
end

"""
Expand Down
68 changes: 62 additions & 6 deletions src/LazySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ abstract type LazySet{N} end
# --- common LazySet functions ---


@inline function ρ_helper(d::AbstractVector{N},
S::LazySet{N},
ρ_rec::Function)::N where {N<:Real}
return dot(d, σ(d, S))
end

ρ_args(kwargs...) = (d, X) -> ρ(d, X, kwargs...)

ρ_upper_bound_args(kwargs...) = (d, X) -> ρ_upper_bound(d, X, kwargs...)

"""
ρ(d::AbstractVector{N}, S::LazySet{N})::N where {N<:Real}
Evaluate the support function of a set in a given direction.
### Input
- `d` -- direction
- `S` -- convex set
### Output
The support function of the set `S` in the direction `d`.
### Algorithm
This is the default implementation that relies on the computation of the support
vector, `σ`.
"""
function ρ(d::AbstractVector{N}, X::LazySet{N}) where {N<:Real}
return ρ_helper(d, X, ρ)
end

"""
ρ(d::AbstractVector{N}, S::LazySet{N}; kwargs...)::N where {N<:Real}
Expand All @@ -80,8 +113,30 @@ The support function of the set `S` in the direction `d`.
This is the default implementation that relies on the computation of the support
vector, `σ`.
"""
function ρ(d::AbstractVector{N}, S::LazySet{N}; kwargs...)::N where {N<:Real}
return dot(d, σ(d, S))
function ρ(d::AbstractVector{N}, X::LazySet{N}, kwargs...) where {N<:Real}
return ρ_helper(d, X, ρ_args(kwargs...))
end

"""
ρ_upper_bound(d::AbstractVector{N}, X::LazySet{N}) where {N<:Real}
Return an upper bound of the support function of a given set.
### Input
- `d` -- direction
- `X` -- set
### Output
An upper bound of the support function of the given set.
### Algorithm
The default implementation of `ρ_upper_bound` is the exact `ρ(d, X)`.
"""
function ρ_upper_bound(d::AbstractVector{N}, X::LazySet{N}) where {N<:Real}
return ρ_helper(d, X, ρ_upper_bound)
end

"""
Expand All @@ -93,8 +148,9 @@ Return an upper bound of the support function of a given set.
### Input
- `d` -- direction
- `X` -- set
- `d` -- direction
- `X` -- set
- `kwargs` -- additional keyword arguments
### Output
Expand All @@ -105,9 +161,9 @@ An upper bound of the support function of the given set.
The default implementation of `ρ_upper_bound` is the exact `ρ(d, X)`.
"""
function ρ_upper_bound(d::AbstractVector{N},
X::LazySet{N};
X::LazySet{N},
kwargs...) where {N<:Real}
return ρ(d, X)
return ρ_helper(d, X, ρ_upper_bound_args(kwargs...))
end

"""
Expand Down
10 changes: 4 additions & 6 deletions src/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ end

@inline function ρ_helper(d::AbstractVector{N},
ms::MinkowskiSum{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
return ρ_rec(d, ms.X; kwargs...) + ρ_rec(d, ms.Y; kwargs...)
ρ_rec::Function) where {N<:Real}
return ρ_rec(d, ms.X) + ρ_rec(d, ms.Y)
end

"""
Expand Down Expand Up @@ -273,9 +272,8 @@ end

@inline function ρ_helper(d::AbstractVector{N},
msa::MinkowskiSumArray{N},
ρ_rec::Function;
kwargs...) where {N<:Real}
return sum([ρ_rec(d, Xi; kwargs...) for Xi in msa.array])
ρ_rec::Function) where {N<:Real}
return sum([ρ_rec(d, Xi) for Xi in msa.array])
end

"""
Expand Down

0 comments on commit 3fbf13a

Please sign in to comment.