-
-
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
RFC: Move Colon translation out of the parser #10331
Conversation
@@ -67,6 +67,8 @@ immutable UnitRange{T<:Real} <: OrdinalRange{T,Int} | |||
end | |||
UnitRange{T<:Real}(start::T, stop::T) = UnitRange{T}(start, stop) | |||
|
|||
colon() = Colon() |
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 don't think we need this. colon
is never called with 0 arguments as far as I know. The front end can just produce (top :)
or (call (top Colon))
instead.
Nice! This is something I've wanted for a while. |
ref #9419 |
Sorry, can you give a little more detail about what you want me to look at? Currently I don't think there is a My current proposal is that this shouldn't involve any metaprogramming at all: it should be
and let a new reshape handle it. I suspect it will be cleaner and more efficient. (There is at least one nasty SubArray method I'm looking forward to deleting, if that proposal passes muster.) |
Sure. I'm slowly grokking Cartesian more and more as I work my way through this, myself, too. Right now, indexing a SubArray with a Colon() bails in the middle of the complicated Thanks for taking a look. :) |
|
Any comments you have on the reshape proposal would certainly be helpful, though. I'm worried about the nesting, but since it allows us to avoid calling |
By using recursive multiple dispatch for the index_shape with that extra dims argument, we seem to be running up against an inference boundary one dimension sooner than on master here: julia> Base.return_types(getindex, (Array{Int,4}, UnitRange{Int}, Int))
1-element Array{Any,1}:
Array{Int64,1}
julia> # This is well-typed and returns a Matrix on master, but not on this branch
Base.return_types(getindex, (Array{Int,4}, UnitRange{Int}, UnitRange{Int}, Int))
1-element Array{Any,1}:
Array{T,N}
julia> # Inference isn't precise on either my branch or master
Base.return_types(getindex, (Array{Int,4}, UnitRange{Int}, UnitRange{Int}, UnitRange{Int}, Int))
1-element Array{Any,1}:
Array{T,N} |
I like the reshape proposal, but I don't understand the comment that this avoids calling |
Thanks for looking! Regarding |
Great, looking forward to that. But probably it's still a good idea to reimplement stagedfunction myind2sub{N}(dims::NTuple{N,Integer}, ind::Integer)
subsyms = [symbol("i$k") for k=1:N]
subex = Expr(:block,[:($(subsyms[k])=rem(ind,dims[$k])+1;ind=div(ind,dims[$k])) for k=1:N-1]...)
quote
ind-=1
$(subex)
$(subsyms[N]) = ind+1
$(Expr(:tuple,subsyms...))
end
end I already obtain
I'll submit a PR later today. |
👍 |
On a related note, although I apologize for hijacking the original discussion, should we also have a |
There seemed to be some enthusiasm for this general idea in #6837. Not exactly sure what you mean by "type parameter cannot be determined at compile time," can you elaborate? I presume you're thinking of putting the actual permutation as a tuple into the parameters. If you can't get julia to dispatch on the tuple, you can use a 2-stage process:
The |
I did indeed not explain myself properly, I meant, at the time where the |
Got it. I agree that it's not necessary to infer the permutation at compile time. Any computationally-heavy work should be in a separate function anyway. |
I'm on the case! I may have a fix for this soon. I've been limiting argument lists too aggressively. I'm trying to switch this to only limit argument lists that are growing due to recursion. |
Updated! Now the only blocker is #10341. I temporarily lowered the number of tested dimensions in the test-suite to see if AppVeyor or Travis will catch any other failures (all other tests pass on my machine). The other thing I think needs a conscious decision here is if or how we want to handle a deprecation-like warning. Custom array types in packages probably aren't prepared to handle |
Does Travis use 32-bit BLAS binaries? That was handy for catching a missing method that wasn't covered in the test suite. (It's tested now). |
32-bit-ints, yeah. Generally distributions don't ship ILP64 BLAS, if they do they better be really careful about marking them as conflicting with every other BLAS package. |
Hm, now there's a strange OS X failure that I'm not seeing locally:
All other platforms seem to be fine. |
Requires JuliaLang/julia#10331. But I think it is also running into a MAX_TUPLE_LEN issue, which is messing up my workaround for JuliaLang/julia#10191. Needs tests, too.
9a46031
to
3908e2b
Compare
Ok #10341 is merged. |
3908e2b
to
48fcacf
Compare
wha? |
Hah, I suppose I should have tried building this first. It's just that part of the indexing machinery isn't available by the time inference wants to use it. Should be a simple fix. |
Add news and a minor documentation update.
5/6 tests passed (one OOMkill). I'll rip the space-time continuum and reorder the commits so we don't have an intermediate breakage. I'd prefer to keep them separate since they're discrete operations. Then this will actually be good to go. |
82b5024
to
ca99175
Compare
Good call, thanks. I think I restarted a few other OOM failures here so the actual numbers were worse, but +1 for merging. |
@mbauman is having a hell of a week |
I'm all for it. |
Yes please |
Move Colon translation out of the parser
Done! |
💯 awesome! |
Cool! |
We should really start re-running appveyor on some of these more complicated PR's right before merging. This is freezing during second-stage inference builds on win64 https://ci.appveyor.com/project/StefanKarpinski/julia/build/1.0.5619/job/xln3xt63xsxs4m1i, |
we clearly need a better long-term strategy for this [av skip] because there's a separate failure right now, freezing from #10331
@tkelman I was going to re-enable the bad commit in my gc codgen PR to test this. Do you have a backtrace to see where it gets stuck? |
I don't think there's any way of getting a backtrace while frozen in compiling inference. Maybe I could try attaching gdb, but the backtraces aren't always great on Windows. I might have a much better fix, taking Colon |
I don't have any experience with backtrace on windows but that might be useful enough... |
|
This is a work
in progressto move the translation of[:]
out of the parser. I've squashed-and-split @andreasnoack's ambitious work from #9150 to exclude the bigger change (returning views from indexing with UnitRanges) and just focus on indexing withColon
. While this previously included the code that adapted base array types to acceptColon()
as an index, that portion was broken out and subsumed by #10525. This is now only the parser change.This is still a work-in-progress as it hasn't made it through the test suite yet. Right now the blocker is ingetindex(::SubArray, ::Colon)
, which is a pretty gnarly piece of metaprogramming. But I think it's pretty close. Would you have a chance to look into it, @timholy?This takes a cue from SubArray and doesn't even create a range for indexing into Array types, which is really cool. In general, this approach will require all customAbstractArray
types to allow indexing withColon
. We could define a fallbackgetindex(::AbstractArray, ::Union(Real, AbstractArray, Colon)…)
to do the lowering step, but it's then a little tricky for custom types to define their indexing methods without ambiguities.Todo:
SubArray getindex(subsumed by RFC: Give AbstractArrays smart and performant indexing behaviors for free #10525)SharedArray get/setindex!(subsumed by RFC: Give AbstractArrays smart and performant indexing behaviors for free #10525)Improve inference (RFH (request for help): LLVM assertion #10341) and revert a733b1f(subsumed by RFC: Give AbstractArrays smart and performant indexing behaviors for free #10525)Decide if we need a deprecation/warning strategy for indexing custom AbstractArray types withBecame non-breaking with RFC: Give AbstractArrays smart and performant indexing behaviors for free #10525.:
. I don't think this is possible in a sensible manner.Fixes #9419.