array-api-compat icon indicating copy to clipboard operation
array-api-compat copied to clipboard

add `is_*_namespace` helper functions

Open lucascolley opened this issue 1 year ago • 11 comments

closes gh-156

lucascolley avatar Aug 15 '24 16:08 lucascolley

Let's make these not depend on the name array_api_compat. Vendoring supports renaming the module. We should be able to just compare against __name__.

asmeurer avatar Aug 15 '24 18:08 asmeurer

Let's make these not depend on the name array_api_compat. Vendoring supports renaming the module. We should be able to just compare against name.

How should we do that? Create an array and pass it to is_*_array or is there a cheaper way?

Using just xp.__name__ seems to have problems when there are both {custom name for array_api_compat}.numpy and jax.numpy, right?

lucascolley avatar Aug 15 '24 18:08 lucascolley

I mean the global variable __name__ will contain the name of the current module.

asmeurer avatar Aug 15 '24 18:08 asmeurer

sorry, I don't follow - what would one of the functions look like?

lucascolley avatar Aug 15 '24 19:08 lucascolley

Something like

def _compat_module_name():
    assert __name__.endswith('.common._helpers')
    return __name__.removesuffix('.common._helpers')

asmeurer avatar Aug 15 '24 19:08 asmeurer

thanks, done

lucascolley avatar Aug 15 '24 19:08 lucascolley

Can we add some simple tests for this and also something in the vendoring test to make sure that works?

asmeurer avatar Aug 16 '24 18:08 asmeurer

Okay. Are there existing tests for the is_*_array functions or should I add tests for those too?

lucascolley avatar Aug 16 '24 18:08 lucascolley

Yes, those are tested in test_common.py

asmeurer avatar Aug 16 '24 19:08 asmeurer

One more change and this can be merged: can you add these functions to the API docs?

asmeurer avatar Aug 19 '24 21:08 asmeurer

can you add these functions to the API docs?

done (I think)!

lucascolley avatar Aug 20 '24 17:08 lucascolley