mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
more threading using ThreadsX;
rename generate_balls → wlmetric_ball
This commit is contained in:
parent
8923912367
commit
837312d020
@ -6,6 +6,7 @@ version = "0.4.2"
|
|||||||
[deps]
|
[deps]
|
||||||
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
|
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
|
||||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||||
|
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
|
||||||
|
|
||||||
[compat]
|
[compat]
|
||||||
AbstractAlgebra = "^0.9.0"
|
AbstractAlgebra = "^0.9.0"
|
||||||
|
@ -258,7 +258,8 @@ function (==)(g::Automorphism{N}, h::Automorphism{N}) where N
|
|||||||
# cheap
|
# cheap
|
||||||
# if hashes differ, images must have differed as well
|
# if hashes differ, images must have differed as well
|
||||||
hash(g) != hash(h) && return false
|
hash(g) != hash(h) && return false
|
||||||
# equal elements, or possibly a hash conflict
|
|
||||||
|
# hashes equal, hence either equal elements, or a hash conflict
|
||||||
begin
|
begin
|
||||||
if !img_computed
|
if !img_computed
|
||||||
img_task = Threads.@spawn img = compute_images(g)
|
img_task = Threads.@spawn img = compute_images(g)
|
||||||
@ -271,6 +272,8 @@ function (==)(g::Automorphism{N}, h::Automorphism{N}) where N
|
|||||||
!img_computed && fetch(img_task)
|
!img_computed && fetch(img_task)
|
||||||
!imh_computed && fetch(imh_task)
|
!imh_computed && fetch(imh_task)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
img != imh && @warn "hash collision in == :" g h
|
||||||
return img == imh
|
return img == imh
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,24 +64,59 @@ Return vector of generators of `G`, as its elements.
|
|||||||
AbstractAlgebra.gens(G::AbstractFPGroup) = G.(G.gens)
|
AbstractAlgebra.gens(G::AbstractFPGroup) = G.(G.gens)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
metric_ball(S::AbstractVector{<:GroupElem}
|
wlmetric_ball(S::AbstractVector{<:GroupElem}
|
||||||
[, center=one(first(S)); radius=2, op=*])
|
[, center=one(first(S)); radius=2, op=*])
|
||||||
Compute metric ball as a list of elements of non-decreasing length, given the
|
Compute metric ball as a list of elements of non-decreasing length, given the
|
||||||
word-length metric on the group generated by `S`. The ball is centered at `center`
|
word-length metric on the group generated by `S`. The ball is centered at `center`
|
||||||
(by default: the identity element). `radius` and `op` keywords specify the
|
(by default: the identity element). `radius` and `op` keywords specify the
|
||||||
radius and multiplication operation to be used.
|
radius and multiplication operation to be used.
|
||||||
"""
|
"""
|
||||||
function generate_balls(S::AbstractVector{T}, center::T=one(first(S));
|
|
||||||
radius=2, op=*) where T<:Union{GroupElem, NCRingElem}
|
function wlmetric_ball_serial(S::AbstractVector{T}; radius=2, op=*) where T<:Union{GroupElem, NCRingElem}
|
||||||
sizes = Int[]
|
old = unique!([one(first(S)), S...])
|
||||||
B = [one(first(S))]
|
sizes = [1, length(old)]
|
||||||
for i in 1:radius
|
for i in 2:radius
|
||||||
BB = [op(i,j) for (i,j) in Base.product(B,S)]
|
new = collect(op(i,j) for (i,j) in Base.product(@view(old[sizes[end-1]:end]), S))
|
||||||
B = unique([B; vec(BB)])
|
append!(old, new)
|
||||||
push!(sizes, length(B))
|
resize!(new, 0)
|
||||||
|
old = unique!(old)
|
||||||
|
push!(sizes, length(old))
|
||||||
end
|
end
|
||||||
isone(center) && return B, sizes
|
return old, sizes[2:end]
|
||||||
return c.*B, sizes
|
end
|
||||||
|
|
||||||
|
function wlmetric_ball_thr(S::AbstractVector{T}; radius=2, op=*) where T<:Union{GroupElem, NCRingElem}
|
||||||
|
old = unique!([one(first(S)), S...])
|
||||||
|
sizes = [1, length(old)]
|
||||||
|
for r in 2:radius
|
||||||
|
begin
|
||||||
|
new = ThreadsX.collect(op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S)
|
||||||
|
ThreadsX.foreach(hash, new)
|
||||||
|
end
|
||||||
|
append!(old, new)
|
||||||
|
resize!(new, 0)
|
||||||
|
old = ThreadsX.unique(old)
|
||||||
|
push!(sizes, length(old))
|
||||||
|
end
|
||||||
|
return old, sizes[2:end]
|
||||||
|
end
|
||||||
|
|
||||||
|
function wlmetric_ball_serial(S::AbstractVector{T}, center::T; radius=2, op=*) where T<:Union{GroupElem, NCRingElem}
|
||||||
|
E, sizes = metric_ball_serial(S, radius=radius, op=op)
|
||||||
|
isone(center) && return E, sizes
|
||||||
|
return c.*E, sizes
|
||||||
|
end
|
||||||
|
|
||||||
|
function wlmetric_ball_thr(S::AbstractVector{T}, center::T, radius=2, op=*) where T<:Union{GroupElem, NCRingElem}
|
||||||
|
E, sizes = metric_ball_thr(S, radius=radius, op=op)
|
||||||
|
isone(center) && return E, sizes
|
||||||
|
return c.*E, sizes
|
||||||
|
end
|
||||||
|
|
||||||
|
function wlmetric_ball(S::AbstractVector{T}, center::T=one(first(S);
|
||||||
|
radius=2, op=*, threading=true)
|
||||||
|
threading && return wlmetric_ball_thr(S, center, radius=radius, op=op)
|
||||||
|
return return wlmetric_ball_serial(S, center, radius=radius, op=op)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -13,7 +13,7 @@ using LinearAlgebra
|
|||||||
s = one(M); s[1,3] = 2; s[3,2] = -1;
|
s = one(M); s[1,3] = 2; s[3,2] = -1;
|
||||||
|
|
||||||
S = [w,r,s]; S = unique([S; inv.(S)]);
|
S = [w,r,s]; S = unique([S; inv.(S)]);
|
||||||
_, sizes = Groups.generate_balls(S, radius=4);
|
_, sizes = Groups.wlmetric_ball(S, radius=4);
|
||||||
@test sizes == [7, 33, 141, 561]
|
@test sizes == [7, 33, 141, 561]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user