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

lambdify loggamma now works for mpmath #19913

Merged
merged 4 commits into from
Aug 31, 2020
Merged

Conversation

abhaydhiman
Copy link
Contributor

@abhaydhiman abhaydhiman commented Aug 7, 2020

References to other Issues or PRs

Fixed #17411

Brief description of what is fixed or changed

Lambdifying an expression with loggamma doesn't work for mpmath previously but I made some fixes so that it works. File changed are pycode and test_pycode.

Other comments

Nan

Release Notes

  • printing
    • The mpmath code printer now correctly prints the loggamma function.
  • utilities
    • Lambdifying an expression with loggamma using mpmath no longer raises ImportError.

@sympy-bot
Copy link

sympy-bot commented Aug 7, 2020

Hi, I am the SymPy bot (v160). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • printing

    • The mpmath code printer now correctly prints the loggamma function. (#19913 by @abhaydhiman)
  • utilities

    • Lambdifying an expression with loggamma using mpmath no longer raises ImportError. (#19913 by @abhaydhiman)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixed #17411

#### Brief description of what is fixed or changed
Lambdifying an expression with loggamma doesn't work for mpmath previously but I made some fixes so that it works. File changed are pycode and test_pycode.

#### Other comments
Nan

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* printing
    * The mpmath code printer now correctly prints the `loggamma` function.
* utilities
    * Lambdifying an expression with `loggamma` using mpmath no longer raises `ImportError`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #19913 into master will decrease coverage by 4.467%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##            master    #19913       +/-   ##
=============================================
- Coverage   75.811%   71.344%   -4.468%     
=============================================
  Files          668       668               
  Lines       173237    173186       -51     
  Branches     40841     40842        +1     
=============================================
- Hits        131334    123558     -7776     
- Misses       36172     43777     +7605     
- Partials      5731      5851      +120     

@abhaydhiman
Copy link
Contributor Author

As sympy.__dict__ doesn't contains lgamma. Its used to pass the test case for lgamma as main function for it is defined in mpmath.__dict__.

@eric-wieser
Copy link
Member

You need to change the mpmath specific lines I linked to above.

@abhaydhiman
Copy link
Contributor Author

You need to change the mpmath specific lines I linked to above.

What exactly do I have to change in that line of code.

@eric-wieser
Copy link
Member

Updating the dictionary to correct the lgamma key on the next line would probably do the trick.

@abhaydhiman
Copy link
Contributor Author

well, I actually did that.

@eric-wieser
Copy link
Member

You should add to _known_functions_mpmath

@abhaydhiman
Copy link
Contributor Author

abhaydhiman commented Aug 9, 2020

'lgamma': 'loggamma' if I add this in _known_functions_mpmath that again gives the same error. Or I have to add "loggamma": "loggamma" without deleting the previous "loggamma": "lgamma", I tried this and this works perfectly fine.

@eric-wieser
Copy link
Member

Or I have to add "loggamma": "loggamma" without deleting the previous "loggamma": "lgamma", I tried this and this works perfectly fine.

This sounds ideal to me - this effectively does delete the previous entry.

@abhaydhiman
Copy link
Contributor Author

Is it good to go now?

@eric-wieser
Copy link
Member

No. You need to add "loggamma": "loggamma" to _known_functions_mpmath

@abhaydhiman
Copy link
Contributor Author

oh! Sorry, I am on it.

@eric-wieser
Copy link
Member

eric-wieser commented Aug 9, 2020

This fix now looks correct - can you add a test next to the other python code printer tests?

@abhaydhiman
Copy link
Contributor Author

Testcase for this nsolve(im(loggamma(I*x)), x, 3.439*I) equation?

@abhaydhiman
Copy link
Contributor Author

Also, do I have to add a test in test_pycode.py?

@eric-wieser
Copy link
Member

Yes, please add a test to that file. Simply checking the result of something like pycode(loggamma(x)) should be enough, no need to complicate the test

@abhaydhiman
Copy link
Contributor Author

Ok Thanks, can I make a separate function for that?

@abhaydhiman
Copy link
Contributor Author

Or I have to add that in test_PythonCodePrinter

@eric-wieser
Copy link
Member

test_MpmathPrinter looks like a good place to add it, since this is about mpmath.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Release notes need updating to describe what was fixed (and not how), but the code is good.

@abhaydhiman
Copy link
Contributor Author

But it got AssertionError. I don't know why that's happen

@abhaydhiman
Copy link
Contributor Author

I have updated the release notes please review it. Thanks!!

@eric-wieser
Copy link
Member

Still not quite right - will defer to @oscarbenjamin, since they reported the original bug.

@oscarbenjamin
Copy link
Collaborator

It looks like this fixes the original issue. What is not quite right?

Is it the release note?

Maybe it should say:

* printing
    * The mpmath code printer now correctly prints the loggamma function.
* utilities
    * Lambdifying an expression with loggamma using mpmath no longer raises NameError.

@eric-wieser
Copy link
Member

Yeah, just the release note which decribed the diff not the result. That looks like a good note to me.

@eric-wieser
Copy link
Member

Although I think it was ImportError

@oscarbenjamin
Copy link
Collaborator

Maybe there could also be a test for lambdify

@abhaydhiman
Copy link
Contributor Author

So do I have to include a test for lambdify also?

@abhaydhiman
Copy link
Contributor Author

@oscarbenjamin or @eric-wieser Do I have to add Test in test_lambdify.py file specifically in test_special_printers function if not please guide me where I have to add the Testcase for lambdify?

@abhaydhiman
Copy link
Contributor Author

Is this lambdify(x, loggamma(x), 'mpmath')(5) test is valid?

@oscarbenjamin
Copy link
Collaborator

Yes, that seems good. You could test that it gives a couple of expected values for the loggamma function.

@abhaydhiman
Copy link
Contributor Author

Yes, tried different values for x and it gives the expected output. So Is one test case is sufficient or I have to add more than one test for lambdify.

@abhaydhiman
Copy link
Contributor Author

@oscarbenjamin I have added the test case please review it.

@oscarbenjamin
Copy link
Collaborator

Looks good

@abhaydhiman
Copy link
Contributor Author

Thanks!

@abhaydhiman
Copy link
Contributor Author

@oscarbenjamin any other change, you wanted in this PR.

Copy link
Contributor

@Ayush-Malik Ayush-Malik left a comment

Choose a reason for hiding this comment

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

Looks good to me , @oscarbenjamin please review this PR

@czgdp1807
Copy link
Member

@oscarbenjamin Is this good to go?

@oscarbenjamin
Copy link
Collaborator

Looks good. Thanks!

@oscarbenjamin oscarbenjamin merged commit f7c7217 into sympy:master Aug 31, 2020
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.

lambdify loggamma doesn't work for mpmath
6 participants