diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 91b37ee..bf097a2 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -5,7 +5,7 @@ end function _preallocate_output(X::AlgebraElement, Y::AlgebraElement, op) T = Base._return_type(op, Tuple{eltype(X),eltype(Y)}) - if coeffs(Y) isa DenseArray + if coeffs(Y) isa DenseArray # what a hack :) return similar(Y, T) end return similar(X, T) @@ -108,5 +108,3 @@ function MA.operate_to!( MA.operate_to!(coeffs(res), mstr, coeffs(X), coeffs(Y)) return res end - - diff --git a/src/bases.jl b/src/bases.jl index 50cd807..afd5951 100644 --- a/src/bases.jl +++ b/src/bases.jl @@ -62,11 +62,7 @@ end Translate coefficients `cfs` in `source::AbstractBasis` to basis `target::AbstractBasis`. """ -function coeffs( - cfs, - source::AbstractBasis, - target::AbstractBasis, -) +function coeffs(cfs, source::AbstractBasis, target::AbstractBasis) source === target && return cfs source == target && return cfs res = zero_coeffs(valtype(cfs), target) diff --git a/src/bases_dirac.jl b/src/bases_dirac.jl index d04b2c5..e4135ef 100644 --- a/src/bases_dirac.jl +++ b/src/bases_dirac.jl @@ -2,7 +2,7 @@ mutable struct DiracBasis{T,I,S,M<:DiracMStructure} <: ImplicitBasis{T,I} object::S # any iterable moperation::M - function DiracBasis{I}(itr, operation=*) where {I} + function DiracBasis{I}(itr, operation = *) where {I} @assert !isempty(itr) mstr = DiracMStructure(operation) return new{eltype(itr),I,typeof(itr),typeof(mstr)}(itr, mstr) @@ -12,8 +12,9 @@ end object(db::DiracBasis) = db.object mstructure(db::DiracBasis{T}) where {T} = db.moperation - -Base.IteratorSize(::Type{<:DiracBasis{T,I,S}}) where {T,I,S} = Base.IteratorSize(S) +function Base.IteratorSize(::Type{<:DiracBasis{T,I,S}}) where {T,I,S} + return Base.IteratorSize(S) +end function Base.length(db::DiracBasis) @assert Base.haslength(object(db)) return length(object(db)) diff --git a/src/bases_fixed.jl b/src/bases_fixed.jl index d37e059..ce302b7 100644 --- a/src/bases_fixed.jl +++ b/src/bases_fixed.jl @@ -39,4 +39,3 @@ Base.@propagate_inbounds Base.getindex( b::FixedBasis{T,I}, i::I, ) where {T,I<:Integer} = b.elts[i] - diff --git a/src/mstructures.jl b/src/mstructures.jl index 686cca7..8c288f4 100644 --- a/src/mstructures.jl +++ b/src/mstructures.jl @@ -5,12 +5,15 @@ struct ProductNotWellDefined <: Exception end function Base.showerror(io::IO, ex::ProductNotWellDefined) - print(io, "Product of elements $(ex.i) and $(ex.j) is not defined on the basis") + print( + io, + "Product of elements $(ex.i) and $(ex.j) is not defined on the basis", + ) print(io, " or the multiplicative structure could not be completed") if isdefined(ex, :msg) print(io, ": $(ex.msg)") end - print(io, ".") + return print(io, ".") end """ @@ -86,4 +89,3 @@ function (mstr::DiracMStructure)(x::T, y::T) where {T} xy = mstr.op(x, y) return SparseCoefficients((xy,), (1,)) end - diff --git a/src/sparse_coeffs.jl b/src/sparse_coeffs.jl index 0808299..4d8e031 100644 --- a/src/sparse_coeffs.jl +++ b/src/sparse_coeffs.jl @@ -68,11 +68,7 @@ function MA.operate!(::typeof(canonical), res::SparseCoefficients) return MA.operate!(canonical, res, comparable(key_type(res))) end -function MA.operate!( - ::typeof(canonical), - res::SparseCoefficients, - cmp, -) +function MA.operate!(::typeof(canonical), res::SparseCoefficients, cmp) sorted = issorted(res.basis_elements; lt = cmp) distinct = allunique(res.basis_elements) if sorted && distinct && !any(iszero, res.values) diff --git a/src/types.jl b/src/types.jl index ae4d827..11a37d5 100644 --- a/src/types.jl +++ b/src/types.jl @@ -11,8 +11,7 @@ function _sanity_checks(coeffs::AbstractVector, A::AbstractStarAlgebra) end # concrete implementation -struct StarAlgebra{O,T,B<:AbstractBasis{T}} <: - AbstractStarAlgebra{O,T} +struct StarAlgebra{O,T,B<:AbstractBasis{T}} <: AbstractStarAlgebra{O,T} object::O basis::B @@ -47,7 +46,7 @@ end function AlgebraElement( coeffs::SparseCoefficients{T}, - A::AbstractStarAlgebra{O,T} + A::AbstractStarAlgebra{O,T}, ) where {O,T} return AlgebraElement{typeof(A),valtype(coeffs),typeof(coeffs)}(coeffs, A) end @@ -103,7 +102,9 @@ end (A::AbstractStarAlgebra)(x::Number) = x * one(A) -Base.similar(X::AlgebraElement, T=eltype(X)) = AlgebraElement(similar(coeffs(X), T), parent(X)) +function Base.similar(X::AlgebraElement, T = eltype(X)) + return AlgebraElement(similar(coeffs(X), T), parent(X)) +end function AlgebraElement{T}(X::AlgebraElement) where {T} v = coeffs(X) diff --git a/test/mtables.jl b/test/mtables.jl index 3d56b77..7c38f6a 100644 --- a/test/mtables.jl +++ b/test/mtables.jl @@ -1,5 +1,5 @@ @testset "TrivialMStructure" begin - b = StarAlgebras.Basis{UInt8}(words([:a, :b, :c], radius=4)) + b = StarAlgebras.Basis{UInt8}(words([:a, :b, :c]; radius = 4)) mstr = StarAlgebras.TrivialMStructure(b) @@ -36,9 +36,9 @@ end @testset "MTable" begin - b = StarAlgebras.Basis{UInt16}(words([:a, :b, :c, :d], radius=4)) + b = StarAlgebras.Basis{UInt16}(words([:a, :b, :c, :d]; radius = 4)) k = findfirst(w -> length(w) == 3, b) - 1 - mstr = StarAlgebras.MTable(b, size=(k, k)) + mstr = StarAlgebras.MTable(b; size = (k, k)) @test_throws String StarAlgebras.basis(mstr) @@ -47,25 +47,31 @@ end mstr[i, j] == b[b[i]*b[j]] for i in axes(mstr, 1) for j in axes(mstr, 2) ) @test all( - mstr[-i, j] == b[star(b[i])*b[j]] for i in axes(mstr, 1) for j in axes(mstr, 2) + mstr[-i, j] == b[star(b[i])*b[j]] for i in axes(mstr, 1) for + j in axes(mstr, 2) ) @test all( - mstr[i, -j] == b[b[i]*star(b[j])] for i in axes(mstr, 1) for j in axes(mstr, 2) + mstr[i, -j] == b[b[i]*star(b[j])] for i in axes(mstr, 1) for + j in axes(mstr, 2) ) @test all( - mstr[-i, -j] == b[star(b[i])*star(b[j])] for i in axes(mstr, 1) for j in axes(mstr, 2) + mstr[-i, -j] == b[star(b[i])*star(b[j])] for i in axes(mstr, 1) for + j in axes(mstr, 2) ) end @testset "CachedMTable" begin - b = StarAlgebras.Basis{UInt8}(words([:a, :b, :c], radius=4)) + b = StarAlgebras.Basis{UInt8}(words([:a, :b, :c]; radius = 4)) k = findfirst(w -> length(w) == 3, b) - 1 - mstr = StarAlgebras.CachedMTable(b, table_size=(k, k)) + mstr = StarAlgebras.CachedMTable(b; table_size = (k, k)) @test mstr isa StarAlgebras.CachedMTable{UInt8,Word{Symbol}} @test mstr.table.table isa Matrix{UInt8} - @test_throws StarAlgebras.ProductNotDefined StarAlgebras._check(mstr.table.table, StarAlgebras.basis(mstr)) + @test_throws StarAlgebras.ProductNotDefined StarAlgebras._check( + mstr.table.table, + StarAlgebras.basis(mstr), + ) StarAlgebras.complete!(mstr) @test all(!iszero, mstr.table) @@ -78,7 +84,7 @@ end @test mstr == mstr_sparse - mstr = StarAlgebras.CachedMTable(b, table_size=(k, k)) + mstr = StarAlgebras.CachedMTable(b; table_size = (k, k)) @test all(iszero, mstr.table.table) StarAlgebras.cache!(mstr, 1, 2) @@ -100,7 +106,7 @@ end @test_throws StarAlgebras.ProductNotDefined mstr[k+1, k] - mstr = StarAlgebras.CachedMTable(b, table_size=(k, k)) + mstr = StarAlgebras.CachedMTable(b; table_size = (k, k)) @test all(iszero, mstr.table.table) @test mstr[-1, 2] == 2 @test mstr[-2, 3] == b[star(b[2])*b[3]] diff --git a/test/perm_grp_algebra.jl b/test/perm_grp_algebra.jl index 9de784b..950431f 100644 --- a/test/perm_grp_algebra.jl +++ b/test/perm_grp_algebra.jl @@ -31,7 +31,6 @@ @test x * z == xz @testset "Augmented basis" begin - ad = SA.AugmentedBasis(db) @test SA.mstructure(ad) == SA.AugmentedMStructure(SA.mstructure(db)) @test ad[SA.Augmented(h)] isa SA.Augmented diff --git a/test/runtests.jl b/test/runtests.jl index 89228dc..8e9866c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,4 +43,3 @@ include("test_example_words.jl") end include("sum_of_squares.jl") end - diff --git a/test/test_example_words.jl b/test/test_example_words.jl index 83ce257..5093366 100644 --- a/test/test_example_words.jl +++ b/test/test_example_words.jl @@ -17,7 +17,9 @@ function Base.show(io::IO, w::Word) end end -Base.:(==)(w::Word, v::Word) = w.alphabet == v.alphabet && w.letters == v.letters +function Base.:(==)(w::Word, v::Word) + return w.alphabet == v.alphabet && w.letters == v.letters +end Base.hash(w::Word, h::UInt) = hash(w.alphabet, hash(w.letters, hash(Word, h))) Base.one(w::Word) = Word(w.alphabet, Int[])