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

Now uses specialised functions for complex abs #1648

Merged
merged 4 commits into from May 6, 2017

Conversation

da-woods
Copy link
Collaborator

@da-woods da-woods commented Mar 28, 2017

This patch avoids abs(a_complex_number) casting the complex number back to a Python object and instead uses the __pyx_c_abs* functions that are already defined. It also modifies the specialization for abs on int and long to not require the GIL.

Also added a test case to confirm it's working

Notes:

  • I don't think the correct utility code is loaded for complex abs
    (but it should be loaded by the complex data types hopefully)
    This might be worth someone double checking
  • Would probably be worth making double and float abs not require GIL
    (but this is a minor improvement to existing code)

da-woods added 2 commits March 28, 2017 14:32
Also doesn't require gil for int and long abs.

Notes:
* I don't think the correct utility code is loaded for complex abs
  (but it should be loaded by the complex data types hopefully)
* Would probably be worth making double and float abs not require gil
@scoder
Copy link
Contributor

scoder commented Apr 9, 2017

Seems worth putting this in a list comprehension by now.
And yes, the utility code will get loaded automatically by the type declarations in user code.

@da-woods
Copy link
Collaborator Author

da-woods commented Apr 9, 2017

I've updated it to use generator expressions to reduce the code duplication. (I've used generator expressions with list() instead of a list comprehension to avoiding adding the iteration variables to the module).

I've done it for both my new code (for complex numbers) and the existing code (for integer types). The integer types are a bit more messy since they needed strings and getattr on the PyrexTypes module to work, so it's possible you may not want to keep this.

@scoder scoder merged commit 41ad840 into cython:master May 6, 2017
@da-woods da-woods deleted the cmplx_abs branch November 21, 2017 19:38
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.

None yet

2 participants