Skip to content

Commit 03e77a9

Browse files
committed
_find_medoid(): use view() to reduce memory usage
1 parent cbc1486 commit 03e77a9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/kmedoids.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,8 @@ end
231231

232232

233233
# find medoid for a given group
234-
#
235-
# TODO: faster way without creating temporary arrays
236-
function _find_medoid(dist::AbstractMatrix, grp::Vector{Int})
234+
function _find_medoid(dist::AbstractMatrix, grp::AbstractVector{Int})
237235
@assert !isempty(grp)
238-
p = argmin(sum(dist[grp, grp], dims=2))
239-
return grp[p]::Int
236+
p = argmin(sum(view(dist, grp, grp), dims=2))
237+
return grp[p]
240238
end

0 commit comments

Comments
 (0)