Skip to content

Commit 626dec3

Browse files
authored
Merge pull request #30 from Arkoniak/todo_doc_cleanup
removed type instability
2 parents 0055088 + 0501eb3 commit 626dec3

File tree

4 files changed

+18
-40
lines changed

4 files changed

+18
-40
lines changed

src/ParallelKMeans.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ include("lloyd.jl")
99
include("light_elkan.jl")
1010

1111
export kmeans
12+
export Lloyd, LightElkan
1213

1314
end # module

src/kmeans.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ function update_centroids!(centroids, containers, alg, design_matrix, n_threads)
167167

168168
if n_threads == 1
169169
r = axes(design_matrix, 2)
170-
J = chunk_update_centroids!(centroids, containers, alg, design_matrix, r, 0)
170+
J = chunk_update_centroids!(centroids, containers, alg, design_matrix, r, 1)
171171

172-
centroids .= containers.new_centroids ./ containers.centroids_cnt'
172+
centroids .= containers.new_centroids[1] ./ containers.centroids_cnt[1]'
173173
else
174174
ranges = splitter(ncol, n_threads)
175175

src/light_elkan.jl

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@ Internal function for the creation of all necessary intermidiate structures.
3030
- `centroids_dist` - symmetric matrix k x k which holds weighted distances between centroids
3131
"""
3232
function create_containers(alg::LightElkan, k, nrow, ncol, n_threads)
33-
if n_threads == 1
34-
new_centroids = Array{Float64, 2}(undef, nrow, k)
35-
centroids_cnt = Vector{Int}(undef, k)
36-
else
37-
new_centroids = Vector{Array{Float64, 2}}(undef, n_threads)
38-
centroids_cnt = Vector{Vector{Int}}(undef, n_threads)
39-
40-
for i in 1:n_threads
41-
new_centroids[i] = Array{Float64, 2}(undef, nrow, k)
42-
centroids_cnt[i] = Vector{Int}(undef, k)
43-
end
33+
new_centroids = Vector{Array{Float64, 2}}(undef, n_threads)
34+
centroids_cnt = Vector{Vector{Int}}(undef, n_threads)
35+
36+
for i in 1:n_threads
37+
new_centroids[i] = Array{Float64, 2}(undef, nrow, k)
38+
centroids_cnt[i] = Vector{Int}(undef, k)
4439
end
4540

4641
labels = zeros(Int, ncol)
@@ -103,13 +98,8 @@ function chunk_update_centroids!(centroids, containers, ::LightElkan,
10398
design_matrix, r, idx)
10499

105100
# unpack containers for easier manipulations
106-
if idx == 0
107-
new_centroids = containers.new_centroids
108-
centroids_cnt = containers.centroids_cnt
109-
else
110-
new_centroids = containers.new_centroids[idx]
111-
centroids_cnt = containers.centroids_cnt[idx]
112-
end
101+
new_centroids = containers.new_centroids[idx]
102+
centroids_cnt = containers.centroids_cnt[idx]
113103
centroids_dist = containers.centroids_dist
114104
labels = containers.labels
115105

src/lloyd.jl

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@ Internal function for the creation of all necessary intermidiate structures.
2222
- `labels` - vector which holds labels of corresponding points
2323
"""
2424
function create_containers(::Lloyd, k, nrow, ncol, n_threads)
25-
if n_threads == 1
26-
new_centroids = Array{Float64, 2}(undef, nrow, k)
27-
centroids_cnt = Vector{Int}(undef, k)
28-
else
29-
new_centroids = Vector{Array{Float64, 2}}(undef, n_threads)
30-
centroids_cnt = Vector{Vector{Int}}(undef, n_threads)
25+
new_centroids = Vector{Array{Float64, 2}}(undef, n_threads)
26+
centroids_cnt = Vector{Vector{Int}}(undef, n_threads)
3127

32-
for i in 1:n_threads
33-
new_centroids[i] = Array{Float64, 2}(undef, nrow, k)
34-
centroids_cnt[i] = Vector{Int}(undef, k)
35-
end
28+
for i in 1:n_threads
29+
new_centroids[i] = Array{Float64, 2}(undef, nrow, k)
30+
centroids_cnt[i] = Vector{Int}(undef, k)
3631
end
3732

3833
labels = Vector{Int}(undef, ncol)
@@ -43,20 +38,12 @@ end
4338

4439
update_containers!(containers, ::Lloyd, centroids, n_threads) = nothing
4540

46-
"""
47-
# TODO: Docs
48-
"""
4941
function chunk_update_centroids!(centroids, containers, ::Lloyd,
5042
design_matrix, r, idx)
5143

5244
# unpack containers for easier manipulations
53-
if idx == 0
54-
new_centroids = containers.new_centroids
55-
centroids_cnt = containers.centroids_cnt
56-
else
57-
new_centroids = containers.new_centroids[idx]
58-
centroids_cnt = containers.centroids_cnt[idx]
59-
end
45+
new_centroids = containers.new_centroids[idx]
46+
centroids_cnt = containers.centroids_cnt[idx]
6047
labels = containers.labels
6148

6249
new_centroids .= 0.0

0 commit comments

Comments
 (0)