Skip to content

Summing multiple dimensions of a Static Array with sum() throws an error #880

Description

@mroavi

Minimal example:

julia> using StaticArrays

julia> a = @SArray rand(2,2,2);

julia> sum(a, dims=(1,2))
ERROR: MethodError: no method matching _mapfoldl(::typeof(identity), ::typeof(+), ::Tuple{Int64, Int64}, ::StaticArrays._InitialValue, ::Size{(2, 2, 2)}, ::SArray{Tuple{2, 2, 2}, Float64, 3, 8})
Closest candidates are:
  _mapfoldl(::Any, ::Any, ::Colon, ::Any, ::Size{S}, ::StaticArray...) where S at /home/mroavi/.julia/packages/StaticArrays/LJQEe/src/mapreduce.jl:115
  _mapfoldl(::Any, ::Any, ::Val{D}, ::Any, ::Size{S}, ::StaticArray) where {S, D} at /home/mroavi/.julia/packages/StaticArrays/LJQEe/src/mapreduce.jl:161
Stacktrace:
 [1] _mapreduce
   @ ~/.julia/packages/StaticArrays/LJQEe/src/mapreduce.jl:113 [inlined]
 [2] _reduce (repeats 2 times)
   @ ~/.julia/packages/StaticArrays/LJQEe/src/mapreduce.jl:209 [inlined]
 [3] #sum#285
   @ ~/.julia/packages/StaticArrays/LJQEe/src/mapreduce.jl:250 [inlined]
 [4] top-level scope
   @ REPL[7]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions