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

StackOverflowError in similar with Colons #122

Closed
jishnub opened this issue Jun 26, 2020 · 0 comments
Closed

StackOverflowError in similar with Colons #122

jishnub opened this issue Jun 26, 2020 · 0 comments

Comments

@jishnub
Copy link
Member

jishnub commented Jun 26, 2020

julia> oa = OffsetArray(rand(3,3),-1:1,-1:1)
3×3 OffsetArray(::Array{Float64,2}, -1:1, -1:1) with eltype Float64 with indices -1:1×-1:1:
 0.780486  0.736212  0.62076
 0.465256  0.477541  0.478559
 0.839068  0.50454   0.0118495

julia> similar(oa, Float64, (:,:))
ERROR: StackOverflowError:
Stacktrace:
 [1] similar(::OffsetArray{Float64,2,Array{Float64,2}}, ::Type{Float64}, ::Tuple{Colon,Colon}) at /home/jishnu/.julia/packages/OffsetArrays/Z45he/src/OffsetArrays.jl:102 (repeats 79984 times)

Presumably this happens because

function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where T
B = similar(A, T, map(indexlength, inds))
return OffsetArray(B, map(offset, axes(B), inds))
end

and

indexlength(i::Colon) = Colon()

johnnychen94 pushed a commit that referenced this issue Jul 24, 2020
This attempts to get around #122 by explicitly preventing colons being passed to similar. This means that the StackOverflowError now becomes a MethodError
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

2 participants