mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
generalize signatures of wlmetric_ball
This commit is contained in:
parent
217be597c3
commit
472e78af27
@ -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
|
||||
radius and multiplication operation to be used.
|
||||
"""
|
||||
function wlmetric_ball_serial(
|
||||
S::AbstractVector{T};
|
||||
radius = 2,
|
||||
op = *,
|
||||
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
|
||||
function wlmetric_ball_serial(S::AbstractVector{T}; radius = 2, op = *) where {T}
|
||||
@assert radius > 0
|
||||
old = unique!([one(first(S)), S...])
|
||||
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)
|
||||
append!(old, new)
|
||||
resize!(new, 0)
|
||||
@ -88,18 +85,14 @@ function wlmetric_ball_serial(
|
||||
return old, sizes[2:end]
|
||||
end
|
||||
|
||||
function wlmetric_ball_thr(
|
||||
S::AbstractVector{T};
|
||||
radius = 2,
|
||||
op = *,
|
||||
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
|
||||
function wlmetric_ball_thr(S::AbstractVector{T}; radius = 2, op = *) where {T}
|
||||
@assert radius > 0
|
||||
old = unique!([one(first(S)), S...])
|
||||
sizes = [1, length(old)]
|
||||
for r = 2:radius
|
||||
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
|
||||
)
|
||||
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)
|
||||
@ -110,23 +103,13 @@ function wlmetric_ball_thr(
|
||||
return old, sizes[2:end]
|
||||
end
|
||||
|
||||
function wlmetric_ball_serial(
|
||||
S::AbstractVector{T},
|
||||
center::T;
|
||||
radius = 2,
|
||||
op = *,
|
||||
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
|
||||
function wlmetric_ball_serial(S::AbstractVector{T}, center::T; radius = 2, op = *) where {T}
|
||||
E, sizes = wlmetric_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{GroupElement,AbstractAlgebra.NCRingElem}}
|
||||
function wlmetric_ball_thr(S::AbstractVector{T}, center::T; radius = 2, op = *) where {T}
|
||||
E, sizes = wlmetric_ball_thr(S, radius = radius, op = op)
|
||||
isone(center) && return E, sizes
|
||||
return c .* E, sizes
|
||||
@ -138,9 +121,9 @@ function wlmetric_ball(
|
||||
radius = 2,
|
||||
op = *,
|
||||
threading = true,
|
||||
) where {T<:Union{GroupElement,AbstractAlgebra.NCRingElem}}
|
||||
) where {T}
|
||||
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
|
||||
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user