Skip to content

Commit

Permalink
Merge pull request #467 from oscar-system/bl/cfun
Browse files Browse the repository at this point in the history
avoid closure cfunctions
  • Loading branch information
benlorenz authored Jan 25, 2024
2 parents c58cb20 + 5cc6791 commit 4a5f80d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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.10"
version = "0.11.11"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down
8 changes: 4 additions & 4 deletions src/Polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ include(type_translator)

_pm_rand_helper() = rand(Int64)

function set_rand_source(f::Function)
cf = CxxWrap.@safe_cfunction($f, Int64, ())
set_rand_source(cf)
function set_rand_source()
_default_rand_helper = CxxWrap.@safe_cfunction(_pm_rand_helper, Int64, ())
set_rand_source(_default_rand_helper)
end

function __init__()
Expand Down Expand Up @@ -273,7 +273,7 @@ function __init__()
application("common")
end

set_rand_source(_pm_rand_helper)
set_rand_source()

# We need to set the Julia types as c types for polymake
for (name, c_type) in C_TYPES
Expand Down
9 changes: 7 additions & 2 deletions test/util.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_test_rand_fun() = return 42

@testset verbose=true "utilities" begin
facets = [ 0 1 0 ; 0 0 1 ; 1 -1 0 ; 1 0 -1 ]

Expand Down Expand Up @@ -85,9 +87,12 @@
@test Polymake.shell_execute(raw"""$c->apply_rule("_4ti2.integer_points");""") isa NamedTuple
@test Polymake.exists(c, "LATTICE_POINTS_GENERATORS") || Polymake.exists(c, "HILBERT_BASIS_GENERATORS")
end


@testset verbose=true "seeding" begin
try
Polymake.set_rand_source(() -> return 42)
_test_rand_cfun = Polymake.CxxWrap.@safe_cfunction(_test_rand_fun, Int64, ())
Polymake.set_rand_source(_test_rand_cfun)
v1 = Polymake.polytope.rand_sphere(3,10).VERTICES
v2 = Polymake.polytope.rand_sphere(3,10).VERTICES
vs1 = Polymake.polytope.rand_sphere(3,10; seed=42).VERTICES
Expand All @@ -99,7 +104,7 @@
vr = Polymake.polytope.rand_sphere(3,10).VERTICES
@test v1 != vr
finally
Polymake.set_rand_source(Polymake._pm_rand_helper)
Polymake.set_rand_source()
end
end
end

2 comments on commit 4a5f80d

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

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.11 -m "<description of version>" 4a5f80d5ee3eb7d86ab656e88ba8cbcd644c4a54
git push origin v0.11.11

Please sign in to comment.