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 units consistently in handle_infinites #96

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

lxvm
Copy link
Contributor

@lxvm lxvm commented Nov 13, 2023

Fixes #95
This pr changes handle_infinities to always pass limits with units to do_quadgk so that the same segbuf can be used with finite and infinite limits.
It also adds some tests to check this works for inplace and batched integrands.

Unfortunately, the endpoints of the segments in a segbuf don't correspond to the intervals used in the original domain when using the infinity transformation. However, changing that would be a lot more involved than what is needed for this pr.

Copy link

codecov bot commented Nov 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (135432c) 98.21% compared to head (f328bd7) 98.27%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
+ Coverage   98.21%   98.27%   +0.06%     
==========================================
  Files           6        6              
  Lines         615      637      +22     
==========================================
+ Hits          604      626      +22     
  Misses         11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return workfunc(f, s, identity)
I, E = workfunc(BatchIntegrand((y, t) -> begin resize!(f.x, length(t));
f.f!(y, f.x .= u .* t); end, f.y, f.x, f.t, f.max_batch),
map(x -> x/oneunit(x), s),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pays the cost of a division for every integrand evaluation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that is just for the segments.

@lxvm
Copy link
Contributor Author

lxvm commented Dec 30, 2023

@stevengj this pr is now updated to pass unitless limits to do_quadgk and the new tests are more careful about verifying this behavior.
Here are also timings on Julia 1.10 that show a median slowdown under 2.5% in general:

branch integrand median time
pr x 35.839 ns
master x 35.007 ns
pr sin(100x) 11.965 μs
master sin(100x) 11.762 μs
benchmark for this pr
julia> using BenchmarkTools

julia> using QuadGK

julia> @benchmark quadgk(x -> x, 0, 1) # zero-cost integrand, no subdivisions
BenchmarkTools.Trial: 10000 samples with 993 evaluations.
 Range (min  max):  35.383 ns  107.806 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     35.839 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   36.505 ns ±   4.703 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █▄                                                            
  ██▃▃▂▂▂▂▂▂▁▂▂▂▁▂▁▂▁▁▁▁▁▁▂▁▁▂▁▁▂▂▁▁▂▂▂▂▁▁▂▂▂▂▂▂▂▂▂▂▂▁▂▂▂▁▁▁▂▂ ▂
  35.4 ns         Histogram: frequency by time         63.2 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark quadgk(x -> sin(100x), 0, 1) # low-cost integrand with subdivisions
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  11.611 μs  55.500 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     11.965 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   12.100 μs ±  1.526 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

                        ▃█▇█▅▄▂▁                               
  ▂▂▂▂▂▂▂▁▂▁▁▂▁▁▁▂▁▂▂▃▅█████████▇▆▆▅▄▄▃▃▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  11.6 μs         Histogram: frequency by time        12.4 μs <

 Memory estimate: 1.69 KiB, allocs estimate: 3.
benchmark on master
julia> using BenchmarkTools

julia> using QuadGK

julia> @benchmark quadgk(x -> x, 0, 1) # zero-cost integrand, no subdivisions
BenchmarkTools.Trial: 10000 samples with 992 evaluations.
 Range (min  max):  33.998 ns  402.374 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     35.007 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   36.006 ns ±   7.741 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▃█                                                            
  ██▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁
  34 ns           Histogram: frequency by time         70.1 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark quadgk(x -> sin(100x), 0, 1) # low-cost integrand with subdivisions
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  11.362 μs  57.351 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     11.762 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   12.303 μs ±  1.512 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

     █▄                                                        
  ▇▅▂██▃▂▂▂▂▁▁▁▂▃▄▃▃▇▆▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▁▂▁▂▂▂▂▂▂▂▂▁▂▂▁▁▂▁▁▁▂ ▃
  11.4 μs         Histogram: frequency by time          17 μs <

 Memory estimate: 1.69 KiB, allocs estimate: 3.

I think this is ready and could be a patch release

# in-place function f!(y, x) that takes an array of x values and outputs an array of results in-place
f!::F
y::Ty
x::Tx
t::T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not great that we pay the price of having an additional point array here …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

infinite limits with units and segbuf broken
2 participants