-
Notifications
You must be signed in to change notification settings - Fork 52
Add specifications for array manipulation functions #42
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
I'd say apply the regular type casting rules. So regular within-dtype-family upcasting
This makes sense to include (but leaving out
I'd be okay with just a tuple for consistency. It's pretty unusual to do
That's a little odd, regular ints/tuples should be fine I'd think.
+1
Sounds good to me. Functions I noticed that you left out are:
Of all those, the ones I'd at least consider for inclusion in addition to the ones in this PR are |
Transpose was added with the linear algebra functions. See here. |
Updates:
|
Added Re: This PR should be ready for another round of review based on the aforementioned changes. |
I can provide a follow-up PR with manipulation functions which, while not universally implemented across array libraries, are commonly implemented and commonly used by downstream libraries (e.g., |
I think it may make sense to open an issue for those with a summary, but wait with adding them to the standard until they're implemented universally. They're not all that important I'd say. EDIT: or do nothing, not sure we need un-actionable issues right now. |
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.
Changes LGTM, and no further comments, so merging. Thanks @kgryte
This PR
Notes
This list of array manipulation functions is an initial set of array manipulation functions which can pave the way for additional specs in subsequent pull requests. These functions were identified as the set of functions with the broadest support among array libraries and relatively higher usage among downstream libraries.
Some comments/questions regarding particular APIs...
concat: CuPy requires a tuple rather than a sequence for first argument. Went with tuple as more consistent with rest of specification (e.g., we require a list of axes to be specified as a tuple, but not a sequence). What happens if provided arrays having different dtypes? What should we the dtype of the returned array? How do type promotion rules factor in here?
expand_dims: NumPy supports providing a tuple or an
int
. All other array libraries considered support only anint
. Torch names this methodunsqueeze
. Went withexpand_dims
and only accepting anint
for the second positional argument.flip: TensorFlow lacks this exact API. Torch/CuPy/ spec
axis
/dims
as position argument. Based proposal on NumPy whereaxis
is a keyword argument, as more versatile.reshape: Torch requires a tuple (does not allow
int
). TensorFlow requires shape to be aint32
/int64
tensor. NumPy allows providing anint
as shorthand. Based proposal on Torch's more restricted API for consistency.roll: TensorFlow requires tensors for axis and shifts.
squeeze: Torch only allows specifying one axis and does not error if you attempt to squeeze non-singleton dimensions. NumPy/TensorFlow error if you attempt to squeeze a dimension which is not
1
. Sided with Torch regarding error behavior, as not clear why attempting to squeeze a non-singleton dimension should error.stack: CuPy requires a tuple rather than a sequence for the first argument. Went with tuple for same reasons as in
concat
. Samedtype
question(s) apply as forconcat
above.