diff --git a/src/metrics.jl b/src/metrics.jl index 01a921d..7439f35 100644 --- a/src/metrics.jl +++ b/src/metrics.jl @@ -713,6 +713,10 @@ function _pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix) end # CorrDist +# This part of codes is accelerated because: +# 1. It calls the accelerated `_pairwise` specilization for CosineDist +# 2. pre-calculated `_centralize_colwise` avoids four times of redundant computations +# of `_centralize` -- ~4x speed up _centralize_colwise(x::AbstractVector) = x .- mean(x) _centralize_colwise(x::AbstractMatrix) = x .- mean(x, dims=1) function colwise!(r::AbstractVector, dist::CorrDist, a::AbstractMatrix, b::AbstractMatrix) @@ -727,4 +731,4 @@ function _pairwise!(r::AbstractMatrix, dist::CorrDist, end function _pairwise!(r::AbstractMatrix, dist::CorrDist, a::AbstractMatrix) _pairwise!(r, CosineDist(), _centralize_colwise(a)) -end \ No newline at end of file +end