-
-
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
Move Cartesian to base #5387
Move Cartesian to base #5387
Conversation
Also CC @carlobaldassi |
|
I should have added: in my view this material is quite reasonable for 0.3, but we shouldn't export any of Cartesian. (No exports have been added in this PR.) The advantages of merging sooner rather than later are that:
|
Wow. A net -400 lines to get speedups puts this change in a distinguished category indeed. I think we're all on the same page that needing to switch to an alternate syntactic universe of |
Wow, this is super impressive. I think the last major change that was anywhere near this big of a net code deletion was the sort refactor. While I agree that we definitely want to move past doing all of this with macros, I think this is a good intermediate point and the macros tell us what kinds of things language primitives need to be able to do well. I'm all for merging it once various TODOs are taken care of. |
Totally cool. I put them back. I also:
If you disagree with any of these, feel free to make changes. |
I'm glad that you were able to make sense of #2591 :) and thanks for putting them back. This looks really impressive! |
Woot! Now let's wait for the bug reports to start flowing in... Next issue: with the exception of the |
One of the things I love about julia is it's readability, so while I really appreciate the speed improvements and reduction in code, and at a high level I understand what you're doing, da8f1dd is somewhat opaque to me. |
Mmh, yes, I vaguely remember about a time when I used to know how those BitArray functions worked ;) More seriously, nice job! I'll look into this issue of getting rid of |
@kmsquire, For any function that has historically been implemented using linear indexing and gets migrated to Cartesian, all one really needs to know is one screenful's worth of documentation. From that perspective, it's perhaps not so bad. But I share your concern, and for that reason I am genuinely of two minds about whether more examples like |
@carlobaldassi, no hurry. I may be able to help, too, but like you for now I should move on to other things. Thanks for your interest, though! |
@kmsquire and others, to see the macros in operation just do something like this:
where you just copy-paste the whole function definition (including the |
Thanks, Tim. I really do find this work quote impressive! |
I'm not going to revert this, but it was merged slightly hastily. We have lost a lot of type information in the changed functions, due to calling a function taken from a dictionary. In many cases this can be fixed using the pattern:
|
Sorry, I interpreted earlier comments as a go-ahead. I was about to say that they already work that way: Should be fixed by c6d359b. Let me know about other problems. |
Perhaps we should have type checks in the tests for those functions? On Wednesday, January 15, 2014, Tim Holy wrote:
|
Okay, I see that you are two steps ahead of me, Tim. :-) |
sum(A::AbstractArray{Bool}, region) = sum!(reduction_init(A,region,0), A) | ||
eval(ngenerate(:N, :(sum!{T,N}(R::AbstractArray, A::AbstractArray{T,N})), N->gen_reduction_body(N, +))) | ||
prod{T}(A::AbstractArray{T}, region) = prod!(reduction_init(A,region,one(T)), A) | ||
eval(ngenerate(:N, :(prod!{T,N}(R::AbstractArray, A::AbstractArray{T,N})), N->gen_reduction_body(N, *))) |
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.
Can we bring back something like Dahua's @code_reducedim
to make these easier to read?
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.
That's kind of what @ngenerate
is, but I didn't want to use it here because I was re-using a body-generator. But I can create a macro for that, too---good idea.
@timholy I think you might want to add the document, so people can learn to use these? |
I've not added anything to Julia's documentation because I think these should remain unexported---we all hope they'll go away ASAP. Most of it is documented pretty thoroughly in Cartesian.jl (there were only small changes needed for the transition into base), but perhaps I should add some description of |
* Use setindex_shape_check and DimensionMismatch instead of generic errors; this (and a couple of extra minor fixes) makes BitArrays behave like Arrays (again) * Move portions of the indexing code to multidimensional.jl * Restrict signatures so as to avoid to_index and convert, then create very generic methods which do the conversion and the dispatch: this greatly simplifies the logic and removes most of the need for disambiguation. Should also improve code generation.
This introduces a new-and-improved version of Cartesian, and rewrites certain functionality from base to use it.
Main points:
@ngenerate
that takes away most of the "wrapper pain" from using Cartesiangetindex
,setindex!
,reducedim
, andbroadcast
.cartesian.jl
(a 400+ line file), this leads to a net reduction of the codebase by approximately 400 lines; almost 800 lines were deleted by reimplementing just those 4 core functions.broadcast
, the new version is more general in that it supportsAbstractArray
s and not justStridedArray
s.fill!
.TODO:
broadcast_getindex
andbroadcast_setindex!
are supposed to work (what are theinds
arrays?); these function have been deleted from this PR, but can be restored if needed.BitArray
functions, so thatgen_cartesian_map
could be eliminated. I chickened out in the face of their complexity, but if this PR makes it in we could do that at a later time.All times are after suitable warmup.
On master:
This PR:
Approximately 7-fold better.
Other times are shown below. Test code is in this gist, as are the results of running
arrayperf
intest/
.reducedim
(first set of rows is for Arrays, 2nd for SubArrays; left column is the region, middle column is timing for master, right column is this PR):arrayperf results are in the gist.
CC @lindahua, @toivoh.