Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/sampled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 for i in 2:n
out += weights[i] * data[i]
if weights isa TrapezoidalUniformWeights
@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
Expand Down
22 changes: 22 additions & 0 deletions test/sampled_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading