Skip to content

Add element-wise function specifications, incl. type casting and broadcasting rules #12

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 68 commits into from
Aug 11, 2020

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Jul 30, 2020

This PR

@rgommers
Copy link
Member

Should we require element-wise function output arguments to have the exact same shape as input arguments or should we allow broadcasting?

That's a good question. I'd prefer requiring out being of the correct shape. For functions with a single array input that implies the same shape as the input; for multiple array inputs or for other keywords that may support broadcasting, those can affect the expected shape of the output array. out itself is a special keyword in this case, the intent is for it to be filled in-place so it should not participate in broadcasting I believe.

Although some may have a use case for func(in_shape_1_by4, out=shape_10_by_4). That breaks this equivalence though:

out1 = func(inputs)
out2 = np.empty((some_shape))
func(inputs, out=out2).shape == func(inputs, out=None).shape

My mental model is that those shapes should be equal, and hence out= doesn't broadcast.

@kgryte
Copy link
Contributor Author

kgryte commented Jul 30, 2020

@rgommers Thanks for the feedback.

Re: broadcasting. My understanding is that, e.g., NumPy permits such broadcasting semantics.

@kgryte
Copy link
Contributor Author

kgryte commented Aug 8, 2020

I've updated the proposed specification to include supported data types and promotion rules, which should now roughly complete the spec for element-wise functions. Remaining concerns include:

  • minimum precision requirements
  • casting rules

However, these concerns can be addressed in follow-up PRs.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Thanks @kgryte. I think this is in good shape, and all the important decisions have been reviewed by multiple people in the various linked issues and meetings.

Let's go ahead and merge this.

@rgommers rgommers merged commit 63d7216 into master Aug 11, 2020
@rgommers rgommers deleted the elementary-mathematical-functions branch August 11, 2020 18:58
@rgommers rgommers changed the title Add element-wise function specifications Add element-wise function specifications, incl. type casting and broadcasting rules Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants