Repository navigation
__array_ufunc__ *args and 'out' always a tuple - #6
Conversation
eb07f7c to
84fed38
Compare
There was a problem hiding this comment.
All ``out`` arguments, both positional and keyword, are passed as a :obj:`tuple` in *kwargs*.
There was a problem hiding this comment.
and which may eventually be deprecated?
There was a problem hiding this comment.
Furthermore, unless it is set to `None`,
There was a problem hiding this comment.
Remove ( and if your class....
Does this imply the subclasses cannot opt out? @
There was a problem hiding this comment.
With this ufuncs will treat your class..
There was a problem hiding this comment.
Hmm, I think it needs to be stated that for the python numeric ops this is equivalent to ndarray returning NotImplemented.
There was a problem hiding this comment.
Good comments; I'll implement them later.
For now, in answer to your question, I think the text is not quite right: for a proper subclass of ndarray, the right operators will be given preference by CPython already.
There was a problem hiding this comment.
I don't think this is correct. It is the calling class, ndarray and subclasses thereof, for which it is equivalent to calling NotImplemented. The effect is that unary ops fail and binary ops get passed to the corresponding right op. Or am I missing something?
There was a problem hiding this comment.
I'll try to separate more clearly what happens for binary operators and inside ufuncs (I've gotten myself confused right now...).
p.s. Will do this over the weekend -- some horrible money proposal is taking all my time right now.
There was a problem hiding this comment.
No problem. We all need to earn a living...
a3130f1 to
648e711
Compare
84fed38 to
4bcb03e
Compare
|
@charris - rebased, and now with updated documentation (which I think may correspond to reality...) |
16d89ca to
c5fb325
Compare
c5fb325 to
c3d20fe
Compare
| Any class (ndarray subclass or not) can define this method to | ||
| override behavior of NumPy's ufuncs. This works quite similarly to | ||
| Python's ``__mul__`` and other binary operation routines. | ||
| Any class (ndarray subclass or not) can define this method (or set it to |
There was a problem hiding this comment.
Commas, not "(ndarray....)". I'd also remove the parenthesis around "or set...".
| that you avoid confusion by neither setting | ||
| :func:`__array_ufunc__` to :obj:`None` (which seems to make no | ||
| sense for an array subclass), nor defining it and also defining | ||
| reverse methods (which will be called by ``CPython`` in |
| ufunc for computation. | ||
|
|
||
| .. note:: It is hoped to eventually deprecate this method in favour of | ||
| :func:__array_ufunc__`. |
| continue; | ||
| } | ||
| else if (i == 1) { | ||
| if (i == 1) { |
There was a problem hiding this comment.
We could eventually turn these into a switch statement.
There was a problem hiding this comment.
Could even make a switch on nargs and complete by falling through in reverse order, thus avoiding the loop.
| PyDict_DelItemString(normal_kwds, "out"); | ||
| } | ||
| } | ||
| else if (out != Py_None) { /* not already a tuple and not None */ |
There was a problem hiding this comment.
Put trailing comment on next line.
| if(PyTuple_Check(out)) { | ||
| int all_none; | ||
| int i; | ||
| for (i==0; i<PyTuple_GET_SIZE(out); i++) { |
There was a problem hiding this comment.
Also i==0 and spaces around operators.
| Py_XDECREF(method_name); | ||
| Py_XDECREF(normal_args); | ||
| Py_XDECREF(normal_kwds); | ||
| Py_DECREF(override_args); |
There was a problem hiding this comment.
No, it isn't if an error check is performed.
| } | ||
|
|
||
| Py_ssize_t len = PyTuple_GET_SIZE(normal_args); | ||
| PyObject *override_args = PyTuple_New(len + 2); |
There was a problem hiding this comment.
Really need to check for NULL here. Then you will want Py_XDECREF in failure path.
There was a problem hiding this comment.
Also, no declarations except at top of blocks.
| } | ||
| } | ||
| else if (out != Py_None) { /* not already a tuple and not None */ | ||
| PyObject *out_tuple = PyTuple_New(1); |
|
Do you want to correct the comments? If you are short on time I can do it after the merge. |
|
Note that the normalization routines still need error checking at some point. |
|
Merged, I'll do a maintenance PR on top of this. |
|
OK, thanks! I'll have a look at those just in case, and then rebase #5 on top. |
|
I merged a fixup with this as it doesn't compile as is. |
|
Thanks for all the corrections; I'm amazed at how much I missed (and that it compiled...) |
commit 9c833bed5879d77e625556260690c349de18b433 Author: Thomas Li <[email protected]> Date: Wed Nov 17 16:21:27 2021 -0800 Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Add Windows config to GHA update script [wheel build] typo [wheel build] fix typo? [wheel build] fix linux builds? [wheel build] typo [wheel build] add license and pin to windows 2016 skip tests [wheel build] pin to windows 2019 instead [wheel build] try to find out the error on windows [wheel build] maybe fix? [wheel build] maybe fix? [wheel build] fix? [wheel build] cleanup [wheel build] Update LICENSE_win32.txt Update LICENSE_win32.txt Update cibw_test_command.sh commit 4bd12df Author: Thomas Li <[email protected]> Date: Mon Nov 15 17:28:47 2021 -0800 # This is a combination of 14 commits. # This is the 1st commit message: Add Windows config to GHA # This is the commit message #2: update script [wheel build] # This is the commit message #3: typo [wheel build] # This is the commit message #4: fix typo? [wheel build] # This is the commit message #5: fix linux builds? [wheel build] # This is the commit message #6: typo [wheel build] # This is the commit message #7: add license and pin to windows 2016 # This is the commit message #8: skip tests [wheel build] # This is the commit message #9: pin to windows 2019 instead [wheel build] # This is the commit message #10: try to find out the error on windows [wheel build] # This is the commit message #11: maybe fix? [wheel build] # This is the commit message #12: maybe fix? [wheel build] # This is the commit message #13: fix? [wheel build] # This is the commit message #14: cleanup [wheel build]
(comments in main thread)