Skip to content

Array api extension support function #332

Closed as not planned
Closed as not planned
@purepani

Description

@purepani

Right now, the dask library has a linalg attribute, but doesn't currently implement the entire linalg extension spec. The lack of full support is mentioned here: https://data-apis.org/array-api-compat/supported-array-libraries.html

This means that an array api library consumer can't do

if hasattr(xp, 'linalg'):
    xp.linalg.cross(x, y)

as recommended here,
and work with dask. I suppose this is hard to change for existing array libraries that have such an attribute already. I'm generally thinking that this is best added as part of the array api spec(see data-apis/array-api#950), but in the meantime, a supports_extension(xp, extension_name: str) in array_api_compat would be helpful, so that

from array_api_compat import supports_extension

if supports_extension(xp, 'linalg'):
    xp.linalg.cross(x, y)

is possible.

Alternatively(or additionally), returning a list might be a good idea:

from array_api_compat import get_supported_extensions

print(get_supported_extensions(xp)) # ['linalg', 'fft'], or [] for dask
if 'linalg' in get_supported_extensions(xp):
    xp.linalg.cross(x, y)

(discussed in magpylib/magpylib#844)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions