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

Element type of an OffsetArray must match that of the parent array #162

Closed
jishnub opened this issue Oct 7, 2020 · 2 comments · Fixed by #163
Closed

Element type of an OffsetArray must match that of the parent array #162

jishnub opened this issue Oct 7, 2020 · 2 comments · Fixed by #163

Comments

@jishnub
Copy link
Member

jishnub commented Oct 7, 2020

OffsetArray merely provides a map between indices, so it should always have the same element type as the parent array. Currently something like this is possible:

julia> b = OffsetArray{Float64,2,Matrix{ComplexF64}}(zeros(ComplexF64,2,2), (1,1))
2×2 OffsetArray(::Array{Complex{Float64},2}, 2:3, 2:3) with eltype Float64 with indices 2:3×2:3:
 0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im

julia> b[1]
0.0 + 0.0im

julia> eltype(b)
Float64

This should be a bug. Would disallowing this be construed as a breaking change?

@johnnychen94
Copy link
Member

Good catch!

we may just add one more type check in

function OffsetArray{T, N, AA}(parent::AA, offsets::NTuple{N, Int}) where {T, N, AA<:AbstractArray}
@boundscheck overflow_check.(axes(parent), offsets)
new{T, N, AA}(parent, offsets)
end

a patch release seems good to me.

@timholy
Copy link
Member

timholy commented Oct 7, 2020

Clearly a bugfix. If it breaks anything, well it's just a case of

image

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.

3 participants