-
Notifications
You must be signed in to change notification settings - Fork 37
Safe functional indexing #316
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #316 +/- ##
==========================================
+ Coverage 91.74% 91.86% +0.12%
==========================================
Files 9 9
Lines 1429 1439 +10
==========================================
+ Hits 1311 1322 +11
+ Misses 118 117 -1
Continue to review full report at Codecov.
|
@wangl-cc, you're welcome to review this since it may be of interest to you. |
If julia> x = 1:2
1:2
julia> Meta.@lower x[begin:3]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = Base.firstindex(x)
│ %2 = %1:3
│ %3 = Base.getindex(x, %2)
└── return %3
)))) Besides, I think we can create some "functional range" like |
The reason I used min and max was because those functions are returning all indices below or above the provided value. This is the same as if you filtered the axis with those functions. Maybe this needs to be clarified more in the docs. We can't create a functional range like that because it would be type piracy. |
With this interpretation, I think keeping them always inbounds is OK.
Maybe we can create new types as alternatives to |
There is a package for the last suggestion, so it's probably more intuitive to do something similar or provide support through that package. I'll remove the |
This allows common comparison operators be parsed into indices (
<
,<=
,>
,>=
). So instead of doingx[3:end]
you can dox[>=(3)]
(ifx
usesArrayInterface.getindex
. The main utility right now is that we can ensure that the indices are always inbounds using this syntax. I'm still working out the best way to communicate this info tocheckbounds
so that bounds checking is passed over (similar to how:
becomesSlice
which is known to be inbounds); but that will probably be more involved so I'm going to make that a separate effort.