From 10bf3f3a9e86061309aaab10bf6e5e7237ca04c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 10 Jun 2024 17:08:46 +0200 Subject: [PATCH] Add test for MA.broadcast! with sparse array (#291) * Add test for MA.broadcast! with sparse array * Add tests * Fix format * Fix tests for Julia v1.6 * up --- src/broadcast.jl | 6 +++++- test/matmul.jl | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/broadcast.jl b/src/broadcast.jl index 7356e809..4b8d3761 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -151,7 +151,11 @@ end # If A is `Symmetric`, we cannot do a normal broadcast because we might modify # the same entry twice. See https://github.com/jump-dev/JuMP.jl/issues/2102 -function broadcast!(op::F, A::Array, args::Vararg{Any,N}) where {F<:Function,N} +function broadcast!( + op::F, + A::Union{Array,SparseArrays.AbstractSparseArray}, + args::Vararg{Any,N}, +) where {F<:Function,N} bc = Broadcast.broadcasted(op, A, args...) instantiated = Broadcast.instantiate(bc) return copyto!(A, mutable_broadcasted(instantiated)) diff --git a/test/matmul.jl b/test/matmul.jl index 90fc3632..9e8d3b86 100644 --- a/test/matmul.jl +++ b/test/matmul.jl @@ -476,6 +476,9 @@ function test_sparse_vector_sum(::Type{T}) where {T} x = SparseArrays.sparsevec([1, 3], T[5, 7]) y = copy(x) z = copy(y) + # FIXME not sure what is allocating + alloc_test_le(() -> MA.operate!(+, y, z), 200) + alloc_test_le(() -> MA.operate!(-, y, z), 200) alloc_test(() -> MA.operate_to!(x, +, y, z), 0) alloc_test(() -> MA.operate_to!(x, -, y, z), 0) alloc_test(() -> MA.operate_to!(x, +, y), 0)