- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
Fix Tensor.Reshape with wildcard #120801
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
Fix Tensor.Reshape with wildcard #120801
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support fix for Tensor.Reshape when using a wildcard (-1) by returning the computed newLengths instead of the original lengths, and extends test coverage to include wildcard reshape scenarios for Tensor, TensorSpan, and ReadOnlyTensorSpan, including zero-stride cases.
- Fixes return value in Reshape to use computed inferred dimension array.
 - Adds wildcard (-1) reshape tests (including error cases) for Tensor, TensorSpan, and ReadOnlyTensorSpan.
 - Extends zero-stride reshape scenario tests with wildcard use.
 
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description | 
|---|---|
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs | Fixes Reshape to return newLengths (wildcard-inferred) instead of original input lengths. | 
| src/libraries/System.Numerics.Tensors/tests/TensorTests.cs | Adds wildcard reshape tests and zero-stride reshape with wildcard for Tensor. | 
| src/libraries/System.Numerics.Tensors/tests/TensorSpanTests.cs | Adds equivalent wildcard and zero-stride reshape tests for TensorSpan. | 
| src/libraries/System.Numerics.Tensors/tests/ReadOnlyTensorSpanTests.cs | Adds equivalent wildcard and zero-stride reshape tests for ReadOnlyTensorSpan. | 
| 
           Tagging subscribers to this area: @dotnet/area-system-numerics-tensors  | 
    
| 
           /backport to release/10.0  | 
    
| 
           Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18566317228  | 
    
Backport of #120801 to release/10.0 /cc @tannergooding @lilinus ## Customer Impact - [x] Customer reported - [ ] Found internally #120343 - Calling `Tensor.Reshape` will fail if using the `-1` wildcard to indicate "remaining". It works as expected for `TensorSpan.Reshape` and `ReadOnlyTensorSpan.Reshape` ## Regression - [ ] Yes - [x] No This is a net new API in .NET 10 ## Testing Explicit tests were added validating the behavior works as expected. ## Risk Low. This is a net new API in .NET 10 and was already working as expected for the other types. --------- Co-authored-by: Linus Hamlin <linus.hamlin@soderbergpartners.se>
| 
           /ba-g unrelated wasm failure  | 
    
Fixes #120343.
Also added unit tests for
Tensor.ReshapeforTensorSpanandReadOnlyTensorSpan