Browse files

fix #5823, mean() over dimension of integer arrays

  • Loading branch information...
1 parent 639abc6 commit 499e418623e7828f4ec8b535d120caaf050da2df @JeffBezanson JeffBezanson committed Feb 17, 2014
Showing with 4 additions and 2 deletions.
  1. +2 −1 base/statistics.jl
  2. +2 −1 test/statistics.jl
View
3 base/statistics.jl
@@ -17,7 +17,8 @@ mean(v::AbstractArray) = sum(v) / length(v)
function mean(v::AbstractArray, region)
rs = regionsize(v, region)
- dst = sum(v, region)
+ dst = reduction_init(v, region, zero((v[1]+v[1])/rs))
+ sum!(dst, v)
if rs != 1
for i = 1 : length(dst)
@inbounds dst[i] /= rs
View
3 test/statistics.jl
@@ -17,7 +17,8 @@
@test_throws median([NaN,0.0])
@test mean([1,2,3]) == 2.
-@test mean([0 1 2; 4 5 6], 1) == [2. 3. 4.]
+@test mean([0 1 2; 4 5 6], 1) == [2. 3. 4.]
+@test mean([1 2 3; 4 5 6], 1) == [2.5 3.5 4.5]
@test var([1,2,3]) == 1.
@test var(1:8) == 6.
@test var([1 2 3 4 5; 6 7 8 9 10], 2) == [2.5 2.5]'

0 comments on commit 499e418

Please sign in to comment.