You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is inconsistent with how non-cumulative functions work in Julia, e.g.:
julia> A =rand(3,4)
3×4 Array{Float64,2}:0.2391830.4205380.7600690.3495760.7688020.9245630.9346260.4468430.7678480.7615470.5185250.758667
julia>sum(A)
7.650786585136748
julia>cumsum(A)
3×4 Array{Float64,2}:0.2391830.4205380.7600690.3495761.007981.34511.69470.7964191.775832.106652.213221.55509
Correspondingly, cumsum(A) should, rather than asymmetrically defaulting to the first dimension, either be an error, or return an accumulation of the elements of A such that cumsum(A)[end] == sum(A) and such that cumsum(v')' == cumsum(v) for any vector v. One possibility is performing a cumulative sum in column-major order. Another is that each output value is the sum of values to the values to the left or above that slot in the intput. I.e.:
julia> [sum(A[1:i,1:j]) for i=1:size(A,1), j=1:size(A,2)]
3×4 Array{Float64,2}:0.2391830.659721.419791.769371.007982.353084.047784.84421.775833.882486.09577.65079
This answer has the above properties, can be computed efficiently, and is useful.
The text was updated successfully, but these errors were encountered:
I agree that cumsum shouldn't default to dim=1 but I think it is better to throw an error if no dimension is specified and ndims>1. I don't like that storage order becomes significant for anything but performance and floating point errors. Short term, there would also be a deprecation issue.
I agree that it's not desirable for storage order to become semantically visible. That's why I proposed the [sum(A[1:i,1:j]) for i=1:size(A,1), j=1:size(A,2)] definition as well. Wanting cumsum(v')' == cumsum(v) may tie into JuliaLang/LinearAlgebra.jl#42 depending on how that pans out.
Make not supplying a dimension an error unless all dimensions but the first are singleton.
Make accumulate on a row vector work as accumulate(f, r.').'.
In the future, this could be generalized to the n-dimensional prefix summation behavior I proposed above, which is generally useful and ties the desired behavior for vectors and row vectors together.
This is inconsistent with how non-cumulative functions work in Julia, e.g.:
Correspondingly,
cumsum(A)
should, rather than asymmetrically defaulting to the first dimension, either be an error, or return an accumulation of the elements ofA
such thatcumsum(A)[end] == sum(A)
and such thatcumsum(v')' == cumsum(v)
for any vectorv
. One possibility is performing a cumulative sum in column-major order. Another is that each output value is the sum of values to the values to the left or above that slot in the intput. I.e.:This answer has the above properties, can be computed efficiently, and is useful.
The text was updated successfully, but these errors were encountered: