Skip to content

Commit

Permalink
make extrema with dims inferrable (#39321)
Browse files Browse the repository at this point in the history
fixes #39281

(cherry picked from commit caeacef)
  • Loading branch information
JeffBezanson authored and KristofferC committed Jan 20, 2021
1 parent 9719e6e commit 14ba71b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1698,9 +1698,9 @@ extrema(f, A::AbstractArray; dims=:) = _extrema_dims(f, A, dims)
_extrema_dims(f, A::AbstractArray, ::Colon) = _extrema_itr(f, A)

function _extrema_dims(f, A::AbstractArray, dims)
sz = [size(A)...]
sz = size(A)
for d in dims
sz[d] = 1
sz = setindex(sz, 1, d)
end
T = promote_op(f, eltype(A))
B = Array{Tuple{T,T}}(undef, sz...)
Expand Down
3 changes: 3 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,6 @@ x = [j+7 for j in i]
Iterators.flatten((1:2, 3:4)),
) == (1, 4)
end

# issue #39281
@test @inferred(extrema(rand(2), dims=1)) isa Vector{Tuple{Float64,Float64}}

0 comments on commit 14ba71b

Please sign in to comment.