Skip to content

Commit

Permalink
PolyhedralGeometry: minor fixes (#4253)
Browse files Browse the repository at this point in the history
* Polyhedron: fix one scalar detection case

* tests: move some helper functions to if block to avoid warnings on duplicate include
  • Loading branch information
benlorenz authored Oct 30, 2024
1 parent 84ad208 commit 852b6d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ function _parent_or_coefficient_field(::Type{T}, x, y...) where {T<:scalar_types
missing
end

function _parent_or_coefficient_field(::Type{T}, c::Tuple) where {T<:FieldElem}
return _parent_or_coefficient_field(T, c...)
end

function _determine_parent_and_scalar(f::Union{Field,ZZRing}, x...)
_check_field_polyhedral(elem_type(f))
return (f, elem_type(f))
Expand Down
5 changes: 5 additions & 0 deletions test/PolyhedralGeometry/scalar_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
)
@test number_field(coefficient_field(j)) == number_field(coefficient_field(jj))
end
let ng = n_gon(5)
(A,b) = halfspace_matrix_pair(facets(ng))
@test typeof(polyhedron(A,b)) == typeof(ng)
@test coefficient_field(polyhedron(A,b)) == coefficient_field((ng))
end
end

@testset "Cross scalar operations" begin
Expand Down
34 changes: 17 additions & 17 deletions test/PolyhedralGeometry/setup_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ if !isdefined(Main, :_prepare_scalar_types)
KK, (a1, a2) = embedded_number_field([x^2 - 2, x^3 - 5], [(0, 2), (0, 2)])
return [(f, elem_type(f)) for f in (QQ, K, KK)]
end
end

function _check_im_perm_rows(inc::IncidenceMatrix, o)
oinc = incidence_matrix(o)
nr, nc = size(inc)
(nr, nc) == size(oinc) &&
issetequal(Polymake.row.(Ref(inc), 1:nr),
Polymake.row.(Ref(oinc), 1:nr))
end
function _check_im_perm_rows(inc::IncidenceMatrix, o)
oinc = incidence_matrix(o)
nr, nc = size(inc)
(nr, nc) == size(oinc) &&
issetequal(Polymake.row.(Ref(inc), 1:nr),
Polymake.row.(Ref(oinc), 1:nr))
end

_matrix_from_property(b::SubObjectIterator{<:Union{LinearHalfspace, LinearHyperplane}}) = permutedims(hcat([normal_vector(be) for be in b]...))
_matrix_from_property(b::SubObjectIterator{<:Union{LinearHalfspace, LinearHyperplane}}) = permutedims(hcat([normal_vector(be) for be in b]...))

_matrix_from_property(b::SubObjectIterator{<:Union{AffineHalfspace, AffineHyperplane}}) = permutedims(hcat([vcat(-negbias(be), normal_vector(be)) for be in b]...))
_matrix_from_property(b::SubObjectIterator{<:Union{AffineHalfspace, AffineHyperplane}}) = permutedims(hcat([vcat(-negbias(be), normal_vector(be)) for be in b]...))

# only used for cones that are linear halfspaces
_matrix_from_property(b::SubObjectIterator{Cone{T}}) where T = _matrix_from_property(SubObjectIterator{LinearHalfspace{T}}(b.Obj, b.Acc, b.n))
# only used for cones that are linear halfspaces
_matrix_from_property(b::SubObjectIterator{Cone{T}}) where T = _matrix_from_property(SubObjectIterator{LinearHalfspace{T}}(b.Obj, b.Acc, b.n))

_matrix_from_property(b::SubObjectIterator) = permutedims(hcat(b...))
_matrix_from_property(b::SubObjectIterator) = permutedims(hcat(b...))

_oscar_matrix_from_property(a, b::SubObjectIterator) = matrix(a, _matrix_from_property(b))
_oscar_matrix_from_property(a, b::SubObjectIterator) = matrix(a, _matrix_from_property(b))

function _polymake_matrix_from_property(b::SubObjectIterator)
m = _matrix_from_property(b)
return Polymake.Matrix{Oscar._scalar_type_to_polymake(eltype(m))}(m)
function _polymake_matrix_from_property(b::SubObjectIterator)
m = _matrix_from_property(b)
return Polymake.Matrix{Oscar._scalar_type_to_polymake(eltype(m))}(m)
end
end

0 comments on commit 852b6d1

Please sign in to comment.