Skip to content
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

Empty tensors are valid for new shape #472

Closed
zolkis opened this issue Oct 20, 2023 · 2 comments
Closed

Empty tensors are valid for new shape #472

zolkis opened this issue Oct 20, 2023 · 2 comments

Comments

@zolkis
Copy link
Collaborator

zolkis commented Oct 20, 2023

Originally posted by @fdwr in #446 (comment)

If any value in newShape is 0, then throw a "DataError" DOMException.

Empty tensors are valid in ML. If the input tensor shape contains zeros, then it's correct for newShape to contain zeros. Indeed, if the input shape contains zeros, then newShape must have at least one zero, because otherwise that would be an error. It's only an error if the number of total input element count differs from the total output element count, and so it's good to remove this redundant clause because the element count check is both necessary and sufficient.

oldShape newShape validity
[1,2,3] [1,2,3]
[2,3,1] [3,2,1]
[1,2,3] [6]
[0,0,0] [0,0,0]
[1,2,0] [0,0,0]
[1,2,0] [0,2,1]
[1,2,3] [1,0,3]
[1,0,3] [1,2,3]
@fdwr
Copy link
Collaborator

fdwr commented Oct 20, 2023

Thanks @zolkis. My comment was specific to the wording in the reshape operator, but the more general related issue is here: #391

@zolkis
Copy link
Collaborator Author

zolkis commented Mar 25, 2024

Closing since #476 addresses this.

@zolkis zolkis closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants