-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should get_namespace support more than arrays? #799
Comments
In scikit-learn we have our own Could you do something like that in efax? Or asked differently, aren't you going to end up having something like this sooner or later anyway, in which case it could also take care of dealing with "things that aren't arrays but contain them"? |
How is the linked function related? It doesn't deal with aggregate structures, which is the motivation for this proposal. |
I'm a little confused how your proposal would work. If a function takes a Distribution object, then that function already needs to know how to extract the relevant arrays from that object in order to use the array API on them, no?
Happy to upstream some of those features to array_api_compat. We already implement some flags on top of |
Yes, but it's just a question of convenience. Sometimes, you have a method that accepts an aggregate object (say, |
If you want to, go for it. No strong feelings from my side. I have a slight preference/find it nicer to keep the The reason I linked to the custom |
Ah, right, that makes sense!
Right, which is what I'm doing. The reason I suggested upstreaming aggregate structure support is in case there are ever functions that accept aggregate structure types from different libraries. |
Background
Consider a probability distribution library such as efax. To add Array API support, each probability distribution class will contain a number of parameters, and it makes sense that they will all be from the same namespace. Thus, the a standard pattern for methods that use the parameters will be to query the namespace of
self
by feeding in all of the parameters toget_namespace
.This pattern is not unique to efax. I imagine it will pop up in SciPy's future distribution classes (that are being developed and will support the Array API). It could be added to any object exposing the "Jax PyTrees" interface (see the registry) or generally any aggregate structure with a homogenous set of arrays.
Motivation
To simplify getting the namespace in functions that interact with aggregate structure containing homogeneous sets of arrays.
Example
Suppose that
Distribution
is an aggregate structure containing array-valued parameters. Instead of:we would like to simply have:
Proposal
Extend
get_namespace(o)
to first reado.__namespace_arrays__
, which returns an iterable of arrays thatget_namespace
can use as before.Thus, instead of aggregate structures proving a method that queries the namespace like this function, we would instead have
A simple recursive extension of
get_namespace
is illustrated here.Alternative proposal
One alternative is to support
__array_namespace__
on all inputs toget_namespace
. Thus, we would haveThe problem with this is that it complicates extending the parameter specification of
get_namespace
.The text was updated successfully, but these errors were encountered: