implement minimal Basis struct

This commit is contained in:
Marek Kaluba 2021-06-19 00:45:15 +02:00
parent 96d4b8f009
commit e103059b23
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 31 additions and 0 deletions

View File

@ -563,4 +563,9 @@ function initializepm!(RG::GroupRing; fill::Bool=false)
return RG
end
module New
include("bases.jl")
end
end # of module GroupRings

26
src/bases.jl Normal file
View File

@ -0,0 +1,26 @@
abstract type AbstractBasis{T,I} <: AbstractVector{T} end
struct Basis{T,I,A<:AbstractVector{T}} <: AbstractBasis{T,I}
basis::A
rbasis::Dict{T,I}
end
function Basis{I}(basis::AbstractVector) where I
length(basis) <= typemax(I) ||
throw("index type $I is to small for basis of length $(length(basis))")
@assert !(eltype(basis) <: Integer)
return Basis(basis, Dict(b => I(idx) for (idx, b) in pairs(basis)))
end
Base.size(b::Basis) = size(b.basis)
Base.IndexStyle(::Type{<:Basis{T,I,A}}) where {T,I,A} = Base.IndexStyle(A)
Base.@propagate_inbounds Base.getindex(b::Basis, i::Integer) = b.basis[i]
Base.@propagate_inbounds Base.getindex(b::Basis{T}, g::T) where {T} = b.rbasis[g]
Base.in(g, b::Basis) = haskey(b.rbasis, g)
## are these really that useful?
SparseArrays.indtype(::Type{<:Basis{T,I}}) where {T,I} = I
SparseArrays.indtype(b::Basis) = SparseArrays.indtype(typeof(b))