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
Best practice on properly supporting OffsetArrays #281
Conversation
Codecov Report
@@ Coverage Diff @@
## master #281 +/- ##
=======================================
Coverage 95.90% 95.90%
=======================================
Files 5 5
Lines 464 464
=======================================
Hits 445 445
Misses 19 19 Continue to review full report at Codecov.
|
README.md
Outdated
-- use `for i in eachindex(x)` instead. | ||
- For multi-dimensional array, there are also `LinearIndices` and `CartesianIndices`. | ||
- Instead of checking the size `size(A) == size(B)`, check the axes `axes(A) == axes(B)`. | ||
- Use `OffsetArrays.no_offset_view(x)` to put everything back to 1-based indexing. But don't |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit vague, and I'm not certain that I fully understand the cases where it might not work. Maybe we can suggest OffsetArrays.no_offset_view
if one requires 1-indexed arrays in their own code, and Base.require_one_based_indexing
if they require users to pass 1-indexed arrays as arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I was thinking of the A * B
example for offset arrays -- for this we don't have a well-defined behavior on what axes should be used or what axes should be output, in this case, it's better to just use Base.require_one_based_indexing
and leave it to users to do the conversion.
(coming in as a julia newbie), maybe something like (this text is probably awful, feel free to edit / ignore) Only use
|
@ChrisJefferson this is a useful comment from my experience! The But I'm afraid the most appropriate place to put this comment is somewhere in the Julia documentation, I'll try to find out a place to add this and submit a PR to the upstream Julia repo. |
Isn't it best to merge this in whole (or in part? at least the pointer on I read the text and it seems fine by me (I'm not the expert). My proposal #284 (trying to avoid the issue) was closed. I may need to think it more carefully, until then having best (or better) practice is good. Please do not delay too much merging some "best" practice. Perfect is the enemy of the good. The text can always be improved later. |
There's also https://docs.julialang.org/en/v1/devdocs/offset-arrays/ which goes into more detail. |
This package is catching the eyes of the entire community, let's write some best practices on this so that people know how to handle it appropriately.
closes #282
cc: @t-bltg