Skip to content

Commit 0c88cd1

Browse files
Merge pull request #29 from JuliaDiffEq/7
fix v0.7 indexing
2 parents 9c4a4f4 + c4462c5 commit 0c88cd1

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

src/array_partition.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ end
144144

145145
## indexing
146146

147+
# Interface for the linear indexing. This is just a view of the underlying nested structure
148+
@static if VERSION >= v"0.7-"
149+
@inline Base.firstindex(A::ArrayPartition) = 1
150+
@inline Base.lastindex(A::ArrayPartition) = length(A)
151+
else
152+
@inline Base.endof(A::ArrayPartition) = length(A)
153+
end
154+
147155
@inline function Base.getindex(A::ArrayPartition, i::Int)
148156
@boundscheck checkbounds(A, i)
149157
@inbounds for j in 1:length(A.x)

src/utils.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,6 @@ function recursive_mean(vecvec::Vector{T}) where T<:AbstractArray
113113
out/length(vecvec)
114114
end
115115

116-
function recursive_mean(matarr::Matrix{T},region=0) where T<:AbstractArray
117-
if region == 0
118-
return recursive_mean(vec(matarr))
119-
elseif region == 1
120-
out = [zeros(matarr[1,i]) for i in 1:size(matarr,2)]
121-
for j in 1:size(matarr,2), i in 1:size(matarr,1)
122-
out[j] += matarr[i,j]
123-
end
124-
return out/size(matarr,1)
125-
elseif region == 2
126-
return recursive_mean(matarr',1)
127-
end
128-
end
129-
130-
131116
# From Iterators.jl. Moved here since Iterators.jl is not precompile safe anymore.
132117

133118
# Concatenate the output of n iterators

src/vector_of_array.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ DiffEqArray(vec::AbstractVector,ts::AbstractVector) = DiffEqArray(vec, ts, (size
1818

1919

2020
# Interface for the linear indexing. This is just a view of the underlying nested structure
21-
@inline Base.endof(VA::AbstractVectorOfArray) = endof(VA.u)
21+
@static if VERSION >= v"0.7-"
22+
@inline Base.firstindex(VA::AbstractVectorOfArray) = firstindex(VA.u)
23+
@inline Base.lastindex(VA::AbstractVectorOfArray) = lastindex(VA.u)
24+
else
25+
@inline Base.endof(VA::AbstractVectorOfArray) = endof(VA.u)
26+
end
27+
2228
@inline Base.length(VA::AbstractVectorOfArray) = length(VA.u)
2329
@inline Base.eachindex(VA::AbstractVectorOfArray) = Base.OneTo(length(VA.u))
2430
@inline Base.iteratorsize(VA::AbstractVectorOfArray) = Base.HasLength()

test/utils_test.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ data = convert(Array,randomized)
1010
A = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]]
1111
@test recursive_mean(A) [2.33333333 3.666666666
1212
4.6666666666 6.0]
13-
B = Matrix{Matrix{Int64}}(2,3)
14-
B[1,:] = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]]
15-
B[2,:] = [[1 2; 3 4],[1 5;4 3],[5 8;2 1]]
16-
17-
ans = [[1 2; 3 4],[1 4; 4 4.5],[5 7; 4.5 4.5]]
18-
@test recursive_mean(B,1)[1] ans[1]
19-
@test recursive_mean(B,1)[2] ans[2]
20-
@test recursive_mean(B,1)[3] ans[3]
21-
22-
ans = [[2.333333333333 4.666666666666; 3.6666666666666 6.0], [2.3333333 3.0; 5.0 2.6666666]]
23-
@test recursive_mean(B,2)[1] ans[1]
24-
@test recursive_mean(B,2)[2] ans[2]
2513

2614
A = zeros(5,5)
2715
recursive_unitless_eltype(A) == Float64

0 commit comments

Comments
 (0)