Skip to content

Commit

Permalink
document minimal AbstractCoefficients API
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Apr 14, 2024
1 parent ece736f commit c707b89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/coefficients.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
abstract type AbstractCoefficients{V,K} end
Implements `Base.keys`, `Base.values`.
Everything that implements a fixed set of methods can be used as
`SparseCoefficients` without subtyping it.
# "Read-only" coefficients
E.g. returned by calls to a `MultiplicativeStructure` need to implement
* `Base.keys`
* `Base.values`
* `StarAlgebras.canonical`
* `StarAlgebras.star`
"""
abstract type AbstractCoefficients{K,V} end

Expand Down
6 changes: 1 addition & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import StarAlgebras as SA
import MutableArithmetics as MA

begin
# turning GroupsCore.GroupElement into SparseCoefficients
# turning GroupsCore.GroupElement into "read-only" SparseCoefficients
import GroupsCore: GroupElement
Base.iszero(::GroupElement) = false
Base.keys(g::GroupElement) = (g,)
Base.values(::GroupElement) = (1,)
SA.canonical(g::GroupElement) = g
function Base.getindex(g::GroupElement, h::GroupElement)
return ifelse(g == h, SA.aug(g), 0 * SA.aug(g))
end
# missing above: Base.isless for the SA.canonical
# TODO: implement sort by hashing for non-comparable elements?

Expand Down

0 comments on commit c707b89

Please sign in to comment.