Skip to content

Commit

Permalink
add == for AbstractCoefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Dec 6, 2023
1 parent 06cad36 commit 532db45
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ Base.valtype(b::AbstractCoefficients) = valtype(typeof(b))

Base.iszero(sc::AbstractCoefficients) = isempty(keys(sc))

function Base.:(==)(ac1::AbstractCoefficients, ac2::AbstractCoefficients)
for x in (ac1, ac2)
if !__iscanonical(x)
__canonicalize!(x)
end
end
return keys(ac1) == keys(ac2) && values(ac1) == values(ac2)
end

struct DiracDelta{K,V} <: AbstractCoefficients{K,V}
element::K
value::V
Expand All @@ -19,6 +28,8 @@ DiracDelta(x) = DiracDelta(x, 1)
Base.getindex::DiracDelta{K,V}, i::K) where {K,V} =
ifelse(i == δ.element, δ.value, zero.value))

__iscanonical(::DiracDelta) = true

Base.keys::DiracDelta) =.element,)
Base.values::DiracDelta) =.value,)

Expand Down

0 comments on commit 532db45

Please sign in to comment.