From 038f2c09407ce86a7010c3a4cb035d8aff04058e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 16 Mar 2024 08:07:35 +0100 Subject: [PATCH] Add key_type --- src/bases.jl | 6 ++++++ src/types.jl | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bases.jl b/src/bases.jl index e9d738f..2cd8fb0 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -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. diff --git a/src/types.jl b/src/types.jl index ca6d777..0a599e6 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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