Skip to content

Commit

Permalink
simplify result_type on UnionMetrics (#179)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <dev+github@devmotion.de>
Co-authored-by: Daniel Karrasch <Daniel.Karrasch@gmx.de>
  • Loading branch information
3 people committed Oct 7, 2020
1 parent d547d3a commit 777f023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,6 +1,6 @@
name = "Distances"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.9.1"
version = "0.9.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
14 changes: 7 additions & 7 deletions src/metrics.jl
Expand Up @@ -213,12 +213,12 @@ for dist in weightedmetrics
@eval parameters(d::$dist) = d.weights
end

result_type(dist::UnionMetrics, a::AbstractArray, b::AbstractArray) =
result_type(dist, a, b, parameters(dist))
result_type(dist::UnionMetrics, a::AbstractArray, b::AbstractArray, ::Nothing) =
typeof(_evaluate(dist, oneunit(eltype(a)), oneunit(eltype(b))))
result_type(dist::UnionMetrics, a::AbstractArray, b::AbstractArray, p) =
typeof(_evaluate(dist, oneunit(eltype(a)), oneunit(eltype(b)), oneunit(eltype(p))))
result_type(dist::UnionMetrics, ::Type{Ta}, ::Type{Tb}) where {Ta,Tb} =
result_type(dist, Ta, Tb, parameters(dist))
result_type(dist::UnionMetrics, ::Type{Ta}, ::Type{Tb}, ::Nothing) where {Ta,Tb} =
typeof(_evaluate(dist, oneunit(Ta), oneunit(Tb)))
result_type(dist::UnionMetrics, ::Type{Ta}, ::Type{Tb}, p) where {Ta,Tb} =
typeof(_evaluate(dist, oneunit(Ta), oneunit(Tb), oneunit(eltype(p))))

Base.@propagate_inbounds function _evaluate(d::UnionMetrics, a::AbstractArray, b::AbstractArray)
_evaluate(d, a, b, parameters(d))
Expand Down Expand Up @@ -261,7 +261,7 @@ Base.@propagate_inbounds function _evaluate(d::UnionMetrics, a::AbstractArray, b
throw(DimensionMismatch("arrays have length $(length(a)) but parameters have length $(length(p))."))
end
if length(a) == 0
return zero(result_type(d, a, b, p))
return zero(result_type(d, a, b))
end
@inbounds begin
s = eval_start(d, a, b)
Expand Down

2 comments on commit 777f023

@dkarrasch
Copy link
Member

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/22508

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.9.2 -m "<description of version>" 777f02307d152adc8dedca27df736a61efd975b8
git push origin v0.9.2

Please sign in to comment.