Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/array_partition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 0 additions & 12 deletions test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

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]

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 = zeros(5,5)
recursive_unitless_eltype(A) == Float64
Expand Down