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

Numpy2.0 complex types update #905

Draft
wants to merge 12 commits into
base: numpy2
Choose a base branch
from

Conversation

brendan-m-murphy
Copy link

Description

Related Issue

  • Closes #
  • Related to #

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

Numpy 2.0 uses C99 complex variables, which come in three varieties:
complex floats, complex doubles, and complex long doubles. Numpy
defines corresponding types: npy_cfloat, npy_cdouble, npy_clongdouble.

We need to translate between these sizes and bit-width sizes,
like npy_complex64 and npy_complex128. The alises added do so,
as least in the cases where doubles have 32 or 64 bits
Updated pytensor_complex struct to use get/set real/imag
aliases defined above.

Note: redefining the complex arithmetic here means that we
aren't treating NaNs and infinities as carefully as the C99
standard suggets (see Appendix G of the standard).

The code has been like this since it was added to Theano,
so we're keeping the existing behavior.
We need the bit width of the complex types so that
we can choose the right get/set operators
Many more tests pass after fixing this.
@brendan-m-murphy brendan-m-murphy mentioned this pull request Jul 8, 2024
11 tasks
@brendan-m-murphy brendan-m-murphy changed the base branch from main to numpy2 July 9, 2024 08:39
brendan-m-murphy and others added 6 commits July 9, 2024 09:44
Github merge added back some changes from the
commit that removed custom complex types, which
caused some tests to start failing again.
The macros select based on the underlying numpy
type, so we don't need to find this explicitly, like
the previous solution was doing.
@brendan-m-murphy brendan-m-murphy marked this pull request as draft July 10, 2024 08:20
These need to be copied into the source code
since they're not available in Numpy 1.x.

They define macros with the Numpy 1.x behavior
for getting real and imaginary parts. In Numpy 2.0
these macros are already defined with the new definitions,
so this addition to our code will be ignored in Numpy 2.0
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.

1 participant