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

polyhedral/remove_zero_rows: use polymake epsilon for float comparison #3521

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ Base.convert(::Type{<:Polymake.Graph{T}}, g::Graph{T}) where T<:Union{Directed,U
function remove_zero_rows(A::AbstractMatrix)
A[findall(x->!iszero(x),collect(eachrow(A))),:]
end
function remove_zero_rows(A::AbstractMatrix{Float64})
A[findall(x->!isapprox(x,zero(x),atol=Polymake._get_global_epsilon()),collect(eachrow(A))),:]
end
function remove_zero_rows(A::Oscar.MatElem)
remove_zero_rows(Matrix(A))
end
Expand Down
16 changes: 16 additions & 0 deletions test/PolyhedralGeometry/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
R,x = polynomial_ring(QQ, "x")
v = T[f(1), f(1)]

# test that remove_zero_rows uses the correct epsilon
pm_eps = Polymake._get_global_epsilon()
@test pm_eps < 0.00005

pf1 = polyhedron([1.0 0.0; 0.0 1.0; 0.0 0.0], [1.0, 1.0, 0.0])
# three proper ineq, minus the zero row but plus the 1,0,0... row
@test nrows(Oscar.pm_object(pf1).INEQUALITIES) == 3
@test n_vertices(pf1) == 1
pf2 = polyhedron([1.0 0.0; 0.0 1.0; 0.0 0.0], [1.0, 1.0, pm_eps/2])
@test nrows(Oscar.pm_object(pf2).INEQUALITIES) == 3
@test n_vertices(pf2) == 1
# non-zero row is not removed
pf3 = polyhedron([1.0 0.0; 0.0 1.0; 0.0 0.0], [1.0, 1.0, pm_eps*2])
@test nrows(Oscar.pm_object(pf3).INEQUALITIES) == 4
@test n_vertices(pf3) == 1

@testset "core functionality" begin
@test matrix(f, rays(Q1))*v == T[f(2)]
@test matrix(f, vertices(Q1))*v == T[f(1), f(0), f(1)]
Expand Down
Loading