diff --git a/src/common.jl b/src/common.jl index 82ac3d4a..87ea60a5 100644 --- a/src/common.jl +++ b/src/common.jl @@ -332,9 +332,9 @@ function truncate!(ps::Vector{T}; nothing end -function truncate!(ps::Dict{Int,T}; +function truncate!(ps::Dict{S,T}; rtol::Real = Base.rtoldefault(real(T)), - atol::Real = 0,) where {T} + atol::Real = 0,) where {S,T} isempty(ps) && return nothing max_coeff = norm(values(ps), Inf) diff --git a/src/polynomial-basetypes/mutable-sparse-polynomial.jl b/src/polynomial-basetypes/mutable-sparse-polynomial.jl index dbfdcedc..fc5af259 100644 --- a/src/polynomial-basetypes/mutable-sparse-polynomial.jl +++ b/src/polynomial-basetypes/mutable-sparse-polynomial.jl @@ -141,15 +141,15 @@ end trim_trailing_zeros!!(d::Dict) = chop_exact_zeros!(d) # Not properly named, but what is expected in other constructors chop!(p::MutableSparsePolynomial; kwargs...) = (chop!(p.coeffs; kwargs...); p) -function chop!(p::Dict; atol=nothing, rtol=nothing) - isempty(p.coeffs) && return p +function chop!(d::Dict; atol=nothing, rtol=nothing) + isempty(d) && return d δ = something(rtol,0) ϵ = something(atol,0) - τ = max(ϵ, norm(values(p.coeffs),2) * δ) - for (i,pᵢ) ∈ pairs(p) - abs(pᵢ) ≤ τ && delete!(p.coeffs, i) + τ = max(ϵ, norm(values(d),2) * δ) + for (i,pᵢ) ∈ pairs(d) + abs(pᵢ) ≤ τ && delete!(d, i) end - p + d end ## ---