mTRFpy icon indicating copy to clipboard operation
mTRFpy copied to clipboard

how to experiment with array API

Open lucascolley opened this issue 5 months ago • 1 comments

  1. add a dependency on array-api-compat (https://data-apis.org/array-api-compat/index.html#)
  2. add xp = array_namespace({array inputs}) to the start of function calls
  3. replace np with xp everywhere
  4. for public functions like https://github.com/powerfulbean/mTRFpy/blob/b7662577f5b1e9a3a18be4beb5e405562ceaca67/mtrf/matrices.py#L101 which are also called internally, refactor them into
    • a private version to call internally, which has a required xp kwarg
    • a public version which is a thin wrapper, just calling xp = array_namespace({array inputs}) and then passing args to the private version

For the future:

  • you might want to add a file like https://github.com/scipy/scipy/blob/main/scipy/_lib/_array_api_override.py, which is doing the following things:
    • only enabling this with an experimental environment variable
    • raising exceptions for known unsupported types early
    • falling back to NumPy for non-array input

lucascolley avatar Aug 22 '25 09:08 lucascolley

Thanks @lucascolley !

OleBialas avatar Aug 22 '25 09:08 OleBialas