From 7b21b02cc1c198868b8fdc3af78a9d70e1b9c89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 27 May 2024 16:41:51 +0200 Subject: [PATCH] Fix zeroing of sparsevector when coefficient is MOI.ScalarAffineFunction --- src/coefficients.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coefficients.jl b/src/coefficients.jl index 735be39..35eaacb 100644 --- a/src/coefficients.jl +++ b/src/coefficients.jl @@ -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)