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

Unsqueeze at Any Dimension #876

Closed
agelas opened this issue Oct 18, 2023 · 0 comments · Fixed by #966
Closed

Unsqueeze at Any Dimension #876

agelas opened this issue Oct 18, 2023 · 0 comments · Fixed by #966
Labels
feature The feature request

Comments

@agelas
Copy link
Contributor

agelas commented Oct 18, 2023

Feature description

Implement a more flexible unsqueeze() function that matches the behavior of PyTorch's unsqueeze(). The new function should allow inserting a singleton dimension anywhere in the tensor, as opposed to only prepending.

Feature motivation

The current implementation of unsqueeze() only prepends singleton dimensions. This limitation imposes constraints when manipulating tensor shapes. Having a more flexible unsqueeze operation will increase the usability and compatibility of the library.

(Optional) Suggest a Solution

  • Modify the unsqueeze() function to take an additional argument, dim, which indicates the position where the singleton dimension should be inserted. Something like this:
// Before `dim`
dims[0..dim].copy_from_slice(&shape.dims[0..dim]);
// Insert singleton dimension at `dim`
dims[dim] = 1;
// After `dim`
dims[(dim+1)..].copy_from_slice(&shape.dims[dim..]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature The feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants