Skip to content

Integrate with hints - #1

Merged
alexandrehoffmann merged 13 commits into
mainfrom
integrate_with_hints
Jul 24, 2026
Merged

alexandrehoffmann merged 13 commits into
mainfrom
integrate_with_hints

Conversation

@alexandrehoffmann

@alexandrehoffmann alexandrehoffmann commented Jul 24, 2026

Copy link
Copy Markdown
Owner

The goal of this PR is to use adaptive quadrature over $\mathbb{R}$ with hints on where the most relevant features of the integrate functions are.

The user provides a std::span of mean and a single variance corresponding to the function's peaks the adaptive quadrature then computes an initial subdivision of $\mathbb{R}$ from theses informations.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the finite-interval adaptive quadrature implementation by extracting the iterative “adaptation” loop into a reusable helper, likely as groundwork for alternative initialization strategies (e.g., hinted subdivision).

Changes:

  • Extracted the core adaptive refinement loop into a new private helper (addaptQuadrature).
  • Reworked integrate(xmin, xmax) to only build the initial subdivision and then delegate refinement to the helper.
  • Minor local cleanup in the refinement loop (structured binding for the second interval estimate).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase.hpp Declares a new private helper to run the adaptive refinement loop.
include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp Moves the refinement loop into the helper and makes integrate delegate to it after initial subdivision.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase.hpp Outdated
Comment thread include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp Outdated
Comment thread include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp Outdated
Comment on lines +71 to +73
template<class Derived> template<class Function>
auto AdaptiveQuadratureBase<Derived>::integrate(const Function& f, const Scalar& xmin, const Scalar& xmax) -> LongScalar
{
alexandrehoffmann and others added 6 commits July 24, 2026 10:57
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (3)

include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp:125

  • Range-for iterates mu as const double&, which forces a conversion from Scalar to double and can lose precision (and breaks if Scalar isn’t implicitly convertible to double). Iterate using Scalar instead.
	for (const double& mu_i : mu)

include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp:123

  • If mu is empty, no sub-intervals are created and adaptQuadrature() will call max_element() on an empty error vector (UB). Consider falling back to the existing infinite-range integrate(f) behavior when no hints are provided.
	m_intervals.clear();
	m_subIntergrals.clear();
	m_subIntergralsErr.clear();

	m_intervals.reserve(2*mu.size());

include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp:179

  • fmt::print(..., "{}", m_intervals) requires fmt range formatting support (e.g., <fmt/ranges.h>) and a formatter for Interval/pair. With only <fmt/core.h> included here, this is likely to fail to compile. Consider logging only the number of intervals, or include the necessary fmt headers.
	if (m_out) { fmt::print(m_out, "#NumericalIntegrator adapting quadrature over {}\n", m_intervals); }

Comment on lines 78 to +81
template<class Function> LongScalar integrate(const Function& f, const Scalar& xmin, const Scalar& xmax);


template<class Function> LongScalar integrateWithHints(const Function& f, const std::span<const Scalar> mu, const Scalar& sigma);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

PR comment was fixed to a std::span of means and a single sigma.

Comment thread include/LNIT/AdaptiveQuadratures/AdaptiveQuadratureBase_impl.hpp
@alexandrehoffmann
alexandrehoffmann merged commit 133f4f0 into main Jul 24, 2026
5 checks passed
@alexandrehoffmann
alexandrehoffmann deleted the integrate_with_hints branch July 24, 2026 10:46
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.

2 participants