Skip to content

Commit 8541e13

Browse files
Fix zipping of extrema outputs
1 parent 5adad1e commit 8541e13

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/vmapreduce.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ vvminimum(A::AbstractArray) = vvmapreduce(identity, min, typemax, A, :)
131131
# a custom implementation of extrema is not really worth it, as the time/memory
132132
# cost is approximately the same. Also, it suffers from first dimension reduction error.
133133

134+
# Convenience to handle zipping of results
135+
_vvextrema_zip(a::Number, b::Number) = a, b
136+
_vvextrema_zip(a, b) = collect(zip(a, b))
137+
134138
"""
135139
vvextrema(f, A::AbstractArray, dims=:)
136140
@@ -140,7 +144,7 @@ over the given `dims`.
140144
# Warning
141145
`NaN` values are not handled!
142146
"""
143-
vvextrema(f::F, A, dims) where {F} = collect(zip(vvminimum(f, A, dims), vvmaximum(f, A, dims)))
147+
vvextrema(f::F, A, dims) where {F} = _vvextrema_zip(vvminimum(f, A, dims), vvmaximum(f, A, dims))
144148
vvextrema(f::F, A, ::Colon) where {F} = (vvminimum(f, A, :), vvmaximum(f, A, :))
145149
vvextrema(f::F, A) where {F<:Function} = vvextrema(f, A, :)
146150
# ::AbstractArray required in order for kwargs interface to work
@@ -260,7 +264,7 @@ of the 2-tuple `init`, which can be any combination of values `<:Number` or func
260264
which accept a single type argument.
261265
"""
262266
vvextrema(f, A; dims=:, init=(typemax, typemin)) =
263-
collect(zip(vvmapreduce(f, min, init[1], A, dims), vvmapreduce(f, max, init[2], A, dims)))
267+
_vvextrema_zip(vvmapreduce(f, min, init[1], A, dims), vvmapreduce(f, max, init[2], A, dims))
264268

265269
"""
266270
vvextrema(A::AbstractArray; dims=:, init=(typemax, typemin))
@@ -269,7 +273,7 @@ Compute the minimum and maximum values of `A` over the given `dims`,
269273
with the min and max initialized by `init`.
270274
"""
271275
vvextrema(A; dims=:, init=(typemax, typemin)) =
272-
collect(zip(vvmapreduce(identity, min, init[1], A, dims), vvmapreduce(identity, max, init[2], A, dims)))
276+
_vvextrema_zip(vvmapreduce(identity, min, init[1], A, dims), vvmapreduce(identity, max, init[2], A, dims))
273277

274278

275279
# reduction over all dims
@@ -707,7 +711,7 @@ over the given `dims`.
707711
# Warning
708712
`NaN` values are not handled!
709713
"""
710-
vtextrema(f::F, A, dims) where {F} = collect(zip(vtminimum(f, A, dims), vtmaximum(f, A, dims)))
714+
vtextrema(f::F, A, dims) where {F} = _vvextrema_zip(vtminimum(f, A, dims), vtmaximum(f, A, dims))
711715
vtextrema(f::F, A, ::Colon) where {F} = (vtminimum(f, A, :), vtmaximum(f, A, :))
712716
vtextrema(f::F, A) where {F<:Function} = vtextrema(f, A, :)
713717
# ::AbstractArray required in order for kwargs interface to work
@@ -823,7 +827,7 @@ of the 2-tuple `init`, which can be any combination of values `<:Number` or func
823827
which accept a single type argument.
824828
"""
825829
vtextrema(f, A; dims=:, init=(typemax, typemin)) =
826-
collect(zip(vtmapreduce(f, min, init[1], A, dims), vtmapreduce(f, max, init[2], A, dims)))
830+
_vvextrema_zip(vtmapreduce(f, min, init[1], A, dims), vtmapreduce(f, max, init[2], A, dims))
827831

828832
"""
829833
vtextrema(A::AbstractArray; dims=:, init=(typemax, typemin))
@@ -832,7 +836,7 @@ Compute the minimum and maximum values of `A` over the given `dims`,
832836
with the min and max initialized by `init`.
833837
"""
834838
vtextrema(A; dims=:, init=(typemax, typemin)) =
835-
collect(zip(vtmapreduce(identity, min, init[1], A, dims), vtmapreduce(identity, max, init[2], A, dims)))
839+
_vvextrema_zip(vtmapreduce(identity, min, init[1], A, dims), vtmapreduce(identity, max, init[2], A, dims))
836840

837841
# reduction over all dims
838842
@generated function vtmapreduce(f::F, op::OP, init::I, A::AbstractArray{T, N}, ::Colon) where {F, OP, I, T, N}

0 commit comments

Comments
 (0)