Skip to content

MAINT: Minor ufunc cleanup - #8876

Merged
eric-wieser merged 3 commits into
numpy:masterfrom
eric-wieser:ufunc-refactor
May 1, 2017
Merged

eric-wieser merged 3 commits into
numpy:masterfrom
eric-wieser:ufunc-refactor

Conversation

@eric-wieser

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

Comment thread numpy/core/src/umath/ufunc_object.c Outdated

Copy link
Copy Markdown
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

Comment thread numpy/core/src/umath/ufunc_object.c Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@jaimefrio jaimefrio left a comment

Copy link
Copy Markdown
Member

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.

Comment thread numpy/core/src/umath/ufunc_object.c Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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...

Comment thread numpy/core/src/umath/ufunc_object.c Outdated

Copy link
Copy Markdown
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

mhvk commented Mar 31, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Member Author

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

@eric-wieser

Copy link
Copy Markdown
Member Author

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

@mhvk

mhvk commented Apr 11, 2017

Copy link
Copy Markdown
Contributor

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

eric-wieser commented Apr 11, 2017 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member Author

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

@mhvk

mhvk commented Apr 29, 2017

Copy link
Copy Markdown
Contributor

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

@eric-wieser

Copy link
Copy Markdown
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