From 42905536a2b7948d617af8044a694f57e3d6b065 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 11:14:27 +0100 Subject: [PATCH 1/7] use Base._return_type instead of promote_type --- src/arithmetic.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 376638a..40c1450 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -1,6 +1,10 @@ # module structure: -Base.:*(a::Number, X::AlgebraElement) = - mul!(similar(X, promote_type(eltype(X), typeof(a))), X, a) + +function Base.:*(a::Number, X::AlgebraElement) + T = Base._return_type(*, Tuple{eltype(X),typeof(a)}) + return mul!(similar(X, T), X, a) +end + Base.:*(X::AlgebraElement, a::Number) = a * X Base.:(/)(X::AlgebraElement, a::Number) = inv(a) * X From 35d74876cd9f91d3fe61a9f81d3ea8bd8085ea24 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 11:14:58 +0100 Subject: [PATCH 2/7] remove the show method for types --- src/show.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/show.jl b/src/show.jl index 1ae427e..21d7515 100644 --- a/src/show.jl +++ b/src/show.jl @@ -1,7 +1,4 @@ -Base.show(io::IO, A::AbstractStarAlgebra) = - print(io, "*-algebra of $(object(A))") -Base.show(io::IO, ::Type{<:StarAlgebra{O,T}}) where {O,T} = - print(io, "StarAlgebra{$O, $T, …}") +Base.show(io::IO, A::AbstractStarAlgebra) = print(io, "*-algebra of", object(A)) __prints_with_minus(::Any) = false __prints_with_minus(x::Real) = x < 0 From 990c511acf069eba5cc2f367e09a08a12dd486a3 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 11:15:52 +0100 Subject: [PATCH 3/7] reorganize workarounds in tests a bit --- test/arithmetic.jl | 13 +------------ test/runtests.jl | 11 +++++++++++ test/sum_of_squares.jl | 3 --- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test/arithmetic.jl b/test/arithmetic.jl index 24fe89e..0ce5294 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -1,14 +1,3 @@ -using GroupsCore -using PermutationGroups -import Random - -StarAlgebras.star(g::PermutationGroups.GroupElement) = inv(g) - -using SparseArrays -if VERSION < v"1.9" - Base.sum(v::SparseVector) = sum(nonzeros(v)) -end - @testset "Arithmetic" begin G = PermGroup(perm"(1,2,3)", perm"(1,2)") b = StarAlgebras.Basis{UInt8}(collect(G)) @@ -114,7 +103,7 @@ end @test supp(z) == StarAlgebras.basis(parent(z)) @test supp(RG(1) + RG(g)) == [one(G), g] - @test supp(a) == [one(G), h, g] + @test supp(a) == [one(G), g, h] @testset "Projections in star algebras" begin b = StarAlgebras.basis(RG) diff --git a/test/runtests.jl b/test/runtests.jl index 01cb81c..4781da1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,7 +8,18 @@ include("test_example_words.jl") @testset "StarAlgebras" begin include("mtables.jl") include("constructors.jl") + + using GroupsCore + StarAlgebras.star(g::GroupsCore.GroupElement) = inv(g) + + using SparseArrays + if VERSION < v"1.9" + Base.sum(v::SparseVector) = sum(nonzeros(v)) + end + + using PermutationGroups include("arithmetic.jl") + using Groups include("sum_of_squares.jl") end diff --git a/test/sum_of_squares.jl b/test/sum_of_squares.jl index 80ef114..bfba90e 100644 --- a/test/sum_of_squares.jl +++ b/test/sum_of_squares.jl @@ -1,7 +1,4 @@ -using Groups - @testset "sum of squares in FreeGroup *-algebra" begin - StarAlgebras.star(g::Groups.GroupElement) = inv(g) F = Groups.FreeGroup(4) S = [Groups.gens(F); inv.(Groups.gens(F))] From 40ff9db1eb02b16f257d1ce0c6aae9581648a7fc Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 11:16:12 +0100 Subject: [PATCH 4/7] mark printing test as broken --- test/arithmetic.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/arithmetic.jl b/test/arithmetic.jl index 0ce5294..f57ec5a 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -4,7 +4,7 @@ l = length(b) RG = StarAlgebra(G, b, (l, l)) - @test contains(sprint(show, RG), "*-algebra of Permutation group") + @test_broken contains(sprint(show, RG), "*-algebra of Permutation group") @testset "Module structure" begin a = AlgebraElement(ones(Int, order(G)), RG) From 71a10dfc15b68aa761cb1b98efaf7648c8fa7be8 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 11:19:37 +0100 Subject: [PATCH 5/7] add compats and bump to 0.2.1 --- Project.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 90de204..1002b26 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,17 @@ name = "StarAlgebras" uuid = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1" authors = ["Marek Kaluba "] -version = "0.2.0" +version = "0.2.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] +Groups = "0.8" +GroupsCore = "0.5" +PermutationGroups = "0.6" +SparseArrays = "1" julia = "1.6" [extras] From a5f46e8946505b1a72470980e9c5fda2241084f6 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 14:17:27 +0100 Subject: [PATCH 6/7] reenable the test for sprint-ing --- src/show.jl | 5 ++++- test/arithmetic.jl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/show.jl b/src/show.jl index 21d7515..82301ed 100644 --- a/src/show.jl +++ b/src/show.jl @@ -1,4 +1,7 @@ -Base.show(io::IO, A::AbstractStarAlgebra) = print(io, "*-algebra of", object(A)) +function Base.show(io::IO, A::AbstractStarAlgebra) + ioc = IOContext(io, :limit => true, :compact => true) + return print(ioc, "*-algebra of ", object(A)) +end __prints_with_minus(::Any) = false __prints_with_minus(x::Real) = x < 0 diff --git a/test/arithmetic.jl b/test/arithmetic.jl index f57ec5a..19b71e9 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -4,7 +4,7 @@ l = length(b) RG = StarAlgebra(G, b, (l, l)) - @test_broken contains(sprint(show, RG), "*-algebra of Permutation group") + @test contains(sprint(show, RG), "*-algebra of") @testset "Module structure" begin a = AlgebraElement(ones(Int, order(G)), RG) From a1325f830b2c3004c7fe6249efa2e06f875dbf75 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 14 Feb 2024 14:20:31 +0100 Subject: [PATCH 7/7] simplify star(w::Word) in tests --- test/test_example_words.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/test_example_words.jl b/test/test_example_words.jl index fc327ce..276a20e 100644 --- a/test/test_example_words.jl +++ b/test/test_example_words.jl @@ -29,18 +29,13 @@ function Base.:*(w::Word, z::Word) end function StarAlgebras.star(w::Word) - newletters = similar(w.letters) - # star(:a) = :b # star(:b) = :a # star(:c) = :c star_d = Dict(1 => 2, 2 => 1) - for (i, l) in enumerate(Iterators.reverse(w.letters)) - k = haskey(star_d, l) ? star_d[l] : l - newletters[i] = k - end + newletters = [get(star_d, l, l) for l in Iterators.reverse(w.letters)] return Word(w.alphabet, newletters) end