Skip to content

Commit

Permalink
Implement broadcasting for SparseCoefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 3, 2024
1 parent 2d643d2 commit f87c542
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/sparse_coeffs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ function Base.setindex!(sc::SparseCoefficients{K}, val, key::K) where {K}
return sc
end

################
# Broadcasting #
################
# Inspired from `JuMP.Containers.SparseAxisArray`

struct BroadcastStyle{K} end

Base.broadcastable(sc::SparseCoefficients) = sc
Base.Broadcast.BroadcastStyle(::Type{<:SparseCoefficients{K}}) where {K} = BroadcastStyle{K}()
Base.axes(sc::SparseCoefficients) = (sc.basis_elements,)

function Base.zero(sc::SparseCoefficients)
return SparseCoefficients(empty(keys(sc)), empty(values(sc)))
end
Expand Down

0 comments on commit f87c542

Please sign in to comment.