JuliaArrays / JuliaArrays/MappedArrays.jl

Domain error when inferring array type in 0-length degenerated case

Open
#29 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
88
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Hi!

do you plan to support degenerated cases like the one below in the future?

Just for curiosity, how would you fix this in the library? Is it possible to fix it without calling something like Base._return_type?

Thanks for the help!

julia> using MappedArrays

julia> a = fill(1,0)
0-element Array{Int64,1}

julia> f(x) = sqrt(x-1)
f (generic function with 1 method)

julia> mappedarray(f,a)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] f at ./REPL[3]:1 [inlined]
 [5] mappedarray(::typeof(f), ::Array{Int64,1}) at /home/fverdugo/.julia/packages/MappedArrays/8HESW/src/MappedArrays.jl:61
 [6] top-level scope at REPL[4]:1

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 mappedarray entry point in src/MappedArrays.jl:61 and reproduce the empty-array example using MappedArrays and sqrt(x-1). Determine how the result type is inferred for a zero-length array and whether the reported DomainError can be avoided without Base._return_type; done means the degenerate case is handled with an agreed result type and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.