Skip to content

Commit

Permalink
Merge pull request #4336 from paemurru/ep/fix_empty_cones
Browse files Browse the repository at this point in the history
Fix zero-dimensional cone in `cones` in PolyhedralGeometry
  • Loading branch information
lkastner authored Nov 21, 2024
2 parents 5a737af + 53ad859 commit de39b82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/PolyhedralGeometry/PolyhedralFan/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,21 @@ julia> cones(PF, 2)
"""
function cones(PF::_FanLikeType, cone_dim::Int)
l = cone_dim - length(lineality_space(PF))
l < 1 && return nothing
return SubObjectIterator{Cone{_get_scalar_type(PF)}}(
t = Cone{_get_scalar_type(PF)}
(l < 0 || dim(PF) == -1) && return _empty_subobjectiterator(t, PF)

if l == 0
return SubObjectIterator{t}(
PF,
(_, _, _) -> positive_hull(
coefficient_field(PF), zeros(Int, ambient_dim(PF)), lineality_space(PF)
),
1,
NamedTuple(),
)
end

return SubObjectIterator{t}(
PF, _cone_of_dim, size(Polymake.fan.cones_of_dim(pm_object(PF), l), 1), (c_dim=l,)
)
end
Expand Down
9 changes: 8 additions & 1 deletion test/PolyhedralGeometry/polyhedral_fan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@
@test size(cones(F2, 2)) == (2,)
@test lineality_space(cones(F2, 2)[1]) == [[0, 1, 0]]
@test rays.(cones(F2, 2)) == [[], []]
@test isnothing(cones(F2, 1))
@test _check_im_perm_rows(ray_indices(cones(F1, 2)), incidence1)
@test _check_im_perm_rows(incidence_matrix(cones(F1, 2)), incidence1)
@test _check_im_perm_rows(cones(IncidenceMatrix, F1, 2), incidence1)

A3 = affine_space(NormalToricVariety, 3)
@test length(cones(A3, 1)) == 3
@test length(cones(A3, 0)) == 1
@test length(cones(A3, -1)) == 0
@test cones(A3, 1) isa SubObjectIterator{Cone{QQFieldElem}}
@test cones(A3, 0) isa SubObjectIterator{Cone{QQFieldElem}}
@test cones(A3, -1) isa SubObjectIterator{Cone{QQFieldElem}}

II = ray_indices(maximal_cones(NFsquare))
NF0 = polyhedral_fan(II, rays(NFsquare))
@test n_rays(NF0) == 4
Expand Down

0 comments on commit de39b82

Please sign in to comment.