Skip to content
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

Incorrect estimation of the numeric type of the distance between Real elements: result is Int64, not Float64 or Real #267

Closed
aborzunov opened this issue Dec 10, 2024 · 1 comment

Comments

@aborzunov
Copy link

Steps to reproduce:

julia> result_type(SqEuclidean(), Matrix{Real}(undef, 1, 1), Vector{Real}(undef, 1))
Int64

Julia: Version 1.11.1 (2024-10-16)
Distances: [b4f34e82] Distances v0.10.12

Issue originally was found during use of Clustering.jl: JuliaStats/Clustering.jl#285

@dkarrasch
Copy link
Member

In the OP, why is the data of generic type Real? This is not an issue with Distances.jl, this behaviour is deeply rooted in julia itself:

julia> typeof(one(Real))
Int64

This is because one(::Type{T}) where {T<:Number} = convert(T,1). If you have floating point data anyway, it's better to use the most specific eltype possible. In your case, the elements of your arrays (in the OP) are all (but one) of type Float64. If, for some reason, you need to be more flexible, you could even use AbstractFloat:

julia> typeof(one(AbstractFloat))
Float64

or otherwise

convert(Array{Float64}, fs)

@dkarrasch dkarrasch closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants