Skip to content

Commit fc7f71b

Browse files
Merge pull request #116 from SciML/apindex
workaround Base changes for multi-indexing array partition
2 parents 1de8724 + e201774 commit fc7f71b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RecursiveArrayTools"
22
uuid = "731186ca-8d62-57ce-b412-fbd966d074cd"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "2.7.1"
4+
version = "2.7.2"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/array_partition.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ Base.@propagate_inbounds function Base.setindex!(A::ArrayPartition, v, i::Int)
182182
end
183183
end
184184

185+
# workaround for https://github.com/SciML/RecursiveArrayTools.jl/issues/49
186+
function Base._unsafe_getindex(::IndexStyle, A::ArrayPartition, I::Vararg{Union{Real, AbstractArray}, N}) where N
187+
# This is specifically not inlined to prevent excessive allocations in type unstable code
188+
shape = Base.index_shape(I...)
189+
dest = similar(A.x[1], shape)
190+
Base._unsafe_getindex!(dest, A, I...) # usually a generated function, don't allow it to impact inference result
191+
return dest
192+
end
193+
185194
"""
186195
setindex!(A::ArrayPartition, v, i::Int, j...)
187196

test/basic_indexing.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ ref = sqrt.(abs.(x .* x))
119119
fill!(mulX, 0)
120120
mulX .= sqrt.(abs.(testva .* testvb))
121121
@test mulX == ref
122+
123+
# https://github.com/SciML/RecursiveArrayTools.jl/issues/49
124+
a = ArrayPartition(1:5, 1:6)
125+
a[1:8]
126+
a[[1,3,8]]

0 commit comments

Comments
 (0)