Support n-dimensional empty tensors in TensorShape methods.#9362
Support n-dimensional empty tensors in TensorShape methods.#9362gchanan wants to merge 5 commits intopytorch:masterfrom
Conversation
This includes either bug fixes or NumPy semantics changes for the following methods: chunk, diagonal, unfold, repeat, flatten, reshape, split, unsqueeze. The n-dimensional empty tensor feature is still hidden behind a feature flag.
aten/src/ATen/native/TensorShape.cpp
Outdated
| // a call to split would discard the number of chunks (because we can have an arbitrary number of | ||
| // 0-sized chunks adding up to 0). So, call split_with_sizes with the correct number of chunks, | ||
| // and do this for all cases for consistency. | ||
| std::vector<int64_t> split_sizes(chunks, split_size); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| urtensor = urtensor.unfold(i, xtensor.size(i), xtensor.size(i)); | ||
| // can't unfold with step 0, so make sure step is at least 1 | ||
| // (it doesn't matter what it is in that case, because the size is 0). | ||
| urtensor = urtensor.unfold(i, xtensor.size(i), std::max<int64_t>(xtensor.size(i), 1)); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| } | ||
| if (start_idx >= dim_size) { | ||
| break; | ||
| } |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Man, these test cases are breaking my brain. Maybe it'd be helpful to have the equations around which justify the generalizations to zero (though, I guess if we're just tracking Numpy on everything, that works too...) |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@gchanan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Yes, the test cases aren't clear, but they do follow NumPy, except when they don't (looking at you |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@gchanan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@gchanan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This includes either bug fixes or NumPy semantics changes for the following methods: chunk, diagonal, unfold, repeat, flatten, reshape, split, unsqueeze. The n-dimensional empty tensor feature is still hidden behind a feature flag. Pull Request resolved: pytorch/pytorch#9362 Reviewed By: ezyang Differential Revision: D8817002 Pulled By: gchanan fbshipit-source-id: 6ff704ec96375f00b4dd39ebcd976efac0607fb4
Summary: This includes either bug fixes or NumPy semantics changes for the following methods: chunk, diagonal, unfold, repeat, flatten, reshape, split, unsqueeze. The n-dimensional empty tensor feature is still hidden behind a feature flag. Pull Request resolved: pytorch/pytorch#9362 Reviewed By: ezyang Differential Revision: D8817002 Pulled By: gchanan fbshipit-source-id: 6ff704ec96375f00b4dd39ebcd976efac0607fb4
…9362) Summary: This includes either bug fixes or NumPy semantics changes for the following methods: chunk, diagonal, unfold, repeat, flatten, reshape, split, unsqueeze. The n-dimensional empty tensor feature is still hidden behind a feature flag. Pull Request resolved: pytorch#9362 Reviewed By: ezyang Differential Revision: D8817002 Pulled By: gchanan fbshipit-source-id: 6ff704ec96375f00b4dd39ebcd976efac0607fb4
This includes either bug fixes or NumPy semantics changes for the following methods:
chunk, diagonal, unfold, repeat, flatten, reshape, split, unsqueeze.
The n-dimensional empty tensor feature is still hidden behind a feature flag.