Skip to content

Commit 8d23c98

Browse files
authored
distancematrix conversion clauses #19 from JuliaDynamics/distancematrix_clauses
2 parents a6a1048 + 5fa4818 commit 8d23c98

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

Project.toml

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/matrices.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ distancematrix(x::Vector, y::Vector, metric=Chebyshev()) = abs.(x .- y')
4848
# If the metric is supplied as a string, get the corresponding Metric from Distances
4949
distancematrix(x, y, metric::String) = distancematrix(x, y, getmetric(metric))
5050

51-
const MAXDIM = 10
51+
const MAXDIM = 9
5252
function distancematrix(x::Tx, y::Ty, metric::Metric=Chebyshev()) where
5353
{Tx<:Union{AbstractMatrix, Dataset}} where {Ty<:Union{AbstractMatrix, Dataset}}
5454
sx, sy = size(x), size(y)
5555
if sx[2] != sy[2]
5656
error("the dimensions of `x` and `y` data points must be the equal")
5757
end
58-
if sx[2] < MAXDIM # convert to Dataset here, it is significantly faster
59-
return _distancematrix(Dataset(x), Dataset(y), metric)
60-
else
58+
if sx[2] MAXDIM && typeof(metric) == Euclidean # Blas optimization
59+
return _distancematrix(Matrix(x), Matrix(y), metric)
60+
elseif Tx <: Matrix && Ty <: Matrix && metric == Chebyshev()
6161
return _distancematrix(x, y, metric)
62+
else
63+
return _distancematrix(Dataset(x), Dataset(y), metric)
6264
end
6365
end
6466

0 commit comments

Comments
 (0)