Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 6, 2023
1 parent 14b3799 commit eb3fefe
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
11 changes: 0 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,3 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
julia = "1.6"

[extras]
Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Pkg", "Groups", "GroupsCore", "PermutationGroups", "Random", "Test"]
18 changes: 12 additions & 6 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract type AbstractBasis{T,I} end

Base.eltype(::Type{<:AbstractBasis{T}}) where {T} = T
Base.keytype(::Type{<:AbstractBasis{T,I}}) where {T,I} = I
Base.keytype(b::AbstractBasis) = SparseArrays.indtype(typeof(b))
Base.keytype(b::AbstractBasis) = keytype(typeof(b))

"""
ImplicitBasis{T,I}
Expand Down Expand Up @@ -40,15 +40,21 @@ function Basis{I}(basis::AbstractVector) where {I}
end

Base.size(b::Basis) = size(b.basis)
Base.length(b::Basis) = length(b.basis)
Base.keys(b::Basis) = keys(b.basis)
Base.iterate(b::Basis) = iterate(b.basis)
Base.iterate(b::Basis, state) = iterate(b.basis, state)
Base.IndexStyle(::Type{<:Basis{T,I,A}}) where {T,I,A} = Base.IndexStyle(A)

Base.@propagate_inbounds Base.getindex(b::Basis{T,I}, i::I) = 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)

Base.@propagate_inbounds Base.getindex(b::Basis{T,I}, i::I) where {T,I} = b.basis[i]
Base.@propagate_inbounds Base.getindex(b::Basis{T}, g::T) where {T} = b.rbasis[g]

# convenience only:
Base.@propagate_inbounds function Base.getindex(b::Basis, i::Integer)
idx = convert(SparseArrays.indtype(b), i)
Base.@propagate_inbounds function Base.getindex(b::Basis{T,I}, i::Integer) where {T,I<:Integer}
idx = convert(keytype(b), i)
return b[idx]
end
# To break ambiguity
Base.@propagate_inbounds Base.getindex(b::Basis{T,I}, i::I) where {T,I<:Integer} = b.basis[i]
12 changes: 3 additions & 9 deletions src/coefficients.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
implements `Base.keys`, `Base.values`
abstract type AbstractCoefficients{V,K} end
Implements `Base.keys`, `Base.values`.
"""
abstract type AbstractCoefficients{V,K} end

Expand All @@ -8,7 +9,7 @@ struct DiracDelta{V,K} <: AbstractCoefficients{V,K}
element::K
end
DiracDelta(x) = DiracDelta(1, x)
Base.getindex::DiracDelta{V,K}, i::K) =
Base.getindex::DiracDelta{V,K}, i::K) where {V,K} =
ifelse(i == δ.element, δ.value, zero.value))

Base.keys::DiracDelta) =.element,)
Expand All @@ -22,13 +23,6 @@ end
Base.keys(sc::SparseCoefficients) = sc.basis_elements
Base.values(sc::SparseCoefficients) = sc.values

function SparseCoefficients(
values::AbstractVector{V},
basis_elements::AbstractVector{K}
) where {K,V}
return SparseCoefficients{V,K,typeof(values),typeof(basis)}(values, basis_elements)
end

function mul!(
ms::MultiplicativeStructure,
res::SparseCoefficients,
Expand Down
2 changes: 1 addition & 1 deletion src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Base.@propagate_inbounds function Base.getindex(
mstr::LazyMStructure{I},
g::I,
h::I,
)
) where {I}
gh = g * h
gh in basis(mstr) || throw(ProductNotWellDefined(i, j, "$g · $h = $gh"))
return DiracDelta(gh)
Expand Down
6 changes: 3 additions & 3 deletions src/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ struct MTable{I,M<:AbstractMatrix{I},B<:AbstractBasis{I}} <: MultiplicativeStruc
basis::B
end

function MTable(basis::AbstractBasis{V,K}; size::Tuple{Int,Int}) where {K<:Integer}
function MTable(basis::AbstractBasis{V,K}; size::Tuple{Int,Int}) where {V,K<:Integer}
return MTable(zeros(K, size), _star_of(basis, max(size...)), basis)
end

basis(mt::MTable) = mt.basis
Base.size(mt::MTable) = size(mt.table)

Base.@propagate_inbounds __iscomputed(mt::MTable, i, j) = !iszero(mt.table[i, j])
function Base.@propagate_inbounds Base.getindex(mt::MTable, i::Integer, j::Integer)
Base.@propagate_inbounds function Base.getindex(mt::MTable, i::Integer, j::Integer)
i = ifelse(i 0, i, oftype(i, mt.star_of[abs(i)]))
j = ifelse(j 0, j, oftype(j, mt.star_of[abs(j)]))
@boundscheck checkbounds(mt.table, i, j)
Expand All @@ -50,7 +50,7 @@ Base.@propagate_inbounds function __compute_product!(mt::MTable, i::Integer, j::
return mt
end

function complete!(table::AbstractMatrix, basis::AbstractBasis{V,K}) where {K<:Integer}
function complete!(table::AbstractMatrix, basis::AbstractBasis{V,K}) where {V,K<:Integer}
Base.require_one_based_indexing(table)
Threads.@threads for j in axes(table, 2)
y = basis[j]
Expand Down
7 changes: 7 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StarAlgebras = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2 changes: 1 addition & 1 deletion test/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end
@testset "MTable" begin
b = StarAlgebras.Basis{UInt16}(words([:a, :b, :c, :d], radius=4))
k = findfirst(w -> length(w) == 3, b) - 1
mstr = StarAlgebras.MTable(b, table_size=(k, k))
mstr = StarAlgebras.MTable(b, size=(k, k))

@test_throws String StarAlgebras.basis(mstr)

Expand Down
2 changes: 1 addition & 1 deletion test/sum_of_squares.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Groups

b = StarAlgebras.Basis{UInt32}(E_R)

mstr = StarAlgebras.MTable(b, table_size=(sizes[RADIUS], sizes[RADIUS]))
mstr = StarAlgebras.MTable(b, size=(sizes[RADIUS], sizes[RADIUS]))

RG = StarAlgebra(F, b, mstr)

Expand Down

0 comments on commit eb3fefe

Please sign in to comment.