Skip to content

Conversation

@PinkShnack
Copy link
Contributor

@PinkShnack PinkShnack commented Nov 6, 2025

See explanation in #17

Todo:

  • Make sure that all numpy functions used by qpretrieve have an equivalent in cupy.
  • make the qpretrieve code ndarray backend agnostic. For example, all mentions of np. would be xp., with xp being either import numpy as xp or import cupy as xp. See example from Cupy's docs here. In our case, we would want to generalise xp = cp.get_array_module(x).
  • ensure that the correct backend is being used per desired FFTFilter. I would prefer to have a warning here, to let advanced users manually choose their desired backend.
  • figure out why docs code reference isnt working for new module
    • was due to open use of getattr, which made sphinx think that it was importing maaaany attrs from e.g. numpy, which causes sphinx to ignore out _ndarray_backend module. Fix was to create a class that contains a __getattr__ method.
  • create tests for backend being used with FFTFilter
    • pytest fixture that handles backend setting
  • make sure test warnings are reasonable
  • remove mentions of numpy import
  • ci/cd pass
  • update changelog

@PinkShnack PinkShnack changed the title 17 cupy ndarray agnostic Draft: Make codebase ndarray backend agnostic Nov 7, 2025
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 91.91176% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.56%. Comparing base (9e6c35c) to head (8c54102).

Files with missing lines Patch % Lines
qpretrieve/fourier/ff_cupy.py 12.50% 7 Missing ⚠️
qpretrieve/_ndarray_backend.py 87.50% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
- Coverage   90.66%   90.56%   -0.10%     
==========================================
  Files          13       14       +1     
  Lines         525      562      +37     
==========================================
+ Hits          476      509      +33     
- Misses         49       53       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PinkShnack
Copy link
Contributor Author

Hey @paulmueller please have a look at this when you have a chance.

Copy link
Member

@paulmueller paulmueller left a comment

Choose a reason for hiding this comment

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

Have you read this? https://numpy.org/devdocs/user/basics.interoperability.html#example-cupy-arrays

I think it is not necessary to replace every instance of np with xp, except for initially creating the arrays, since np would automatically realize that the object is a cupy array and call the corresponding cupy methods. Did you test this?


Since version 0.6.0, you can control the desired ndarray backend.
An "ndarray backend" is defined as the library used to define the
ndarrays in qpretrieve during runtime. By default it is set to ``'numpy'``.
Copy link
Member

Choose a reason for hiding this comment

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

When looking at the new comparison, I think cupy should be the default, if available.

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.

4 participants