-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
colwise!(dist, res, A, B) does not consider eltype(res) #268
Comments
I think it's rather the other way around: it's pure luck (and due to a specific implementation) that julia> SqEuclidean()(vec(X), vec(Y))
-31616 But we may transfer the same trick from |
Maybe the core method for the distance API should be |
But what would that help? For your |
That will help with |
To prevent the overflow, you would need to promote your input (as you can see from your OP), which you can do as the user/package author. I don't think we want to silently promote eltypes here. |
These matrices might be large, so promoting Int16 to Float64 just to tell |
That's why I said the fact that Lines 616 to 617 in 35c6d0d
So, what you're asking for is not about controlling the target type, but a preprocessing of the data, which you can currently do like: X = reshape(Int16[0, 0], 2, 1)
Y = reshape(Int16[1000, 1000], 2, 1)
using Distances
map((x, y) -> sqeuclidean(float(x), float(y)), eachcol(X), eachcol(Y))
map!((x, y) -> sqeuclidean(float(x), float(y)), Matrix{Float64}(undef, 1, 1), eachcol(X), eachcol(Y)) Note that the |
Thank you for the detailed explanations! Implementing the workaround in the user script is probably the optimal strategy now, but look at it from the perspective of the other packages, in particular Clustering.jl.
It was my assumption that Distances.jl -- in addition to defining the metric types -- also implements the efficient distances calculation for the large datasets, so it could be used as the plug-in solutions to these problems. AFAIU, the immediate solution is to check whether the distances are negative if SemiMetric is used and warn the user. |
Here's a test case (Julia 1.11.2, Distances.jl 0.10.12):
The text was updated successfully, but these errors were encountered: