Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/adv/serialize-dict' into adv/ser…
Browse files Browse the repository at this point in the history
…ialize-dict
  • Loading branch information
antonydellavecchia committed Feb 19, 2024
2 parents 8bac3b1 + 7cce3ef commit ba781cb
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,18 @@ matrix_for_polymake(x::Union{Oscar.ZZMatrix, Oscar.QQMatrix, AbstractMatrix}) =

number_of_rows(x::SubArray{T, 2, U, V, W}) where {T, U, V, W} = size(x, 1)

function Polymake.Matrix{Polymake.Rational}(x::Union{Oscar.QQMatrix,AbstractMatrix{Oscar.QQFieldElem}})
res = Polymake.Matrix{Polymake.Rational}(size(x)...)
for i in eachindex(x)
res[i] = x[i]
end
return res
end

function Polymake.Matrix{Polymake.OscarNumber}(x::Union{MatElem, AbstractMatrix{<:FieldElem}})
res = Polymake.Matrix{Polymake.OscarNumber}(size(x)...)
for i in eachindex(x)
res[i] = x[i]
end
return res
end

_isempty_halfspace(x::Pair{<:Union{Oscar.MatElem, AbstractMatrix}, Any}) = isempty(x[1])
_isempty_halfspace(x) = isempty(x)

function Polymake.Matrix{T}(x::Union{MatElem,AbstractMatrix{<:FieldElem}}) where T<:Union{Float64, Polymake.Rational, Polymake.Integer, Polymake.OscarNumber}
res = Polymake.Matrix{T}(size(x)...)
return res .= x
end

Base.convert(::Type{Polymake.Matrix{T}}, x::MatElem) where T = Polymake.Matrix{T}(x)

Base.convert(::Type{Polymake.QuadraticExtension{Polymake.Rational}}, x::QQFieldElem) = Polymake.QuadraticExtension(convert(Polymake.Rational, x))

Base.convert(T::Type{<:Polymake.Matrix}, x::Union{ZZMatrix,QQMatrix}) = Base.convert(T, Matrix(x))

Base.convert(::Type{<:Polymake.Integer}, x::ZZRingElem) = GC.@preserve x return Polymake.new_integer_from_fmpz(x)

Base.convert(::Type{<:Polymake.Rational}, x::QQFieldElem) = GC.@preserve x return Polymake.new_rational_from_fmpq(x)
Expand Down Expand Up @@ -182,8 +170,6 @@ Base.convert(::Type{Polymake.OscarNumber}, x::FieldElem) = Polymake.OscarNumber(

(::Type{T})(x::Polymake.OscarNumber) where T<:FieldElem = convert(T, Polymake.unwrap(x))

Base.convert(::Type{Polymake.Matrix{Polymake.OscarNumber}}, x::MatElem{<:FieldElem}) = Polymake.Matrix{Polymake.OscarNumber}(x)

(R::QQField)(x::Polymake.Rational) = convert(QQFieldElem, x)
(Z::ZZRing)(x::Polymake.Rational) = convert(ZZRingElem, x)

Expand All @@ -202,13 +188,14 @@ end
(F::Field)(x::Polymake.Rational) = F(QQ(x))
(F::Field)(x::Polymake.OscarNumber) = F(Polymake.unwrap(x))

Polymake.convert_to_pm_type(::Type{Oscar.ZZMatrix}) = Polymake.Matrix{Polymake.Integer}
Polymake.convert_to_pm_type(::Type{Oscar.QQMatrix}) = Polymake.Matrix{Polymake.Rational}
Polymake.convert_to_pm_type(::Type{Oscar.ZZRingElem}) = Polymake.Integer
Polymake.convert_to_pm_type(::Type{Oscar.QQFieldElem}) = Polymake.Rational
Polymake.convert_to_pm_type(::Type{ZZMatrix}) = Polymake.Matrix{Polymake.Integer}
Polymake.convert_to_pm_type(::Type{QQMatrix}) = Polymake.Matrix{Polymake.Rational}
Polymake.convert_to_pm_type(::Type{ZZRingElem}) = Polymake.Integer
Polymake.convert_to_pm_type(::Type{QQFieldElem}) = Polymake.Rational
Polymake.convert_to_pm_type(::Type{T}) where T<:FieldElem = Polymake.OscarNumber
Polymake.convert_to_pm_type(::Type{<:Oscar.MatElem}) = Polymake.Matrix{Polymake.OscarNumber}
Polymake.convert_to_pm_type(::Type{<:Graph{T}}) where T<:Union{Directed,Undirected} = Polymake.Graph{T}
Polymake.convert_to_pm_type(::Type{<:MatElem{Float64}}) = Polymake.Matrix{Float64}

Base.convert(::Type{<:Polymake.Graph{T}}, g::Graph{T}) where T<:Union{Directed,Undirected} = Oscar.pm_object(g)

Expand Down

0 comments on commit ba781cb

Please sign in to comment.