From 4b60407fc09ac182855abc420119972d8093b27f Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 9 Oct 2026 19:05:39 -0400 Subject: [PATCH 1/2] Make substitute_v follow the evaluation-point container type. Leading Base.map with Vector domain bounds forced a Vector of transformed points on every HCubatureJL evaluation; ordering the map by the SVector point removes those allocations and matches what HCubature passes directly. Co-Authored-By: Chris Rackauckas Co-Authored-By: Cursor Agent Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/integrals/int-substv/log.txt on amdci2 --- src/infinity_handling.jl | 2 +- test/inf_integral_tests.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/infinity_handling.jl b/src/infinity_handling.jl index 07364218..3c701022 100644 --- a/src/infinity_handling.jl +++ b/src/infinity_handling.jl @@ -10,7 +10,7 @@ end # without batching point container type should match the inputs substitute_v(v2ujac, v, lb::Number, ub::Number) = v2ujac(only(v), lb, ub) function substitute_v(v2ujac, v, lb::AbstractVector, ub::AbstractVector) - xjac = map((l, u, v) -> v2ujac(v, l, u), lb, ub, v) # ordering may influence container type + xjac = map((v, l, u) -> v2ujac(v, l, u), v, lb, ub) # ordering may influence container type x = map(first, xjac) jac = prod(last, xjac) return x, jac diff --git a/test/inf_integral_tests.jl b/test/inf_integral_tests.jl index dd9779dd..1d2facac 100644 --- a/test/inf_integral_tests.jl +++ b/test/inf_integral_tests.jl @@ -256,3 +256,23 @@ end @test sol.prob == IntegralProblem(f, domain) @test sol.alg == alg end + +@testset "substitute_v follows evaluation-point container type" begin + v = @SVector [0.25, 0.5] + lb = [-1.0, 0.0] + ub = [1.0, 2.0] + x, jac = Integrals.substitute_v(Integrals.t2ujac, v, lb, ub) + @test x isa SVector{2, Float64} + @test jac isa Real + + f_gauss(x, p) = pdf(MvNormal([0.0, 0.0], [0.4 0.0; 0.0 0.4]), x) + for domain in (([-Inf, -Inf], [Inf, Inf]), (@SVector[-Inf, -Inf], @SVector[Inf, Inf])) + sol = solve(IntegralProblem(f_gauss, domain), HCubatureJL(); abstol, reltol) + @test abs(only(sol) - 1.0) < max(abstol, reltol) + end + f_one(x, p) = 1.0 + for domain in ((zeros(2), ones(2)), (zeros(SVector{2}), ones(SVector{2}))) + sol = solve(IntegralProblem(f_one, domain), HCubatureJL(); abstol, reltol) + @test abs(only(sol) - 1.0) < max(abstol, reltol) + end +end From e1342b7faa0eb2a733124a8a60d6de1f0099af21 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 9 Oct 2026 22:22:18 -0400 Subject: [PATCH 2/2] Keep domain point types while cutting substitute_v allocations. Map via immutable evaluation points (HCubature SVectors) then copy once into similar(lb) so Vector domains still pass Vector to the integrand, matching the ded0128 container-type contract with ~half the allocations. Co-Authored-By: Chris Rackauckas Co-Authored-By: Cursor Agent Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/integrals/int-substv/log.txt on amdci2 --- src/infinity_handling.jl | 11 ++++++++++- test/inf_integral_tests.jl | 21 ++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/infinity_handling.jl b/src/infinity_handling.jl index 3c701022..80baaf65 100644 --- a/src/infinity_handling.jl +++ b/src/infinity_handling.jl @@ -10,7 +10,16 @@ end # without batching point container type should match the inputs substitute_v(v2ujac, v, lb::Number, ub::Number) = v2ujac(only(v), lb, ub) function substitute_v(v2ujac, v, lb::AbstractVector, ub::AbstractVector) - xjac = map((v, l, u) -> v2ujac(v, l, u), v, lb, ub) # ordering may influence container type + # Immutable eval point + mutable domain: map via `v`, then one similar(lb) copy. + if !ArrayInterface.ismutable(v) && ArrayInterface.ismutable(lb) + xjac = map((vi, l, u) -> v2ujac(vi, l, u), v, lb, ub) + xs = map(first, xjac) + jac = prod(last, xjac) + x = similar(lb, eltype(xs)) + copyto!(x, xs) + return x, jac + end + xjac = map((l, u, vi) -> v2ujac(vi, l, u), lb, ub, v) # ordering may influence container type x = map(first, xjac) jac = prod(last, xjac) return x, jac diff --git a/test/inf_integral_tests.jl b/test/inf_integral_tests.jl index 1d2facac..bdcfa1a7 100644 --- a/test/inf_integral_tests.jl +++ b/test/inf_integral_tests.jl @@ -257,22 +257,29 @@ end @test sol.alg == alg end -@testset "substitute_v follows evaluation-point container type" begin +@testset "substitute_v matches domain container type" begin v = @SVector [0.25, 0.5] lb = [-1.0, 0.0] ub = [1.0, 2.0] x, jac = Integrals.substitute_v(Integrals.t2ujac, v, lb, ub) - @test x isa SVector{2, Float64} + @test x isa Vector{Float64} @test jac isa Real + xs, _ = Integrals.substitute_v( + Integrals.t2ujac, v, (@SVector[-1.0, 0.0]), (@SVector[1.0, 2.0]) + ) + @test xs isa SVector{2, Float64} + + # Vector-domain HCubatureJL must keep Vector points (broadcast / typed integrands) + sol = solve( + IntegralProblem((x, p) -> x .^ 2, (zeros(2), ones(2))), HCubatureJL(); + abstol, reltol + ) + @test sol.u isa Vector + @test sol.u ≈ [1 / 3, 1 / 3] atol = max(abstol, reltol) f_gauss(x, p) = pdf(MvNormal([0.0, 0.0], [0.4 0.0; 0.0 0.4]), x) for domain in (([-Inf, -Inf], [Inf, Inf]), (@SVector[-Inf, -Inf], @SVector[Inf, Inf])) sol = solve(IntegralProblem(f_gauss, domain), HCubatureJL(); abstol, reltol) @test abs(only(sol) - 1.0) < max(abstol, reltol) end - f_one(x, p) = 1.0 - for domain in ((zeros(2), ones(2)), (zeros(SVector{2}), ones(SVector{2}))) - sol = solve(IntegralProblem(f_one, domain), HCubatureJL(); abstol, reltol) - @test abs(only(sol) - 1.0) < max(abstol, reltol) - end end