Skip to content

Commit ab097cd

Browse files
Merge pull request #31 from JuliaDiffEq/ChrisRackauckas-patch-1
Bump to v0.7
2 parents 2d9cb72 + 2541a9d commit ab097cd

13 files changed

+77
-78
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: julia
33
os:
44
- linux
55
julia:
6-
- 0.6
6+
- 0.7
77
- nightly
88
matrix:
99
allow_failures:

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
1+
julia 0.7-alpha
22
Requires
33
RecipesBase 0.1.0
44
StaticArrays

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
55
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
66
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77
matrix:

src/RecursiveArrayTools.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ __precompile__()
22

33
module RecursiveArrayTools
44

5-
using Requires, RecipesBase, StaticArrays
5+
using Requires, RecipesBase, StaticArrays, Statistics
66

77
abstract type AbstractVectorOfArray{T, N} <: AbstractArray{T, N} end
88
abstract type AbstractDiffEqArray{T, N} <: AbstractVectorOfArray{T, N} end
@@ -11,7 +11,7 @@ module RecursiveArrayTools
1111
include("vector_of_array.jl")
1212
include("array_partition.jl")
1313
include("juno_rendering.jl")
14-
14+
1515
export VectorOfArray, DiffEqArray, AbstractVectorOfArray, AbstractDiffEqArray,
1616
vecarr_to_arr, vecarr_to_vectors, tuples
1717

src/array_partition.jl

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ end
44

55
## constructors
66

7-
ArrayPartition(x...) = ArrayPartition((x...))
7+
ArrayPartition(x...) = ArrayPartition((x...,))
88

99
function ArrayPartition(x::S, ::Type{Val{copy_x}}=Val{false}) where {S<:Tuple,copy_x}
1010
T = promote_type(eltype.(x)...)
@@ -124,7 +124,7 @@ end
124124

125125
Base.mapreduce(f,op,A::ArrayPartition) = mapreduce(f,op,(mapreduce(f,op,x) for x in A.x))
126126
Base.any(f,A::ArrayPartition) = any(f,(any(f,x) for x in A.x))
127-
function Base.copy!(dest::Array,A::ArrayPartition)
127+
function Base.copyto!(dest::Array,A::ArrayPartition)
128128
@assert length(dest) == length(A)
129129
cur = 1
130130
@inbounds for i in 1:length(A.x)
@@ -133,7 +133,7 @@ function Base.copy!(dest::Array,A::ArrayPartition)
133133
end
134134
end
135135

136-
function Base.copy!(A::ArrayPartition,src::ArrayPartition)
136+
function Base.copyto!(A::ArrayPartition,src::ArrayPartition)
137137
@assert length(src) == length(A)
138138
cur = 1
139139
@inbounds for i in 1:length(A.x)
@@ -145,12 +145,8 @@ end
145145
## indexing
146146

147147
# 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
148+
@inline Base.firstindex(A::ArrayPartition) = 1
149+
@inline Base.lastindex(A::ArrayPartition) = length(A)
154150

155151
@inline function Base.getindex(A::ArrayPartition, i::Int)
156152
@boundscheck checkbounds(A, i)
@@ -220,9 +216,8 @@ recursive_eltype(A::ArrayPartition) = recursive_eltype(first(A.x))
220216

221217
## iteration
222218

223-
Base.start(A::ArrayPartition) = start(Chain(A.x))
224-
Base.next(A::ArrayPartition,state) = next(Chain(A.x),state)
225-
Base.done(A::ArrayPartition,state) = done(Chain(A.x),state)
219+
Base.iterate(A::ArrayPartition) = iterate(Chain(A.x))
220+
Base.iterate(A::ArrayPartition,state) = iterate(Chain(A.x),state)
226221

227222
Base.length(A::ArrayPartition) = sum((length(x) for x in A.x))
228223
Base.size(A::ArrayPartition) = (length(A),)
@@ -238,14 +233,19 @@ Base.show(io::IO, m::MIME"text/plain", A::ArrayPartition) = show(io, m, A.x)
238233

239234
## broadcasting
240235

241-
Base.Broadcast._containertype(::Type{<:ArrayPartition}) = ArrayPartition
242-
Base.Broadcast.promote_containertype(::Type{ArrayPartition}, ::Type) = ArrayPartition
243-
Base.Broadcast.promote_containertype(::Type, ::Type{ArrayPartition}) = ArrayPartition
244-
Base.Broadcast.promote_containertype(::Type{ArrayPartition}, ::Type{ArrayPartition}) = ArrayPartition
245-
Base.Broadcast.promote_containertype(::Type{ArrayPartition}, ::Type{Array}) = ArrayPartition
246-
Base.Broadcast.promote_containertype(::Type{Array}, ::Type{ArrayPartition}) = ArrayPartition
236+
struct APStyle <: Broadcast.BroadcastStyle end
237+
Base.BroadcastStyle(::Type{<:ArrayPartition}) = Broadcast.ArrayStyle{ArrayPartition}()
238+
Base.BroadcastStyle(::Broadcast.ArrayStyle{ArrayPartition},::Broadcast.ArrayStyle) = Broadcast.Style{ArrayPartition}()
239+
Base.BroadcastStyle(::Broadcast.ArrayStyle,::Broadcast.ArrayStyle{ArrayPartition}) = Broadcast.Style{ArrayPartition}()
240+
Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}},::Type{ElType}) where ElType = similar(bc)
241+
242+
function Base.copy(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}})
243+
ret = Broadcast.flatten(bc)
244+
__broadcast(ret.f,ret.args...)
245+
end
246+
247+
@generated function __broadcast(f,as...)
247248

248-
@generated function Base.Broadcast.broadcast_c(f, ::Type{ArrayPartition}, as...)
249249
# common number of partitions
250250
N = npartitions(as...)
251251

@@ -254,12 +254,15 @@ Base.Broadcast.promote_containertype(::Type{Array}, ::Type{ArrayPartition}) = Ar
254254
# index partitions
255255
$((as[d] <: ArrayPartition ? :(as[$d].x[i]) : :(as[$d])
256256
for d in 1:length(as))...)))
257-
258257
build_arraypartition(N, expr)
259258
end
260259

261-
@generated function Base.Broadcast.broadcast_c!(f, ::Type{ArrayPartition}, ::Type,
262-
dest::ArrayPartition, as...)
260+
function Base.copyto!(dest::AbstractArray,bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{ArrayPartition}})
261+
ret = Broadcast.flatten(bc)
262+
__broadcast!(ret.f,dest,ret.args...)
263+
end
264+
265+
@generated function __broadcast!(f, dest, as...)
263266
# common number of partitions
264267
N = npartitions(dest, as...)
265268

src/utils.jl

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function recursivecopy!(b::AbstractArray{T,N},a::AbstractArray{T2,N}) where {T<:
2626
end
2727

2828
function recursivecopy!(b::AbstractArray{T,N},a::AbstractArray{T2,N}) where {T<:Number,T2<:Number,N}
29-
copy!(b,a)
29+
copyto!(b,a)
3030
end
3131

3232
function recursivecopy!(b::AbstractArray{T,N},a::AbstractArray{T2,N}) where {T<:AbstractArray,T2<:AbstractArray,N}
@@ -145,30 +145,24 @@ Base.length(it::Chain) = sum(length, it.xss)
145145

146146
Base.eltype(::Type{Chain{T}}) where {T} = typejoin([eltype(t) for t in T.parameters]...)
147147

148-
function Base.start(it::Chain)
148+
function Base.iterate(it::Chain)
149149
i = 1
150150
xs_state = nothing
151151
while i <= length(it.xss)
152-
xs_state = start(it.xss[i])
153-
if !done(it.xss[i], xs_state)
154-
break
155-
end
152+
xs_state = iterate(it.xss[i])
153+
xs_state !== nothing && return xs_state[1], (i, xs_state[2])
156154
i += 1
157155
end
158-
return i, xs_state
156+
return nothing
159157
end
160158

161-
function Base.next(it::Chain, state)
159+
function Base.iterate(it::Chain, state)
162160
i, xs_state = state
163-
v, xs_state = next(it.xss[i], xs_state)
164-
while done(it.xss[i], xs_state)
161+
xs_state = iterate(it.xss[i], xs_state)
162+
while xs_state == nothing
165163
i += 1
166-
if i > length(it.xss)
167-
break
168-
end
169-
xs_state = start(it.xss[i])
164+
i > length(it.xss) && return nothing
165+
xs_state = iterate(it.xss[i])
170166
end
171-
return v, (i, xs_state)
167+
return xs_state[1], (i, xs_state[2])
172168
end
173-
174-
Base.done(it::Chain, state) = state[1] > length(it.xss)

src/vector_of_array.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ 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-
@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
21+
@inline Base.firstindex(VA::AbstractVectorOfArray) = firstindex(VA.u)
22+
@inline Base.lastindex(VA::AbstractVectorOfArray) = lastindex(VA.u)
2723

2824
@inline Base.length(VA::AbstractVectorOfArray) = length(VA.u)
2925
@inline Base.eachindex(VA::AbstractVectorOfArray) = Base.OneTo(length(VA.u))
30-
@inline Base.iteratorsize(VA::AbstractVectorOfArray) = Base.HasLength()
26+
@inline Base.IteratorSize(VA::AbstractVectorOfArray) = Base.HasLength()
3127
# Linear indexing will be over the container elements, not the individual elements
3228
# unlike an true AbstractArray
3329
@inline Base.getindex(VA::AbstractVectorOfArray{T, N}, I::Int) where {T, N} = VA.u[I]
@@ -83,6 +79,8 @@ end
8379
# Need this for ODE_DEFAULT_UNSTABLE_CHECK from DiffEqBase to work properly
8480
@inline Base.any(f, VA::AbstractVectorOfArray) = any(any(f,VA[i]) for i in eachindex(VA))
8581
@inline Base.all(f, VA::AbstractVectorOfArray) = all(all(f,VA[i]) for i in eachindex(VA))
82+
@inline Base.any(f::Function, VA::AbstractVectorOfArray) = any(any(f,VA[i]) for i in eachindex(VA))
83+
@inline Base.all(f::Function, VA::AbstractVectorOfArray) = all(all(f,VA[i]) for i in eachindex(VA))
8684

8785
# conversion tools
8886
@deprecate vecarr_to_arr(VA::AbstractVectorOfArray) convert(Array,VA)

test/basic_indexing.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using RecursiveArrayTools
22

33
# Example Problem
44
recs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
5-
testa = cat(2, recs...)
5+
testa = cat(recs..., dims=2)
66
testva = VectorOfArray(recs)
77
t = [1,2,3]
88
diffeq = DiffEqArray(recs,t)
@@ -13,7 +13,7 @@ testa[1:2, 1:2] == [1 4; 2 5]
1313

1414
# # ndims == 2
1515
recs = [rand(8) for i in 1:10]
16-
testa = cat(2, recs...)
16+
testa = cat(recs...,dims=2)
1717
testva = VectorOfArray(recs)
1818

1919
# ## Linear indexing
@@ -36,7 +36,7 @@ testva = VectorOfArray(recs)
3636

3737
# # ndims == 3
3838
recs = recs = [rand(10, 8) for i in 1:15]
39-
testa = cat(3, recs...)
39+
testa = cat(recs...,dims=3)
4040
testva = VectorOfArray(recs)
4141

4242
# ## (Int, Int, Int)
@@ -65,11 +65,11 @@ testva = VectorOfArray(recs)
6565

6666
# ## Test ragged arrays work, or give errors as needed
6767
#TODO: I am not really sure what the behavior of this is, what does Mathematica do?
68-
recs = [[1, 2, 3], [3 5; 6 7], [8, 9, 10, 11]]
68+
recs = [[1, 2, 3], [3, 5, 6, 7], [8, 9, 10, 11]]
6969
testva = VectorOfArray(recs) #TODO: clearly this printed form is nonsense
7070
@test testva[:, 1] == recs[1]
7171
testva[1:2, 1:2]
7272

7373
# Test broadcast
7474
a = testva .+ rand(3,3)
75-
a.= testva
75+
@test_broken a.= testva

test/copy_static_array_test.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Base.Test, RecursiveArrayTools, StaticArrays
1+
using Test, RecursiveArrayTools, StaticArrays
22

33
struct ImmutableFV <: FieldVector{2,Float64}
44
a::Float64
@@ -13,7 +13,7 @@ end
1313
# Immutable FieldVector
1414
vec = ImmutableFV(1.,2.)
1515
a = [vec]
16-
b = zeros(a)
16+
b = zero(a)
1717
recursivecopy!(b, a)
1818
@test a[1] == b[1]
1919
copyat_or_push!(a, 2, b[1])
@@ -25,7 +25,7 @@ copyat_or_push!(a, 2, b[1])
2525
# Mutable FieldVector
2626
vec = MutableFV(1.,2.)
2727
a = [vec]
28-
b = zeros(a)
28+
b = zero(a)
2929
recursivecopy!(b, a)
3030
@test a[1] == b[1]
3131
a[1][1] *= 5
@@ -41,7 +41,7 @@ copyat_or_push!(a, 2, b[1])
4141
# SArray
4242
vec = @SArray [1., 2.]
4343
a = [vec]
44-
b = zeros(a)
44+
b = zero(a)
4545
recursivecopy!(b, a)
4646
@test a[1] == b[1]
4747
copyat_or_push!(a, 2, b[1])
@@ -53,7 +53,7 @@ copyat_or_push!(a, 2, b[1])
5353
# MArray
5454
vec = @MArray [1., 2.]
5555
a = [vec]
56-
b = zeros(a)
56+
b = zero(a)
5757
recursivecopy!(b, a)
5858
a[1][1] *= 5
5959
@test a[1] != b[1]

test/interface_tests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RecursiveArrayTools, Base.Test
1+
using RecursiveArrayTools, Test
22

33
recs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
44
testva = VectorOfArray(recs)
@@ -36,7 +36,7 @@ testva[4, 9] # == testva.data[9][4]
3636
# convert array from VectorOfArray
3737
recs = [rand(10, 7) for i = 1:8]
3838
testva = VectorOfArray(recs)
39-
testa = cat(3, recs...)
39+
testa = cat(recs...,dims=3)
4040
@test convert(Array,testva) == testa
4141

4242
recs = [[1, 2, 3], [3 5; 6 7], [8, 9, 10, 11]]
@@ -54,7 +54,7 @@ testva2 = similar(testva)
5454
testval = 3.0
5555
fill!(testva2, testval)
5656
@test all(x->(x==testval), testva2)
57-
testts = rand(size(testva.u))
57+
testts = rand(Float64, size(testva.u))
5858
testda = DiffEqArray(recursivecopy(testva.u), testts)
5959
fill!(testda, testval)
6060
@test all(x->(x==testval), testda)

0 commit comments

Comments
 (0)