JuliaArrays / JuliaArrays/StaticArrays.jl

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

Open
#880 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the StaticArrays example with sum(a, dims=(1,2)), then inspect src/mapreduce.jl around the _mapfoldl and _reduce methods named in the stack trace. Determine why a tuple of dimensions is not handled; done means the example runs without a MethodError and has regression coverage for multi-dimensional reduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.