Skip to content

reduce with dims argument over empty arrays #30928

@simonbyrne

Description

@simonbyrne

Currently this is a bit inconsistent:

julia> a = zeros(0,0)
0×0 Array{Float64,2}

julia> sum(a,dims=1)
1×0 Array{Float64,2}

julia> minimum(a,dims=1)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
 [1] _empty_reduce_error() at ./reduce.jl:216
 [2] reducedim_init(::Function, ::typeof(min), ::Array{Float64,2}, ::Int64) at ./reducedim.jl:135
 [3] _mapreduce_dim at ./reducedim.jl:313 [inlined]
 [4] #mapreduce#543 at ./reducedim.jl:304 [inlined]
 [5] #mapreduce at ./none:0 [inlined]
 [6] _minimum at ./reducedim.jl:675 [inlined]
 [7] _minimum at ./reducedim.jl:674 [inlined]
 [8] #minimum#551 at ./reducedim.jl:648 [inlined]
 [9] (::getfield(Base, Symbol("#kw##minimum")))(::NamedTuple{(:dims,),Tuple{Int64}}, ::typeof(minimum), ::Array{Float64,2}) at ./none:0
 [10] top-level scope at REPL[10]:1

Basically it comes down to whether or not Base.reduce_empty(op, eltype(a)) is defined. Is it possible to support this more generally?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions