From 8869a6a38b6432f136afa209eef17e7b5d6b98ea Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 10 Jun 2018 15:56:48 -0700 Subject: [PATCH 1/2] fix v0.7 indexing --- src/array_partition.jl | 8 ++++++++ src/vector_of_array.jl | 8 +++++++- test/utils_test.jl | 14 +++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/array_partition.jl b/src/array_partition.jl index afe21f72..0dbaaf97 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -144,6 +144,14 @@ end ## indexing +# Interface for the linear indexing. This is just a view of the underlying nested structure +@static if VERSION >= v"0.7-" + @inline Base.firstindex(A::ArrayPartition) = 1 + @inline Base.lastindex(A::ArrayPartition) = length(A) +else + @inline Base.endof(A::ArrayPartition) = length(A) +end + @inline function Base.getindex(A::ArrayPartition, i::Int) @boundscheck checkbounds(A, i) @inbounds for j in 1:length(A.x) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index ed5c2bb8..e26bd838 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -18,7 +18,13 @@ DiffEqArray(vec::AbstractVector,ts::AbstractVector) = DiffEqArray(vec, ts, (size # Interface for the linear indexing. This is just a view of the underlying nested structure -@inline Base.endof(VA::AbstractVectorOfArray) = endof(VA.u) +@static if VERSION >= v"0.7-" + @inline Base.firstindex(VA::AbstractVectorOfArray) = firstindex(VA.u) + @inline Base.lastindex(VA::AbstractVectorOfArray) = lastindex(VA.u) +else + @inline Base.endof(VA::AbstractVectorOfArray) = endof(VA.u) +end + @inline Base.length(VA::AbstractVectorOfArray) = length(VA.u) @inline Base.eachindex(VA::AbstractVectorOfArray) = Base.OneTo(length(VA.u)) @inline Base.iteratorsize(VA::AbstractVectorOfArray) = Base.HasLength() diff --git a/test/utils_test.jl b/test/utils_test.jl index e156c1f4..0ccf4229 100644 --- a/test/utils_test.jl +++ b/test/utils_test.jl @@ -14,14 +14,14 @@ B = Matrix{Matrix{Int64}}(2,3) B[1,:] = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]] B[2,:] = [[1 2; 3 4],[1 5;4 3],[5 8;2 1]] -ans = [[1 2; 3 4],[1 4; 4 4.5],[5 7; 4.5 4.5]] -@test recursive_mean(B,1)[1] ≈ ans[1] -@test recursive_mean(B,1)[2] ≈ ans[2] -@test recursive_mean(B,1)[3] ≈ ans[3] +a = [[1 2; 3 4],[1 4; 4 4.5],[5 7; 4.5 4.5]] +@test recursive_mean(B,1)[1] ≈ a[1] +@test recursive_mean(B,1)[2] ≈ a[2] +@test recursive_mean(B,1)[3] ≈ a[3] -ans = [[2.333333333333 4.666666666666; 3.6666666666666 6.0], [2.3333333 3.0; 5.0 2.6666666]] -@test recursive_mean(B,2)[1] ≈ ans[1] -@test recursive_mean(B,2)[2] ≈ ans[2] +a = [[2.333333333333 4.666666666666; 3.6666666666666 6.0], [2.3333333 3.0; 5.0 2.6666666]] +@test_broken recursive_mean(B,2)[1] ≈ a[1] +@test_broken recursive_mean(B,2)[2] ≈ a[2] A = zeros(5,5) recursive_unitless_eltype(A) == Float64 From c4462c5dbe31127ccdc550ca027760b9a79e6324 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 10 Jun 2018 16:16:47 -0700 Subject: [PATCH 2/2] remove extra recursive_mean --- src/utils.jl | 15 --------------- test/utils_test.jl | 12 ------------ 2 files changed, 27 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 6351f2cc..4fb63f97 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -113,21 +113,6 @@ function recursive_mean(vecvec::Vector{T}) where T<:AbstractArray out/length(vecvec) end -function recursive_mean(matarr::Matrix{T},region=0) where T<:AbstractArray - if region == 0 - return recursive_mean(vec(matarr)) - elseif region == 1 - out = [zeros(matarr[1,i]) for i in 1:size(matarr,2)] - for j in 1:size(matarr,2), i in 1:size(matarr,1) - out[j] += matarr[i,j] - end - return out/size(matarr,1) - elseif region == 2 - return recursive_mean(matarr',1) - end -end - - # From Iterators.jl. Moved here since Iterators.jl is not precompile safe anymore. # Concatenate the output of n iterators diff --git a/test/utils_test.jl b/test/utils_test.jl index 0ccf4229..2dd95b5a 100644 --- a/test/utils_test.jl +++ b/test/utils_test.jl @@ -10,18 +10,6 @@ data = convert(Array,randomized) A = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]] @test recursive_mean(A) ≈ [2.33333333 3.666666666 4.6666666666 6.0] -B = Matrix{Matrix{Int64}}(2,3) -B[1,:] = [[1 2; 3 4],[1 3;4 6],[5 6;7 8]] -B[2,:] = [[1 2; 3 4],[1 5;4 3],[5 8;2 1]] - -a = [[1 2; 3 4],[1 4; 4 4.5],[5 7; 4.5 4.5]] -@test recursive_mean(B,1)[1] ≈ a[1] -@test recursive_mean(B,1)[2] ≈ a[2] -@test recursive_mean(B,1)[3] ≈ a[3] - -a = [[2.333333333333 4.666666666666; 3.6666666666666 6.0], [2.3333333 3.0; 5.0 2.6666666]] -@test_broken recursive_mean(B,2)[1] ≈ a[1] -@test_broken recursive_mean(B,2)[2] ≈ a[2] A = zeros(5,5) recursive_unitless_eltype(A) == Float64