Skip to content

Commit

Permalink
Fix mean with dimension argument
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Aug 15, 2018
1 parent ab4904c commit db2709f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DistributedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module DistributedArrays
using Distributed
using Serialization
using LinearAlgebra
using Statistics

import Base: +, -, *, div, mod, rem, &, |, xor
import Base.Callable
Expand Down
3 changes: 3 additions & 0 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function Base.mapreducedim!(f, op, R::DArray, A::DArray)
return mapreducedim_between!(identity, op, R, B, region)
end

## Some special cases
function Base._all(f, A::DArray, ::Colon)
B = asyncmap(procs(A)) do p
remotecall_fetch(p) do
Expand Down Expand Up @@ -159,6 +160,8 @@ function Base.extrema(d::DArray)
return reduce((t,s) -> (min(t[1], s[1]), max(t[2], s[2])), r)
end

Statistics._mean(A::DArray, region) = sum(A, dims = region) ./ prod((size(A, i) for i in region))

# Unary vector functions
(-)(D::DArray) = map(-, D)

Expand Down
2 changes: 1 addition & 1 deletion test/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ check_leaks()
@testset "test statistical functions on DArrays" begin
dims = (20,20,20)
DA = drandn(dims)
A = convert(Array, DA)
A = Array(DA)

@testset "test $f for dimension $dms" for f in (mean, ), dms in (1, 2, 3, (1,2), (1,3), (2,3), (1,2,3))
# std is pending implementation
Expand Down

0 comments on commit db2709f

Please sign in to comment.