Skip to content

Commit

Permalink
compat patch for Polynomials v3.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed May 25, 2023
1 parent 1c1ca1c commit 4daa9b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/basic_arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ end

# not exported
@inline function conv(x::AbstractVector{GF}, y::AbstractVector{GF}) where {GF<:GFNumber}
return reverse(coeffs(Polynomial(reverse(x)) * Polynomial(reverse(y))))
return reverse(_patched_coeffs(Polynomial(reverse(x)) * Polynomial(reverse(y))))
end
8 changes: 6 additions & 2 deletions src/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ end
function _naive_multiply(a::GF, b::GF) where {GF<:GFNumber}
pa, pb = Polynomial(a), Polynomial(b)
pp = Polynomial(_int2poly(ppoly(a))) # prime poly
pc = Polynomial(_naive_conv(coeffs(pa), coeffs(pb)))
pc = Polynomial(_naive_conv(_patched_coeffs(pa), _patched_coeffs(pb)))
r = Polynomial{Int}(_naive_divrem(pc, pp)[2])
return GF(r)
end
Expand Down Expand Up @@ -164,7 +164,7 @@ end

Base.convert(::Type{Polynomial}, x::GFNumber) = Polynomial(_int2poly(x.x))
function Base.convert(::Type{T}, p::Polynomial) where {T<:GFNumber}
return T(_poly2int(coeffs(p)))
return T(_poly2int(_patched_coeffs(p)))
end

Polynomials.Polynomial(x::GFNumber) = convert(Polynomial, x)
Expand All @@ -181,3 +181,7 @@ end
function _poly2int(coeffs::AbstractVector{<:Integer})
return reduce((x, y) -> x * 2 + y, reverse(coeffs))
end

# Polynomials v3.2.9 changes the behavior of coeffs for zero polynomial
# https://github.com/JuliaMath/Polynomials.jl/issues/503
_patched_coeffs(x::Polynomial) = iszero(x) ? [zero(eltype(x))] : coeffs(x)

0 comments on commit 4daa9b0

Please sign in to comment.