JuliaArrays / JuliaArrays/AxisArrays.jl
`map(f)` allocates infinite amount of memory
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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