mTRFpy
mTRFpy copied to clipboard
how to experiment with array API
- add a dependency on array-api-compat (https://data-apis.org/array-api-compat/index.html#)
- add
xp = array_namespace({array inputs})to the start of function calls - replace
npwithxpeverywhere - 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
xpkwarg - a public version which is a thin wrapper, just calling
xp = array_namespace({array inputs})and then passing args to the private version
- a private version to call internally, which has a required
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
Thanks @lucascolley !