Skip to content

Commit

Permalink
Fix zeroing of sparsevector when coefficient is MOI.ScalarAffineFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 27, 2024
1 parent 344e773 commit 7b21b02
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ end

# general mutable API
# why here?
MA.operate!(::typeof(zero), v::SparseVector) = (v .= 0; v)
function MA.operate!(::typeof(zero), v::SparseVector)
empty!(SparseArrays.nonzeroinds(v))
empty!(SparseArrays.nonzeros(v))
return v
end

Base.zero(X::AbstractCoefficients) = MA.operate!(zero, similar(X))
Base.:-(X::AbstractCoefficients) = MA.operate_to!(__prealloc(X, -1, *), -, X)
Expand Down

0 comments on commit 7b21b02

Please sign in to comment.