Skip to content

Empty tensors are valid for new shape #472

Description

@zolkis

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]

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions