-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Tensor<T> select. Iteration along dimensions #113697
base: main
Are you sure you want to change the base?
Conversation
Note regarding the
|
1 similar comment
Note regarding the
|
Tagging subscribers to this area: @dotnet/area-system-numerics-tensors |
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
This PR introduces new functionality for operating on subdimensions of tensors by adding methods to slice along a given dimension and perform per-dimension operations via the new DimensionCollection.
- Adjusts enumerator initialization and termination in TensorSpan and ReadOnlyTensorSpan.
- Adds a DimensionCollection (with enumerators) to Tensor, TensorSpan, and ReadOnlyTensorSpan for iterating over tensor segments.
- Introduces new methods SliceAlongDimension and Select (with associated delegate types) to process tensor segments.
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
TensorSpan.cs | Updated enumerator initialization/termination and added a DimensionCollection property. |
ReadOnlyTensorSpan.cs | Updated enumerator logic and introduced a DimensionCollection. |
Tensor.cs | Added SliceAlongDimension, a DimensionCollection property, and new Select-overload in Tensor. Also introduced a regression in AsReadOnlyTensorSpan. |
TensorExtensions.cs | Added new Select extension methods and related delegate types. |
Tests files | Added tests for dimensions functionality and sub-tensor slicing. |
Interface/ref files | Updated API surface for new methods and properties. |
ThrowHelper.cs | Minor adjustments to support new exception messages. |
Files not reviewed (1)
- src/libraries/System.Numerics.Tensors/src/Resources/Strings.resx: Language not supported
public ReadOnlyTensorSpan<T> AsReadOnlyTensorSpan(params scoped ReadOnlySpan<nint> start) => AsReadOnlyTensorSpan().Slice(start); | ||
|
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.
This method recursively calls itself instead of invoking AsTensorSpan() to produce a valid ReadOnlyTensorSpan, which can lead to a stack overflow. It should likely call AsTensorSpan().Slice(start) instead.
public ReadOnlyTensorSpan<T> AsReadOnlyTensorSpan(params scoped ReadOnlySpan<nint> start) => AsReadOnlyTensorSpan().Slice(start); | |
public ReadOnlyTensorSpan<T> AsReadOnlyTensorSpan(params scoped ReadOnlySpan<nint> start) => AsTensorSpan().Slice(start); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
Fixes #113068.
Adds a new method,
SliceAlongDimension
, that lets you slice any given subdimension out of a tensor.Adds a new method,
Select
, that lets you runTensor
operations on segments of theTensor
instead of the wholeTensor
.Adds a
DimensionCollection
, which is similar to a Dictionary's KeyCollection, in that it has anEnumerator
that lets you iterate over theTensor
along a given dimension (compared to the KeyCollection that lets you iterate by the keys).