Skip to content

Commit

Permalink
applied suggested changes from PR on github
Browse files Browse the repository at this point in the history
  • Loading branch information
alexej-jordan committed Sep 17, 2023
1 parent 0a60487 commit 31bb3d4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 37 deletions.
8 changes: 2 additions & 6 deletions src/PolyhedralGeometry/Polyhedron/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ Construct a `Polyhedron` corresponding to a `Polymake.BigObject` of type `Polyto
"""
function polyhedron(p::Polymake.BigObject)
T, f = _detect_scalar_and_field(Polyhedron, p)
if T == EmbeddedElem{nf_elem} && Hecke.isquadratic_type(number_field(f))[1]
scalar_regexp = match(r"[^<]*<(.*)>[^>]*", String(Polymake.type_name(p)))
typename = scalar_regexp[1]
if typename == "QuadraticExtension<Rational>"
p = _polyhedron_qe_to_on(p, f)
end
if T == EmbeddedElem{nf_elem} && Hecke.isquadratic_type(number_field(f))[1] && Polymake.bigobject_eltype(p) == "QuadraticExtension"
p = _polyhedron_qe_to_on(p, f)
end
return Polyhedron{T}(p, f)
end
Expand Down
41 changes: 18 additions & 23 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ _get_scalar_type(::NormalToricVarietyType) = QQFieldElem
const scalar_types = Union{FieldElem, Float64}

const scalar_type_to_oscar = Dict{String, Type}([("Rational", QQFieldElem),
("QuadraticExtension<Rational>", Hecke.EmbeddedNumFieldElem{nf_elem}),
("Float", Float64)])
("QuadraticExtension<Rational>", Hecke.EmbeddedNumFieldElem{nf_elem}),
("QuadraticExtension", Hecke.EmbeddedNumFieldElem{nf_elem}),
("Float", Float64)])

const scalar_types_extended = Union{scalar_types, ZZRingElem}

Expand Down Expand Up @@ -480,32 +481,27 @@ _detect_default_field(::Type{QQFieldElem}, p::Polymake.BigObject) = QQ
_detect_default_field(::Type{Float64}, p::Polymake.BigObject) = AbstractAlgebra.Floats{Float64}()

function _detect_default_field(::Type{T}, p::Polymake.BigObject) where T<:FieldElem
# we only want to check existing properties
f = x -> Polymake.exists(p, string(x))
propnames = intersect(propertynames(p), [:INPUT_RAYS, :POINTS, :RAYS, :VERTICES, :VECTORS, :INPUT_LINEALITY, :LINEALITY_SPACE, :FACETS, :INEQUALITIES, :EQUATIONS, :LINEAR_SPAN, :AFFINE_HULL])
i = findfirst(f, propnames)
# find first OscarNumber wrapping a FieldElem
while !isnothing(i)
prop = getproperty(p, propnames[i])
for el in prop
on = Polymake.unwrap(el)
if on isa T
return parent(on)
end
end
i = findnext(f, propnames, i + 1)
# we only want to check existing properties
propnames = intersect(Polymake.list_properties(p), ["INPUT_RAYS", "POINTS", "RAYS", "VERTICES", "VECTORS", "INPUT_LINEALITY", "LINEALITY_SPACE", "FACETS", "INEQUALITIES", "EQUATIONS", "LINEAR_SPAN", "AFFINE_HULL"])
# find first OscarNumber wrapping a FieldElem
for pn in propnames
prop = getproperty(p, pn)
for el in prop
on = Polymake.unwrap(el)
if on isa T
return parent(on)
end
end
throw(ArgumentError("BigObject does not contain information about a parent Field"))
end
throw(ArgumentError("BigObject does not contain information about a parent Field"))
end

function _detect_wrapped_type_and_field(p::Polymake.BigObject)
# we only want to check existing properties
f = x -> Polymake.exists(p, string(x))
propnames = intersect(propertynames(p), [:INPUT_RAYS, :POINTS, :RAYS, :VERTICES, :VECTORS, :INPUT_LINEALITY, :LINEALITY_SPACE, :FACETS, :INEQUALITIES, :EQUATIONS, :LINEAR_SPAN, :AFFINE_HULL])
i = findfirst(f, propnames)
propnames = intersect(Polymake.list_properties(p), ["INPUT_RAYS", "POINTS", "RAYS", "VERTICES", "VECTORS", "INPUT_LINEALITY", "LINEALITY_SPACE", "FACETS", "INEQUALITIES", "EQUATIONS", "LINEAR_SPAN", "AFFINE_HULL"])
# find first OscarNumber wrapping a FieldElem
while !isnothing(i)
prop = getproperty(p, propnames[i])
for pn in propnames
prop = getproperty(p, pn)
for el in prop
on = Polymake.unwrap(el)
if on isa FieldElem
Expand All @@ -514,7 +510,6 @@ function _detect_wrapped_type_and_field(p::Polymake.BigObject)
return (T, f)
end
end
i = findnext(f, propnames, i + 1)
end
throw(ArgumentError("BigObject does not contain information about a parent Field"))
end
Expand Down
3 changes: 1 addition & 2 deletions src/PolyhedralGeometry/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ for f in ("_point_matrix", "_vector_matrix", "_generator_matrix")
M = Symbol(f)
@eval begin
function $M(::Val{_empty_access}, P::PolyhedralObjectUnion; homogenized=false)
scalar_regexp = match(r"[^<]*<(.*)>[^>]*", String(Polymake.type_name(pm_object(P))))
typename = scalar_regexp[1]
typename = Polymake.bigobject_eltype(pm_object(P))
T = typename == "OscarNumber" ? Polymake.OscarNumber : _scalar_type_to_polymake(scalar_type_to_oscar[typename])
return Polymake.Matrix{T}(undef, 0, Polymake.polytope.ambient_dim(pm_object(P)) + homogenized)
end
Expand Down
3 changes: 1 addition & 2 deletions src/PolyhedralGeometry/type_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


function detect_scalar_type(n::Type{T}, p::Polymake.BigObject) where T<:Union{Polyhedron, Cone, PolyhedralFan, SubdivisionOfPoints, PolyhedralComplex}
scalar_regexp = match(r"[^<]*<(.*)>[^>]*", String(Polymake.type_name(p)))
typename = scalar_regexp[1]
typename = Polymake.bigobject_eltype(p)
return typename == "OscarNumber" ? nothing : scalar_type_to_oscar[typename]
end

Expand Down
4 changes: 2 additions & 2 deletions test/PolyhedralGeometry/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ for f in (QQ, ENF)
if S == Pair{Matrix{T}, T}
@test facets(S, D) == [Pair(A[i], b[i]) for i in 1:12]
elseif S == Polyhedron{T}
# @test facets(S, D) == [polyhedron(R, A[i], b[i]) for i in 1:12]
@test nvertices.(facets(S, D)) == repeat([5], 12)
else
@test facets(S, D) == [affine_halfspace(R, A[i], b[i]) for i in 1:12]
end
Expand Down Expand Up @@ -565,7 +565,7 @@ for f in (QQ, ENF)
@test isempty(rays(D))
@test lineality_dim(D) == 0
@test isempty(lineality_space(D))
# @test faces(D, 0) == convex_hull.(T, V)
@test faces(D, 0) == convex_hull.(T, V)
@test isempty(affine_hull(D))
@test relative_interior_point(D) == [0, 0, 0]
end
Expand Down
2 changes: 0 additions & 2 deletions test/PolyhedralGeometry/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@

@test *(g(3), A) == 3 * a

# @test [A; B] == [a; b]

end

end
Expand Down

0 comments on commit 31bb3d4

Please sign in to comment.