Skip to content

[math][mathmore] Fix setting optional parameters for GSLMCIntegrator#14058

Merged
lmoneta merged 2 commits into
root-project:masterfrom
lmoneta:mathmore_fix_mc_integration
Jan 22, 2024
Merged

[math][mathmore] Fix setting optional parameters for GSLMCIntegrator#14058
lmoneta merged 2 commits into
root-project:masterfrom
lmoneta:mathmore_fix_mc_integration

Conversation

@lmoneta

@lmoneta lmoneta commented Nov 15, 2023

Copy link
Copy Markdown
Member

Calling GSLMCIntegrator::SetMode crashed because the internal workspace was not yet created.
This PR fixes this and also the way the extra option parameters are retrieved and set in the GSLMCIntegrator.

A small change in the interface is done by returning now a unique_ptr instead of a row pointer in
GSLMCIntegrator::ExtraOptions()

@phsft-bot

Copy link
Copy Markdown

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@github-actions

github-actions Bot commented Nov 15, 2023

Copy link
Copy Markdown

Test Results

     9 files       9 suites   1d 16h 37m 51s ⏱️
 2 491 tests  2 491 ✅ 0 💤 0 ❌
21 387 runs  21 387 ✅ 0 💤 0 ❌

Results for commit ebb2113.

♻️ This comment has been updated with latest results.

Comment thread math/mathmore/src/GSLMCIntegrator.cxx Outdated
Comment on lines +474 to +475
auto extraOpts = ExtraOptions();
ROOT::Math::IntegratorMultiDimOptions opt(extraOpts.release());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
auto extraOpts = ExtraOptions();
ROOT::Math::IntegratorMultiDimOptions opt(extraOpts.release());
ROOT::Math::IntegratorMultiDimOptions opt(ExtraOptions().release());

Can be shortened (which also makes clear that the output of ExtraOptions(I) is not used anywhere else)

Comment thread math/mathmore/src/MCParameters.cxx Outdated
opt->SetIntValue("mode",mode);
opt->SetIntValue("verbose",verbose);
return opt;
return std::unique_ptr<ROOT::Math::IOptions>(opt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return std::unique_ptr<ROOT::Math::IOptions>(opt);
return opt;

To really avoid manual memory management with operator new, it would be better to directly create opt as a unique_ptr and then simply return it.

And then further up, this would mean doing:

auto opt = std::make_unique<GenAlgoOptions>();

Comment thread math/mathmore/src/MCParameters.cxx Outdated
opt->SetIntValue("min_calls",min_calls);
opt->SetIntValue("min_calls_per_bisection",min_calls_per_bisection);
return opt;
return std::unique_ptr<ROOT::Math::IOptions>(opt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return std::unique_ptr<ROOT::Math::IOptions>(opt);
auto opt = std::make_unique<GenAlgoOptions>();
....
return out;

Same as in my other comment.

Comment thread math/mathmore/inc/Math/MCParameters.h Outdated

/// convert to options (return object is managed by the user)
ROOT::Math::IOptions * operator() () const;
std::unique_ptr<ROOT::Math::IOptions> operator() () const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<ROOT::Math::IOptions> operator() () const;
std::unique_ptr<ROOT::Math::IOptions> makeIOptions() const;

Since you are already changing the return type of that function, can we maybe also change the name?
Personally, I don't like implementing operator() if there is not a really good reason for it, because if is harder to grep the code for where it is actually called. It's better to have an explicit name I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, since this returns now a unique_ptr, the comment "is managed by the user" is not necessary anymore:

Convert to options.

Further note that doxygen comments should begin uppercase and end with a period.

Comment thread math/mathmore/inc/Math/MCParameters.h Outdated

/// convert to options (return object is managed by the user)
ROOT::Math::IOptions * operator() () const;
std::unique_ptr<ROOT::Math::IOptions> operator() () const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<ROOT::Math::IOptions> operator() () const;
std::unique_ptr<ROOT::Math::IOptions> makeIOptions() const;

Same here.

std::unique_ptr<ROOT::Math::IOptions> ExtraOptions() const;

/**
* set the extra options for Vegas and Miser

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* set the extra options for Vegas and Miser
* Set the extra options for Vegas and Miser.

@guitargeek guitargeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM in principle! I just have a few technical suggestions that would be nice to see implemented.

Calling GSLMCIntegrator::SetMode crashed because the internal workspace wss not yet created. This is now fixed and also the way the extra option parameters are retrieved and set.
Avoid now potential memory leak by using a unique_ptr
use MakeIOptions() instead of operator()
@lmoneta
lmoneta force-pushed the mathmore_fix_mc_integration branch from 62ada10 to ebb2113 Compare January 22, 2024 11:19
@phsft-bot

Copy link
Copy Markdown

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants