Skip to content

Commit

Permalink
Add key_type
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 16, 2024
1 parent ecd714d commit 038f2c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Base.eltype(b::AbstractBasis) = eltype(typeof(b))
Base.keytype(::Type{<:AbstractBasis{T,I}}) where {T,I} = I
Base.keytype(b::AbstractBasis) = keytype(typeof(b))

key_type(b) = keytype(b)
# `keytype(::Type{SparseVector{V,K}})` is not defined so it falls
# back to `keytype{::Type{<:AbstractArray})` which returns `Int`.
key_type(::Type{SparseArrays.SparseVector{V,K}}) where {V,K} = K
key_type(v::SparseArrays.SparseVector) = key_type(typeof(v))

"""
ImplicitBasis{T,I}
Implicit bases are not stored in memory and can be potentially infinite.
Expand Down
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ struct AlgebraElement{A,T,V} <: MA.AbstractMutable
end

function _sanity_checks(coeffs, A::AbstractStarAlgebra)
@assert keytype(coeffs) == keytype(basis(A))
@assert key_type(coeffs) == keytype(basis(A))
end
function _sanity_checks(coeffs::AbstractVector, A::AbstractStarAlgebra)
@assert keytype(coeffs) == keytype(basis(A))
@assert key_type(coeffs) == keytype(basis(A))
@assert Base.haslength(basis(A))
@assert length(coeffs) == length(basis(A))
end
Expand Down

0 comments on commit 038f2c0

Please sign in to comment.