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

Improve Strided Arrays interface documentation with "user-defined" example #32560

Open
JeffFessler opened this issue Jul 12, 2019 · 5 comments
Open
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation

Comments

@JeffFessler
Copy link
Contributor

JeffFessler commented Jul 12, 2019

The documentation for Strided Array interfaces needs a "user-defined" example.
https://docs.julialang.org/en/latest/manual/interfaces/#man-interface-strided-arrays-1

(Updated url: https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-strided-arrays)

The text there says "A typical example of a user-defined strided array is one that wraps a standard Array with additional structure." But the only examples given are pre-existing data types. I made my own attempt at a strided array and it works, but matrix multiplication operations with it seem to be no faster than for a generic AbstractArray leaving me wondering what was the benefit of endowing my data type with a strides() method. Having a "typical example" where adding strides() is beneficial would be very useful in the manual, even if just a URL pointing to some package that uses it.

This is especially subtle here because "user-defined" might be read as meaning that one can define a subtype of a StridedArray, but I found out the hard way that one cannot because it is a Union type. (Mentioning that limitation explicitly in the manual would be good.)

I realize there is ongoing work to improve the docstring here #28144 and to improve the reference section of the manual here #26150.
And there are many open topics related to improving the stride interface #30432 JuliaLang/LinearAlgebra.jl#186 and general discussions about the array hierarchy #987.
I am also aware of the Strided.jl package, but its documentation also does not give any examples of user-defined strided arrays, only wrappers around preexisting array types.

I would have submitted PR instead of a new issue if I had a compelling example.

@kshyatt kshyatt added arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation labels Jul 22, 2019
@cmichelenstrofer
Copy link
Contributor

I am reading through the manual (it is great! :) ) and this is the first time I got stumped. I don't get it, at all. It says the strides are in memory, but then in the example the strides are in the values. The benefit is not clear at all either.

@JeffFessler
Copy link
Contributor Author

the strides are in the value

What is the URL of that example?

@cmichelenstrofer
Copy link
Contributor

The link is the one you shared above. I am probably misunderstanding the whole concept tbh (I don't have a CS background). The example is:

1:5   # not strided (there is no storage associated with this array.)
Vector(1:5)  # is strided with strides (1,)
A = [1 5; 2 6; 3 7; 4 8]  # is strided with strides (1,4)
V = view(A, 1:2, :)   # is strided with strides (1,4)
V = view(A, 1:2:3, 1:2)   # is strided with strides (2,4)
V = view(A, [1,2,4], :)   # is not strided, as the spacing between rows is not fixed.

@JeffFessler
Copy link
Contributor Author

The strides documented there are the related to the spacings of elements in memory:
https://en.wikipedia.org/wiki/Stride_of_an_array
It has nothing to do with the actual values stored in memory.
Vector(5:10:25) is also strided with strides (1,) and probably the example should be changed to something like that to make it more clear.

@cmichelenstrofer
Copy link
Contributor

That example helps a lot! Since the "stride" in values is different from the stride (in memory). Thanks, I finally get it! I think an example where the values have no obvious pattern (e.g. using randn) would also be beneficial.

The other thing I realize now and I was missing is that view is a wrapper array. Giving a preview of how view is defined would be extremely helpful and make it more clear what the stride is.

I think those two changes would go a long way to help people who are seeing this concept for the first time (like me). And then, as you mention, a real example of how this is useful would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation
Projects
None yet
Development

No branches or pull requests

3 participants