From 726bfc3988267c3cd352cc291257bd000fb4d432 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Thu, 8 Oct 2026 06:40:55 -0400 Subject: [PATCH] Add @inline to unpack_args(i, ::Tuple{Any}) in ArrayPartition broadcast The tuple-recursion base case was missing @inline, forcing a runtime dispatch whenever an ArrayPartition broadcast mixes partition eltypes (e.g. Float32 and Float64 partitions). Homogeneous partitions were unaffected since the compiler could already fold the single-method recursion. Co-Authored-By: Chris Rackauckas Co-Authored-By: Claude Agent-Harness: Claude Code 2.1.294 Agent-Model: claude-sonnet-5 Agent-Session: https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv --- src/array_partition.jl | 2 +- test/Core/partitions_test.jl | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/array_partition.jl b/src/array_partition.jl index a1220451..9504b7a9 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -572,7 +572,7 @@ end @inline function unpack_args(i, args::Tuple) return (unpack(args[1], i), unpack_args(i, Base.tail(args))...) end -unpack_args(i, args::Tuple{Any}) = (unpack(args[1], i),) +@inline unpack_args(i, args::Tuple{Any}) = (unpack(args[1], i),) unpack_args(::Any, args::Tuple{}) = () ## utils diff --git a/test/Core/partitions_test.jl b/test/Core/partitions_test.jl index 93a3e7b8..c5b4debf 100644 --- a/test/Core/partitions_test.jl +++ b/test/Core/partitions_test.jl @@ -416,3 +416,14 @@ end struct TestIsnanFunctor end (::TestIsnanFunctor)(x) = isnan(x) @test all(TestIsnanFunctor(), AP[[NaN], [NaN]]) + +@testset "Mixed-eltype in-place broadcast does not allocate" begin + # unpack_args(i, ::Tuple{Any}) was missing @inline, forcing a runtime + # dispatch at the tuple-recursion base case whenever the partitions + # have different element types. + f!(a, b, c, d) = (@. a = b + c * d; nothing) + mk() = ArrayPartition(rand(10), rand(Float32, 20), rand(5)) + a, b, c, d = mk(), mk(), mk(), mk() + f!(a, b, c, d) + @test (@allocated f!(a, b, c, d)) == 0 +end