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

reduce invalidations #445

Merged
merged 5 commits into from
Jul 7, 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
6 changes: 4 additions & 2 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
# github services (for mongodb service) only works on linux
test-with-mongodb:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.julia-version == 'nightly' }}
continue-on-error: ${{ matrix.julia-version == 'nightly' || matrix.julia-version == '~1.10.0-0' }}
strategy:
matrix:
julia-version:
- '~1.6.0-0'
- '~1.8.0-0'
- '~1.9.0-0'
- '~1.10.0-0'
- 'nightly'
os: ['ubuntu-latest']
fail-fast: false
Expand Down Expand Up @@ -72,14 +73,15 @@ jobs:
# this one is only for macos, ubuntu is run with mongodb in the other job
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.julia-version == 'nightly' }}
continue-on-error: ${{ matrix.julia-version == 'nightly' || matrix.julia-version == '~1.10.0-0' }}
env:
JULIA_PKG_SERVER: ""
strategy:
matrix:
julia-version:
- '~1.6.0-0'
- '~1.9.0-0'
- '~1.10.0-0'
- 'nightly'
os: ['macOS-latest']
fail-fast: false
Expand Down
6 changes: 6 additions & 0 deletions OscarCI.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ julia-version = [ "~1.6.0-0", "~1.9.0-0"]
Polymake = ""
julia-version = "nightly"
os = "ubuntu-latest"

[include.julia_1_10]
Oscar = "<matching>"
Polymake = ""
julia-version = "~1.10.0-0"
os = "ubuntu-latest"
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.0"
version = "0.11.1"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down
19 changes: 11 additions & 8 deletions src/integers.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# One arguments constructors used by convert:
# specialized Int64 constructors handled by Cxx side
(::Type{<:Integer})(int::BigInt) = new_integer_from_bigint(int)

Check warning on line 3 in src/integers.jl

View check run for this annotation

Codecov / codecov/patch

src/integers.jl#L3

Added line #L3 was not covered by tests
(::Type{<:Integer})(int::Number) = Integer(BigInt(int))
# to avoid ambiguities:
(::Type{<:Integer})(rat::Base.Rational) = Integer(BigInt(rat))
(::Type{<:Integer})(flt::BigFloat) = Integer(BigInt(flt))

Check warning on line 7 in src/integers.jl

View check run for this annotation

Codecov / codecov/patch

src/integers.jl#L6-L7

Added lines #L6 - L7 were not covered by tests
Integer(int::BigInt) = new_integer_from_bigint(int)
Integer(int::Number) = Integer(BigInt(int))
# to avoid ambiguities:
Integer(rat::Base.Rational) = Integer(BigInt(rat))
Integer(flt::BigFloat) = Integer(BigInt(flt))

# we need thie to make the fallbacks like Base.one work
IntegerAllocated(int::Union{BigInt,Base.Rational,BigFloat,<:Number}) = Integer(int)

import Base: ==, <, <=
# These are operations we delegate to gmp
for op in (:(==), :(<), :(<=))
Expand Down Expand Up @@ -37,22 +38,24 @@
@eval Base.$T(int::Integer) = $T(BigInt(int))
end

Base.Int64(int::Integer) = convert(Int64, new_int_from_integer(int))
Base.Int64(int::Integer) = Int64(new_int_from_integer(int))

for T in [:Int8, :Int16, :Int32, :UInt8, :UInt16, :UInt32]
@eval Base.$T(int::Integer) = $T(Int64(int))
end

(::Type{<:Rational})(int::Integer) = new_rational_from_integer(int)

Check warning on line 47 in src/integers.jl

View check run for this annotation

Codecov / codecov/patch

src/integers.jl#L47

Added line #L47 was not covered by tests
Rational(int::Integer) = new_rational_from_integer(int)
(::Type{T})(int::Integer) where {T<:Number} = convert(T, BigInt(int))
(::Type{T})(int::Integer) where {T<:AbstractFloat} = convert(T, Float64(int))
(::Type{T})(int::Integer) where T <: Number = convert(T, BigInt(int))
(::Type{T})(int::Integer) where T <: AbstractFloat = convert(T, Float64(int))

Check warning on line 50 in src/integers.jl

View check run for this annotation

Codecov / codecov/patch

src/integers.jl#L49-L50

Added lines #L49 - L50 were not covered by tests
# to avoid ambiguity
Float64(int::Integer) = Float64(CxxWrap.CxxRef(int))
BigFloat(int::Integer) = BigFloat(BigInt(int))
Base.float(int::Integer) = Float64(int)

# no-copy converts
convert(::Type{<:Integer}, int::T) where T <: Integer = int
(::Type{<:Integer})(int::Integer) = int
Integer(int::Integer) = int

Check warning on line 58 in src/integers.jl

View check run for this annotation

Codecov / codecov/patch

src/integers.jl#L58

Added line #L58 was not covered by tests
Base.Integer(int::Integer) = int

Base.trailing_zeros(int::Integer) = trailing_zeros(BigInt(int))
Expand Down
19 changes: 17 additions & 2 deletions src/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
return OscarNumber
end

OscarNumber(a::Union{Base.Integer, Base.Rational{<:Base.Integer}}) = OscarNumber(Rational(a))
(::Type{<:OscarNumber})(a::Union{Base.Integer, Base.Rational{<:Base.Integer}}) = OscarNumber(Rational(a))

Check warning on line 6 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L6

Added line #L6 was not covered by tests
# this needs to be separate to avoid ambiguities
OscarNumber(a::Union{Base.Integer, Base.Rational{<:Base.Integer}}) = OscarNumber(Rational(a))
(::Type{<:OscarNumber})(a::Integer) = OscarNumber(Rational(a))

Check warning on line 9 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L9

Added line #L9 was not covered by tests
OscarNumber(a::Integer) = OscarNumber(Rational(a))
(::Type{<:OscarNumber})(a::Rational) = OscarNumber(CxxWrap.ConstCxxRef(a))

Check warning on line 11 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L11

Added line #L11 was not covered by tests
OscarNumber(a::Rational) = OscarNumber(CxxWrap.ConstCxxRef(a))

Base.zero(::Type{<:OscarNumber}) = OscarNumber(0)
Base.zero(::OscarNumber) = OscarNumber(0)
Expand Down Expand Up @@ -299,6 +303,17 @@
return field_count
end

convert(::Type{T}, on::OscarNumber) where T<:Number = convert(T, unwrap(on))
(::Type{T})(on::OscarNumber) where T<:Number = convert(T, unwrap(on))
(::Type{<:Integer})(on::OscarNumber) = convert(Integer, unwrap(on))
(::Type{<:Rational})(on::OscarNumber) = convert(Rational, unwrap(on))

Check warning on line 308 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L307-L308

Added lines #L307 - L308 were not covered by tests
Integer(on::OscarNumber) = convert(Integer, unwrap(on))
Rational(on::OscarNumber) = convert(Rational, unwrap(on))

# we don't support conversion for concrete types inside the OscarNumber here
(::Type{<:QuadraticExtension{<:Rational}})(on::OscarNumber) = QuadraticExtension{Rational}(Rational(on))
QuadraticExtension{<:Rational}(on::OscarNumber) = QuadraticExtension{Rational}(Rational(on))

Check warning on line 314 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L313-L314

Added lines #L313 - L314 were not covered by tests
QuadraticExtension{Rational}(on::OscarNumber) = QuadraticExtension{Rational}(Rational(on))
(::Type{<:OscarNumber})(qe::QuadraticExtension) = OscarNumber(Rational(qe))
OscarNumber(qe::QuadraticExtension) = OscarNumber(Rational(qe))

Check warning on line 317 in src/oscarnumber.jl

View check run for this annotation

Codecov / codecov/patch

src/oscarnumber.jl#L316-L317

Added lines #L316 - L317 were not covered by tests

Base.float(on::OscarNumber) = float(unwrap(on))
21 changes: 18 additions & 3 deletions src/quadraticextension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
QuadraticExtension{T}(convert(T, a), convert(T, b), convert(T, r))

QuadraticExtension{T}(a::Number) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)
(::Type{<:QuadraticExtension{T}})(a::Number) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)

QuadraticExtension(x...) = QuadraticExtension{Rational}(x...)
(::Type{<:QuadraticExtension})(x...) = QuadraticExtension{Rational}(x...)

Check warning on line 10 in src/quadraticextension.jl

View check run for this annotation

Codecov / codecov/patch

src/quadraticextension.jl#L10

Added line #L10 was not covered by tests

# needed to avoid ambiguities
QuadraticExtension{T}(a::Integer) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)
(::Type{<:QuadraticExtension{T}})(a::Integer) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)

Check warning on line 14 in src/quadraticextension.jl

View check run for this annotation

Codecov / codecov/patch

src/quadraticextension.jl#L14

Added line #L14 was not covered by tests
QuadraticExtension(x::Integer) = QuadraticExtension{Rational}(x)
QuadraticExtension{T}(a::Rational) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)
(::Type{<:QuadraticExtension{T}})(a::Rational) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0)

Check warning on line 17 in src/quadraticextension.jl

View check run for this annotation

Codecov / codecov/patch

src/quadraticextension.jl#L17

Added line #L17 was not covered by tests
QuadraticExtension(a::Rational) = QuadraticExtension{Rational}(a, 0, 0)

Base.zero(::Type{<:QuadraticExtension{T}}) where T<:qe_suppT = QuadraticExtension{T}(0)
Base.zero(::QuadraticExtension{T}) where T<:qe_suppT = QuadraticExtension{T}(0)
Expand Down Expand Up @@ -37,14 +43,23 @@

# no-copy convert
convert(::Type{<:QuadraticExtension{T}}, qe::QuadraticExtension{T}) where T<:qe_suppT = qe
(::Type{<:QuadraticExtension{T}})(qe::QuadraticExtension{T}) where T<:qe_suppT = qe
(QuadraticExtension{T})(qe::QuadraticExtension{T}) where T<:qe_suppT = qe

Check warning on line 47 in src/quadraticextension.jl

View check run for this annotation

Codecov / codecov/patch

src/quadraticextension.jl#L47

Added line #L47 was not covered by tests

function convert(to::Type{<:Number}, qe::QuadraticExtension)
function _qe_to_rational(::Type{T}, qe::QuadraticExtension) where T<:Number
!iszero(_b(qe)) && !iszero(_r(qe)) && throw(DomainError("Given QuadraticExtension not trivial."))
return convert(to, _a(qe))
return convert(T, _a(qe))
end

# compatibility with Float64
Float64(x::QuadraticExtension{T}) where T<:qe_suppT = Float64(_a(x)) + Float64(_b(x)) * sqrt(Float64(_r(x)))
Base.promote_rule(::Type{<:QuadraticExtension{Rational}}, ::Type{<:AbstractFloat}) = Float64

convert(to::Type{<:AbstractFloat}, qe::QuadraticExtension) = convert(to, Float64(qe))
(::Type{T})(qe::QuadraticExtension) where {T<:AbstractFloat} = convert(T, Float64(qe))

# avoid ambiguities
(::Type{<:Rational})(qe::QuadraticExtension) = _qe_to_rational(Rational,qe)
(::Type{<:Integer})(qe::QuadraticExtension) = _qe_to_rational(Integer,qe)

Check warning on line 62 in src/quadraticextension.jl

View check run for this annotation

Codecov / codecov/patch

src/quadraticextension.jl#L61-L62

Added lines #L61 - L62 were not covered by tests
Rational(qe::QuadraticExtension) = _qe_to_rational(Rational,qe)
Integer(qe::QuadraticExtension) = _qe_to_rational(Integer,qe)
(::Type{T})(qe::QuadraticExtension) where {T<:Base.Integer} = _qe_to_rational(T,qe)
21 changes: 16 additions & 5 deletions src/rationals.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
(::Type{<:Rational})(num::Int64, den::Int64) =

Check warning on line 1 in src/rationals.jl

View check run for this annotation

Codecov / codecov/patch

src/rationals.jl#L1

Added line #L1 was not covered by tests
rational_si_si(convert(CxxLong, num), convert(CxxLong, den))
Rational(num::Int64, den::Int64) =
rational_si_si(convert(CxxLong, num), convert(CxxLong, den))

function Rational(num::T, den::S) where {T<:Base.Integer, S<:Base.Integer}
function (::Type{<:Rational})(num::T, den::S) where {T<:Base.Integer, S<:Base.Integer}
R = promote_type(promote_type(T, Int64), promote_type(S, Int64))
R == Int64 && return Rational(convert(Int64, num), convert(Int64, den))
return Rational(Integer(convert(BigInt, num)), Integer(convert(BigInt, den)))
end

(::Type{<:Rational})(x::Base.Rational) = Rational(numerator(x), denominator(x))

Check warning on line 12 in src/rationals.jl

View check run for this annotation

Codecov / codecov/patch

src/rationals.jl#L12

Added line #L12 was not covered by tests
Rational(x::Base.Rational) = Rational(numerator(x), denominator(x))

@inline function Rational(x::Base.Rational{BigInt})
GC.@preserve x new_rational_from_baserational(pointer_from_objref(numerator(x)), pointer_from_objref(denominator(x)))
end

(::Type{<:Rational})(int::Base.Integer) = Rational(int, one(int))
(::Type{<:Rational})(x::Number) = Rational(Base.Rational(x))

Check warning on line 20 in src/rationals.jl

View check run for this annotation

Codecov / codecov/patch

src/rationals.jl#L20

Added line #L20 was not covered by tests
Rational(int::Base.Integer) = Rational(int, one(int))
Rational(x::Number) = Rational(Base.Rational(x))

Expand Down Expand Up @@ -51,13 +58,17 @@
Base.Rational(rat::Rational) = Base.Rational{BigInt}(rat)
Base.big(rat::Rational) = Base.Rational{BigInt}(rat)

convert(::Type{Integer}, rat::Rational) = new_integer_from_rational(rat)
convert(::Type{T}, rat::Rational) where T<:Number = convert(T, big(rat))
convert(::Type{T}, rat::Rational) where T<:AbstractFloat = convert(T, Float64(rat))
(::Type{<:Integer})(rat::Rational) = new_integer_from_rational(rat)

Check warning on line 61 in src/rationals.jl

View check run for this annotation

Codecov / codecov/patch

src/rationals.jl#L61

Added line #L61 was not covered by tests
Integer(rat::Rational) = new_integer_from_rational(rat)
(::Type{T})(rat::Rational) where T<:Number = convert(T, big(rat))
(::Type{T})(rat::Rational) where T<:AbstractFloat = convert(T, Float64(rat))
Base.float(rat::Rational) = Float64(rat)
# to avoid ambiguities...
Float64(rat::Rational) = Float64(CxxWrap.CxxRef(rat))

# no-copy convert
convert(::Type{<:Rational}, rat::T) where T <: Rational = rat
(::Type{<:Rational})(rat::Rational) = rat
Rational(rat::Rational) = rat

Check warning on line 71 in src/rationals.jl

View check run for this annotation

Codecov / codecov/patch

src/rationals.jl#L71

Added line #L71 was not covered by tests

# Rational division:

Expand Down
2 changes: 0 additions & 2 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ end

Base.Vector(s::Set) = collect(s)

Base.Set(s::Set{T}) where T = Base.Set{to_jl_type(T)}(Base.Vector(s))

function Base.Set{T}(s::Set{S}) where {T, S}
jls = Base.Set{T}()
sizehint!(jls, length(s))
Expand Down
8 changes: 7 additions & 1 deletion src/tropicalnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ TropicalNumber{A,S}(scalar::Union{Real, TropicalNumber}) where {A <: TropicalNum
TropicalNumber{A}(scalar::Union{Real, TropicalNumber}) where A = TropicalNumber{A,Rational}(scalar)
TropicalNumber{A}() where A = TropicalNumber{A, Rational}()


#polymake requires an explicit statement what kind of tropical number (i.e. min or max) we want to construct
TropicalNumber(x...) = throw(ArgumentError("TropicalNumber needs to be called with type parameter 'Max' or 'Min'."))
TropicalNumber(::TropicalNumber) = TropicalNumber()
TropicalNumber(::Rational) = TropicalNumber()

# to avoid ambiguities
TropicalNumber{Min, Rational}(r::Rational) = TropicalNumber{Min, Rational}(CxxWrap.ConstCxxRef(r))
TropicalNumber{Max, Rational}(r::Rational) = TropicalNumber{Max, Rational}(CxxWrap.ConstCxxRef(r))

# to avoid ambiguities with rather generic constructors for Polymake.Integer
TropicalNumber{A,S}(scalar::Integer) where {A <: TropicalNumber_suppAddition, S <: TropicalNumber_suppScalar} = TropicalNumber{A,S}(convert(S,scalar))
TropicalNumber{A}(scalar::Integer) where A = TropicalNumber{A,Rational}(scalar)
TropicalNumber(::Integer) = TropicalNumber()
TropicalNumber{A}(a::Rational) where A = TropicalNumber{A,Rational}(a)

# workaround for https://github.com/JuliaInterop/CxxWrap.jl/issues/199
for (jlF, pmF) in (
Expand Down
12 changes: 10 additions & 2 deletions test/integers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@
@testset verbose=true "Arithmetic" begin
a = Polymake.Integer(2)
@test -a == -2
# for T in [IntTypes; Polymake.Integer]
for T in IntTypes

@test sign(a) == 1
@test sign(-a) == -1
@test sign(a-a) == 0

@test abs(a) * sign(a) == a
@test abs(-a) * -sign(a) == -a

#for T in IntTypes
for T in [IntTypes; Polymake.Integer]
b = T(5)
# Equality
@test a == T(2)
Expand Down
3 changes: 2 additions & 1 deletion test/matrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@

@test (Z .= T.(jl_m)) isa Polymake.Matrix{Polymake.OscarNumber}

@test X == U == V == W == Y == Z
@test X == U == V == W == Y
@test W == Z

# TODO:
# @test (V .== jl_m) isa BitPolymake.Array
Expand Down
13 changes: 12 additions & 1 deletion test/quadraticextension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,18 @@
a /= b
@test a == Polymake.QuadraticExtension{Polymake.Rational}(735//40328, -85//40328, 5)
end


@testset verbose=true "sign abs" begin
a = Polymake.QuadraticExtension{Polymake.Rational}(5)
b = Polymake.QuadraticExtension{Polymake.Rational}(17, 1, 5)
@test sign(a) == 1
@test sign(b) == 1
@test sign(-b) == -1
@test sign(b-b) == 0

@test abs(a) * sign(a) == a
@test abs(-a) * -sign(a) == -a
end
end

@testset verbose=true "zero / one" begin
Expand Down
10 changes: 10 additions & 0 deletions test/rationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@
end
end

@testset verbose=true "sign abs" begin
a = Polymake.Rational(2, 3)
@test sign(a) == 1
@test sign(-a) == -1
@test sign(a-a) == 0

@test abs(a) * sign(a) == a
@test abs(-a) * -sign(a) == -a
end

@testset verbose=true "zero / one" begin
ZERO = Polymake.Rational(0)
ONE = Polymake.Rational(1)
Expand Down
3 changes: 2 additions & 1 deletion test/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ using Polymake.SparseArrays

@test (Z .= T.(jl_m)) isa Polymake.SparseMatrix{Polymake.OscarNumber}

@test U == V == W == Y == Z
@test U == V == W == Y
@test W == Z

# TODO:
# @test (V .== jl_m) isa BitPolymake.Array
Expand Down
3 changes: 2 additions & 1 deletion test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ using Polymake.SparseArrays

@test (Z .= T.(jl_v)) isa Polymake.SparseVector{Polymake.OscarNumber}

@test U == V == W == Y == Z
@test U == V == W == Y
@test W == Z

# TODO:
# @test (V .== jl_v) isa BitArray
Expand Down
3 changes: 2 additions & 1 deletion test/vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
@test (Z .= T.(jl_v)) isa Polymake.Vector{Polymake.OscarNumber}
@test (Z .= T.(jl_v).//1) isa Polymake.Vector{Polymake.OscarNumber}

@test X == U == V == W == Y == Z
@test X == U == V == W == Y
@test W == Z

# TODO:
# @test (V .== jl_v) isa BitPolymake.Array
Expand Down
Loading