@@ -2,98 +2,15 @@ __precompile__()
22
33module RecursiveArrayTools
44
5- import Base: mean
6-
7- function recursivecopy! {T<:Number,N} (b:: Array{T,N} ,a:: Array{T,N} )
8- @inbounds copy! (b,a)
9- end
10-
11- function recursivecopy! {T<:AbstractArray,N} (b:: Array{T,N} ,a:: Array{T,N} )
12- @inbounds for i in eachindex (a)
13- recursivecopy! (b[i],a[i])
14- end
15- end
16-
17- function vecvec_to_mat (vecvec)
18- mat = Matrix {eltype(eltype(vecvec))} (length (vecvec),length (vecvec[1 ]))
19- for i in 1 : length (vecvec)
20- mat[i,:] = vecvec[i]
21- end
22- mat
23- end
24-
25-
26- function vecvecapply (f,v)
27- sol = Vector {eltype(eltype(v))} (0 )
28- for i in eachindex (v)
29- for j in eachindex (v[i])
30- push! (sol,v[i][j])
31- end
32- end
33- f (sol)
34- end
5+ using Iterators
356
36- function vecvecapply {T<:Number} (f,v:: Array{T} )
37- f (v)
38- end
39-
40- function vecvecapply {T<:Number} (f,v:: T )
41- f (v)
42- end
43-
44- @inline function copyat_or_push! {T,perform_copy} (a:: AbstractVector{T} ,i:: Int ,x,nc:: Type{Val{perform_copy}} = Val{true })
45- @inbounds if length (a) >= i
46- if T <: Number || ! perform_copy
47- a[i] = x
48- else
49- recursivecopy! (a[i],x)
50- end
51- else
52- if eltype (x) <: Number && (typeof (x) <: Array || typeof (x) <: Number )
53- # Have to check that it's <: Array or can have problems
54- # with abstract arrays like MultiScaleModels.
55- # Have to check <: Number since it could just be a number...
56- if perform_copy
57- push! (a,copy (x))
58- else
59- push! (a,x)
60- end
61- else
62- if perform_copy
63- push! (a,deepcopy (x))
64- else
65- push! (a,x)
66- end
67- end
68- end
69- nothing
70- end
71-
72- recursive_one (a) = recursive_one (a[1 ])
73- recursive_one {T<:Number} (a:: T ) = one (a)
74-
75- function mean {T<:AbstractArray} (vecvec:: Vector{T} )
76- out = zeros (vecvec[1 ])
77- for i in eachindex (vecvec)
78- out+= vecvec[i]
79- end
80- out/ length (vecvec)
81- end
7+ import Base: mean
828
83- function mean {T<:AbstractArray} (matarr:: Matrix{T} ,region= 0 )
84- if region == 0
85- return mean (vec (matarr))
86- elseif region == 1
87- out = [zeros (matarr[1 ,i]) for i in 1 : size (matarr,2 )]
88- for j in 1 : size (matarr,2 ), i in 1 : size (matarr,1 )
89- out[j] += matarr[i,j]
90- end
91- return out/ size (matarr,1 )
92- elseif region == 2
93- return mean (matarr' ,1 )
94- end
95- end
9+ include (" utils.jl" )
10+ include (" array_partition.jl" )
9611
9712 export recursivecopy!, vecvecapply, copyat_or_push!, vecvec_to_mat, recursive_one,mean
9813
14+ export ArrayPartition
15+
9916end # module
0 commit comments