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

oscarnumber: add float conversion #456

Merged
merged 7 commits into from
Sep 28, 2023
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
10 changes: 2 additions & 8 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ jobs:
os: ['ubuntu-latest']
cxxwrap: [ '' ]
include:
- cxxwrap: '0.13.4'
- cxxwrap: '0.14'
os: ubuntu-latest
julia-version: 1.9
- cxxwrap: '0.14.0'
os: ubuntu-latest
julia-version: 1.9
- cxxwrap: '0.13.4'
os: ubuntu-latest
julia-version: nightly
- cxxwrap: '0.14.0'
- cxxwrap: '0.14'
os: ubuntu-latest
julia-version: nightly

Expand Down
6 changes: 3 additions & 3 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.5"
version = "0.11.6"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand All @@ -24,7 +24,7 @@ polymake_oscarnumber_jll = "10f31823-b687-53e6-9f29-edb9d4da9f9f"

[compat]
BinaryWrappers = "~0.1.0"
CxxWrap = "~0.10.1, ~0.11, ~0.12, ~0.13.1, ~0.14"
CxxWrap = "~0.14"
JSON = "^0.20, ^0.21"
Mongoc = "~0.6.0, ~0.7.0, ~0.8.0, ~0.9.0"
Ninja_jll = "^1.11.1"
Expand All @@ -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.5"
polymake_oscarnumber_jll = "~0.2.7"
12 changes: 2 additions & 10 deletions src/Polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ module LibPolymake
using polymake_oscarnumber_jll
import ..Polymake: libcxxwrap_build_version

if libcxxwrap_build_version() >= v"0.11.0"
@wrapmodule(() -> joinpath(libpolymake_julia), :define_module_polymake)
else
@wrapmodule(joinpath(libpolymake_julia), :define_module_polymake)
end
@wrapmodule(() -> joinpath(libpolymake_julia), :define_module_polymake)

function __init__()

Expand Down Expand Up @@ -142,11 +138,7 @@ module LibOscarNumber
import ..LibPolymake: show_small_obj
import ..Polymake: libcxxwrap_build_version

if libcxxwrap_build_version() >= v"0.11.0"
@wrapmodule(() -> joinpath(libpolymake_oscarnumber), :define_module_polymake_oscarnumber)
else
@wrapmodule(joinpath(libpolymake_oscarnumber), :define_module_polymake_oscarnumber)
end
@wrapmodule(() -> joinpath(libpolymake_oscarnumber), :define_module_polymake_oscarnumber)

function __init__()

Expand Down
21 changes: 19 additions & 2 deletions src/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
abs::Ptr{Cvoid}
hash::Ptr{Cvoid}
to_rational::Ptr{Cvoid}
to_float::Ptr{Cvoid}
end
oscar_number_dispatch_helper() = oscar_number_dispatch_helper(-1, repeat([C_NULL], 21)...)
oscar_number_dispatch_helper() = oscar_number_dispatch_helper(-1, repeat([C_NULL], 22)...)

Check warning on line 68 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L68

Added line #L68 was not covered by tests

const _on_gc_refs = IdDict()

Expand Down Expand Up @@ -135,6 +136,22 @@
@cfunction(_on_sign_int, Clong, (Ref{ArgT},))
end

function _fieldelem_to_float(e::T) where T
if !hasmethod(Float64, Tuple{T})
error("OscarNumber: cannot coerce to Float64, please define 'Polymake._fieldelem_to_float(e::$T)::Float64'")

Check warning on line 141 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L139-L141

Added lines #L139 - L141 were not covered by tests
end
return Float64(e)

Check warning on line 143 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L143

Added line #L143 was not covered by tests
end

function _on_to_float(e::ArgT)::Float64 where ArgT
return _fieldelem_to_float(e)

Check warning on line 147 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L146-L147

Added lines #L146 - L147 were not covered by tests
end

@generated _on_gen_to_float(::Type{ArgT}) where ArgT =

Check warning on line 150 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L150

Added line #L150 was not covered by tests
quote
@cfunction(_on_to_float, Float64, (Ref{ArgT},))

Check warning on line 152 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L152

Added line #L152 was not covered by tests
end

function _fieldelem_to_rational(e::T) where T
if !hasmethod(Rational{BigInt}, Tuple{T})
error("OscarNumber: cannot check is_rational, please define 'Polymake._fieldelem_to_rational(e::$T)::Rational{BigInt}'")
Expand Down Expand Up @@ -285,6 +302,7 @@
dispatch.hash = _on_gen_hash(t)

dispatch.to_rational = _on_gen_to_rational(t)
dispatch.to_float = _on_gen_to_float(t)

Check warning on line 305 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L305

Added line #L305 was not covered by tests

dispatch.cmp = _on_gen_cmp(t)

Expand Down Expand Up @@ -316,4 +334,3 @@
(::Type{<:OscarNumber})(qe::QuadraticExtension) = OscarNumber(Rational(qe))
OscarNumber(qe::QuadraticExtension) = OscarNumber(Rational(qe))

Base.float(on::OscarNumber) = float(unwrap(on))
6 changes: 6 additions & 0 deletions test/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
if _with_oscar
@test M * A2 == A2 * M == Polymake.OscarNumber(a1*a2 + 15 + 7*a2)
@test Polymake.OscarNumber(5) // A2 == Polymake.OscarNumber(a2^2)
# avoid test error for older oscar versions
if length(methods(Polymake._fieldelem_to_float, (EmbeddedElem,), Oscar)) > 0
@test Polymake.common.convert_to{Float64}(A2) isa Float64
fa2 = Polymake.common.convert_to{Float64}(A2)
@test isapprox(fa2, 1.71; rtol=0.001)
end
end
end

Expand Down
Loading