Skip to content

Commit

Permalink
ensure unit gets applied in ordinary case
Browse files Browse the repository at this point in the history
  • Loading branch information
lxvm committed Dec 30, 2023
1 parent abcc700 commit 55fc7d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/adapt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function handle_infinities(workfunc, f, s)
end
end
end
I, E = workfunc(f, map(x -> x/oneunit(x), s), identity)
I, E = workfunc(t -> f(t*u), map(x -> x/oneunit(x), s), identity)
return u * I, u * E
end

Expand Down Expand Up @@ -185,7 +185,7 @@ function handle_infinities(workfunc, f::InplaceIntegrand, s)
end
end
end
I, E = workfunc(InplaceIntegrand(f.f!, f.fg, f.fk, f.Ig, f.Ik, f.fx, f.Idiff, similar(f.fx)),
I, E = workfunc(InplaceIntegrand((y,t) -> f.f!(y, t*u), f.fg, f.fk, f.Ig, f.Ik, f.fx, f.Idiff, similar(f.fx)),
map(x -> x/oneunit(x), s),
identity)
result .= u .* I
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ module Test19626
ulims = map(x -> map(MockQuantity, x), lims)
for (lb, ub) in ulims
## function
f = x -> 1/(1+(x/oneunit(x))^2)
f = x -> 1/(1+(x/MockQuantity(1.0))^2)
buf = QuadGK.alloc_segbuf(MockQuantity, Float64, MockQuantity)
@test QuadGK.quadgk(f, lb, ub, atol=MockQuantity(0.0))[1]
QuadGK.quadgk(f, lb, ub, atol=MockQuantity(0.0), segbuf=buf)[1]
## inplace
fiip = (y, x) -> y[1] = 1/(1+(x/oneunit(x))^2)
fiip = (y, x) -> y[1] = 1/(1+(x/MockQuantity(1.0))^2)
ibuf = QuadGK.alloc_segbuf(MockQuantity, Array{Float64,1}, MockQuantity)
@test QuadGK.quadgk!(fiip, [MockQuantity(0.0)], lb, ub, atol=MockQuantity(0.0), norm=absfirst)[1][]
QuadGK.quadgk!(fiip, [MockQuantity(0.0)], lb, ub, atol=MockQuantity(0.0), norm=absgetindex, segbuf=ibuf)[1][]
## batch
fbatch = BatchIntegrand{Float64}((y, x) -> y .= 1 ./ (1 .+ (x ./ oneunit.(x)) .^ 2))
fbatch = BatchIntegrand{Float64}((y, x) -> y .= 1 ./ (1 .+ (x ./ MockQuantity(1.0)) .^ 2))
@test QuadGK.quadgk(fbatch, lb, ub, atol=MockQuantity(0.0))[1]
QuadGK.quadgk(fbatch, lb, ub, atol=MockQuantity(0.0), segbuf=buf)[1]
end
Expand Down

0 comments on commit 55fc7d6

Please sign in to comment.