mirror of
https://github.com/kalmarek/GroupRings.jl.git
synced 2024-10-19 08:50:36 +02:00
implement minimal Basis struct
This commit is contained in:
parent
96d4b8f009
commit
e103059b23
@ -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
26
src/bases.jl
Normal 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))
|
Loading…
Reference in New Issue
Block a user