Skip to content

Refactor symmetric_interval_hull of Hyperrectangle #2783

@schillic

Description

@schillic

function symmetric_interval_hull(S::LazySet{N}) where {N}
# fallback returns a hyperrectangular set
(c, r) = box_approximation_helper(S)
if r[1] < 0
return EmptySet{N}(dim(S))
end
return Hyperrectangle(zeros(N, length(c)), abs.(c) .+ r)
end

# hyperrectangle specialization
@inline function _maxabs(c::N, r::N) where {N}
return c >= zero(N) ? c + r : -c + r
end
function symmetric_interval_hull(H::Hyperrectangle{N}) where {N}
n = dim(H)
r = Vector{N}(undef, n)
@inbounds for i in 1:n
r[i] = _maxabs(H.center[i], H.radius[i])
end
return Hyperrectangle(zeros(N, n), r)
end

One of them is probably faster. Both methods should use that same code (add a new helper function with arguments c and r).

We should also try out yet another version with low and high, which may be even faster than box_approximation_helper in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions