-
-
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
make cumsum result type consistent with sum #9665
Conversation
…use same codepath for 1d arrays (see discussion in JuliaLang#9650)
Hmm, getting:
Not sure how this patch is causing that failure, since |
Could it be https://github.com/JuliaLang/julia/blob/master/base/sparse/sparsematrix.jl#L1078 that now widens the integer type? |
+1 on the pairwise behavior. Neutral on the promotion. The promotion argument is strong for |
Yikes, yes, |
It shouldn't be difficult to adapt the sparse code to this change, if we want it. |
+1 for this |
Seems odd to me to have |
It also seems odd to have While we removed promotion from |
@tkelman, |
I have no problem with |
OTOH if |
I'm also concerned about this breaking all of the sparse code. We can grep for |
There are only 6 mentions of Off-topic, but it would be nice to know what you'd want to do in a rewrite of the sparse code. Perhaps file an issue with your thoughts? I plan to hack on it over the next few days. |
And elsewhere in base? In packages that deal with sparse matrices?
I already more or less did, JuliaLang/LinearAlgebra.jl#136. I'd like sparse matrices to be first class in terms of the array operations and reductions that work efficiently on them. A few days of hacking can improve things gradually, but I'm envisioning a more comprehensive rewrite that will need changes to the way the rest of the standard library interacts with array objects to make sparse or dense both work well. A more formal concept of interfaces, and a few generic iterator protocols will likely be required here. |
Just to make sure the bikeshedding stays in perspective:
|
Yes, that part absolutely makes sense.
You're also returning an array. I really strongly dislike element type promotion in functions that return arrays. |
@timholy, you don't need this patch to control the answer, because But that being said, I'm fine with dropping the promotion, and just pushing the patch for the change in |
Sounds fine, let's do it that way. We may want to add something to the docs for
|
There is nothing in
|
That's fine, and closer to what I originally wrote. I was just trying to be brief. |
Why brief, when we get so much complains that people don't understand our documentation and people beg for examples? |
Seems like @stevengj just nailed it and wrote something both brief and correct. |
Entirely reasonable. |
This means that
cumsum(Int8[1,2,3])
isInt[1,3,6]
rather than anInt8
array, for example. If you really want to do the sum asInt8
, you can still documsum!(Array(Int8,3), Int8[1,2,3])
.In principle, this is a breaking change, but I'm not sure if any code in the wild actually relied on the lack of promotion in the cumsum results? (The most common usage seems to be for
Float64
andFloat32
arrays, which are unaffected.)Also, this makes
cumsum!
andcumsum
use the same pairwise code for 1d arrays (whereas previouslycumsum!
used a completely different codepath based on the one for multidimensional arrays, which just does naive summation). Ideally, we'd use the pairwise algorithm for multidimensional arrays too, but that requires a much bigger code rewrite.(See discussion in #9650 with @timholy.)