Skip to content

Commit f31f160

Browse files
committed
Optimize pairwise for Sinus and scalar inputs
1 parent 9a2f7bb commit f31f160

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/distances/sinus.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ Distances.result_type(::Sinus{T}, Ta::Type, Tb::Type) where {T} = promote_type(T
2121
end
2222
return sum(abs2, sinpi.(a - b) ./ d.r)
2323
end
24+
25+
# Optimizations for scalar inputs (avoiding allocations)
26+
pairwise(d::Sinus, x::AbstractVector{<:Real}) = pairwise(d, x, x)
27+
pairwise(d::Sinus, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}) = abs2.(sinpi.(x .- y') ./ only(d.r))

0 commit comments

Comments
 (0)