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

Faster intersection between a hyperrectangular set and an axis-aligned halfspace #1800

Closed
mforets opened this issue Nov 28, 2019 · 2 comments · Fixed by #2580
Closed

Faster intersection between a hyperrectangular set and an axis-aligned halfspace #1800

mforets opened this issue Nov 28, 2019 · 2 comments · Fixed by #2580
Assignees
Labels
good first issue 🐤 Good for newcomers performance 🐎 More efficient code
Projects

Comments

@mforets
Copy link
Member

mforets commented Nov 28, 2019

The intersection between a hyperrectangular set and an axis-aligned halfspace is currently slow:

julia> H = rand(Hyperrectangle)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([-1.4381908949978408, -0.8011047849004614], [2.3769552574965234, 1.2955065044055676])

julia> G = HalfSpace([1.0, 0.0], 0.0)
HalfSpace{Float64,Array{Float64,1}}([1.0, 0.0], 0.0)

julia> @btime intersection($G, $H)
  46.620 μs (334 allocations: 22.80 KiB)

HPolytope{Float64}(HalfSpace{Float64,VN} where VN<:AbstractArray{Float64,1}[HalfSpace{Float64,SingleEntryVector{Float64}}([1.0, 0.0], 0.0), HalfSpace{Float64,SingleEntryVector{Float64}}([0.0, 1.0], 0.49440171950510614), HalfSpace{Float64,SingleEntryVector{Float64}}([-1.0, 0.0], 3.815146152494364), HalfSpace{Float64,SingleEntryVector{Float64}}([0.0, -1.0], 2.096611289306029)])

Compare with:

julia> Q = Hyperrectangle(low=[-10., -10.], high=[0., 10]); # contains the intersection of H and G

julia> @btime intersection($Q, $H)
  108.345 ns (5 allocations: 416 bytes)
Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}([-1.907573076247182, -0.8011047849004616], [1.907573076247182, 1.2955065044055676])

Note that by using single entry vectors, with the signature intersection(::HalfSpace{N, <:SingleEntryVector{N}}, ::AbstractHyperrectangle{N}), we are able to dispatch on axis-aligned halfspaces, so no run-time checks are needed.

@mforets mforets added the performance 🐎 More efficient code label Nov 28, 2019
@mforets mforets added this to Issues in SEV specs Dec 17, 2019
@IssueHuntBot
Copy link

@mforets has funded $10.00 to this issue.


@IssueHuntBot
Copy link

@mforets has rewarded $9.00 to @sebastianguadalupe. See it on IssueHunt

  • 💰 Total deposit: $10.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $1.00

mforets added a commit that referenced this issue Feb 15, 2021
…ectangular set (#2580)

* intersection of axis aligned halfspace and hyperrectangle

* add tests

Co-authored-by: mforets <mforets@gmail.com>
@schillic schillic moved this from Issues to Done in SEV specs Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue 🐤 Good for newcomers performance 🐎 More efficient code
Projects
No open projects
3 participants