Skip to content

Commit

Permalink
fix truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Aug 3, 2023
1 parent 0022fec commit 7b3fe93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/polynomial-basetypes/mutable-sparse-polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ end
trim_trailing_zeros!!(d::Dict) = chop_exact_zeros!(d) # Not properly named, but what is expected in other constructors

Check warning on line 141 in src/polynomial-basetypes/mutable-sparse-polynomial.jl

View check run for this annotation

Codecov / codecov/patch

src/polynomial-basetypes/mutable-sparse-polynomial.jl#L141

Added line #L141 was not covered by tests

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

Check warning on line 152 in src/polynomial-basetypes/mutable-sparse-polynomial.jl

View check run for this annotation

Codecov / codecov/patch

src/polynomial-basetypes/mutable-sparse-polynomial.jl#L144-L152

Added lines #L144 - L152 were not covered by tests
end

## ---
Expand Down

0 comments on commit 7b3fe93

Please sign in to comment.