Skip to content

Commit

Permalink
PolyhedralFan: fix for trivial fans (#2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz authored Oct 25, 2023
1 parent d5e7b73 commit 4918a7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/PolyhedralGeometry/PolyhedralFan/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,24 @@ Get the underlying polymake object, which can be used via Polymake.jl.
"""
pm_object(PF::PolyhedralFan) = PF.pm_fan

polyhedral_fan(itr::AbstractVector{Cone{T}}) where T<:scalar_types = PolyhedralFan{T}(Polymake.fan.check_fan_objects(pm_object.(itr)...), coefficient_field(iterate(itr)[1]))
function polyhedral_fan(itr::AbstractVector{Cone{T}}) where T<:scalar_types
@req length(itr) > 0 "list of cones must be non-empty"
pmfan = Polymake.fan.check_fan_objects(pm_object.(itr)...)
if pmfan.N_MAXIMAL_CONES == 0
# if check fan returns no cones then the rays are empty and we have just one trivial cone (maybe with lineality)
C = itr[1]
return polyhedral_fan(coefficient_field(C), rays(C), lineality_space(C), IncidenceMatrix(1,0); non_redundant=true)
end
return PolyhedralFan{T}(pmfan, coefficient_field(iterate(itr)[1]))
end

#Same construction for when the user gives Matrix{Bool} as incidence matrix
polyhedral_fan(f::scalar_type_or_field, Rays::AbstractCollection[RayVector], LS::AbstractCollection[RayVector], Incidence::Matrix{Bool}) =
polyhedral_fan(f, Rays, LS, IncidenceMatrix(Polymake.IncidenceMatrix(Incidence)))
polyhedral_fan(f::scalar_type_or_field, Rays::AbstractCollection[RayVector], Incidence::Matrix{Bool}) =
polyhedral_fan(f, Rays, IncidenceMatrix(Polymake.IncidenceMatrix(Incidence)))


function polyhedral_fan(C::Cone{T}) where T<:scalar_types
pmfan = Polymake.fan.check_fan_objects(pm_object(C))
return PolyhedralFan{T}(pmfan, coefficient_field(C))
end
polyhedral_fan(C::Cone{T}) where T<:scalar_types = polyhedral_fan([C])

###############################################################################
###############################################################################
Expand Down
11 changes: 11 additions & 0 deletions test/PolyhedralGeometry/polyhedral_fan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
@test lineality_space(F2NR) == collect(eachrow(L))
@test ray_indices(maximal_cones(F2NR)) == incidence2
@test IncidenceMatrix(maximal_cones(F2NR)) == incidence2

C = positive_hull(f, identity_matrix(ZZ, 0))
pf = polyhedral_fan(C)
@test n_maximal_cones(pf) == 1
@test dim(pf) == 0
pfc = polyhedral_fan(maximal_cones(pf))
@test n_maximal_cones(pfc) == 1

C = positive_hull(f, vcat(identity_matrix(ZZ, 4), -identity_matrix(ZZ,4)))
pf = polyhedral_fan(C)
@test n_maximal_cones(pf) == 1
end

end
Expand Down

0 comments on commit 4918a7a

Please sign in to comment.