From 7f4e685b4bca286b675ce6758c67c30925094bb4 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 9 Oct 2026 19:02:28 -0400 Subject: [PATCH 1/3] =?UTF-8?q?SIMD=20the=201-D=20sampled-data=20weight?= =?UTF-8?q?=C3=97data=20reduction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The AbstractVector evalrule loop is a plain sum over fast_scalar_indexing arrays; @simd cuts Trapezoidal/Simpson uniform costs ~4–6× at N=1e5 on Julia 1.12, with ~1e-14 relative reassociation vs a sequential reference. 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-simd/log.txt on amdci2 --- src/sampled.jl | 2 +- test/sampled_tests.jl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/sampled.jl b/src/sampled.jl index b2e85c70..ea37e03b 100644 --- a/src/sampled.jl +++ b/src/sampled.jl @@ -54,7 +54,7 @@ function evalrule(data::AbstractVector, weights, dim) n = length(data) n == 0 && throw(ArgumentError("No points to integrate")) out = data[1] * weights[1] - @inbounds for i in 2:n + @inbounds @simd for i in 2:n out += weights[i] * data[i] end return out diff --git a/test/sampled_tests.jl b/test/sampled_tests.jl index 1f8e26ee..8b78b82d 100644 --- a/test/sampled_tests.jl +++ b/test/sampled_tests.jl @@ -32,6 +32,28 @@ using Integrals, Test, Unitful end end +@testset "1-D sampled reduction matches sequential reference sum" begin + for N in (8, 100, 1000, 10_000) + x = range(0.0, 1.0; length = N) + xv = collect(x) + y = sin.(x) .+ 0.1 .* collect(x) + for (grid, alg) in ( + (x, TrapezoidalRule()), + (xv, TrapezoidalRule()), + (x, SimpsonsRule()), + (xv, SimpsonsRule()), + ) + cache = init(SampledIntegralProblem(y, grid), alg) + w = cache.cacheval + ref = w[1] * y[1] + @inbounds for i in 2:length(y) + ref += w[i] * y[i] + end + @test solve!(cache).u ≈ ref rtol = 1.0e-12 + end + end +end + @testset "Sampled integration with dimensional axes" begin data = ones(2, 3) axis = [0.0, 1.0, 2.0]u"m" From f638c83767c9b1140240afc5109dad3adee16dde Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 9 Oct 2026 22:17:11 -0400 Subject: [PATCH 2/3] Gate @simd on UniformWeights for 1-D sampled reduction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unconditional @simd slowed TrapezoidalNonuniformWeights on Julia 1.10 (~1.65×) because the branchy getindex cannot vectorize; keep the sequential loop for NonuniformWeights and @simd only for UniformWeights. 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-simd/log.txt on amdci2 --- src/sampled.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sampled.jl b/src/sampled.jl index ea37e03b..9ab20d6d 100644 --- a/src/sampled.jl +++ b/src/sampled.jl @@ -54,8 +54,14 @@ function evalrule(data::AbstractVector, weights, dim) n = length(data) n == 0 && throw(ArgumentError("No points to integrate")) out = data[1] * weights[1] - @inbounds @simd for i in 2:n - out += weights[i] * data[i] + if weights isa UniformWeights + @inbounds @simd for i in 2:n + out += weights[i] * data[i] + end + else + @inbounds for i in 2:n + out += weights[i] * data[i] + end end return out else From 635644c2791215029bb73ea65f2e43f15c6bd928 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sat, 10 Oct 2026 17:53:00 -0400 Subject: [PATCH 3/3] Restrict @simd to TrapezoidalUniformWeights only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SimpsonUniformWeights getindex is branchy; gating on UniformWeights made SimpsonsRule-on-range ~1.3× slower on Julia 1.10 aarch64. Leave all Simpson paths on the sequential master loop. 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-simd/log.txt on amdci2 --- src/sampled.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sampled.jl b/src/sampled.jl index 9ab20d6d..624d7bbb 100644 --- a/src/sampled.jl +++ b/src/sampled.jl @@ -54,7 +54,7 @@ function evalrule(data::AbstractVector, weights, dim) n = length(data) n == 0 && throw(ArgumentError("No points to integrate")) out = data[1] * weights[1] - if weights isa UniformWeights + if weights isa TrapezoidalUniformWeights @inbounds @simd for i in 2:n out += weights[i] * data[i] end