From 472e78af271a35fc19a891d610b2f15e3ea843e5 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Sun, 9 May 2021 19:37:26 +0200 Subject: [PATCH] generalize signatures of wlmetric_ball --- src/Groups.jl | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Groups.jl b/src/Groups.jl index 431e580..03fa1ec 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -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 """