-
Notifications
You must be signed in to change notification settings - Fork 32
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
#1384 - Add four point case for convex hull #1434
#1384 - Add four point case for convex hull #1434
Conversation
There is a problem with the sorting of vertices (hence the error): julia> using LazySets
julia> B = Ball1(zeros(2), 1.);
# this branch:
julia> P = convert(VPolygon, B)
VPolygon{Float64,Array{Float64,1}}(Array{Float64,1}[[0.0, -1.0], [-1.0, 0.0], [0.0, 1.0], [1.0, 0.0]])
# master:
julia> P = convert(VPolygon, B)
VPolygon{Float64,Array{Float64,1}}(Array{Float64,1}[[-1.0, 0.0], [0.0, -1.0], [1.0, 0.0], [0.0, 1.0]]) Please add a test case that detects this. |
EDIT: This was fixed in #1441. Now you need to rebase (sorry). LazySets.ConvexHull: Test Failed at /home/travis/build/JuliaReach/LazySets.jl/test/unit_ConvexHull.jl:105
Expression: convex_hull!(points, algorithm="")
Expected: ErrorException
No exception thrown This error is a bug in our tests: LazySets.jl/test/unit_ConvexHull.jl Lines 103 to 105 in a5545ae
The tests should instead either use the non- ! function or use copy(points) , e.g.:
@test ispermutation(convex_hull!(copy(points), algorithm="monotone_chain"), sorted)
@test ispermutation(convex_hull!(copy(points), algorithm="monotone_chain_sorted"), sorted)
@test_throws ErrorException convex_hull!(copy(points), algorithm="") |
I wonder why your tests did not catch the first error. Can you add a test for that case? |
Co-Authored-By: Christian Schilling <[email protected]>
Co-Authored-By: Christian Schilling <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the output type forces Julia to convert the result, which means it does not actually return the original points
if the input was not a Vector
.
src/concrete_convex_hull.jl
Outdated
@@ -186,6 +190,124 @@ function _three_points_2d!(points::AbstractVector{<:AbstractVector{N}}) where {N | |||
return points | |||
end | |||
|
|||
function _collinear_case!(points::Vector{VN}, A::VN, B::VN, C::VN, D::VN)::Vector{VN} where {N<:Real, VN<:AbstractVector{N}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function _collinear_case!(points::Vector{VN}, A::VN, B::VN, C::VN, D::VN)::Vector{VN} where {N<:Real, VN<:AbstractVector{N}} | |
function _collinear_case!(points::Vector{VN}, A::VN, B::VN, C::VN, D::VN) where {N<:Real, VN<:AbstractVector{N}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the outer signature is already typed to be a Vector
(in and out), what is kept arbitrary is the representation of each point:
function convex_hull!(points::Vector{VN};
algorithm=default_convex_hull_algorithm(points),
backend=nothing)::Vector{VN} where {N<:Real, VN<:AbstractVector{N}}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, and in full generality, each element could have a different concrete type. The most general version would thus be:
function _collinear_case!(points::AbstractVector{<:AbstractVector{N}}, A::AbstractVector{N},
B::AbstractVector{N}, C::AbstractVector{N}, D::AbstractVector{N}) where {N<:Real}
I think if you do not use this version, the method will crash if you use, e.g., SparseVector
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need the type annotations or can you just remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion on gitter, @SebastianGuadalupe would you please remove type annotations in _collinear_case!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then squash 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion on gitter, @SebastianGuadalupe would you please remove type annotations in _collinear_case!
?
_collinear_case!(points, A, B, C, D)
Co-Authored-By: Christian Schilling <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great job!
For reference,
julia> B = Ball1(zeros(2), 1.0);
julia> points = vertices_list(B);
# master v1.13.0
julia> @btime convex_hull!($(copy(points)))
403.095 ns (7 allocations: 432 bytes)
# this branch
julia> @btime convex_hull!($(copy(points)))
28.775 ns (0 allocations: 0 bytes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (after addressing the open comment and squashing).
i'll handle it, plus some other minor tweaks in the same file that i planned to do, in a follow-up PR.
done (from github). |
Co-Authored-By: Christian Schilling <[email protected]>
Closes #1384.