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

Incorrect result on SubArray of OffsetArray #406

Closed
johnnychen94 opened this issue May 30, 2022 · 2 comments
Closed

Incorrect result on SubArray of OffsetArray #406

johnnychen94 opened this issue May 30, 2022 · 2 comments

Comments

@johnnychen94
Copy link

johnnychen94 commented May 30, 2022

It seems that axes checking is fooled by the nested array types -- I'm not sure if this should be fixed in OffsetArray, ArrayInterface or here.

using LoopVectorization, OffsetArrays
function favx!(out, A)
    @turbo for i in eachindex(out, A)
        out[i] = A[i]
    end
    return out
end

A = centered([1, 2, 3, 4, 5])
out = similar(A)
favx!(out, A) # correct: [1, 2, 3, 4, 5]

out = @view centered(zeros(eltype(A), 5, 5))[:, begin] # SubArray of OffsetArray
favx!(out, A) # incorrect [4, 5, 0, 0, 0]
@chriselrod
Copy link
Member

julia> using ArrayInterface, OffsetArrays, ArrayInterfaceOffsetArrays

julia> A = OffsetArrays.centered([1, 2, 3, 4, 5]);

julia> out = @view OffsetArrays.centered(zeros(eltype(A), 5, 5))[:, begin]; # SubArray of OffsetArray

julia> ArrayInterface.offsets(A)
(-2,)

julia> ArrayInterface.offsets(out)
(static(1),)

So this is a problem with ArrayInterface.

axes_types is also wrong:

julia> ArrayInterface.axes_types(out)
Tuple{Base.OneTo{Int64}}

julia> ArrayInterface.axes_types(A)
Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}

julia> typeof(axes(out))
Tuple{Base.IdentityUnitRange{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}}

julia> typeof(axes(A))
Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}

@johnnychen94
Copy link
Author

Close in favor of the ArrayInterface one.

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