Update pairwise.jl
parent
8c2811b564
commit
b407b186f0
|
@ -28,7 +28,7 @@ julia> pairwise(Levenshtein(), iter, iter2) # asymmetric
|
||||||
"""
|
"""
|
||||||
Distances.pairwise
|
Distances.pairwise
|
||||||
|
|
||||||
function Distances.pairwise(dist::StringDistance, X, Y; preprocess = nothing)
|
function Distances.pairwise(dist::StringDistance, X, Y; preprocess = length(X) >= 5)
|
||||||
T = result_type(dist, eltype(X), eltype(Y))
|
T = result_type(dist, eltype(X), eltype(Y))
|
||||||
R = Matrix{T}(undef, length(X), length(Y))
|
R = Matrix{T}(undef, length(X), length(Y))
|
||||||
pairwise!(R, dist, X, Y; preprocess = preprocess)
|
pairwise!(R, dist, X, Y; preprocess = preprocess)
|
||||||
|
@ -53,11 +53,11 @@ false if no preprocessing should be used, regardless of length.
|
||||||
"""
|
"""
|
||||||
Distances.pairwise!
|
Distances.pairwise!
|
||||||
|
|
||||||
function Distances.pairwise!(R::AbstractMatrix{<:Number}, dist::StringDistance, X, Y; preprocess = nothing)
|
function Distances.pairwise!(R::AbstractMatrix, dist::StringDistance, X, Y; preprocess = nothing)
|
||||||
_asymmetric_pairwise!(R, dist, X, Y; preprocess = preprocess)
|
_asymmetric_pairwise!(R, dist, X, Y; preprocess = preprocess)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Distances.pairwise!(R::AbstractMatrix{<:Number}, dist::StringDistance, X; preprocess = nothing)
|
function Distances.pairwise!(R::AbstractMatrix, dist::StringDistance, X; preprocess = nothing)
|
||||||
(dist isa SemiMetric) ?
|
(dist isa SemiMetric) ?
|
||||||
_symmetric_pairwise!(R, dist, X; preprocess = preprocess) :
|
_symmetric_pairwise!(R, dist, X; preprocess = preprocess) :
|
||||||
_asymmetric_pairwise!(R, dist, X, X; preprocess = preprocess)
|
_asymmetric_pairwise!(R, dist, X, X; preprocess = preprocess)
|
||||||
|
@ -73,7 +73,7 @@ end
|
||||||
_preprocess(X, dist::StringDistance, preprocess) = X
|
_preprocess(X, dist::StringDistance, preprocess) = X
|
||||||
|
|
||||||
|
|
||||||
function _symmetric_pairwise!(R::AbstractMatrix{<:Number}, dist::StringDistance, X; preprocess = nothing)
|
function _symmetric_pairwise!(R::AbstractMatrix, dist::StringDistance, X; preprocess = nothing)
|
||||||
objs = _preprocess(X, dist, preprocess)
|
objs = _preprocess(X, dist, preprocess)
|
||||||
for i in 1:length(objs)
|
for i in 1:length(objs)
|
||||||
R[i, i] = 0
|
R[i, i] = 0
|
||||||
|
@ -84,7 +84,7 @@ function _symmetric_pairwise!(R::AbstractMatrix{<:Number}, dist::StringDistance,
|
||||||
return R
|
return R
|
||||||
end
|
end
|
||||||
|
|
||||||
function _asymmetric_pairwise!(R::AbstractMatrix{<:Number}, dist::StringDistance, X, Y; preprocess = nothing)
|
function _asymmetric_pairwise!(R::AbstractMatrix, dist::StringDistance, X, Y; preprocess = nothing)
|
||||||
objsX = _preprocess(X, dist, preprocess)
|
objsX = _preprocess(X, dist, preprocess)
|
||||||
objsY = _preprocess(Y, dist, preprocess)
|
objsY = _preprocess(Y, dist, preprocess)
|
||||||
for i in 1:length(objsX)
|
for i in 1:length(objsX)
|
||||||
|
|
Loading…
Reference in New Issue