Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concretely type linear constraint arrays #1802

Closed
mforets opened this issue Nov 29, 2019 · 2 comments · Fixed by #2044
Closed

Concretely type linear constraint arrays #1802

mforets opened this issue Nov 29, 2019 · 2 comments · Fixed by #2044
Assignees
Labels
performance 🐎 More efficient code

Comments

@mforets
Copy link
Member

mforets commented Nov 29, 2019

The type parameter of the normal direction in the half-space type was not added from the beginning. As a consequence there are methods which return non-concretely-typed containers where they shouldn't. For instance,

julia> x = rand(Hyperrectangle)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([0.6356749195435474, -0.7138079011876447], [0.6689691491156268, 0.32291592190199064])

julia> constraints_list(x)
4-element Array{HalfSpace{Float64,VN} where VN<:AbstractArray{Float64,1},1}:
 HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([1.0, 0.0], 1.304644068659174)   
 HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 1.0], -0.39089197928565406)
 HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([-1.0, 0.0], 0.03329422957207939)
 HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, -1.0], 1.0367238230896354) 

Searching for LinearConstraint{N} reveals other places.

For ref: https://docs.julialang.org/en/v1/manual/performance-tips/index.html#Avoid-containers-with-abstract-type-parameters-1

@mforets
Copy link
Member Author

mforets commented Dec 12, 2019

h = rand(Hyperrectangle)
m = minkowski_difference(h, h)

HPolytope{Float64}(HalfSpace{Float64,VN} where VN<:AbstractArray{Float64,1}[HalfSpace{Float64,Array{Float64,1}}([1.0, 0.0], 0.0), HalfSpace{Float64,Array{Float64,1}}([0.0, 1.0], 0.0), HalfSpace{Float64,Array{Float64,1}}([-1.0, 0.0], 0.0), HalfSpace{Float64,Array{Float64,1}}([0.0, -1.0], 0.0)])

@mforets
Copy link
Member Author

mforets commented Dec 12, 2019

function overapproximate(X::LazySet{N}, dir::AbstractDirections{N}) where {N}
    halfspaces = Vector{LinearConstraint{N}}() # ??
    sizehint!(halfspaces, length(dir))
    T = isbounding(dir) ? HPolytope : HPolyhedron
    H = T(halfspaces)
    for d in dir
        addconstraint!(H, LinearConstraint(d, ρ(d, X)))
    end
    return H
end

mforets added a commit that referenced this issue Dec 12, 2019
* type constraints_list of hyperrectangular set

* type constraints list of Ball1

* constraints list of cpa

* type for constraints list of ResetMap

* add more type annotations

* more type annotations

* update doctest

* fix last doctest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance 🐎 More efficient code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant