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

Generic coefficient type #163

Merged
merged 18 commits into from
Nov 20, 2024
Merged
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
Manifest.toml
LocalPreferences.toml
.vscode
.benchmarkci

# ignore coverage
*.cov
*.info
*.png
*.html
*.css

# ignore editor settings
.vscode
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ DynamicPolynomials = "0.6.0"
Nemo = "0.45.4, 0.46, 0.47"
PrecompileTools = "1"
Primes = "0.5"
TestSetExtensions = "2"
julia = "1.10"

[extras]
Expand All @@ -38,7 +37,6 @@ DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04"

[targets]
test = ["DynamicPolynomials", "BenchmarkTools", "InteractiveUtils", "Test", "TestSetExtensions", "Nemo"]
test = ["DynamicPolynomials", "BenchmarkTools", "InteractiveUtils", "Test", "Nemo"]
Binary file added benchmark/CI-scripts/.runtests.jl.swp
Binary file not shown.
17 changes: 9 additions & 8 deletions benchmark/CI-scripts/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function clean_data(results)
)
append!(results_master[j], times_master)
append!(results_nightly[j], times_nightly)
results_problems[j] = join(split(problem_name_master, ","), ", ")
results_problems[j] = join(split(problem_name_master, ","), " ")
results_types[j] = type
end
end
Expand All @@ -118,6 +118,7 @@ function compare()
results_problems, results_types, results_master, results_nightly = clean_data(results)
table = Matrix{Any}(undef, length(results_master), 4)
fail = false
tolerance = 0.02
for (i, (master, nightly)) in enumerate(zip(results_master, results_nightly))
if results_types[i] == "time"
master = 1e9 .* master
Expand All @@ -133,22 +134,22 @@ function compare()
0, "insignificant"
elseif (1 + MAX_DEVIATION) * m1 < m2
fail = true
2, "slower❌"
2, "worse❌"
elseif m1 > (1 + MAX_DEVIATION) * m2
1, "faster✅"
1, "better✅"
else
0, "insignificant"
0, "don't care"
end
elseif results_types[i] == "allocs"
label_master = mean(master)
label_nightly = mean(nightly)
indicator = if label_master < label_nightly
indicator = if label_master < (1 - tolerance) * label_nightly
fail = true
2, "worse❌"
elseif label_master > label_nightly
elseif label_master > (1 + tolerance) * label_nightly
1, "better✅"
else
0, "same"
0, "don't care"
end
else
error("Beda!")
Expand Down Expand Up @@ -176,7 +177,7 @@ function post(fail, table)
println(io, "No regressions detected✅")
end
table_header = ["Problem", "Master", "This commit", "Result"]
pretty_table(io, table, header=table_header)
pretty_table(io, table, header=table_header, alignment=[:l, :r, :r, :r])
comment_str = String(take!(io))
println(comment_str)
end
Expand Down
2 changes: 1 addition & 1 deletion ext/GroebnerDynamicPolynomialsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function io_extract_ring(orig_polys::Vector{<:AbstractPolynomialLike{T}}) where
nv = MultivariatePolynomials.nvariables(orig_polys)
ord = dp_ord_to_symbol(MultivariatePolynomials.ordering(orig_polys[1]))
ord_typed = dp_ordering_sym2typed(ord)
Groebner.PolyRing{typeof(ord_typed), UInt}(nv, ord_typed, UInt(0))
Groebner.PolyRing(nv, ord_typed, UInt(0))
end

function io_extract_coeffs(ring, orig_polys)
Expand Down
3 changes: 2 additions & 1 deletion src/Groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ include("monomials/exponent_vector.jl")
include("monomials/packed_vector.jl")

include("arithmetic/CompositeNumber.jl")
include("arithmetic/CoeffGeneric.jl")

# Defines some type aliases
include("types.jl")

# Fast arithmetic modulo a prime
include("arithmetic/Zp.jl")
include("arithmetic/QQ.jl")
include("arithmetic/generic.jl")

# Intermediate representation
include("input_output/intermediate.jl")
Expand Down
23 changes: 23 additions & 0 deletions src/arithmetic/CoeffGeneric.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is a part of Groebner.jl. License is GNU GPL v2.

struct CoeffGeneric{T}
data::T
end

generic_coeff_data(x) = x
generic_coeff_data(x::CoeffGeneric) = x.data

CoeffGeneric(x::CoeffGeneric{T}) where {T} = x
CoeffGeneric{T}(x::CoeffGeneric{T}) where {T} = x

Base.:+(x::CoeffGeneric, y::CoeffGeneric) = CoeffGeneric(x.data + y.data)
Base.:-(x::CoeffGeneric, y::CoeffGeneric) = CoeffGeneric(x.data - y.data)
Base.:*(x::CoeffGeneric, y::CoeffGeneric) = CoeffGeneric(x.data * y.data)
Base.inv(x::CoeffGeneric) = CoeffGeneric(inv(x.data))
Base.:-(x::CoeffGeneric) = zero(x) - x

Base.one(x::CoeffGeneric{T}) where {T} = CoeffGeneric{T}(one(x.data))
Base.zero(x::CoeffGeneric{T}) where {T} = CoeffGeneric{T}(zero(x.data))

Base.isone(x::CoeffGeneric) = isone(x.data)
Base.iszero(x::CoeffGeneric) = iszero(x.data)
7 changes: 3 additions & 4 deletions src/arithmetic/CompositeNumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ function CompositeNumber{N, T}(a::CompositeNumber{N, U}) where {N, T, U}
CompositeNumber{N, T}(a.data .% T)
end

function CompositeNumber{N, FP}(a::CompositeNumber{N, U}) where {N, FP <: AbstractFloat, U}
CompositeNumber{N, FP}(a.data)
end

Base.convert(::Type{CompositeNumber{N, T}}, a::CompositeNumber{N, U}) where {N, T, U} =
CompositeNumber{N, T}(map(x -> convert(T, x), a.data))

Expand All @@ -37,6 +33,9 @@ Base.isless(x::U, ci::CompositeNumber{N, T}) where {N, T, U <: Number} = all(x .
Base.iszero(ci::CompositeNumber) = all(iszero, ci.data)
Base.isone(ci::CompositeNumber) = all(isone, ci.data)

Base.zero(x::CompositeNumber{N, T}) where {N, T} = zero(typeof(x))
Base.one(x::CompositeNumber{N, T}) where {N, T} = one(typeof(x))

Base.zero(::Type{CompositeNumber{N, T}}) where {N, T} =
CompositeNumber(ntuple(_ -> zero(T), Val(N)))
Base.one(::Type{CompositeNumber{N, T}}) where {N, T} = CompositeNumber(ntuple(_ -> one(T), N))
Expand Down
8 changes: 8 additions & 0 deletions src/arithmetic/QQ.jl → src/arithmetic/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ function select_arithmetic(
@invariant iszero(characteristic)
ArithmeticQQ()
end

# Arithmetic with generic coefficients.

struct ArithmeticGeneric{CoeffType, AccumType} <: AbstractArithmetic{CoeffType, AccumType} end

function select_arithmetic(::Type{CoeffGeneric}, _, _, _)
ArithmeticGeneric{CoeffGeneric, CoeffGeneric}()
end
6 changes: 3 additions & 3 deletions src/f4/basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function basis_well_formed(ring::PolyRing, basis::Basis, hashtable::MonomialHash
) && error("Bad polynomial")
for j in 1:length(basis.coeffs[i])
iszero(basis.coeffs[i][j]) && error("Coefficient is zero")
(ring.ch > 0) &&
(ring.ground == :zp) &&
!(basis.coeffs[i][j] < ring.ch) &&
error("Coefficients must be normalized")
(basis.monoms[i][j] > hashtable.load) && error("Bad monomial")
Expand Down Expand Up @@ -405,9 +405,9 @@ end

function basis_make_monic!(
basis::Basis{C},
arithmetic::AbstractArithmeticQQ,
arithmetic::AbstractArithmetic,
changematrix::Bool
) where {C <: CoeffQQ}
) where {C <: Union{CoeffQQ, CoeffGeneric}}
cfs = basis.coeffs
@inbounds for i in 1:(basis.n_filled)
!isassigned(cfs, i) && continue
Expand Down
Loading
Loading