Skip to content

Commit 543d0c8

Browse files
committed
Compure Euclidean distance in a loop to avoid allocations
1 parent 54e822e commit 543d0c8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Loess.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ function loess(
8080
end
8181

8282
# distance to each point
83-
for i in 1:n
84-
ds[i] = euclidean(vec(vert), vec(xs[i,:]))
83+
@inbounds for i in 1:n
84+
s = zero(T)
85+
for j in 1:m
86+
s += (xs[i, j] - vert[j])^2
87+
end
88+
ds[i] = sqrt(s)
8589
end
8690

8791
# find the q closest points

0 commit comments

Comments
 (0)