From 7f3a28c0d1372e3b3edbcbc28f00ba5645e1bbdb Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Sun, 25 Aug 2019 01:57:58 +0800 Subject: [PATCH] comment the reason of performance regression in #144 (#146) --- src/metrics.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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