From 016725465cbbee851c89402b2c9ab548012edb5c Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Mon, 18 Dec 2023 21:20:59 -0800 Subject: [PATCH] initseeds(KmCentralityAlg): vectorize --- src/seeding.jl | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/seeding.jl b/src/seeding.jl index 32107b12..ac77ee0c 100644 --- a/src/seeding.jl +++ b/src/seeding.jl @@ -239,21 +239,11 @@ function initseeds_by_costs!(iseeds::AbstractVector{<:Integer}, alg::KmCentralit k = length(iseeds) check_seeding_args(n, k) - # compute score for each item - coefs = vec(sum(costs, dims=2)) - for i = 1:n - @inbounds coefs[i] = inv(coefs[i]) - end - # scores[j] = \sum_j costs[i,j] / (\sum_{j'} costs[i,j']) - # = costs[i,j] * coefs[i] - scores = costs'coefs + scores = costs'vec(mapslices(invāˆ˜sum, costs, dims=2)) # lower score indicates better seeds - sp = sortperm(scores) - for i = 1:k - @inbounds iseeds[i] = sp[i] - end + copyto!(iseeds, 1, sortperm(scores), 1, k) return iseeds end