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

Calculate nodes and weights at GaussLegendre construction time #149

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

mikeingold
Copy link
Collaborator

@mikeingold mikeingold commented Dec 4, 2024

Changes

Discussion

The Gauss-Legendre nodes and weights are purely a function of order n, so I think it makes sense to just calculate them when constructing the rule itself. This will lead to some moderate performance benefits for rules used more than once, or where the integration occurs in some performance-sensitive user code block.

Currently, FastGaussQuadrature.jl doesn't allow us to request nodes and weights in a particular eltype, and instead always returns Vector{Float64}s. If that support ever materializes then I think it could make sense to add a parameter GaussLegendre{T} to handle this, but for now I don't think it's necessary.

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Benchmark Results

main faaecf3... main/faaecf35e3ef9a...
Differentials/Differential 0.24 ± 0.001 μs 0.24 ± 0.001 μs 1
Differentials/Jacobian 0.207 ± 0.0001 μs 0.205 ± 0.0001 μs 1.01
Integrals/Segment/Scalar GaussKronrod 1.19 ± 0.004 μs 1.19 ± 0.006 μs 1
Integrals/Segment/Scalar GaussLegendre 6.97 ± 0.13 μs 4.16 ± 0.01 μs 1.67
Integrals/Segment/Scalar HAdaptiveCubature 1.43 ± 0.15 μs 1.46 ± 0.15 μs 0.981
Integrals/Segment/Vector GaussKronrod 3.46 ± 0.056 μs 3.42 ± 0.068 μs 1.01
Integrals/Segment/Vector GaussLegendre 22.8 ± 0.52 μs 20.3 ± 0.42 μs 1.12
Integrals/Segment/Vector HAdaptiveCubature 4.32 ± 0.079 μs 4.39 ± 0.092 μs 0.984
Integrals/Sphere/Scalar GaussKronrod 0.0823 ± 0.002 ms 0.0825 ± 0.00094 ms 0.997
Integrals/Sphere/Scalar GaussLegendre 2.26 ± 0.0089 ms 2.25 ± 0.0098 ms 1.01
Integrals/Sphere/Scalar HAdaptiveCubature 0.0584 ± 0.00016 ms 0.0577 ± 0.00011 ms 1.01
Integrals/Sphere/Vector GaussKronrod 0.115 ± 0.00088 ms 0.117 ± 0.0011 ms 0.991
Integrals/Sphere/Vector GaussLegendre 3.61 ± 0.079 ms 3.68 ± 0.075 ms 0.981
Integrals/Sphere/Vector HAdaptiveCubature 0.109 ± 0.00092 ms 0.108 ± 0.0011 ms 1
Rules/GaussLegendre 2.79 ± 0.009 ns 21.5 ± 0.51 μs 0.00013
Specializations/Scalar GaussLegendre/BezierCurve 0.251 ± 0.003 ms 0.246 ± 0.00034 ms 1.02
Specializations/Scalar GaussLegendre/Line 11.1 ± 0.41 μs 8.15 ± 0.08 μs 1.36
Specializations/Scalar GaussLegendre/Plane 0.905 ± 0.0089 ms 0.9 ± 0.0071 ms 1.01
Specializations/Scalar GaussLegendre/Ray 10.4 ± 0.45 μs 7.45 ± 0.071 μs 1.39
Specializations/Scalar GaussLegendre/Rope 0.211 ± 0.0015 ms 0.13 ± 0.00012 ms 1.63
Specializations/Scalar GaussLegendre/Tetrahedron 0.288 ± 0.0022 s 0.315 ± 0.0067 s 0.915
Specializations/Scalar GaussLegendre/Triangle 0.729 ± 0.0083 ms 0.727 ± 0.0057 ms 1
time_to_load 1.54 ± 0.0059 s 1.57 ± 0.034 s 0.979

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3c06d76) to head (faaecf3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #149   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          166       165    -1     
=========================================
- Hits           166       165    -1     

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

@mikeingold mikeingold marked this pull request as ready for review December 4, 2024 16:42
Copy link
Member

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

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

Nice! This can also be helpful if you want to integrate multiple functions even in potentially different geometries because you can reuse the rule object, i.e. also in this case you only need to compute the nodes and weight once.

@mikeingold mikeingold merged commit ab712c7 into main Dec 4, 2024
12 checks passed
@mikeingold mikeingold deleted the gauss branch December 4, 2024 17:48
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.

Possible to cache Gauss-Legendre nodes and weights
2 participants