Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle integrands <: AbstractVector #90

Merged
merged 2 commits into from
Sep 23, 2023
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
8 changes: 4 additions & 4 deletions src/batch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
BatchIntegrand{Y,X}(f!; kws...) where {Y,X} = BatchIntegrand(f!, Y[], X[]; kws...)
BatchIntegrand{Y}(f!; kws...) where {Y} = BatchIntegrand(f!, Y[]; kws...)

function evalrule(fx::AbstractVector{T}, a,b, x,w,gw, nrm) where {T}
function batchevalrule(fx::AbstractVector{T}, a,b, x,w,gw, nrm) where {T}
l = length(x)
n = 2l - 1 # number of Kronrod points
n1 = 1 - (l & 1) # 0 if even order, 1 if odd order
Expand Down Expand Up @@ -79,7 +79,7 @@ function evalrules(f::BatchIntegrand, s::NTuple{N}, x,w,gw, nrm) where {N}
end
f.f!(f.y, f.x) # evaluate integrand
return ntuple(Val(N-1)) do i
return evalrule(view(f.y, (1+(i-1)*m):(i*m)), s[i], s[i+1], x,w,gw, nrm)
return batchevalrule(view(f.y, (1+(i-1)*m):(i*m)), s[i], s[i+1], x,w,gw, nrm)
end
end

Expand Down Expand Up @@ -125,8 +125,8 @@ function refine(f::BatchIntegrand, segs::Vector{T}, I, E, numevals, x,w,gw,n, at
for i in 1:nsegs # evaluate segments and update estimates & heap
s = segs[len-i+1]
mid = (s.a + s.b)/2
s1 = evalrule(view(f.y, 1+2(i-1)*m:(2i-1)*m), s.a,mid, x,w,gw, nrm)
s2 = evalrule(view(f.y, 1+(2i-1)*m:2i*m), mid,s.b, x,w,gw, nrm)
s1 = batchevalrule(view(f.y, 1+2(i-1)*m:(2i-1)*m), s.a,mid, x,w,gw, nrm)
s2 = batchevalrule(view(f.y, 1+(2i-1)*m:2i*m), mid,s.b, x,w,gw, nrm)
I = (I - s.I) + s1.I + s2.I
E = (E - s.E) + s1.E + s2.E
segs[len-i+1] = s1
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,12 @@ end
@test quadgk(g, -Inf, 1.)[1] ≈ quadgk(x -> exp(-x^2), -Inf, 1.)[1]
@test quadgk(g, -Inf, Inf)[1] ≈ quadgk(x -> exp(-x^2), -Inf, Inf)[1]
end

# issue 89: callable objects that are also arrays
struct Test89 <: AbstractVector{Float64}
end
(::Test89)(x::Real) = float(x)
@testset "issue 89" begin
A = Test89()
@test quadgk(A, 0, 10) == (50, 0)
end
Loading