Skip to content

Commit

Permalink
Merge pull request #488 from oscar-system/bl/decoration
Browse files Browse the repository at this point in the history
update polymake 4.12, decorations, nodemaps, tropical matrix pairs, ceil+floor
  • Loading branch information
benlorenz authored Jun 3, 2024
2 parents 80daa74 + 3dfa9a9 commit cda041e
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/oscar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ jobs:
- name: "Inject Test-Dependency for Oscar"
run: |
sed -i -e "s/Test =/Oscar = \"f1435218-dba5-11e9-1e4d-f1a5fab5fc13\"\nTest =/" test/Project.toml
- name: "Remove Oscar/Aqua test"
run: |
rm -f oscar-dev/Oscar/test/Aqua.jl
- name: "Run tests"
run: |
echo '${{ env.oscar_run_tests }}'
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Polymake"
uuid = "d720cf60-89b5-51f5-aff5-213f193123e7"
repo = "https://github.com/oscar-system/Polymake.jl.git"
version = "0.11.17"
version = "0.11.18"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down Expand Up @@ -44,6 +44,6 @@ SparseArrays = "^1.6"
TOPCOM_jll = "~0.17.8"
julia = "^1.6"
lib4ti2_jll = "^1.6.10"
libpolymake_julia_jll = "~0.11.1"
polymake_jll = "^400.1100.1"
polymake_oscarnumber_jll = "~0.2.7"
libpolymake_julia_jll = "~0.12.0"
polymake_jll = "^400.1200.0"
polymake_oscarnumber_jll = "~0.3.0"
2 changes: 1 addition & 1 deletion src/Polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import TOPCOM_jll
using libpolymake_julia_jll
using polymake_oscarnumber_jll

const jlpolymake_version_range = (v"0.11.0", v"0.12")
const jlpolymake_version_range = (v"0.12.0", v"0.13")

struct PolymakeError <: Exception
msg
Expand Down
10 changes: 8 additions & 2 deletions src/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ const Array_suppT = Union{Int64, CxxWrap.CxxLong,
OscarNumber,
String, CxxWrap.StdString,
StdPair{CxxWrap.CxxLong,CxxWrap.CxxLong},
StdPair{Set{CxxWrap.CxxLong},CxxWrap.CxxLong},
StdPair{Set{Int64},Int64},
StdList{StdPair{CxxWrap.CxxLong,CxxWrap.CxxLong}},
Set{Int64}, Set{CxxWrap.CxxLong},
Array{Int64}, Array{CxxWrap.CxxLong},
Array{Integer}, Array{Rational}, Matrix{Integer}}
Array{Integer}, Array{Rational}, Matrix{Integer},
BasicDecoration}

function Array{T}(::UndefInitializer, n::Base.Integer) where
T <: Array_suppT
Expand All @@ -31,7 +34,7 @@ Array(vec::AbstractVector) =
Array{convert_to_pm_type(eltype(vec))}(vec)

Base.size(a::Array) = (length(a),)
Base.eltype(v::Array{T}) where T = to_jl_type(T)
Base.eltype(v::Type{<:Array{T}}) where T = to_jl_type(T)

Base.@propagate_inbounds function getindex(A::Array{T}, n::Base.Integer) where T
@boundscheck checkbounds(A, n)
Expand All @@ -53,3 +56,6 @@ function Base.append!(A::Array{T}, itr) where T
end
return A
end

Array(nm::NodeMap{Dir,T}) where {Dir, T} =
Polymake.call_function(:common, :nodemap_as_array, nm)::Array{T}
11 changes: 10 additions & 1 deletion src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ convert(::Type{Set{T}}, itr::AbstractArray) where T = Set{T}(itr)
convert(::Type{<:Polynomial{C,E}}, itr::Polynomial{C,E}) where {C,E} = itr
convert(::Type{<:Polynomial{C1,E1}}, itr::Polynomial{C2,E2}) where {C1,C2,E1,E2} = Polynomial{C1,E1}(itr)

convert(::Type{BasicDecoration}, p::StdPair) = BasicDecoration(first(p),last(p))

########### Converting to objects polymake understands ###############

struct PolymakeType end
Expand All @@ -31,6 +33,9 @@ convert(::Type{PolymakeType}, v::Visual) = v.obj
convert(::Type{PolymakeType}, ::Nothing) = call_function(PropertyValue, :common, :get_undef)
convert(::Type{OptionSet}, dict) = OptionSet(dict)

as_perl_array(t::SmallObject) = Polymake.call_function(PropertyValue, :common, :as_perl_array, t)
as_perl_array_of_array(t::SmallObject) = Polymake.call_function(PropertyValue, :common, :as_perl_array_of_array, t)

############### Adjusting type parameter to CxxWrap ##################

