Skip to content

Commit

Permalink
Merge pull request #22 from JuliaAlgebra/mk/fix/promote_type
Browse files Browse the repository at this point in the history
Fix: replace `promote_type` with `Base._return_type`
  • Loading branch information
Marek Kaluba authored Feb 14, 2024
2 parents cb6d7f6 + a1325f8 commit f1b98a0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
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 <kalmar@mailbox.org>"]
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

4 comments on commit f1b98a0

@kalmarek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.

@kalmarek
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/100908

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" f1b98a0497e248e1e64a6b0c713447a8f572f850
git push origin v0.2.1

Please sign in to comment.