Skip to content

Commit 0eb078d

Browse files
committed
Julia v0.7/v1.0 compatibility
1 parent 1cc9109 commit 0eb078d

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/array_of_similar_arrays.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of ArraysOfArrays.jl, licensed under the MIT License (MIT).
22

3-
@doc doc"""
3+
"""
44
AbstractArrayOfSimilarArrays{T,M,N} <: AbstractArray{<:AbstractArray{T,M},N}
55
66
An array that contains arrays that have the same size/axes. The array is
@@ -31,7 +31,7 @@ export AbstractVectorOfSimilarVectors
3131

3232

3333

34-
@doc doc"""
34+
"""
3535
ArrayOfSimilarArrays{T,M,N,L,P} <: AbstractArrayOfSimilarArrays{T,M,N}
3636
3737
Represents a view of an array of dimension `L = M + N` as an array of
@@ -118,6 +118,9 @@ Base.parent(A::ArrayOfSimilarArrays) = A.data
118118
Base.size(A::ArrayOfSimilarArrays{T,M,N}) where {T,M,N} = split_tuple(size(A.data), Val{M}())[2]
119119

120120

121+
Base.IndexStyle(A::ArrayOfSimilarArrays) = IndexLinear()
122+
123+
121124
Base.@propagate_inbounds function Base.getindex(A::ArrayOfSimilarArrays{T,M,N}, idxs::Vararg{Integer,N}) where {T,M,N}
122125
@boundscheck checkbounds(A, idxs...)
123126
J = Base.to_indices(A.data, (_ncolons(Val{M}())..., idxs...))

src/vector_of_arrays.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is a part of ArraysOfArrays.jl, licensed under the MIT License (MIT).
22

33

4-
doc"""
4+
"""
55
VectorOfArrays{T,N,M} <: AbstractVector{<:AbstractArray{T,N}}
66
77
An `VectorOfArrays` represents a vector of `N`-dimensional arrays (that may
@@ -144,6 +144,8 @@ Base.parent(A::VectorOfArrays) = A.data
144144

145145
Base.size(A::VectorOfArrays) = size(A.kernel_size)
146146

147+
Base.IndexStyle(A::ArrayOfSimilarArrays) = IndexLinear()
148+
147149

148150
Base.@propagate_inbounds function Base.getindex(A::VectorOfArrays, i::Integer)
149151
@boundscheck checkbounds(A, i)
@@ -170,11 +172,11 @@ Base.@propagate_inbounds function Base._getindex(l::IndexStyle, A::VectorOfArray
170172
A_ep = A.elem_ptr
171173
A_data = A.data
172174

173-
elem_ptr = similar(A_ep, length(linearindices(idxs)) + 1)
175+
elem_ptr = similar(A_ep, length(eachindex(idxs)) + 1)
174176
delta_i = firstindex(elem_ptr) - firstindex(idxs)
175177

176178
elem_ptr[firstindex(elem_ptr)] = firstindex(A_data)
177-
for i in linearindices(idxs)
179+
for i in eachindex(idxs)
178180
idx = idxs[i]
179181
l = A_ep[idx + 1] - A_ep[idx]
180182
elem_ptr[i + 1 + delta_i] = elem_ptr[i + delta_i] + l
@@ -186,7 +188,7 @@ Base.@propagate_inbounds function Base._getindex(l::IndexStyle, A::VectorOfArray
186188
broadcast!(+, elem_ptr, elem_ptr, firstindex(data) - first(elem_ptr))
187189
end
188190

189-
for i in linearindices(idxs)
191+
for i in eachindex(idxs)
190192
idx = idxs[i]
191193
l = A_ep[idx + 1] - A_ep[idx]
192194

@@ -210,8 +212,10 @@ Base.@propagate_inbounds function Base.setindex!(A::VectorOfArrays{T,N}, x::Abst
210212
end
211213

212214
Base.length(A::VectorOfArrays) = length(A.kernel_size)
213-
Base._length(A::VectorOfArrays) = Base._length(A.kernel_size)
214-
Base.linearindices(A::VectorOfArrays) = linearindices(A.kernel_size)
215+
216+
@static if VERSION < v"0.7.0-beta.250"
217+
Base._length(A::VectorOfArrays) = Base._length(A.kernel_size)
218+
end
215219

216220

217221
function Base.append!(A::VectorOfArrays{T,N}, B::VectorOfArrays{U,N}) where {T,N,U}
@@ -223,7 +227,7 @@ function Base.append!(A::VectorOfArrays{T,N}, B::VectorOfArrays{U,N}) where {T,N
223227
idxs_B = firstindex(B_ep):(lastindex(B_ep) - 1)
224228
delta_ep_idx = lastindex(A_ep) + 1 - firstindex(B_ep)
225229
delta_ep = last(A_ep) - first(B_ep)
226-
resize!(A_ep, length(linearindices(A_ep)) + length(idxs_B))
230+
resize!(A_ep, length(eachindex(A_ep)) + length(idxs_B))
227231
@assert checkbounds(Bool, B_ep, idxs_B)
228232
@assert checkbounds(Bool, A_ep, broadcast(+, idxs_B, delta_ep_idx))
229233
@inbounds @simd for i_B in idxs_B
@@ -241,12 +245,12 @@ end
241245

242246
function Base.append!(A::VectorOfArrays{T,N}, B::AbstractVector{AbstractArray{U,N}}) where {T,N,U}
243247
if !isempty(B)
244-
n_A = length(linearindices(A))
245-
n_B = length(linearindices(B))
246-
datalen_A = length(linearindices(A.data))
248+
n_A = length(eachindex(A))
249+
n_B = length(eachindex(B))
250+
datalen_A = length(eachindex(A.data))
247251
datalen_B = zero(Int)
248252
for i in eachindex(B)
249-
datalen_B += Int(length(linearindices(B[i])))
253+
datalen_B += Int(length(eachindex(B[i])))
250254
end
251255

252256
sizehint!(A.data, datalen_A + datalen_B)

0 commit comments

Comments
 (0)