From eb3fefe9075cdbe979c6989cc7bb565eb2dafe7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 6 Dec 2023 11:19:59 +0100 Subject: [PATCH] Fixes --- Project.toml | 11 ----------- src/bases.jl | 18 ++++++++++++------ src/coefficients.jl | 12 +++--------- src/mstructures.jl | 2 +- src/mtables.jl | 6 +++--- test/Project.toml | 7 +++++++ test/mtables.jl | 2 +- test/sum_of_squares.jl | 2 +- 8 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 test/Project.toml diff --git a/Project.toml b/Project.toml index 90de204..c01c637 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/src/bases.jl b/src/bases.jl index cd893b1..80785e1 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -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} @@ -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] diff --git a/src/coefficients.jl b/src/coefficients.jl index 92183eb..ae1f5f8 100644 --- a/src/coefficients.jl +++ b/src/coefficients.jl @@ -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 @@ -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,) @@ -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, diff --git a/src/mstructures.jl b/src/mstructures.jl index d7800d4..9b90729 100644 --- a/src/mstructures.jl +++ b/src/mstructures.jl @@ -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) diff --git a/src/mtables.jl b/src/mtables.jl index a391672..37fbc52 100644 --- a/src/mtables.jl +++ b/src/mtables.jl @@ -22,7 +22,7 @@ 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 @@ -30,7 +30,7 @@ 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) @@ -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] diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..b90c1e4 --- /dev/null +++ b/test/Project.toml @@ -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" diff --git a/test/mtables.jl b/test/mtables.jl index 97cc111..3d56b77 100644 --- a/test/mtables.jl +++ b/test/mtables.jl @@ -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) diff --git a/test/sum_of_squares.jl b/test/sum_of_squares.jl index 80ef114..ba19f67 100644 --- a/test/sum_of_squares.jl +++ b/test/sum_of_squares.jl @@ -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)