# Tuple as argument for size(AbstractArray)

**URL:** <https://discourse.julialang.org/t/tuple-as-argument-for-size-abstractarray/57533>\
**Category:** General Usage\
**Created:** [March 19, 2021, 12:18pm UTC](https://discourse.julialang.org/t/tuple-as-argument-for-size-abstractarray/57533 "2021-03-19T12:18:16Z")\
**Posts on this page:** 1\
**Showing post:** 37

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 24, 2021, 2:40pm UTC](https://discourse.julialang.org/t/tuple-as-argument-for-size-abstractarray/57533/37 "2021-03-24T14:40:12Z")

</div>

> [@RainerHeintzmann](#):
>
> In contrast to Tamas, I do not think that this is a very special use case of [IndexFunArrays.jl](https://github.com/bionanoimaging/IndexFunArrays.jl) package.

Then, again, a use case with broader context (and not the above package) would help.

There are now 35 posts in this topic, and I am still missing that. Please don’t get me wrong: I understand you would find this useful. I am just not convinced that it is _broadly_ useful without seeing some use cases — again, not an example of using this function, but a generic problem where we do not have existing solutions.

The only other place where one encounters “squeezing” dimensions to `1` is `reduce`, `dropdims`, and friends, as in

```julia
reduce(max, ones(3, 3, 3), dims = (1, 3))

```

and that is not generally considered to be especially well-designed — see the related discussions in

> <https://github.com/JuliaLang/julia/issues/16606>
>
> Following this discussion on julia-users: https://groups.google.com/forum/#!topi…c/julia-users/V-meqUZtb7k
> 
> I find the fact that \`sum(A,1)\` and \`A\[1,:\]\` have different shapes in 0.5 counter intuitive. I am not aware of other languages for which the equivalent expressions have different shapes. It leads to unexpected results when computing e.g. \`A\[1,:\] ./ sum(A,1)\`. At least in the case of \`sum\`, it seems like \`sum(A,1)\` should be equivalent to \`A\[1,:\] + A\[2,:\] + A\[3,:\] + ...\`
> 
> However, as @timholy pointed out, this behavior can be useful for broadcasting with expressions like \`A ./ sum(A,1)\`.
> 
> For me, having the default slicing and array reduction behavior be consistent seems the natural choice, meaning that \`sum(A,1)\` should drop the first dimension. But I understand the attractiveness of not dropping dimensions for broadcasting. What are others' thoughts?

> [@Sum + squeeze as one function](https://discourse.julialang.org/t/sum-squeeze-as-one-function/2471):
>
> Is there a built-in version of sum(A, dims) that automatically squeezes the summed out dimension? Something like: sumsqueeze(A, dim) = squeeze(sum(A, dim), dim) Surely, I can just combine 2 functions, but in my use case I generate this code and having it as a single built-in function makes it much easier to optimize it later.

Alternatives like

> **[GitHub - bramtayl/JuliennedArrays.jl: Type stable array slicing](https://github.com/bramtayl/JuliennedArrays.jl/)**
>
> Type stable array slicing. Contribute to bramtayl/JuliennedArrays.jl development by creating an account on GitHub.

are much nicer IMO.

---

_[View the full topic](https://discourse.julialang.org/t/tuple-as-argument-for-size-abstractarray/57533)._
