question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ENH] Exponentiation should follow Python semantics (or the current semantic difference should be documented)

See original GitHub issue

Is your feature request related to a problem? Please describe. Exponentiation is common in scientific code. Currently, the way that Cython processes exponentiation is to have the result type match the operand type. This issue has been brought up many times before (see #2133 for example). This can be surprise to those who choose to compile their code to gain a speed boost, even in Pure Python mode. For example:

def sqrt(x: double):
  return x ** 0.5
print(sqrt(-1)) # -> Prints (6.123233995736766e-17+1j) with Python (3.10.5), and nan with Cython (3.0.0a10 on Windows)

As previously mentioned, this issue have been closed before, but the recommended remedy (which is to add documentation to the Caveats page) has not been done

Describe the solution you’d like Personally, I would like Cython to compile Pure Python code to match Python semantics as much as reasonable, and I think, since Cython 3 is open to breaking changes, that following Python semantics for exponentiation should be the default action moving forward.

Describe alternatives you’ve considered An alternative that I am also happy is to keep the current semantics, but to provide a note in the “Caveats” section of the documentation, in addition to providing a clear compile-time warning whenever the Cython compiler can not guarantee adherence to Python exponentiation semantics.

Additional context I am willing to make a PR to the Caveats documentation if that is the route the core Cython devs want to go. But, as an aside, my current PR for documentation on __cinit__ has yet to be approved.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
da-woodscommented, Sep 11, 2022

I’m going to give this a go today though and see if I can get something working… I’m optimistic that it won’t be a huge change so can be dealt with fairly quickly

0reactions
0dminnimdacommented, Sep 11, 2022

It still will be prettier to have a cpow() function IMHO, but now it’s more about preferences and beauty of the code

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 577 – Augmented Assignment Expressions
To preserve the existing semantics of augmented assignment statements, inline assignment operators will be defined as being of lower ...
Read more >
A ~5 minute guide to Numba — Numba 0.50.1 documentation
Numba is a just-in-time compiler for Python that works best on code that uses NumPy arrays and functions, and loops. The most common...
Read more >
algorithms for enhancing information retrieval using
documents from the query, we will use the WordNet tool in order to capture the semantic information of document words. In summary, this...
Read more >
Event Logs - PM4Py - Process Mining for Python
To get the list of resources and activities contained in the log, the following code could be used. import pm4py if __name__ ==...
Read more >
3.7. Semantic Errors — Foundations of Python Programming
The meaning of the program (its semantics) is wrong. The computer is faithfully carrying out the instructions you wrote, and its results are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found