Skip to content

Commit 2ccd813

Browse files
committed
Fix map and lastwithindex bugs in ResizableArray
1 parent c9a744a commit 2ccd813

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/resizable_array.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,17 @@ function Base.iterate(array::ResizableArray, state)
181181
return nothing
182182
end
183183
nindex, nstate = niterate
184+
while !isassigned(array, nindex.I...)
185+
pstate = nstate
186+
niterate = iterate(indx, pstate)
187+
if isnothing(niterate)
188+
return nothing
189+
end
190+
nindex, nstate = niterate
191+
end
184192
return (array[nindex.I...], isnothing(nstate) ? nothing : (indx, nstate))
185193
end
186194

187-
function Base.map(f, array::ResizableArray{T, V, N}) where {T, V, N}
188-
result = map(f, array.data)
189-
return ResizableArray(result)
190-
end
191-
192195
__length(array::ResizableArray{T, V, N}) where {T, V, N} = __recursive_length(Val(N), array.data)
193196

194197
function __recursive_length(::Val{N}, array) where {N}
@@ -241,7 +244,7 @@ end
241244
function lastwithindex(array::ResizableArray{T, V, N}) where {T, V, N}
242245
for index in reverse(CartesianIndices(reverse(size(array)))) #TODO improve performance of this function since it uses splatting
243246
if isassigned(array, reverse(index.I)...)::Bool
244-
return (index, array[reverse(index.I)...])
247+
return (CartesianIndex(reverse(index.I)), array[reverse(index.I)...])
245248
end
246249
end
247250
end

test/resizable_array_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ end
279279
end
280280
end
281281
s[5, 11] = 16
282-
result = map(elem -> elem .+ 1, s)
282+
result = map(elem -> elem + 1, s)
283283
for i in 1:10
284284
for j in 1:10
285285
@test result[i, j] == s[i, j] + 1

0 commit comments

Comments
 (0)