to_cxx_type(::Type{T}) where T = T
Expand Down Expand Up @@ -68,7 +73,8 @@ Int64(r::Rational) = Int64(new_int_from_rational(r))
convert_to_pm_type(T::Type) = throw(ArgumentError("Unrecognized argument type: $T.\nYou need to convert to polymake compatible type first."))

convert_to_pm_type(::Type{T}) where T <: Union{Int64, Float64} = T
convert_to_pm_type(::Type{T}) where T <: Union{BigObject, PropertyValue, OptionSet, TropicalNumber} = T
convert_to_pm_type(::Type{T}) where T <: Union{BigObject, BigObjectType, PropertyValue, OptionSet} = T
convert_to_pm_type(::Type{T}) where T <: TropicalNumber = T

convert_to_pm_type(::Nothing) = Nothing
convert_to_pm_type(::Type{Int32}) = Int64
Expand All @@ -77,14 +83,17 @@ convert_to_pm_type(::Type{<:AbstractString}) = String
convert_to_pm_type(::Type{<:Union{Base.Integer, Integer}}) = Integer
convert_to_pm_type(::Type{<:Union{Base.Rational, Rational}}) = Rational
convert_to_pm_type(::Type{<:OscarNumber}) = OscarNumber
convert_to_pm_type(::Type{<:NodeMap}) = NodeMap
convert_to_pm_type(::Type{<:Union{AbstractVector, Vector}}) = Vector
convert_to_pm_type(::Type{<:Union{AbstractMatrix, Matrix}}) = Matrix
convert_to_pm_type(::Type{<:Union{AbstractSparseMatrix, SparseMatrix}}) = SparseMatrix
convert_to_pm_type(::Type{<:AbstractSparseMatrix{<:Union{Bool, CxxWrap.CxxBool}}}) = IncidenceMatrix
convert_to_pm_type(::Type{<:Union{AbstractSparseVector, SparseVector}}) = SparseVector
convert_to_pm_type(::Type{<:Array}) = Array
convert_to_pm_type(::Type{<:Union{Pair, <:StdPair}}) = StdPair
convert_to_pm_type(::Type{<:Tuple{A,B}}) where {A,B} = StdPair{convert_to_pm_type(A),convert_to_pm_type(B)}
convert_to_pm_type(::Type{<:Polynomial{<:Rational, <:Union{Int64, CxxWrap.CxxLong}}}) = Polynomial{Rational, CxxWrap.CxxLong}
convert_to_pm_type(::Type{<:AbstractVector{T}}) where T<:Tuple = Polymake.Array{convert_to_pm_type(T)}

# Graph, EdgeMap, NodeMap
const DirType = Union{Directed, Undirected}
Expand Down
2 changes: 1 addition & 1 deletion src/incidencematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ IncidenceMatrix(x...) = IncidenceMatrix{NonSymmetric}(x...)

Base.size(m::IncidenceMatrix) = (nrows(m), ncols(m))

Base.eltype(::IncidenceMatrix) = Bool
Base.eltype(::Type{<:IncidenceMatrix}) = Bool

Base.@propagate_inbounds function Base.getindex(M::IncidenceMatrix , i::Base.Integer, j::Base.Integer)
@boundscheck checkbounds(M, i, j)
Expand Down
2 changes: 1 addition & 1 deletion src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

# Iterator

Base.eltype(M::Map{S,T}) where {S,T} = Pair{to_jl_type(S), to_jl_type(T)}
Base.eltype(::Type{<:Map{S,T}}) where {S,T} = Pair{to_jl_type(S), to_jl_type(T)}

function Base.iterate(M::Map{S,T}) where {S,T}
isempty(M) && return nothing
Expand Down
2 changes: 1 addition & 1 deletion src/matrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Matrix(mat::AbstractMatrix{T}) where T =

Base.size(m::Matrix) = (nrows(m), ncols(m))

Base.eltype(v::Matrix{T}) where T = to_jl_type(T)
Base.eltype(v::Type{<:Matrix{T}}) where T = to_jl_type(T)

function Base.vcat(M::Matrix...)
all(==(ncols(first(M))), ncols.(M)) || throw(DimensionMismatch("matrices must have the same number of columns"))
Expand Down
52 changes: 51 additions & 1 deletion src/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ mutable struct oscar_number_dispatch_helper
hash::Ptr{Cvoid}
to_rational::Ptr{Cvoid}
to_float::Ptr{Cvoid}
is_rational::Ptr{Cvoid}
to_ceil::Ptr{Cvoid}
to_floor::Ptr{Cvoid}
end
oscar_number_dispatch_helper() = oscar_number_dispatch_helper(-1, repeat([C_NULL], 22)...)
oscar_number_dispatch_helper() = oscar_number_dispatch_helper(-1, repeat([C_NULL], 25)...)

