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

avoid closure cfunctions #467

Merged
merged 3 commits into from
Jan 25, 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
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

Choose a reason for hiding this comment

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

Better just " = 42"

Copy link
Member Author

Choose a reason for hiding this comment

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

why?


@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
Loading