Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing array elements out of range in a view is accepted in Julia #269

Open
daniloefl opened this issue Oct 17, 2020 · 0 comments
Open

Comments

@daniloefl
Copy link

daniloefl commented Oct 17, 2020

Dear developers,

as mentioned in SciML/DiffEqFlux.jl#436 ArrayFire crashes due to an access to a[(length(a)+1):end].
However, this is an allowed syntax in Julia and it is expected to return an empty array. See [1] below.

A fix would be to check the indices before doing ccall in indexing.jl.

Best regards,
Danilo

[1]

Example:

julia> a = [1 2 3]
1×3 Array{Int64,2}:
 1  2  3

julia> a[4:end]
Int64[]

julia> a[5:end]
Int64[]

julia> using ArrayFire
ArrayFire v3.7.2 (OpenCL, 64-bit Linux, build 218dd2c9)
[0] Clover: AMD TURKS (DRM 2.50.0 / 5.4.0-40-generic, LLVM 10.0.0), 1024 MB

julia> a2 = AFArray(a)
AFArray: 1×3 Array{Int64,2}:
 1  2  3

julia> a2[4:end]
ERROR: ArrayFire Error (202) : Invalid input argument
In function af_err af_index_gen(void**, af_array, dim_t, const af_index_t*)
In file src/api/c/index.cpp:220


 0# 0x00007F2CBE931DF2 in /home/daniloefl/arrayfire/lib/libafopencl.so.3
 1# af_index_gen in /home/daniloefl/arrayfire/lib/libaf.so.3
 2# 0x00007F2CD0843223
 3# 0x00007F2CD0843346
 4# 0x00007F2CF104D25C in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 5# 0x00007F2CF104CE7A in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 6# 0x00007F2CF104DB50 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 7# 0x00007F2CF104E687 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 8# 0x00007F2CF106C0C1 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 9# 0x00007F2CF106C759 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
10# 0x00007F2CF106C759 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
11# jl_toplevel_eval_in in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
12# 0x00007F2CE2BF1092 in /home/daniloefl/Com
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] _error(::UInt32, ::Bool) at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/util.jl:96
 [3] index_gen_1 at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/indexing.jl:91 [inlined]
 [4] getindex(::AFArray{Int64,2}, ::UnitRange{Int64}) at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/indexing.jl:66
 [5] top-level scope at REPL[6]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant