Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: replace promote_type with Base._return_type #22

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name = "StarAlgebras"
uuid = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1"
authors = ["Marek Kaluba <[email protected]>"]
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]
Expand Down
8 changes: 6 additions & 2 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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, …}")
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
Expand Down
15 changes: 2 additions & 13 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
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))
l = length(b)
RG = StarAlgebra(G, b, (l, l))

@test 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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions test/sum_of_squares.jl
Original file line number Diff line number Diff line change
@@ -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))]

Expand Down
7 changes: 1 addition & 6 deletions test/test_example_words.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading