-
Notifications
You must be signed in to change notification settings - Fork 53
Add array object specification #53
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
Conversation
As just discussed, this PR will add a paragraph on Python operator support, to make explicit which operators need supporting.
I'd say just include it, and add a TODO for |
Re: operators. I've added a section to the spec. Re: Re: status. This should be ready for review. Still some TODOs, but these are either related to concerns regarding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo the few comments I made.
I'd be inclined to not have separate specifications for __r<op>__
and __i<op>__
, but just tables specifying what needs to be supported. The rest is just duplication without much added value.
Rationale: it's arguably not an operator, and the asymmetry with the missing getitem is potentially confusing.
Actually I noticed that EDIT: I can't remember a discussion on this - was there? EDIT 2: maybe that statement is too strong, EDIT 3: some operators aren't symmetrical, but still it's completely obvious what the results and behaviour should be from referencing the left-hand dunder method. Removing all content and adding a table will be much easier. For example, that showed quickly that |
Remove section with details on it.
Most do exist in all/most libs, and this makes sense and should be easy to add if missing (e.g. numpy misses `__imatmul__`).
@kgryte I pushed a set of commits. I'll wait with merging to make it easier to revert one or more in case I made a mistake somewhere. |
`abs` isn't an operator, and it was the only non-operator left in the top-level table in this file. Related: `len(array)` is bad form, and it's not clear what is desired here. Raising an exception may make sense, but that's not what some current libraries do. `abs(array)` also isn't all that great, but seems implemented all around and is well-defined.
Applied last fixes as just discussed @kgryte, and merged. Thanks! Almost there:) |
This PR
adds specifications for array object methods and attributes.
updates language to be more verbose (and explicit) for special cases in several element-wise functions.
only includes magic methods and not non-magic methods (e.g.,
max
,argmax
, etc) in deference to the functional API counterparts.In general, array object methods are inconsistently supported. Some array libraries (e.g.,
Torch
,MXNet
) expose array objects will many, many methods; other array libraries (e.g.,TensorFlow
) expose array objects with only magic methods; and yet other array libraries expose array objects with an inconsistent grab bag of methods. For now, this proposal sides with exposing a minimal array object API surface, nudging array library authors and consumers toward functional APIs.a number of reflective magic methods are inconsistently implemented across array libraries. For completeness and as determined in consortium meetings, this proposal requires that they are implemented.
currently, the PR includes a number of TODOs. These mainly stem from addressing particular potentially thorny edge cases. For example,
shape
,ndim
, andsize
attributes introduce issues for graph tensors whose attributes may be unknown/dynamic. Another example is__setitem__
which may be problematic for immutable arrays and is related to previous discussions regarding theout
keyword argument.Here is a comparative summary of operator support across array libraries. If an array library is listed, this means that I was unable to confirm operator support.