Skip to content

Commit

Permalink
Merge pull request #449 from oscar-system/bl/destruct
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz authored Aug 24, 2023
2 parents d90b81c + 16cb69d commit e501d13
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 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.3"
version = "0.11.4"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down Expand Up @@ -35,4 +35,4 @@ julia = "^1.6"
lib4ti2_jll = "^1.6.10"
libpolymake_julia_jll = "~0.10.3"
polymake_jll = "^400.900.0"
polymake_oscarnumber_jll = "~0.2.2"
polymake_oscarnumber_jll = "~0.2.5"
7 changes: 6 additions & 1 deletion src/Polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ function __init__()
if isdefined(Main, :IJulia) && Main.IJulia.inited
prepare_jupyter_kernel_for_visualization()
end

# this will disable callbacks for oscarnumber gc free calls
# to avoid some crashes during exit
# the data will be cleaned anyway once the iddict is cleared
Base.atexit() do
Polymake.oscarnumber_prepare_cleanup()
end
end

include("setup_apps.jl")
Expand Down
6 changes: 6 additions & 0 deletions src/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function bigobject(fname::String, name::String; kwargsdata...)
return obj
end

function bigobject_eltype(obj::BigObject)
res = call_function(:User, :get_bigobject_elemtype, obj)
res isa CxxWrap.StdString && !isempty(res) || error("could not determine element type of BigObject")
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
10 changes: 10 additions & 0 deletions src/polymake/julia.rules
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ function set_shell_scalar($,$) {
no strict 'refs';
${"Polymake::User::$varname"} = $obj;
}

sub get_bigobject_elemtype($) {
my $params = $_[0]->type->params;
return "" unless defined($params) && @$params > 0;
if ($params->[0]->name =~ /^Min|Max$/) {
return $params->[1]->name;
} else {
return $params->[0]->name;
}
}
7 changes: 6 additions & 1 deletion test/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@

@test (@pm tropical.Polytope{Max}(POINTS=points_int)) isa Polymake.BigObject

@test (@pm tropical.Polytope{Max}(POINTS=points_int)) isa Polymake.BigObject
tp = @pm tropical.Polytope{Max}(POINTS=points_int)
@test Polymake.bigobject_eltype(tp) == "Rational"

@test (@pm tropical.Polytope{Max, Rational}(POINTS=points_int)) isa Polymake.BigObject
@test (@pm tropical.Polytope{Max, QuadraticExtension}(POINTS=points_int)) isa Polymake.BigObject

Expand All @@ -108,10 +110,12 @@
@test P.VERTICES isa Polymake.Matrix{Float64}
P = @pm polytope.Polytope{Float}(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Float64}
@test Polymake.bigobject_eltype(P) == "Float"
P = @pm polytope.Polytope(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Polymake.Rational}
P = @pm polytope.Polytope{Rational}(POINTS=[1 0.5 0; 1 0 1])
@test P.VERTICES isa Polymake.Matrix{Polymake.Rational}
@test Polymake.bigobject_eltype(P) == "Rational"
end

@testset verbose=true "PolymakeException" begin
Expand Down Expand Up @@ -141,6 +145,7 @@
i = Polymake.polytope.icosahedron()
@test i.VERTICES[1, :] == [1, 0, Polymake.QuadraticExtension{Polymake.Rational}(1//4, 1//4, 5), 1//2]
@test i.VOLUME == Polymake.QuadraticExtension{Polymake.Rational}(5//4, 5//12, 5)
@test Polymake.bigobject_eltype(i) == "QuadraticExtension"
end

@testset verbose=true "attachments" begin
Expand Down

2 comments on commit e501d13

@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/90215

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.4 -m "<description of version>" e501d130b54c1bc63eaf3b8b4444ea32745602d2
git push origin v0.11.4

Please sign in to comment.