const _on_gc_refs = IdDict()

Expand Down Expand Up @@ -150,6 +153,14 @@ end
@cfunction(_on_to_float, Float64, (Ref{ArgT},))
end

function _fieldelem_to_ceil(e::T) where T
return BigInt(ceil(e))
end

function _fieldelem_to_floor(e::T) where T
return BigInt(floor(e))
end

function _fieldelem_to_rational(e::T) where T
Polymake._fieldelem_is_rational(e) || error("not a rational number")
return Base.Rational{BigInt}(e)
Expand All @@ -174,6 +185,39 @@ function _fieldelem_is_rational(e::T) where T
error("OscarNumber: cannot check is_rational, please define 'Polymake._fieldelem_is_rational(e::$T)::Bool'")
end

@generated _on_gen_is_rational(::Type{ArgT}) where ArgT =
quote
@cfunction(_fieldelem_is_rational, Bool, (Ref{ArgT},))
end

function _on_to_ceil(e::ArgT)::Ptr{BigInt} where ArgT
i = try
_fieldelem_to_ceil(e)
catch e
return C_NULL
end
return pointer_from_objref(i)
end

@generated _on_gen_to_ceil(::Type{ArgT}) where ArgT =
quote
@cfunction(_on_to_ceil, Ptr{BigInt}, (Ref{ArgT},))
end

function _on_to_floor(e::ArgT)::Ptr{BigInt} where ArgT
i = try
_fieldelem_to_floor(e)
catch e
return C_NULL
end
return pointer_from_objref(i)
end

@generated _on_gen_to_floor(::Type{ArgT}) where ArgT =
quote
@cfunction(_on_to_floor, Ptr{BigInt}, (Ref{ArgT},))
end

function _on_hash(e::T) where T
if !_fieldelem_is_rational(e)
return hash(e)
Expand All @@ -184,6 +228,7 @@ function _on_hash(e::T) where T
end
end


@generated _on_gen_hash(::Type{ArgT}) where ArgT =
quote
@cfunction(_on_hash, Csize_t, (Ref{ArgT},))
Expand Down Expand Up @@ -307,6 +352,11 @@ function register_julia_element(e, p, t::Type)
dispatch.cmp = _on_gen_cmp(t)

dispatch.to_string = _on_gen_to_string(t)

dispatch.is_rational = _on_gen_is_rational(t)

dispatch.to_ceil = _on_gen_to_ceil(t)
dispatch.to_floor = _on_gen_to_floor(t)
# later:
# from_string::Ptr{Cvoid}

Expand Down
5 changes: 5 additions & 0 deletions src/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ function bigobject_qualifiedname(obj::BigObject)
return String(res)
end

function bigobject_prop_type(obj::BigObjectType, path::String)
res = call_function(:common, :bigobject_prop_type, obj, path)
return String(res)
end

# polymake can either just give a reference or do a full copy.
# but even that full copy will contain references to the same data
# objects in memory, but this is fine since most of them are immutable anyway.
Expand Down
4 changes: 2 additions & 2 deletions src/polydb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ end
# Iterator

Base.IteratorSize(::Type{<:Cursor}) = Base.SizeUnknown()
Base.eltype(::Cursor{T}) where T = T
Base.eltype(::Type{Cursor{T}}) where T = T
Base.IteratorSize(::Type{<:Collection}) = Base.SizeUnknown()
Base.eltype(::Collection{T}) where T = T
Base.eltype(::Type{Collection{T}}) where T = T

# default iteration functions returning `Polymake.BigObject`s
function Base.iterate(cursor::Polymake.Polydb.Cursor{Polymake.BigObject}, state::Nothing=nothing)
Expand Down
25 changes: 25 additions & 0 deletions src/polymake/julia.rules
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ function get_bigobject_qualified_name($) {
return $_[0]->type->qualified_name;
}

function nodemap_as_array<Dir,Elem>(NodeMap<Dir,Elem>) {
my ($nm) = @_;
return new Array<Elem>($nm);
}

function as_perl_array($) {
return [@{$_[0]}];
}

function as_perl_array_of_array($) {
return [map {[@$_]} @{$_[0]}];
}

function bigobject_prop_type($$) {
my ($bot, $path) = @_;
while (my ($parent, $elem) = $path =~ /^([^\.]*)\.(.*)$/) {
my $prop = $bot->lookup_property($parent);
$bot = $prop->subobject_type();
return "" unless defined($bot);
$path = $elem;
}
my $t = $bot->lookup_property($path)->type;
return instanceof Core::BigObjectType($t) ? $t->pure_type->name : $t->name;
}

package Polymake::User;

function get_shell_scalar($) {
Expand Down
2 changes: 1 addition & 1 deletion src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ for (jlF, pmF) in (
end
end

Base.eltype(::Set{T}) where T = to_jl_type(T)
Base.eltype(::Type{<:Set{T}}) where T = to_jl_type(T)

### convert FROM polymake object

Expand Down
1 change: 1 addition & 0 deletions src/setup_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SmallObject = Union{
OscarNumber,
EdgeMap,
NodeMap,
BasicDecoration,
}
const VecOrMat_eltypes = Union{Int64, Integer, Rational, Float64, QuadraticExtension{Rational}, OscarNumber, CxxWrap.CxxLong, Polynomial{Rational, CxxWrap.CxxLong}, TropicalNumber{Polymake.Max, Polymake.Rational}, TropicalNumber{Polymake.Min, Polymake.Rational}}

Expand Down
2 changes: 1 addition & 1 deletion src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SparseMatrix(mat::AbstractMatrix{T}) where T =

Base.size(m::SparseMatrix) = (nrows(m), ncols(m))

Base.eltype(m::SparseMatrix{T}) where T = to_jl_type(T)
Base.eltype(::Type{<:SparseMatrix{T}}) where T = to_jl_type(T)

function Base.vcat(M::Union{SparseMatrix,Matrix}...)
all(==(ncols(first(M))), ncols.(M)) || throw(DimensionMismatch("matrices must have the same number of columns"))
Expand Down
4 changes: 2 additions & 2 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SparseVector(vec::AbstractVector{T}) where T =

Base.size(v::SparseVector) = (length(v),)

Base.eltype(m::SparseVector{T}) where T = to_jl_type(T)
Base.eltype(::Type{<:SparseVector{T}}) where T = to_jl_type(T)

Base.@propagate_inbounds function Base.getindex(V::SparseVector, n::Base.Integer)
@boundscheck checkbounds(V, n)
Expand Down Expand Up @@ -83,7 +83,7 @@ end
spzeros(::Type{Bool}, n::Base.Integer) = SparseVectorBool(n, Polymake.Set{to_cxx_type(Int64)}())

Base.size(v::SparseVector{Bool}) = (v.l,)
Base.eltype(::SparseVector{Bool}) = Bool
Base.eltype(::Type{<:SparseVector{Bool}}) = Bool

Base.@propagate_inbounds function Base.getindex(V::SparseVector{Bool}, n::Base.Integer)
@boundscheck checkbounds(V, n)
Expand Down
4 changes: 2 additions & 2 deletions src/std/lists.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Base.eltype(::StdList{StdPair{S, T}}) where {S, T} = Pair{S,T}
Base.eltype(::Type{<:StdList{<:StdPair{S, T}}}) where {S, T} = Pair{S,T}

Base.push!(L::StdList{<:StdPair}, a::Pair) = push!(L, StdPair(a))

Base.eltype(::StdList{T}) where T = T
Base.eltype(::Type{<:StdList{T}}) where T = T

function Base.iterate(L::StdList)
isempty(L) && return nothing
Expand Down
5 changes: 4 additions & 1 deletion src/std/pairs.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
StdPair(a::T,b::T) where T = StdPair{T,T}(a,b)
StdPair(p::Pair) = StdPair(first(p), last(p))
StdPair(t::Tuple{A,B}) where {A,B} = StdPair{A,B}(first(t),last(t))

Base.convert(::Type{<:StdPair{A,B}}, t::Tuple{C,D}) where {A,B,C,D} = StdPair{A,B}(A(first(t)), B(last(t)))

Base.Pair(p::StdPair) = Pair(first(p), last(p))
Base.Pair{S, T}(p::StdPair) where {S, T} = Pair{S, T}(first(p), last(p))

Base.length(p::StdPair) = 2
Base.eltype(p::StdPair{S,T}) where {S, T} = Union{S,T}
Base.eltype(::Type{<:StdPair{S,T}}) where {S, T} = Union{S,T}
Base.iterate(p::StdPair) = first(p), Val{:first}()
Base.iterate(p::StdPair, ::Val{:first}) = last(p), Val{:last}()
Base.iterate(p::StdPair, ::Val{:last}) = nothing
Expand Down
2 changes: 1 addition & 1 deletion src/vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Vector(vec::AbstractVector{T}) where T = Vector{promote_to_pm_type(Vector, T)}(v

Base.size(v::Vector) = (length(v),)

Base.eltype(v::Vector{T}) where T = to_jl_type(T)
Base.eltype(v::Type{<:Vector{T}}) where T = to_jl_type(T)

Base.@propagate_inbounds function Base.getindex(V::Vector, n::Base.Integer)
@boundscheck checkbounds(V, n)
Expand Down

2 comments on commit cda041e

@benlorenz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108131

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.18 -m "<description of version>" cda041eb3d80421f43571524d21fd05aa1024163
git push origin v0.11.18

Please sign in to comment.