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
mean(X; dims=2) not the same as mean of each row #29883
Comments
Yes AFAIK that's because simple |
It seems like we could just use the same algorithm for both, no? |
Not sure. When accumulating over non-contiguous slices, we need to store the result in an array (computing the sum one slice at a time would be much slower). So if we wanted to compute pairwise sum, we would have to allocate one such array per block. |
Note that there's no accumulation here, it's only reduction. The core of the sum reduction algorithm is: https://github.com/JuliaLang/julia/blob/f0017a4964f47d515492167d/base/reduce.jl#L153-L176 I don't think any temporary arrays are required to make such a change. |
Yes I meant reduction. But since reduction over dimensions computes the result for several slices in parallel (except for the special case of the first dimension), I think a temporary storage is needed for each block. See Lines 261 to 267 in f0017a4
|
Not sure if this is expected and/or acceptable behaviour, but I feel that it should at least be documented that
mean(X; dims=2)
can differ from[mean(X[i,:]) for i in 1:size(X,1)]
- at least if the means are very small. I believe this is due tomean(X; dims=n)
usingmean!
to calculate the mean over a given dimension, where as taking the mean of row calculates a "regular" mean (sum of elements divided by number of elements). Example output:The text was updated successfully, but these errors were encountered: