Skip to content

Add a result_type function to the API specification #99

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
Jan 28, 2021

Conversation

rgommers
Copy link
Member

This PR adds a specification for result_type, which is the function needed to be able to do explicit dtype casting for portable results in case of mixed integer - floating point operations. Identified as needed in gh-14, also came up in gh-43 and gh-91.

Notes

  • Most libraries have a result_type function with the signature proposed here; MXNet is the exception.
  • The array-api-comparison tooling says TensorFlow doesn't have it, however in TF 2.4.0 the experimental.numpy namespace does have it.

@rgommers
Copy link
Member Author

@kgryte can you have a quick look at this? I think it's straightforward, it's just the first function spec I add, so want to make sure I've ticked all the right boxes.

@kgryte
Copy link
Contributor

kgryte commented Jan 28, 2021

@rgommers One thing to note is that the Torch API for result_type has the signature

result_type( tensor1, tensor2 );

where tensor1 and tensor2 may be either a tensor or number. This is obviously a bit different than NumPy's API.

@rgommers
Copy link
Member Author

rgommers commented Jan 28, 2021

Yes I missed that, thanks. The PyTorch version can be extended to the one in this PR without backwards compatibility issues though. The PyTorch one is a bit too limited, it's not uncommon to for example do:

result_type(x, y, complex64)

@rgommers
Copy link
Member Author

Filed a PyTorch issue for it: pytorch/pytorch#51284

Copy link
Contributor

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM.

@kgryte kgryte merged commit 56fb2fb into data-apis:main Jan 28, 2021
@rgommers rgommers deleted the result-type branch January 28, 2021 16:58
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