Skip to content

Commit

Permalink
Fix result_type issues (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Jan 29, 2021
1 parent 3cfb742 commit fa867d5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Distances"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.10.1"
version = "0.10.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
1 change: 1 addition & 0 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ result_type(f, a::Type, b::Type) = typeof(f(oneunit(a), oneunit(b))) # don't req

_eltype(a) = __eltype(Base.IteratorEltype(a), a)
_eltype(::Type{T}) where {T} = eltype(T) === T ? T : _eltype(eltype(T))
_eltype(::Type{Union{Missing, T}}) where {T} = Union{Missing, T}

__eltype(::Base.HasEltype, a) = _eltype(eltype(a))
__eltype(::Base.EltypeUnknown, a) = _eltype(typeof(first(a)))
Expand Down
2 changes: 2 additions & 0 deletions src/haversine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ function (dist::SphericalAngle)(x, y)
end

spherical_angle(x, y) = SphericalAngle()(x, y)

result_type(::Union{Haversine, SphericalAngle}, ::Type, ::Type) = Float64
4 changes: 2 additions & 2 deletions src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ function _evaluate(dist::UnionMetrics, a::Number, b::Number, p)
end

eval_start(d::UnionMetrics, a, b) = _eval_start(d, _eltype(a), _eltype(b))
_eval_start(d, ::Type{Ta}, ::Type{Tb}) where {Ta,Tb} =
_eval_start(d, _eltype(Ta), _eltype(Tb), parameters(d))
_eval_start(d::UnionMetrics, ::Type{Ta}, ::Type{Tb}) where {Ta,Tb} =
_eval_start(d, Ta, Tb, parameters(d))
_eval_start(d::UnionMetrics, ::Type{Ta}, ::Type{Tb}, ::Nothing) where {Ta,Tb} =
zero(typeof(eval_op(d, oneunit(Ta), oneunit(Tb))))
_eval_start(d::UnionMetrics, ::Type{Ta}, ::Type{Tb}, p) where {Ta,Tb} =
Expand Down
8 changes: 8 additions & 0 deletions test/test_dists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ end
([4.0, 5.0, 6.0, 7.0], [3. 8.; 9. 1.0]))
x, y = T.(_x), T.(_y)
for (x, y) in ((x, y),
(convert(Array{Union{Missing, T}}, x), convert(Array{Union{Missing, T}}, y)),
((Iterators.take(x, 4), Iterators.take(y, 4))), # iterator
(((x[i] for i in 1:length(x)), (y[i] for i in 1:length(y)))), # generator
)
Expand Down Expand Up @@ -640,6 +641,13 @@ end

test_pairwise(SqMahalanobis(Q), X, Y, T)
test_pairwise(Mahalanobis(Q), X, Y, T)

m, nx, ny = 2, 8, 6

X = rand(T, m, nx)
Y = rand(T, m, ny)
test_pairwise(Haversine(), X, Y, T)
test_pairwise(SphericalAngle(), X, Y, T)
end

function test_scalar_pairwise(dist, x, y, T)
Expand Down

2 comments on commit fa867d5

@dkarrasch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/28949

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.2 -m "<description of version>" fa867d59098dd848fd71bc48005a1bf858928a47
git push origin v0.10.2

Please sign in to comment.