1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-26 02:20:30 +01:00

generalize signatures of wlmetric_ball

This commit is contained in:
Marek Kaluba 2021-05-09 19:37:26 +02:00
parent 217be597c3
commit 472e78af27
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15

View File

@ -71,14 +71,11 @@ word-length metric on the group generated by `S`. The ball is centered at `cente
(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 wlmetric_ball_serial( function wlmetric_ball_serial(S::AbstractVector{T}; radius = 2, op = *) where {T}
S::AbstractVector{T}; @assert radius > 0
radius = 2,
op = *,
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
old = unique!([one(first(S)), S...]) old = unique!([one(first(S)), S...])
sizes = [1, length(old)] sizes = [1, length(old)]
for i = 2:radius for i in 2:radius
new = collect(op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S) new = collect(op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S)
append!(old, new) append!(old, new)
resize!(new, 0) resize!(new, 0)
@ -88,18 +85,14 @@ function wlmetric_ball_serial(
return old, sizes[2:end] return old, sizes[2:end]
end end
function wlmetric_ball_thr( function wlmetric_ball_thr(S::AbstractVector{T}; radius = 2, op = *) where {T}
S::AbstractVector{T}; @assert radius > 0
radius = 2,
op = *,
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
old = unique!([one(first(S)), S...]) old = unique!([one(first(S)), S...])
sizes = [1, length(old)] sizes = [1, length(old)]
for r = 2:radius for r in 2:radius
begin begin
new = ThreadsX.collect( new =
op(o, s) for o in @view(old[sizes[end-1]:end]) for s in S 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)
@ -110,23 +103,13 @@ function wlmetric_ball_thr(
return old, sizes[2:end] return old, sizes[2:end]
end end
function wlmetric_ball_serial( function wlmetric_ball_serial(S::AbstractVector{T}, center::T; radius = 2, op = *) where {T}
S::AbstractVector{T},
center::T;
radius = 2,
op = *,
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
E, sizes = wlmetric_ball_serial(S, radius = radius, op = op) 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( function wlmetric_ball_thr(S::AbstractVector{T}, center::T; radius = 2, op = *) where {T}
S::AbstractVector{T},
center::T;
radius = 2,
op = *,
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
E, sizes = wlmetric_ball_thr(S, radius = radius, op = op) 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
@ -138,9 +121,9 @@ function wlmetric_ball(
radius = 2, radius = 2,
op = *, op = *,
threading = true, threading = true,
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}} ) where {T}
threading && return wlmetric_ball_thr(S, center, radius = radius, op = op) threading && return wlmetric_ball_thr(S, center, radius = radius, op = op)
return return wlmetric_ball_serial(S, center, radius = radius, op = op) return wlmetric_ball_serial(S, center, radius = radius, op = op)
end end
""" """