-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Remove the "experimental" status from non-1 indexing #24899
Conversation
Funny coincidence, I asked if we could do just this the other day in slack :)
Perhaps we can add a |
Why can't we just do |
I wanted to be certain there would be no runtime penalty, so wanted the type system to make the decision. But for all1(A::AbstractArray) = all(r->first(r)==1, indices(A)) compiles down to a no-op on 0.7. I'm still not used to how good constant-propagation has gotten! |
I'm thinking of going with |
I'm going to assume this is considered non-breaking and can be finished after the feature freeze, since all it amounts to is putting guards in place that are currently triggered by |
Yes, I think that's reasonable. Fixing this should break any code that isn't already broken. |
302f648
to
9b89086
Compare
OK, here's a big PR. I manually reviewed nearly every use of The PR became a bit of a grab-bag because I noticed other issues as I went and generally tried to fix them. Most are fairly straightforward. |
Just to be clear, this should be entirely non-breaking, right? |
In principle, completely non-breaking. Though it looks as if, locally, I accidentally tested the master branch rather than this one. Will fix. The caveats: I suppose the main risk is that I put some kind of guard in place on something that formerly worked despite my impression from reading the code. My strategy here was to search for functions that call Changing the parametrization of a couple constructors could also be construed as breaking, though. I do think those were the intent of those constructors. But if I'm wrong I can rework that patch. |
01d9041
to
041a636
Compare
OK, I decided I will split out the cleanups to the LinearAlgebra constructors into a separate PR---it's a separate (and important) enough change that it merits a different set of eyeballs. That does imply that the protection isn't yet complete here, but the combination of the 2 PRs should do it. Since this touches so many files it is a bit of a magnet for merge conflicts, so I'd like to get this in without unnecessary delay. |
041a636
to
b80321c
Compare
One thing to ask about: I went with the name I suggested above, Would its converse---something like Another question is whether we should export this or not. |
FYI I'm going to be out of touch starting Friday July 13. To ensure there's time to shake out any bugs after this gets merged, and to ensure that part 2 of this project gets adequate time for review, I'll merge this by tomorrow morning barring any objections. The name issue (see the post above this one) is probably the main thing to check. |
b80321c
to
c8bd989
Compare
OK, I went with |
Dang, circleci is taking a long time. I'm tempted to merge without it, given my time constraints (#24899 (comment)). Complain now or I'll hit merge shortly. |
As long as you get ~1 pass per platform it's fine, so Travis OR Circle CI for Linux are good enough. I've restarted the Travis 64-bit Linux run which seemed to have failed due to the ongoing httpbin flakiness. |
OK. That test did get through printing "SUCCESS" before starting on the Pkg tests. That was were the failure seemed to occur, perhaps by just overfilling its log? I can't remember how to dig out the previous run, but I thought it looked exactly like this one: https://travis-ci.org/JuliaLang/julia/jobs/402239980. If you scroll down to the end you'll see it's almost like travis just got tired of recording the output. |
NEWS.md
Outdated
@@ -226,6 +226,10 @@ Language changes | |||
* `try` blocks without `catch` or `finally` are no longer allowed. An explicit empty | |||
`catch` block should be written instead ([#27554]). | |||
|
|||
* `AbstractArray` types that use unconventional (not 1-based) indexing can now support | |||
`size`, `length`, and `@inbounds`. To optionally enforce conventional indices, | |||
you can `@assert is_one_indexed(A)`. |
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 still has the old name here. I find the !is_non1_indexed
suboptimal. What about is_offset_indexed
or has_offset_axes
?
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.
Oooh, I like those! Will change to has_offset_axes
.
base/abstractarray.jl
Outdated
|
||
This defaults to false for an arbitrary object. | ||
""" | ||
is_non1_indexed(obj) = false # this is not a required trait |
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.
I think I'd be okay with calling this has_offset_axes
and then requiring axes
to be defined. It's still not defined for Tuples, but I say we rectify that. Everything else that supports broadcasting needs to support axes, so it doesn't seem to be that big of a requirement.
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.
It's not just Tuples, it's also SuiteSparse.Sparse
and a few other similar "opaque" objects. I guess we could define axes
for them too, since even <:Factorization
has axes
defined.
But this raises the thought that going with is_offset_indexed
might be better, depending on whether we think indexing or axes
is the more "fundamental" operation.
Sorry I was slow on the review here! Somehow you managed to work on this during both of my recent vacations. This looks great — and will make working with Offset Arrays so much nicer. |
ce387e8
to
bff597f
Compare
doc/src/devdocs/offset-arrays.md
Outdated
if you can index outside the range `1:size(A,d)` (and not just `0:size(A,d)-1`, either). Such | ||
array types are expected to be supplied through packages. | ||
if you can index outside the range `1:size(A,d)` (and not just `0:size(A,d)-1`, either). | ||
To facilitate such computations, Julia supports array with arbitrary indices. |
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.
arrays
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.
Just a few doc comments, otherwise this is ready to go!
doc/src/devdocs/offset-arrays.md
Outdated
If you find it more convenient to just force your users to supply traditional arrays where indexing starts at one, you can add | ||
|
||
```julia | ||
@assert !Base.is_non1_indexed(arrays...) |
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.
has_offset_axes
doc/src/devdocs/offset-arrays.md
Outdated
## Summary | ||
### For objects that mimic AbstractArray but are not subtypes | ||
|
||
`is_non1_indexed` has a specialized implementation for `AbstractArrays` |
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.
has_offset_axes
here and immediately below, and it no longer defaults to false
a7d8629
to
26c38b3
Compare
26c38b3
to
909f912
Compare
This is now permitted due to JuliaLang/julia#24899
This is now permitted due to JuliaLang/julia#24899
I don't know which factors contributed most, but there's good news about the performance of OffsetArrays: https://discourse.julialang.org/t/performance-of-offsetarrays/5769/5?u=tim.holy In the fullness of time, Julia consistently lets you write code the way it should be written. |
This is now permitted due to JuliaLang/julia#24899
Remove the "experimental" status from non-1 indexing
This is a start at "taking off the training wheels" on custom indexing and allow packages like OffsetArrays to support
size
,length
, and@inbounds
.So far this is almost exclusively documentation. The bigger part of the change will be to make Base safe for this change in policy. That means that for any function that calls
size
orlength
, we either need to generalize it or callassert_oneindex(A)
(new to this PR). Overwhelmingly, the main place we'll need to add this is thelinalg
andsparse
code.I didn't add
assert_oneindex
back in the 0.5 days because I hoped we might soon have traits and could have writtencholfact(A::AbstractMatrix::OneIndexing)
. But at this point, we just need to get this done manually.Before doing the big task, let's bikeshed the name and discuss any other issues folks can think of.