Repository navigation
ENH: Add keepdims argument for generalized ufuncs. - #11098
Conversation
There was a problem hiding this comment.
This function should return an error code (0, -1) not a boolean (1, 0), since it's called _check_support not _is_supported (and sets an exception)
|
@eric-wieser - OK, this now contains also the documentation for |
There was a problem hiding this comment.
Darn, this should be axes here, of course. Will correct together with any other remaining comments.
|
@eric-wieser - you looked at this quite a bit already, do you think it is OK? If so, I can do the follow-up for just |
There was a problem hiding this comment.
nit: would probably combine these two lines - we do that pretty frequently
There was a problem hiding this comment.
As in if (retval = ... < 0)? I don't see any example of that in ufunc_object, and personally don't like it much. Anyway, will await for the more thorough look.
There was a problem hiding this comment.
I mean:
if (_check_keepdims_support(ufunc) < 0) {
goto fail;
}
There was a problem hiding this comment.
But fail needs to have retval set...
There was a problem hiding this comment.
What am I missing here? Is retval sometimes not -1 on failure?
There was a problem hiding this comment.
It left at 0 by the get_ufunc_arguments statement above. There is a debug statement in fail that prints retval, but to be honest I'm not sure it ever has a value other than -1 for failure. Probably would make sense to clean that all up, but perhaps in another PR...
There was a problem hiding this comment.
Yep, no need to change this now - just looked a little worrying
|
Looks pretty reasonable - I'll take a more thorough look later. I can't say I fully understand the gufunc internals yet. |
There was a problem hiding this comment.
minor nit: I'd find this easier to read with an assignment all_num_dims = ufunc->core_num_dims[0] or similar outside the loop - too easy to read this as an elementwise copy. But maybe I'm just tired
There was a problem hiding this comment.
Possibly clearer with an if, because then that gives you somewhere to add a comment explaining why it is 1,
There was a problem hiding this comment.
I expanded the comment above the loop (which is not very useful as is...)
There was a problem hiding this comment.
Unrelated to this PR: I'm struggling to understand what j is, and why its state is kept between outputs
There was a problem hiding this comment.
I agree, I turn from thinking it clear to having no clue almost every time I look at this... Mostly because I only partially understand how the iterator works. But this would be a good place to comment it more heavily. For another PR...
eric-wieser
left a comment
There was a problem hiding this comment.
Only minor things to complain about here - generally looks like an unobtrusive change
The argument can only be used if all inputs share the same number of core dimension, and no output has any core dimensions.
Both in the general documentation and in the release notes. For the latter, also include a description of ``axes``, which was missing so far.
|
@eric-wieser - OK, I made the last changes. Once merged, I'll go ahead and rebase the |
| correctly against the inputs. This option can only be used for generalized | ||
| ufuncs that operate on inputs that all have the same number of core | ||
| dimensions and with outputs that have no core dimensions , i.e., with | ||
| signatures like ``(i),(i)->()`` or ``(m,m)->()``. If used, the location of |
There was a problem hiding this comment.
Do we also want to support (i),(i)->(),(i)?
There was a problem hiding this comment.
I thought about this when I was revisiting the text, and wasn't sure. In principle, there is no reason not too, except I then have to be more careful with the shape of the output... What do you think?
There was a problem hiding this comment.
I don't think we need to decide in this PR - we can add that feature later if we can justify it. I think we should open an issue suggesting it as an enhancement, and merge this PR without any further changes.
There was a problem hiding this comment.
OK, agreed; see #11118. I'll merge this one then.
This is a single commit from #11018, to try to find the reason for the travis build failure.EDIT: this is a split-off of #11018, just implementing
keepdims, to keep discussion more clearly separate.