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

polyhedron: make sure empty [] vector works as right hand side #3278

Merged
merged 2 commits into from
Jan 31, 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
8 changes: 4 additions & 4 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function assure_matrix_polymake(m::Union{AbstractMatrix{Any}, AbstractMatrix{Fie
a, b = size(m)
if a > 0
i = findfirst(_cannot_convert_to_fmpq, m)
t = typeof(m[i])
t = i === nothing ? QQFieldElem : typeof(m[i])
if t <: Union{Polymake.Rational, Polymake.QuadraticExtension{Polymake.Rational}, Polymake.OscarNumber, Float64}
m = Polymake.Matrix{Polymake.convert_to_pm_type(t)}(m)
else
Expand All @@ -93,16 +93,16 @@ end

assure_matrix_polymake(m::AbstractMatrix{<:FieldElem}) = Polymake.Matrix{Polymake.OscarNumber}(m)

assure_matrix_polymake(m::MatElem) = Polymake.OscarNumber.(m)
assure_matrix_polymake(m::MatElem) = Polymake.Matrix{_scalar_type_to_polymake(eltype(m))}(m)

assure_matrix_polymake(m::Union{Oscar.ZZMatrix, Oscar.QQMatrix, AbstractMatrix{<:Union{QQFieldElem, ZZRingElem, Base.Integer, Base.Rational, Polymake.Rational, Polymake.QuadraticExtension, Polymake.OscarNumber, Float64}}}) = m

assure_matrix_polymake(m::SubArray{T, 2, U, V, W}) where {T<:Union{Polymake.Rational, Polymake.QuadraticExtension, Float64}, U, V, W} = Polymake.Matrix{T}(m)

function assure_vector_polymake(v::Union{AbstractVector{Any}, AbstractVector{FieldElem}})
i = findfirst(_cannot_convert_to_fmpq, v)
v = Polymake.Vector{_scalar_type_to_polymake(typeof(v[i]))}(v)
return v
T = i === nothing ? QQFieldElem : typeof(v[i])
return Polymake.Vector{_scalar_type_to_polymake(T)}(v)
end

assure_vector_polymake(v::AbstractVector{<:FieldElem}) = Polymake.Vector{Polymake.OscarNumber}(v)
Expand Down
4 changes: 4 additions & 0 deletions test/PolyhedralGeometry/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CR = cube(f, 2, 0, 3//2)
Pos = polyhedron(f, [-1 0 0; 0 -1 0; 0 0 -1], [0,0,0])
L = polyhedron(f, [-1 0 0; 0 -1 0], [0,0])
full = polyhedron(f, zero_matrix(f, 0, 3), [])
point = convex_hull(f, [0 1 0])
# this is to make sure the order of some matrices below doesn't change
Polymake.prefer("beneath_beyond") do
Expand Down Expand Up @@ -184,6 +185,9 @@
@test length(vertex_sizes(Q2)) == 0

@test length(unique([cube(2), cube(2), simplex(2), simplex(2)])) == 2

@test dim(full) == ambient_dim(full)
@test lineality_dim(full) == 3
end

@testset "volume" begin
Expand Down
Loading