Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed May 15, 2024
1 parent fa7d62c commit cfaca65
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 38 deletions.
4 changes: 1 addition & 3 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -108,5 +108,3 @@ function MA.operate_to!(
MA.operate_to!(coeffs(res), mstr, coeffs(X), coeffs(Y))
return res
end


6 changes: 1 addition & 5 deletions src/bases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/bases_dirac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/bases_fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ Base.@propagate_inbounds Base.getindex(
b::FixedBasis{T,I},
i::I,
) where {T,I<:Integer} = b.elts[i]

8 changes: 5 additions & 3 deletions src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 8 in src/mstructures.jl

View check run for this annotation

Codecov / codecov/patch

src/mstructures.jl#L7-L8

Added lines #L7 - L8 were not covered by tests
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, ".")

Check warning on line 16 in src/mstructures.jl

View check run for this annotation

Codecov / codecov/patch

src/mstructures.jl#L16

Added line #L16 was not covered by tests
end

"""
Expand Down Expand Up @@ -86,4 +89,3 @@ function (mstr::DiracMStructure)(x::T, y::T) where {T}
xy = mstr.op(x, y)
return SparseCoefficients((xy,), (1,))
end

6 changes: 1 addition & 5 deletions src/sparse_coeffs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 17 additions & 11 deletions test/mtables.jl
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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]]
Expand Down
1 change: 0 additions & 1 deletion test/perm_grp_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ include("test_example_words.jl")
end
include("sum_of_squares.jl")
end

4 changes: 3 additions & 1 deletion test/test_example_words.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down

0 comments on commit cfaca65

Please sign in to comment.