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

Bug in strides for reshaped views #2

Open
ranocha opened this issue Jun 2, 2021 · 4 comments
Open

Bug in strides for reshaped views #2

ranocha opened this issue Jun 2, 2021 · 4 comments

Comments

@ranocha
Copy link
Contributor

ranocha commented Jun 2, 2021

julia> using ArrayInterface

julia> u_base = randn(10, 10); u_view = view(u_base, 3, :); u_reshaped_view1 = reshape(u_view, 1, :); u_reshaped_view2 = reshape(u_view, 2, :);

julia> ArrayInterface.strides(u_reshaped_view1)
(static(1), 1)

julia> ArrayInterface.strides(u_reshaped_view2)
(static(1), 2)

These seem to be wrong, I think. Because of ArrayInterface.strides(u_view) == (10,), the strides should be

  • ArrayInterface.strides(u_reshaped_view1) = (10 #= doesn't matter since there is only one element in this dimension =#, 10)
  • ArrayInterface.strides(u_reshaped_view1) = (10, 20)

Is that correct?

@Tokazama
Copy link
Member

Tokazama commented Jun 2, 2021

It does seem to be wrong. We probably need to have more robust support for ReshapedArrays overall in "stridelayout.jl"

@ranocha
Copy link
Contributor Author

ranocha commented Jun 2, 2021

I will give it a shot.

@Tokazama
Copy link
Member

Tokazama commented Jun 6, 2021

I don't think we can actually guarantee that a ReshapedArray can combine with its parent strides unless we know that the the reshaped dimensions are contiguous and dense, because otherwise we would need to split strides. For example:

x = Array{Int}(undef, 5, 2, 5, 2); 
xv = view(x, :, 1, :, :);
xvr = reshape(xv, 10, 5)

If reshaping was done with static information we could figure this out at compile time, but with the current design of ReshapedArray we would have to compute all the parent strides and then see if one of the new dimensions is large enough to split parent strides.

@ranocha
Copy link
Contributor Author

ranocha commented Jun 7, 2021

Yeah, that's like JuliaArrays/ArrayInterface.jl#162 (comment)

@ChrisRackauckas ChrisRackauckas transferred this issue from JuliaArrays/ArrayInterface.jl Feb 18, 2023
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