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

Extra 1 dimensions in reinterpreted arrays cause stack overflow #57170

Open
AaronGhost opened this issue Jan 27, 2025 · 1 comment
Open

Extra 1 dimensions in reinterpreted arrays cause stack overflow #57170

AaronGhost opened this issue Jan 27, 2025 · 1 comment
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior

Comments

@AaronGhost
Copy link

Hi, thanks for everyone's work on Julia!

Following the manual on arrays, one can add extra "1" in indexing Nd arrays.
This works as expected for Array but creates a Stack Overflow with ReinterpretArray on 1.10, last release and nightly.

X = rand(Float32, (2,5))
X[1, :, 1] # works as expected

X2 = rand(ComplexF32, 5)
Xr = reinterpret(reshape, Float32, X2)
Xr[1, :, 1] # Stack overflow

The stack overflow error:

[1] _getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Vararg{Int64})
@ Base ./multidimensional.jl:953
[2] getindex(::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Int64)
 @ Base ./abstractarray.jl:1342
 [3] macro expansion
@ ./multidimensional.jl:979 [inlined]
[4] macro expansion
@ ./cartesian.jl:64 [inlined]
[5] macro expansion
@ ./multidimensional.jl:977 [inlined]
[6] _unsafe_getindex!
@ ./multidimensional.jl:987 [inlined]
[7] _unsafe_getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Int64)
 @ Base ./multidimensional.jl:968
 [8] _getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Vararg{Int64})
@ Base ./multidimensional.jl:954
--- the above 7 lines are repeated 11134 more times ---
 [77947] getindex
 @ ./abstractarray.jl:1342 [inlined]
[77948] macro expansion
@ ./multidimensional.jl:979 [inlined]
[77949] macro expansion
@ ./cartesian.jl:64 [inlined]
[77950] macro expansion
@ ./multidimensional.jl:977 [inlined]
[77951] _unsafe_getindex!
@ ./multidimensional.jl:987 [inlined]
[77952] _unsafe_getindex
 @ ./multidimensional.jl:968 [inlined]
[77953] _getindex
@ ./multidimensional.jl:954 [inlined]
[77954] getindex(::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::UnitRange{Int64}, ::Function, ::Int64)
 @ Base ./abstractarray.jl:1342
@Seelengrab
Copy link
Contributor

This has stackoverflowed since at least 1.6.7, so quite a longstanding bug!

@Seelengrab Seelengrab added bug Indicates an unexpected problem or unintended behavior arrays [a, r, r, a, y, s] labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants