Skip to content

Commit 33b2a7a

Browse files
fix type piracy
1 parent 7df5c1d commit 33b2a7a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/RecursiveArrayTools.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ module RecursiveArrayTools
44

55
using Iterators
66

7-
import Base: mean
8-
97
include("utils.jl")
108
include("vector_of_array.jl")
119
include("array_partition.jl")
1210

1311
export VectorOfArray, AbstractVectorOfArray, vecarr_to_arr
1412

15-
export recursivecopy!, vecvecapply, copyat_or_push!, vecvec_to_mat, recursive_one,mean
13+
export recursivecopy!, vecvecapply, copyat_or_push!, vecvec_to_mat, recursive_one,
14+
recursive_mean
1615

1716
export ArrayPartition
1817

src/utils.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,25 @@ end
6666
recursive_one(a) = recursive_one(a[1])
6767
recursive_one{T<:Number}(a::T) = one(a)
6868

69-
function mean{T<:AbstractArray}(vecvec::Vector{T})
69+
recursive_mean(x) = mean(x)
70+
function recursive_mean{T<:AbstractArray}(vecvec::Vector{T})
7071
out = zeros(vecvec[1])
7172
for i in eachindex(vecvec)
7273
out+= vecvec[i]
7374
end
7475
out/length(vecvec)
7576
end
7677

77-
function mean{T<:AbstractArray}(matarr::Matrix{T},region=0)
78+
function recursive_mean{T<:AbstractArray}(matarr::Matrix{T},region=0)
7879
if region == 0
79-
return mean(vec(matarr))
80+
return recursive_mean(vec(matarr))
8081
elseif region == 1
8182
out = [zeros(matarr[1,i]) for i in 1:size(matarr,2)]
8283
for j in 1:size(matarr,2), i in 1:size(matarr,1)
8384
out[j] += matarr[i,j]
8485
end
8586
return out/size(matarr,1)
8687
elseif region == 2
87-
return mean(matarr',1)
88+
return recursive_mean(matarr',1)
8889
end
8990
end

test/utils_test.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ data = vecvec_to_mat(randomized)
2121

2222
## Test means
2323
A = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]]
24-
@test mean(A) [2.33333333 3.666666666
24+
@test recursive_mean(A) [2.33333333 3.666666666
2525
4.6666666666 6.0]
2626
B = Matrix{Matrix{Int64}}(2,3)
2727
B[1,:] = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]]
2828
B[2,:] = [[1 2; 3 4],[1 5;4 3],[5 8;2 1]]
2929

3030
ans = [[1 2; 3 4],[1 4; 4 4.5],[5 7; 4.5 4.5]]
31-
@test mean(B,1)[1] ans[1]
32-
@test mean(B,1)[2] ans[2]
33-
@test mean(B,1)[3] ans[3]
31+
@test recursive_mean(B,1)[1] ans[1]
32+
@test recursive_mean(B,1)[2] ans[2]
33+
@test recursive_mean(B,1)[3] ans[3]
3434

3535
ans = [[2.333333333333 4.666666666666; 3.6666666666666 6.0], [2.3333333 3.0; 5.0 2.6666666]]
36-
@test mean(B,2)[1] ans[1]
37-
@test mean(B,2)[2] ans[2]
36+
@test recursive_mean(B,2)[1] ans[1]
37+
@test recursive_mean(B,2)[2] ans[2]

0 commit comments

Comments
 (0)