Skip to content

Tensor<T> - Fixed missing memory offset from ReadOnlyTensorSpan #113618

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

Merged
merged 4 commits into from
Mar 17, 2025

Conversation

michaelgsharp
Copy link
Member

When creating #113166 I didn't have any testing for the implicit conversions and so missed a few places where the memory offset was not being passed through. This fixes that, and makes the memory offset no longer have a default value on the internal constructor so it has to be manually specified every time to not miss it anymore. It also adds testing to catch this case moving forward.

@michaelgsharp michaelgsharp self-assigned this Mar 17, 2025
@Copilot Copilot AI review requested due to automatic review settings March 17, 2025 17:06
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.

Copy link
Contributor

@Copilot 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

This pull request fixes the missing memory offset issue in ReadOnlyTensorSpan by requiring an explicit memory offset in internal constructors and updating all related factory, slicing, and conversion methods. The changes ensure that the memory offset is consistently propagated throughout tensor creation, slicing, and conversion operations, and new tests have been added for verifying the correctness of summing and slicing operations.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Numerics.Tensors/tests/TensorTests.cs Added tests for Tensor.Sum and updated tensor creation to include memory offset
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs Updated constructors, conversion operators, and slicing methods to require and propagate memory offset
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.Factory.cs Modified factory methods to pass the mandatory memory offset
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorExtensions.cs Adjusted extension methods to maintain memory offset consistency in tensor broadcasting, reshaping, and other operations

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a small suggestions, LGTM otherwise.

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how did you catch this? Do you have an open issue that needs to be linked in the PR description, or did you find it by testing manually?

@michaelgsharp
Copy link
Member Author

@carlossanlop I'm working on some more complex slicing operations and during that work I discovered this issue. I decided this was important enough that I'd split it off into its own PR instead of trying to piggy back it on the slicing PR since thats going to be bigger/more complex.

@carlossanlop
Copy link
Member

I'm working on some more complex slicing operations and during that work I discovered this issue. I decided this was important enough that I'd split it off into its own PR instead of trying to piggy back it on the slicing PR since thats going to be bigger/more complex.

Cool. Sounds good. I mainly just wanted to learn the process.

@michaelgsharp michaelgsharp merged commit 7a4839b into dotnet:main Mar 17, 2025
80 of 84 checks passed
@michaelgsharp michaelgsharp deleted the missing-offset branch March 17, 2025 22:05
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants