-
Notifications
You must be signed in to change notification settings - Fork 25
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
Request: add option to return strict API #180
Comments
I think it's useful to spell out how this is orthogonal:
Are there other ways in which it is orthogonal? At least for me, installing array-api-strict isn't a blocker for my workflows. I can see that it might be nice to be able to do this with just array-api-compat, though. |
I think what I'd like is essentially |
could you explain why deriving from other array types is useful? They should all be equivalent if they all implement the standard, right? Maybe you are thinking about catching bugs in array-api-compat / the array libraries? |
Yes, exactly; finding bugs, perhaps testing my own array API library, etc. Could be useful in a test suite too. |
I am also interested in this. For what it's worth, I have mostly tried to solve the problem with static typing, along the lines of data-apis/array-api#589 by @nstarman. It seems promising, but also a lot of duplication of signatures, etc. |
The reason non array-api elements are bleeding in is because we do a star import from dask.array (and in other modules). I forget why this is, but I think it's so you can use a module wrapped by array API compat as you would normally, without non-array API methods/attributes missing. cc @asmeurer |
I don't think the explanation about why this is useful is concrete enough. We have several packages with distinct purposes. Here you're talking about two other packages:
Note that this cannot hide for example methods on the array and dtype objects, so this is probably strictly worse than |
I would like a somewhat strict dask API that is array API compatible. It sounds like the conclusion here is "we don't want to provide that, because we don't think you need it", so I'll close the issue. |
FWIW I would be happy to provide it, I just don't quite see the merits as worth working on yet. So far, it would enable us to:
I think that's enough to put it on a wishlist, but personally I feel like my time would be better spent contributing to array-api-strict or array-api-tests. Unless I've missed a use-case? |
(sorry for being late to reply here. I've been on PTO) It would help here to be more concrete about what sorts of bugs you would expect to find that aren't currently findable by using array-api-strict. I think there probably is room to extend array-api-strict to give the functionality you are after here. array-api-strict has a flags feature that allows enabling or disabling different flags that change how the library works to emulate different behaviors that might be seen by real array API packages in the wild. For instance, there are flags to disable data-dependent shape behavior, which is optional in the standard. Since you mentioned Dask, we could add some flags to array-api-strict to make it act like a lazy library (data-apis/array-api-strict#58). A potential issue with this is that some aspects of lazy array behavior haven't been fully codified by the standard yet (see data-apis/array-api#748 (comment)). As for implementing this in the compat library, it wouldn't be too difficult to add a flag that makes the returned namespace only have standard functions. But you should consider whether this would actually be useful or not. The main problem is that this would be a pretty far cry from the sort of "strictness" you'd get from array-api-strict. For instance,
The array-api-strict library does not have any of these issues, and does provide true "strictness". I would really hesitate to implement full "strictness" like this here because I don't see how it would add much value beyond what is already provided by array-api-strict, but it would be a lot of work to get this working. Especially if you consider the last bullet point, the only real way to change the attributes on the array object is to wrap it in a separate object. In that case, you'd really not be using array library X anymore, but rather a wrapper library. This is what array-api-strict already is. There'd be no difference except it would be wrapping library X instead of NumPy, but if everything is strictly wrapped, it shouldn't really matter what the underlying library is. |
All comments here make perfect sense from the perspective of a developer who wants to implement Array API compatible behavior in their library. But, consider how I arrived here: skimage used to support dask in certain context, and then our related tests started failing. Wondering what caused it, I found the place where dask changed. But, then I thought, "as a library that is widely touted to work with the Array API, how does dask operate in an Array API environment"? So, my next thought was: let's take dask through the steps that an Array API-compatible implementation would take, and see what happens. When I did so I ended up with a namespace that looked anything like the Array API; and this was rather confusing—I don't have a list of Array API functions in my head. When I realized what had happend, I requested this feature, because it would have saved me some time if I could have asked for an Array API compatible-ish dask namespace, and would have avoided some confusion. My guess was that it would be trivial to ad (and would hopefully avoid some confusion for future, other developers too) but if it isn't I really don't want to spend time arguing for it. Given that skimage is mostly implemented in Cython, it is not a good use-case for the Array API (as far as I understand), and I was trying to sort out this one-off dask bug. For skimage, the solution was easy enough: drop the dask tests, since they didn't imply a meaningful contract with the users anyway. @asmeurer Thank you for the detailed explanation around what |
The question is whether running your skimage function through array-api-strict would have solved your problem. Based on your description, it sounds like it would have, because array-api-strict only has the functions that are in the array API. But it's also very strict in other ways too. The use-case you describe is really what strict was designed for. The array API isn't very strict in disallowing behaviors beyond what it specifies, and all libraries do implement more functions, keyword arguments, dtypes, etc. So the only way to test if your code is really being portable is to test against every possible array library, or to test against a strict minimal implementation like array-api-strict.
I think SciPy is similar, and they are implementing array API support at least for the pure Python functions. But maybe more of SciPy is pure Python/NumPy than scikit-image (I'm not super familiar with the codebases of either, so I can't really speak to this). |
When writing code that should be widely compatible with multiple Array implementations, it would be helpful if
array-api-compat
could return a strict Array API namespace, that did not blend the Array API with the target type's namespace.E.g., in:
The
nx
object contains non-Array-API-compatible members, such asflatnonzero
. This caused some confusion when examining dask/dask#11298.While developing, I'd like to get a namespace that only consists of Array API functions. I presume the additional blending is done to produce a minimally modified version of a library namespace that, like NumPy, supports the Array API, but also does a bunch of other things. However, I'd argue that this is unhelpful in the context of developing for the Array API. In our example above, I'd be tempted to use
flatnonzero
when, in fact, that function is not in the array API. Worse, in the case above, that would not work (the only guaranteed Array API compatible dask implementations come fromarray-api-compat
).Since the blending of namespaces has the potential for confusion, and reduces the utility of the namespace in coding for Array API compatibility, I am curious why it is the default. However, since it is the default, I'd like to request a new feature, along the lines of:
@lucascolley mentioned to me the
array-api-strict
package for use in test suites, but while helpful, it is somewhat orthogonal to my request here.I am only now really starting to dig into Array API compatibility, thinking about scikit-image in particular, so apologies if I missed some obvious existing mechanisms of doing what I want.
The text was updated successfully, but these errors were encountered: