From 66f170ea944b16ad857fbd64f596967630797eac Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sat, 26 Sep 2026 04:15:20 -0400 Subject: [PATCH 1/2] Fix ArrayPartition A[:] to return flattened vector (#661) Require at least one index after Colon in the (colon, j...) getindex method so A[:] dispatches to the flattening Colon method instead of broadcasting getindex over empty indices. Co-Authored-By: Chris Rackauckas Co-Authored-By: Cursor Agent Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-RecursiveArrayTools.jl-661/log.txt on amdci2.julia.csail.mit.edu --- src/array_partition.jl | 10 ++++++---- test/Core/partitions_test.jl | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/array_partition.jl b/src/array_partition.jl index 2828b159..46ce5c8e 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -317,12 +317,14 @@ Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Int) end """ - getindex(A::ArrayPartition, i::Colon, j...) + getindex(A::ArrayPartition, i::Colon, j, js...) -Returns the entry at index `j...` of every partition of `A`. +Returns the entry at index `j, js...` of every partition of `A`. +Requires at least one index after the colon so that `A[:]` keeps the +flattening `getindex(::ArrayPartition, ::Colon)` method (issue #661). """ -Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Colon, j...) - return getindex.(A.x, (j...,)) +Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Colon, j, js...) + return getindex.(A.x, (j, js...)) end """ diff --git a/test/Core/partitions_test.jl b/test/Core/partitions_test.jl index 44bf10c9..93a3e7b8 100644 --- a/test/Core/partitions_test.jl +++ b/test/Core/partitions_test.jl @@ -90,6 +90,30 @@ x = AP[[1, 2], [3.0, 4.0]] y = ArrayPartition(AP[[1], [2.0]], AP[[3], [4.0]]) @test x[:, 1] == (1, 3.0) +# Issue #661: A[:] must flatten, not hit the (colon, j...) broadcast path +@testset "ArrayPartition A[:] flattening (issue #661)" begin + v = ArrayPartition([1.0, 2.0], [3.0]) + @test v[:] == [1.0, 2.0, 3.0] + @test v[:] == vec(v) + @test v[:] == collect(v) + @test v[1:3] == [1.0, 2.0, 3.0] + + m = ArrayPartition([1.0 2.0], [3.0 4.0 5.0]) + @test m[:] == [1.0, 2.0, 3.0, 4.0, 5.0] + @test m[:] == vec(m) + @test m[:] == collect(m) + @test m[1:4] == [1.0, 2.0, 3.0, 4.0] + + nested = ArrayPartition(ArrayPartition([1.0], [2.0]), ArrayPartition([3.0, 4.0])) + @test nested[:] == [1.0, 2.0, 3.0, 4.0] + @test nested[:] == vec(nested) + @test nested[:] == collect(nested) + + # (colon, j...) from #239 must still work + @test x[:, 1] == (1, 3.0) + @test x[:, 2] == (2, 4.0) +end + # similar partitions @inferred similar(x) @test similar(x, (4,)) isa ArrayPartition{Float64} From 4281ef72a20f0e883f544925247080ecd0589e6b Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sat, 26 Sep 2026 04:20:25 -0400 Subject: [PATCH 2/2] Drop issue number from ArrayPartition colon getindex docstring Co-Authored-By: Chris Rackauckas Co-Authored-By: Cursor Agent Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-RecursiveArrayTools.jl-661/log.txt on amdci2.julia.csail.mit.edu --- src/array_partition.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_partition.jl b/src/array_partition.jl index 46ce5c8e..a1220451 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -321,7 +321,7 @@ end Returns the entry at index `j, js...` of every partition of `A`. Requires at least one index after the colon so that `A[:]` keeps the -flattening `getindex(::ArrayPartition, ::Colon)` method (issue #661). +flattening `getindex(::ArrayPartition, ::Colon)` method. """ Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Colon, j, js...) return getindex.(A.x, (j, js...))