JuliaArrays / JuliaArrays/AxisArrays.jl

`map(f)` allocates infinite amount of memory

Open Beginner friendly
#238 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
207
Forks
41
PR merge metrics
No merged PRs in 30d

Description

This overload:
https://github.com/JuliaArrays/AxisArrays.jl/blob/bbf1f27e3a185353a62a83587de5762bbfde7173/src/core.jl#L431-L435
can be called with an empty As, e.g. map(x->x). This calls matchingdims(()) which calls something like tuple(zip()...):
https://github.com/JuliaArrays/AxisArrays.jl/blob/bbf1f27e3a185353a62a83587de5762bbfde7173/src/combine.jl#L12-L13
Since zip() is an infinite iterator of empty tuples, Julia allocates an infinite amount of memory which is quite unexpected in this case (I stumbled upon this when I forgot an argument to map while using a package that has AxisArrays in its dependency graph and got Julia OOM-killed).
I believe this should be a MethodError instead, e.g. by requiring at least one array:

function Base.map(f, A::AxisArray{T,N,D,Ax}, As::AxisArray{T,N,D,Ax}...) where {T,N,D,Ax<:Tuple{Vararg{Axis}}}
    matchingdims((A, As...)) || error("All axes must be identically-valued")
    data = map(a -> a.data, (A, As...))
    return AxisArray(map(f, data...), A.axes...)
end

Maybe changing matchingdims(()) behavior makes sense as well.

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

Start with the AxisArray map overload in src/core.jl at lines 431-435, then inspect matchingdims in src/combine.jl at lines 12-13. Reproduce map(x -> x) with no array arguments and verify it fails promptly with a MethodError or equivalent error instead of allocating indefinitely. Check that normal map calls with one or more AxisArrays still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.