Skip to content

Commit

Permalink
make extrema with dims inferrable (JuliaLang#39321)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jan 20, 2021
1 parent 78d55e2 commit caeacef
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 @@ -643,3 +643,6 @@ end

# make sure we specialize on mapfoldl(::Type, ...)
@test @inferred(mapfoldl(Int, +, [1, 2, 3]; init=0)) === 6

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

0 comments on commit caeacef

Please sign in to comment.