Skip to content

Commit

Permalink
Fix allocation test
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 27, 2024
1 parent 789bf7a commit 8f3fb92
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sparse_coeffs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ function MA.operate!(::typeof(canonical), res::SparseCoefficients)
return MA.operate!(canonical, res, comparable(key_type(res)))
end

function MA.operate!(::typeof(canonical), res::SparseCoefficients, cmp)
# `::C` is needed to force Julia specialize on the function type
# Otherwise, we get one allocation when we call `issorted`
# See https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing
function MA.operate!(::typeof(canonical), res::SparseCoefficients, cmp::C) where {C}
sorted = issorted(res.basis_elements; lt = cmp)
distinct = allunique(res.basis_elements)
if sorted && distinct && !any(iszero, res.values)
Expand Down

0 comments on commit 8f3fb92

Please sign in to comment.