8000 MAINT: Minor ufunc cleanup by eric-wieser · Pull Request #8876 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Minor ufunc cleanup #8876

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

Merged
merged 3 commits into from
May 1, 2017
Merged

Conversation

eric-wieser
Copy link
Member
  • Pulling a long chunk of code into its own function
  • Using the same name everywhere when ufunc->name == NULL

* argument, would have their size set to 1.
*/
static int
_get_coredim_sizes(PyUFuncObject *ufunc, PyArrayObject **op,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all of this function, and its doc-comment, are a direct move of the code from before, with the exception that:

  • goto fail is just return -1
  • some fields need re-extracting from ufunc
  • ufunc_name is recalculated when needed - only in errors, so performance is irrelevant

@@ -1983,7 +2107,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
int nin, nout;
int i, j, idim, nop;
const char *ufunc_name;
int retval = -1, subok = 1;
int retval = 0, subok = 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting at 0 makes more sense, because our function works by assigning to it until its not zero

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always overwritten, so the value assigned here is irrelevant, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but this the correct base case if we end up with a code path that never sets retval, so seems like a good thing to keep

Copy link
Member
@jaimefrio jaimefrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even after this it's still almost a 500 LOC function, way too much, so this is a step in the right direction, I would say.

ufunc_name, out_op, i, ufunc->core_signature);
/* Collect the lengths of the labelled core dimensions */
retval = _get_coredim_sizes(ufunc, op, core_dim_sizes);
if(retval < 0) {
retval = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this assignment anymore, do you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow - why not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait, yes I do...

@@ -1983,7 +2107,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
int nin, nout;
int i, j, idim, nop;
const char *ufunc_name;
int retval = -1, subok = 1;
int retval = 0, subok = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always overwritten, so the value assigned here is irrelevant, right?

@mhvk
Copy link
Contributor
mhvk commented Mar 31, 2017

I see the point, though #8819 will mean that it will need do_remap and remap_axis arguments, which means it will be less stand-alone than it is now.

@eric-wieser
Copy link
Member Author

I don't think that needing to add extra parameters in future is an argument against this function - even if it needs more inputs, it still has one goal, which is to produce the argument passed to the inner loop.

Also, when passed do_remap and remap_axis, they could be marked as const int, which would be clearer about how they are used in which bits of the code

@eric-wieser
Copy link
Member Author

@jaimefrio: Fixed that stray retval = -1 line. Good to merge?

@eric-wieser
Copy link
Member Author

@mhvk: Are you against merging this before #8819?

@mhvk
Copy link
Contributor
mhvk commented Apr 11, 2017

Not at all -- I think that one hasn't converged, and I can rebase if need be. My main point was that, with it, the case for splitting this part off became a bit less strong, since now more of the function's state has to be passed on.

@eric-wieser
Copy link
Member Author
eric-wieser commented Apr 11, 2017

since now more of the function's state has to be passed on.

This was more about making it clear which state these loops are producing, that about making it clear what state they take as input

@eric-wieser
Copy link
Member Author

I'd like to pull the trigger on this before we accumulate more technical debt in the ufunc machinery

@mhvk
Copy link
Contributor
mhvk commented Apr 29, 2017

I'm OK with this being merged; and certainly we should merge the name part.

@eric-wieser
Copy link
Member Author

In it goes then!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0