format and bump to 0.5.0

This commit is contained in:
kalmarek 2020-10-09 13:55:11 +02:00
parent 837312d020
commit 2d66b4f56e
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 53 additions and 22 deletions

View File

@ -1,7 +1,7 @@
name = "Groups" name = "Groups"
uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>"] authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
version = "0.4.2" version = "0.5.0"
[deps] [deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
@ -9,7 +9,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d" ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
[compat] [compat]
AbstractAlgebra = "^0.9.0" AbstractAlgebra = "^0.10.0"
[extras] [extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

View File

@ -11,6 +11,7 @@ import Base: findfirst, findnext, findlast, findprev, replace
import Base: deepcopy_internal import Base: deepcopy_internal
using LinearAlgebra using LinearAlgebra
using ThreadsX
export gens, FreeGroup, Aut, SAut export gens, FreeGroup, Aut, SAut
@ -46,9 +47,9 @@ end
function Base.show(io::IO, s::T) where {T<:GSymbol} function Base.show(io::IO, s::T) where {T<:GSymbol}
if s.pow == 1 if s.pow == 1
print(io, string(s.id)) print(io, string(s.id))
else else
print(io, "$(s.id)^$(s.pow)") print(io, "$(s.id)^$(s.pow)")
end end
end end
@ -72,11 +73,18 @@ word-length metric on the group generated by `S`. The ball is centered at `cente
radius and multiplication operation to be used. radius and multiplication operation to be used.
""" """
function wlmetric_ball_serial(S::AbstractVector{T}; radius=2, op=*) where T<:Union{GroupElem, NCRingElem} function wlmetric_ball_serial(
S::AbstractVector{T};
radius = 2,
op = *,
) where {T<:Union{GroupElem,NCRingElem}}
old = unique!([one(first(S)), S...]) old = unique!([one(first(S)), S...])
sizes = [1, length(old)] sizes = [1, length(old)]
for i in 2:radius for i = 2:radius
new = collect(op(i,j) for (i,j) in Base.product(@view(old[sizes[end-1]:end]), S)) new = collect(
op(i, j)
for (i, j) in Base.product(@view(old[sizes[end-1]:end]), S)
)
append!(old, new) append!(old, new)
resize!(new, 0) resize!(new, 0)
old = unique!(old) old = unique!(old)
@ -85,12 +93,18 @@ function wlmetric_ball_serial(S::AbstractVector{T}; radius=2, op=*) where T<:Uni
return old, sizes[2:end] return old, sizes[2:end]
end end
function wlmetric_ball_thr(S::AbstractVector{T}; radius=2, op=*) where T<:Union{GroupElem, NCRingElem} function wlmetric_ball_thr(
S::AbstractVector{T};
radius = 2,
op = *,
) where {T<:Union{GroupElem,NCRingElem}}
old = unique!([one(first(S)), S...]) old = unique!([one(first(S)), S...])
sizes = [1, length(old)] sizes = [1, length(old)]
for r in 2:radius for r = 2:radius
begin begin
new = ThreadsX.collect(op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S) new = ThreadsX.collect(
op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S
)
ThreadsX.foreach(hash, new) ThreadsX.foreach(hash, new)
end end
append!(old, new) append!(old, new)
@ -101,22 +115,37 @@ function wlmetric_ball_thr(S::AbstractVector{T}; radius=2, op=*) where T<:Union{
return old, sizes[2:end] return old, sizes[2:end]
end end
function wlmetric_ball_serial(S::AbstractVector{T}, center::T; radius=2, op=*) where T<:Union{GroupElem, NCRingElem} function wlmetric_ball_serial(
E, sizes = metric_ball_serial(S, radius=radius, op=op) S::AbstractVector{T},
center::T;
radius = 2,
op = *,
) where {T<:Union{GroupElem,NCRingElem}}
E, sizes = wlmetric_ball_serial(S, radius = radius, op = op)
isone(center) && return E, sizes isone(center) && return E, sizes
return c.*E, sizes return c .* E, sizes
end end
function wlmetric_ball_thr(S::AbstractVector{T}, center::T, radius=2, op=*) where T<:Union{GroupElem, NCRingElem} function wlmetric_ball_thr(
E, sizes = metric_ball_thr(S, radius=radius, op=op) S::AbstractVector{T},
center::T;
radius = 2,
op = *,
) where {T<:Union{GroupElem,NCRingElem}}
E, sizes = wlmetric_ball_thr(S, radius = radius, op = op)
isone(center) && return E, sizes isone(center) && return E, sizes
return c.*E, sizes return c .* E, sizes
end end
function wlmetric_ball(S::AbstractVector{T}, center::T=one(first(S); function wlmetric_ball(
radius=2, op=*, threading=true) S::AbstractVector{T},
threading && return wlmetric_ball_thr(S, center, radius=radius, op=op) center::T = one(first(S));
return return wlmetric_ball_serial(S, center, radius=radius, op=op) radius = 2,
op = *,
threading = true,
) where {T<:Union{GroupElem,NCRingElem}}
threading && return wlmetric_ball_thr(S, center, radius = radius, op = op)
return return wlmetric_ball_serial(S, center, radius = radius, op = op)
end end
""" """
@ -127,9 +156,11 @@ Evaluate homomorphism `homomorphism` on a group word (element) `w`.
where `hom(;kwargs...)` returns the value at the identity element. where `hom(;kwargs...)` returns the value at the identity element.
""" """
function image(w::GWord, hom; kwargs...) function image(w::GWord, hom; kwargs...)
return reduce(*, return reduce(
*,
(hom(s; kwargs...) for s in syllables(w)), (hom(s; kwargs...) for s in syllables(w)),
init = hom(;kwargs...)) init = hom(; kwargs...),
)
end end
end # of module Groups end # of module Groups