Skip to content

sum(I -> A[I], CartesianIndices(A); dims=1) needs initial value in order to work #54875

@vargonis

Description

@vargonis
A = rand(3,4)
sum(I -> A[I], CartesianIndices(A); dims=1) # ERROR: BoundsError: attempt to access 3×4 Matrix{Float64} at index [0, 0]
sum(I -> A[I], CartesianIndices(A); dims=1, init=0.) # now it works

I'm running the following version:

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd4 (2024-06-04 10:41 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]collectionsData structures holding multiple items, e.g. setsfoldsum, maximum, reduce, foldl, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions