Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mroavi opened this issue Feb 27, 2021 · 1 comment · May be fixed by #909
Open

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

mroavi opened this issue Feb 27, 2021 · 1 comment · May be fixed by #909

Comments

@mroavi
Copy link

mroavi commented Feb 27, 2021

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
@mroavi mroavi changed the title Passing a Static Array to sum() throws an error Summing multiple dimensions of a Static Array with sum() throws an error Apr 6, 2021
@mcabbott
Copy link
Collaborator

mcabbott commented May 8, 2021

Even just one dimension:

julia> sum(SA[1 2; 3 4], dims=1)  # ok!
1×2 SMatrix{1, 2, Int64, 2} with indices SOneTo(1)×SOneTo(2):
 4  6

julia> sum(SA[1 2; 3 4], dims=(1,))  # same error
ERROR: MethodError: no method matching _mapfoldl(::typeof(identity), ::typeof(+), ::Tuple{Int64}, ::StaticArrays._InitialValue, ::Size{(2, 2)}, ::SMatrix{2, 2, Int64, 4})
...

julia> sum(SA[1 2; 3 4], dims=Val(1))  # ok!
1×2 SMatrix{1, 2, Int64, 2} with indices SOneTo(1)×SOneTo(2):
 4  6

julia> sum(SA[1 2; 3 4], dims=Val((1,)))  # different error
ERROR: MethodError: no method matching getindex(::Tuple{Int64, Int64}, ::Tuple{Int64})
Closest candidates are:
  getindex(::Tuple, ::Int64) at tuple.jl:29
  getindex(::Tuple, ::Real) at tuple.jl:30
  getindex(::Tuple, ::Colon) at tuple.jl:33
  ...
Stacktrace:
 [1] #s46#288
   @ ~/.julia/dev/StaticArrays/src/mapreduce.jl:175 [inlined]
 [2] var"#s46#288"(S::Any, D::Any, ::Any, f::Any, op::Any, dims::Any, init::Any, #unused#::Any, a::Any)
   @ StaticArrays ./none:0
 [3] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
   @ Core ./boot.jl:576
 [4] _mapreduce
   @ ~/.julia/dev/StaticArrays/src/mapreduce.jl:113 [inlined]
 [5] _reduce (repeats 2 times)
   @ ~/.julia/dev/StaticArrays/src/mapreduce.jl:209 [inlined]
 [6] #sum#298
   @ ~/.julia/dev/StaticArrays/src/mapreduce.jl:250 [inlined]

@mcabbott mcabbott linked a pull request May 8, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants