Skip to content

basic implementation of NIntegrate#1160

Merged
mmatera merged 30 commits intomasterfrom
nintegrate
Mar 14, 2021
Merged

basic implementation of NIntegrate#1160
mmatera merged 30 commits intomasterfrom
nintegrate

Conversation

@mmatera
Copy link
Copy Markdown
Contributor

@mmatera mmatera commented Feb 18, 2021

Here it is a basic implementation of NIntegrate, working both on intervals and d-dimensional regions.
If scipy.integrate is available, uses quad as a default integrator, and allows to call other routines (romberg, and nquad, but others can be included later). Otherwise, or if these routines fails, a native Simpson's rule adaptative routine is included, and set as default if scipy is not available.
With #1161, I expect that this also works for complex valued functions.

@mmatera mmatera requested review from a team, GarkGarcia and rocky February 20, 2021 19:36
Copy link
Copy Markdown
Member

@rocky rocky left a comment

Choose a reason for hiding this comment

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

Overall I like this! Thanks!

On additional suggestion is to change CompiledCode#str to report which variation of compilation was used now that several methods are tried.

Comment thread mathics/builtin/compilation.py Outdated
>> Compile[{{a, _Integer}, {b, _Integer}}, While[b != 0, {a, b} = {b, Mod[a, b]}]; a] (* GCD of a, b *)
: Expression While[b != 0, {a, b} = {b, Mod[a, b]}] ; a could not be compiled.
= Function[{Global`a, Global`b}, While[b != 0, {a, b} = {b, Mod[a, b]}] ; a]
= CompiledFunction[{a, b}, a, -CompiledCode-]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When I assign this to a variable and run that on anythng anything other than 0 as the b argument this hangs. I am guessing this definition isn't quite right?

Copy link
Copy Markdown
Member

@rocky rocky Feb 21, 2021

Choose a reason for hiding this comment

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

One other thing I note is that when I look compilation.py pyflakes is reporting a number of small lint notes involving unused variables and imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes to both things: we need at some point to review the implementation of Compile in a closer way. However, this is a task for a couple of weekends. What motivated me to dig into this right now is that I needed this work for the NIntegrate implementation.

@rocky rocky self-requested a review February 21, 2021 11:13
Copy link
Copy Markdown
Member

@rocky rocky left a comment

Choose a reason for hiding this comment

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

I like this and it is much needed. Thanks!

As suggestion for improvement if you are up for it is to add in CompiledCode#__str__ an indication of what kind of compiled code we have now that there are several methods.

@mmatera
Copy link
Copy Markdown
Contributor Author

mmatera commented Feb 21, 2021

I like this and it is much needed. Thanks!

As suggestion for improvement if you are up for it is to add in CompiledCode#__str__ an indication of what kind of compiled code we have now that there are several methods.

Thanks! This last commit should attend to your suggestion.

@rocky rocky force-pushed the master branch 2 times, most recently from 96ec58b to e8a5440 Compare March 14, 2021 13:55
@rocky rocky mentioned this pull request Mar 14, 2021
@mmatera mmatera merged commit 494565a into master Mar 14, 2021
@mmatera mmatera deleted the nintegrate branch March 14, 2021 18:17
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