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 — DOC: Migration guide should mention complex number API changes · Issue #25294 · numpy/numpy

DOC: Migration guide should mention complex number API changes #25294

New issue
Copy link
New issue
Copy link
Closed
#25929
Closed
DOC: Migration guide should mention complex number API changes#25294
#25929
Copy link
Labels
04 - Documentation

Description

@djhoese
djhoese
opened on Dec 1, 2023
Issue body actions

Describe the issue:

I'm helping the h5py project migrate to Cython 3 and while doing so also tested with numpy 2.0 (main). I discovered some compilation errors which you can read in detail here:

h5py/h5py#2348

Basically h5py uses a macro from the HDF5 C++ library to get the offset into a struct for the "real" and "imag" members, but now complex types in numpy's C API are not structs (#24085). So I'm wondering what the best long term solution is to work around this. The h5py code doing this looks like this:

 #define h5py_offset_n64_real (HOFFSET(npy_complex64, real)) 

Reproduce the code example:

Not a python problem so no code example. See above for compilation information. Sorry for filing this as a bug but the "support" page on the docs lead to gitter, reddit, and IRC which all seemed inactive. This seems like a possibly specific case to h5py so I didn't really want to put it on stackoverflow either. And I wasn't really sure what else to categorize this as.

Error message:

/tmp/pip-req-build-3skh7xs0/h5py/h5t.c: In function ‘__pyx_f_4h5py_3h5t__c_complex’:
      /tmp/pip-req-build-3skh7xs0/h5py/api_compat.h:38:31: error: request for member ‘real’ in something not a structure or union
         38 | #define h5py_offset_n64_real (HOFFSET(npy_complex64, real))
            |                               ^~~~~~~
      /tmp/pip-req-build-3skh7xs0/h5py/h5t.c:26702:21: note: in expansion of macro ‘h5py_offset_n64_real’
      26702 |     __pyx_v_off_r = h5py_offset_n64_real;
            |                     ^~~~~~~~~~~~~~~~~~~~

Python and NumPy Versions:

Python 3.11
Numpy 2.0 (main)

Runtime Environment:

No response

Context for the issue:

Currently affecting h5py compatibility with numpy 2.0.

Activity

  1. djhoese
    added
    00 - Bug
    on Dec 1, 2023
  2. seberg commented on Dec 1, 2023

    @seberg
    seberg
    on Dec 1, 2023
    Member
    More actions

    Every standard defines this to be ABI equivalent to the struct. So the offsets are trivially 0 and sizeof(floating_type)? I mean, there is also a macro version to get the imag/real, but I doubt it isn't easier to just hardcode something

  3. djhoese commented on Dec 2, 2023

    @djhoese
    djhoese
    on Dec 2, 2023
    ContributorAuthor
    More actions

    Makes sense. So sanity check: complex64 is made up of 2 32-bit floats float, right? So complex128 is two double and complex256 is two long double?

    Reacted by Nathan Goldbaum
  4. ngoldbaum commented on Dec 2, 2023

    @ngoldbaum
    ngoldbaum
    on Dec 2, 2023
    Member
    More actions

    Should we maybe have a paragraph on this in the migration guide that we can point people to? ping @lysnikolaou too since they drove most of the effort on this.

  5. djhoese commented on Dec 2, 2023

    @djhoese
    djhoese
    on Dec 2, 2023
    ContributorAuthor
    More actions

    Oh yes I meant to mention that. I didn't notice the complex change in the C-API issue (#25292 #API) nor in the version 2 release notes.

  6. lysnikolaou commented on Dec 4, 2023

    @lysnikolaou
    lysnikolaou
    on Dec 4, 2023
    Member
    More actions

    There's a section on all of this on https://numpy.org/devdocs/reference/c-api/coremath.html#support-for-complex-numbers. We should probably link to it from the release notes and/or the migration guide though.

    Reacted by David Hoese and Nathan Goldbaum
  7. ngoldbaum
    changed the title [-]BUG: Help migrating C npy_complexN struct usage for numpy 2.0[/-] [+]DOC: Migration guide should mention complex number API changes[/+] on Dec 5, 2023
  8. ngoldbaum
    added
    04 - Documentation
    and removed
    00 - Bug
    on Dec 5, 2023
  9. ngoldbaum commented on Dec 5, 2023

    @ngoldbaum
    ngoldbaum
    on Dec 5, 2023
    Member
    More actions

    Changed the title to reflect that the new docs linked to above just need to be a bit more discoverable for people porting code for numpy 2.0.

  10. seberg commented on Dec 5, 2023

    @seberg
    seberg
    on Dec 5, 2023
    Member
    More actions

    One thing the section might grow, is that it is perfectly fine to vendor the struct definition or the std one especially on C++ (who don't use npy_math anyway). Often that seems simpler than using the new macros.

  11. lucascolley commented on Jan 1, 2024

    @lucascolley
    lucascolley
    on Jan 1, 2024
    Contributor
    More actions

    There's a section on all of this on https://numpy.org/devdocs/reference/c-api/coremath.html#support-for-complex-numbers. We should probably link to it from the release notes and/or the migration guide though.

    +1 for linking to this from the 2.0 migration guide, we just bumped into this in scipy/scipy#19587 and that was the first place I checked.

  12. charris
    closed this as completedin #25929on Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    04 - Documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.