# Passing a StaticArray to sum throws an error

**URL:** https://discourse.julialang.org/t/passing-a-staticarray-to-sum-throws-an-error/56159
**Category:** General Usage
**Tags:** staticarrays
**Created:** [February 27, 2021, 9:45pm UTC](https://discourse.julialang.org/t/passing-a-staticarray-to-sum-throws-an-error/56159 "2021-02-27T21:45:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mroavi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mroavi/32/8804_2.png) [@mroavi](https://discourse.julialang.org/u/mroavi)
#### Post date: [February 27, 2021, 9:45pm UTC](https://discourse.julialang.org/t/passing-a-staticarray-to-sum-throws-an-error/56159/1 "2021-02-27T21:45:25Z")

</div>

Any idea why `sum` throws an error when given a `StaticArray` ? (I’m using Julia 1.5.3)

```julia
using StaticArrays
input = @SArray rand(2,2,2);
sum(input, dims=(1,2)) # throws error

```

Error:

```julia
ERROR: LoadError: 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})

```

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [February 28, 2021, 6:20am UTC](https://discourse.julialang.org/t/passing-a-staticarray-to-sum-throws-an-error/56159/2 "2021-02-28T06:20:58Z")

</div>

> [@mroavi](#):
>
> ```julia
> using StaticArrays
> input = @SArray rand(2,2,2);
> sum(input, dims=(1,2)) # throws error
> 
> ```

I’m not sure why that doesn’t work, but

```julia
 sum(sum(input, dims=2), dims=1)

```

seems to.

---

<div class="post-metadata">

### Author: ![mroavi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mroavi/32/8804_2.png) [@mroavi](https://discourse.julialang.org/u/mroavi)
#### Post date: [February 28, 2021, 12:23pm UTC](https://discourse.julialang.org/t/passing-a-staticarray-to-sum-throws-an-error/56159/3 "2021-02-28T12:23:38Z")

</div>

I opened an issue in their GitHub repo. Thanks for the workaround!
