GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: Replace npy complex structs with native complex types by lysnikolaou · Pull Request #24085 · numpy/numpy

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented Jun 30, 2023

Copy link
Copy Markdown
Member

See discussion in #20880.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lysnikolaou added 12 commits June 30, 2023 15:29
@lysnikolaou
Replace npy_c* structs with native types
fd455d2
@lysnikolaou
Format
9eb7053
@lysnikolaou
Fix f2py
d2b5512
@lysnikolaou
Rename complex to singlecomplex in all f2c'd files
4a246bb
@lysnikolaou
Fix complex init
5c38f35
@lysnikolaou
Fix uninitialized values in arraytypes
b240b10
@lysnikolaou
Make GET_REAL and GET_IMAG into inline functions that use unions
725a8d6
@lysnikolaou
Fix call to memset with std::complex in umath_linalg
6050aad
@lysnikolaou
Fix call to SET_REAL/SET_IMAG in umath matmul
a7fea9b
@lysnikolaou
Remove c99 compat layer from npymath
8749082
@lysnikolaou
Fix log10 and log2
ea282c7
@lysnikolaou
Fix initialization of complex in npy_math_complex
a926e01
@github-actions github-actions Bot added the 01 - Enhancement label Jun 30, 2023
@lysnikolaou
Merge branch 'main' into real-imag-remove
3d29fb1
@charris

charris commented Jun 30, 2023

Copy link
Copy Markdown
Member

The lapack_lite files are generated, you should leave them alone if possible, otherwise generate a patch to apply the differences.

I don't know if this will cause problems or not, the complex types were late to arrive in C and there might be some compatibility problems.

lysnikolaou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Jul 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

The lapack_lite files are generated, you should leave them alone if possible, otherwise generate a patch to apply the differences.

Thanks a lot for the pointers! Unfortunately, the generated files will need to change, since complex is a reserved keyword now by importing complex.h. I figured I'd need to change the patch files, but I still opened this, mostly for the CI to run. As soon as I've got everything working, I'll revert the changes to the f2c'd files and patch them instead.

I don't know if this will cause problems or not, the complex types were late to arrive in C and there might be some compatibility problems.

Yeah, this has been mostly about checking whether everything would work fine. I guess there's no better way than to do the work.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou added 2 commits July 4, 2023 18:14
@lysnikolaou
First attempt to fix CI // Add static inline
2b2c597
@lysnikolaou
Fix inline setters
ad60798
@lysnikolaou
lysnikolaou force-pushed the real-imag-remove branch 4 times, most recently from 30b3af7 to ad60798 Compare July 5, 2023 12:37
@lysnikolaou
Initialize complex numbers
f65c643
mattip
mattip reviewed Jul 5, 2023
View reviewed changes
Comment thread numpy/core/include/numpy/npy_common.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou
Fix implicit declaration of CMPLX on musllinux
bf3fa21
@lysnikolaou
lysnikolaou force-pushed the real-imag-remove branch from 5c5d5f7 to bf3fa21 Compare July 5, 2023 17:18
@lysnikolaou
Hopefully fix Windows stuff
57e204b
@lysnikolaou
lysnikolaou force-pushed the real-imag-remove branch 3 times, most recently from d9bfd27 to 717141f Compare July 7, 2023 09:17
@mattip

mattip commented Jul 31, 2023

Copy link
Copy Markdown
Member

I wish we could swap in std::complex, unless MSVC thwarts that

You hit the nail on the head. MSVC made this PR so much harder than it should have been.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou added 2 commits July 31, 2023 15:21
@lysnikolaou
Address feedback
530cbc5
@lysnikolaou
Merge branch 'main' into real-imag-remove
2665d56
@seberg

seberg commented Jul 31, 2023

Copy link
Copy Markdown
Member

Yeah, but unlike C99 support, I think the C++ std::complex class exists? Although maybe it is newer. But making the C++ code nicer probably requires getting rid of those tags (i.e. using C++17 features that were avoided when it was written).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Jul 31, 2023

Copy link
Copy Markdown
Member Author

Yeah, but unlike C99 support, I think the C++ std::complex class exists?

It does exist, but it makes using these types more complicated, since std::complex is a template and we need to mix C++/C linkage.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Jul 31, 2023

Copy link
Copy Markdown
Member Author

CI failures appear to be unrelated, so, someone, please restart the two failing jobs. 🙏

rgommers reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rgommers

rgommers commented Jul 31, 2023

Copy link
Copy Markdown
Member

Failures were down to one, and I restarted that last one now. If it fails again, please simply ignore it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mattip
mattip merged commit 1cd92a1 into numpy:main Jul 31, 2023
@mattip

mattip commented Jul 31, 2023

Copy link
Copy Markdown
Member

Thanks @lysnikolaou

seberg reacted with thumbs up emoji lysnikolaou reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seberg seberg added this to the 2.0.0 release milestone Jul 31, 2023
@seberg

seberg commented Jul 31, 2023

Copy link
Copy Markdown
Member

A few follow-ups we might want to look into:

  • This still needs a release note pointing to the compat header, or nobody will find it :). (i.e. to say what changed and what new API exists)
  • The Cython definitions are still based on the struct. I am not quite sure if we want to change it. The definitions are easy to avoid and losing .real and .imag might be annoying, while npymath isn't even easily available.

Is there anything else to think about?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Jul 31, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

This still needs a release note pointing to the compat header, or nobody will find it :). (i.e. to say what changed and what new API exists)

I can do this in a new PR, if that's okay. It'll be my first time writing anything more than a one-liner for a release note though, so it's okay if someone else wants to take this.

The Cython definitions are still based on the struct. I am not quite sure if we want to change it. The definitions are easy to avoid and losing .real and .imag might be annoying, while npymath isn't even easily available.

Agreed that it's okay to leave as-is for now. Cython's handling of complex's is a bit complicated as well because of the MSVC issues, so it might make things harder to reason about.

Is there anything else to think about?

We could write a few words in the NumPy core math library section of the docs about complex handling as well, although I guess that wouldn't be a priority. Also, I'm already working on removing as much of the complex compat layer in npy_math as possible. We'll have to see how much we can strip it down.

seberg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charris charris mentioned this pull request Aug 2, 2023
MAINT: Massive update of files from main for numpy 1.26 #24308
Merged
@mroeschke mroeschke mentioned this pull request Aug 2, 2023
COMPAT: Change khcomplex64/128_t typedefs pandas-dev/pandas#54375
Merged
rgommers pushed a commit to scipy/scipy that referenced this pull request Aug 3, 2023
@lysnikolaou
ENH: Port scipy to use new numpy complex types (#18975)
d1da380
Fixes breakage with numpy's main branch after
numpy/numpy#24085
@rgommers

rgommers commented Aug 3, 2023

Copy link
Copy Markdown
Member

I can do this in a new PR, if that's okay. It'll be my first time writing anything more than a one-liner for a release note though, so it's okay if someone else wants to take this.

Sounds like a good exercise to me:) Describing the reason for the change and how to adapt to it is the main thing, which I think is easiest for you to do. We can help tweak so it fits with the other release notes if needed. Given that this is causing a fair amount of breakage (at least SciPy, pandas, and h5py I've seen), it'd be nice to get this drafted.

lysnikolaou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lysnikolaou

lysnikolaou commented Aug 3, 2023

Copy link
Copy Markdown
Member Author

Sounds good! I'll get started on this tomorrow.

rgommers reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

WarrenWeckesser
WarrenWeckesser reviewed Aug 5, 2023
View reviewed changes
Comment thread numpy/core/include/numpy/npy_common.h
#ifdef __cplusplus
}
#endif
#undef complex

@WarrenWeckesser WarrenWeckesser Aug 5, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't think this #undef should be here. This breaks the use of complex in extensions modules that use #include <complex.h> that also include this NumPy header.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@mattip mattip Aug 5, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

xref #24343

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@WarrenWeckesser WarrenWeckesser mentioned this pull request Aug 5, 2023
BUG: Use of #undef complex in npy_common.h breaks extension modules that use #include <complex.h> #24344
Closed
@mattip mattip mentioned this pull request Aug 6, 2023
BUG: core: Do not use '#undef complex' in npy_common.h. #24343
Closed
@lysnikolaou lysnikolaou mentioned this pull request Aug 8, 2023
DOC: Add documentation and release notes for new complex types #24361
Closed
@ngoldbaum ngoldbaum mentioned this pull request Aug 25, 2023
MAINT: NumPy complex shim needed? serge-sans-paille/pythran#2143
Closed
@lysnikolaou lysnikolaou mentioned this pull request Oct 4, 2023
stringdtype fails to build on Linux numpy/numpy-user-dtypes#90
Closed
@tacaswell tacaswell mentioned this pull request Nov 20, 2023
support new numpy complex types pydata/numexpr#458
Closed
@avalentino avalentino mentioned this pull request Nov 22, 2023
CI workflow failures with numpy>=2.dev0 PyTables/PyTables#1083
Closed
This was referenced Dec 1, 2023
Numpy 2.x incompatibilities h5py/h5py#2348
Closed
DOC: Migration guide should mention complex number API changes #25294
Closed
@lucascolley lucascolley mentioned this pull request Jan 1, 2024
ENH:MAINT:special:Rewrite amos F77 code scipy/scipy#19587
Merged
3 tasks done
@Saviq Saviq mentioned this pull request Feb 8, 2024
FTBFS on armhf: expected unqualified-id before ‘_Complex’ canonical/checkbox-mir#9
Closed
@WarrenWeckesser WarrenWeckesser mentioned this pull request Jun 27, 2024
BUG: Performance regression of np.log with complex64 input on Linux #26807
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seberg seberg seberg approved these changes
@rgommers rgommers rgommers left review comments
@WarrenWeckesser WarrenWeckesser WarrenWeckesser left review comments
@mattip mattip mattip approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

01 - Enhancement

Projects

NumPy first-time contributor PRs
Status: Completed
NumPy 2.0 Roadmap
Status: ✅ Done

Milestone

2.0.0 release

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@lysnikolaou @charris @rgommers @mattip @seberg @WarrenWeckesser
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.