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: small improvements #468

Merged
merged 2 commits into from
Feb 1, 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.11"
version = "0.11.12"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down
21 changes: 9 additions & 12 deletions src/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@
end
end

_on_cmp_int(e1::T, e2::T) where T = Clong(Base.cmp(e1, e2))

Check warning on line 119 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L119

Added line #L119 was not covered by tests
@generated _on_gen_cmp(::Type{ArgT}) where ArgT =
quote
@cfunction(Base.cmp, Clong, (Ref{ArgT}, Ref{ArgT}))
@cfunction(_on_cmp_int, Clong, (Ref{ArgT}, Ref{ArgT}))

Check warning on line 122 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L122

Added line #L122 was not covered by tests
end

@generated _on_gen_is_zero(::Type{ArgT}) where ArgT =
Expand All @@ -130,16 +131,13 @@
@cfunction(Base.isone, Bool, (Ref{ArgT},))
end

_on_sign_int(e::T) where T = Base.cmp(e,0)::Int
_on_sign_int(e::T) where T = Clong(Base.cmp(e,0))

Check warning on line 134 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L134

Added line #L134 was not covered by tests
@generated _on_gen_sign_int(::Type{ArgT}) where ArgT =
quote
@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'")
end
return Float64(e)
end

Expand All @@ -153,9 +151,6 @@
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}'")
end
Polymake._fieldelem_is_rational(e) || error("not a rational number")
return Base.Rational{BigInt}(e)
end
Expand Down Expand Up @@ -204,10 +199,14 @@
@cfunction(_on_init, Ref{ArgT}, (Clong, Ptr{ArgT}, Clong))
end

function _fieldelem_from_rational(f::Any, r::Base.Rational{BigInt})
return f(r)

Check warning on line 203 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L202-L203

Added lines #L202 - L203 were not covered by tests
end

function _on_init_frac(id::Clong, ::Ptr{ArgT}, np::Ptr{BigInt}, dp::Ptr{BigInt})::ArgT where ArgT
n = unsafe_load(np)::BigInt
d = unsafe_load(dp)::BigInt
return _on_parent_by_id[id](Base.Rational{BigInt}(n, d))
return _fieldelem_from_rational(_on_parent_by_id[id], Base.Rational{BigInt}(n, d))::ArgT

Check warning on line 209 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L209

Added line #L209 was not covered by tests
end
@generated _on_gen_init_frac(::Type{ArgT}) where ArgT =
quote
Expand Down Expand Up @@ -277,9 +276,7 @@
error("OscarNumber: immutable julia types not supported")
end

for type in (Int64, Base.Rational{BigInt})
hasmethod(p, (type,)) || error("OscarNumber: no constructor ($p)($type)")
end
hasmethod(p, (Int64,)) || error("OscarNumber: no constructor ($p)(Int64)")

Check warning on line 279 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L279

Added line #L279 was not covered by tests

dispatch = oscar_number_dispatch_helper()
dispatch.index = newid
Expand Down
Loading