Skip to content

Conversation

@lilinus
Copy link
Contributor

@lilinus lilinus commented Oct 16, 2025

Fixes #120343.

Also added unit tests for Tensor.Reshape for TensorSpan and ReadOnlyTensorSpan

Copilot AI review requested due to automatic review settings October 16, 2025 14:51
Copy link
Contributor

Copilot AI left a 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.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 16, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics-tensors
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18566317228

artl93 pushed a commit that referenced this pull request Oct 17, 2025
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>
@tannergooding
Copy link
Member

/ba-g unrelated wasm failure

@tannergooding tannergooding merged commit f169b52 into dotnet:main Oct 23, 2025
85 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Numerics.Tensors community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tensor.Reshape fails when used with Wildcard

2 participants