Skip to content

Possible bug: StackOverflowError with inds::Tuple{Int32,Colon} #235

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

Closed
toollu opened this issue May 13, 2021 · 1 comment · Fixed by #243
Closed

Possible bug: StackOverflowError with inds::Tuple{Int32,Colon} #235

toollu opened this issue May 13, 2021 · 1 comment · Fixed by #243

Comments

@toollu
Copy link

toollu commented May 13, 2021

Vec64  = zeros(6)
Vec32  = Float32.(zeros(6))
ind_a_64 = 3
ind_a_32 =Int32.(ind_a_64)
julia> reshape(Vec64,ind_a_64,:)
3×2 Matrix{Float64}:
 0.0  0.0
 0.0  0.0
 0.0  0.0

julia> reshape(Vec32,ind_a_64,:)
3×2 Matrix{Float32}:
 0.0  0.0
 0.0  0.0
 0.0  0.0

julia> reshape(Vec64,ind_a_32,:)
ERROR: StackOverflowError:
Stacktrace:
 [1] reshape(A::Vector{Float64}, inds::Tuple{Int32, Colon}) (repeats 79984 times)
   @ OffsetArrays ~/.julia/packages/OffsetArrays/5zoKM/src/OffsetArrays.jl:306

julia> reshape(Vec32,ind_a_32,:)
ERROR: StackOverflowError:
Stacktrace:
 [1] reshape(A::Vector{Float32}, inds::Tuple{Int32, Colon}) (repeats 79984 times)
   @ OffsetArrays ~/.julia/packages/OffsetArrays/5zoKM/src/OffsetArrays.jl:306

julia> reshape(Vec32,ind_a_32,2)
3×2 Matrix{Float32}:
 0.0  0.0
 0.0  0.0
 0.0  0.0
julia> VERSION
v"1.6.0"

@johnnychen94
Copy link
Member

johnnychen94 commented May 13, 2021

Julia explicitly uses Int as index type (See Base.Dims). For some indices-related functions, there might be fallback methods for Integer types, but many functions don't.

julia> x = rand(8, 8);

julia> reshape(x, 4, :)
4×16 Matrix{Float64}:
 0.690637  0.555645  0.821886  0.406586  0.539375     0.0998133  0.546501  0.913381  0.778848
 0.189625  0.559087  0.849438  0.163502  0.0132832     0.769946   0.951078  0.20459   0.38723
 0.901638  0.48459   0.471441  0.440043  0.256732      0.23922    0.506384  0.482037  0.120117
 0.377634  0.161835  0.841939  0.722828  0.877613      0.0740276  0.066585  0.820278  0.807347

julia> reshape(x, Int32(4), :)
ERROR: MethodError: no method matching reshape(::Matrix{Float64}, ::Int32, ::Colon)

The StackOverFlow is not good, so definitely needs improvement.

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

Successfully merging a pull request may close this issue.

2 participants