-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add some additional Tensor APIs #117739
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
Add some additional Tensor APIs #117739
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics-tensors |
5ee338d
to
34139ac
Compare
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 factory methods (CreateFromShape
/CreateFromShapeUninitialized
), implements span-based GetSpan
and TryGetSpan
APIs across Tensor
, TensorSpan
, and ReadOnlyTensorSpan
, adds TensorMarshal
interop helpers, and cleans up unused usings.
- Renamed static creation methods and updated all references and tests to
CreateFromShape…
. - Added
GetSpan
/TryGetSpan
overloads (withnint
andNIndex
) and corresponding unit tests. - Introduced
TensorMarshal
for creating tensor spans from raw memory.
Reviewed Changes
Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/TensorTests.cs | Renamed factory calls, added GetSpan /TryGetSpan tests |
tests/TensorSpanTests.cs | Added GetSpan /TryGetSpan tests for TensorSpan |
src/.../Runtime/InteropServices/TensorMarshal.cs | New interop API for creating tensor spans |
src/.../Tensor_1.cs & related files | Implemented GetSpan /TryGetSpan on Tensor , updated interface |
src/.../ITensor_1.cs | Updated interface to declare new span-based methods |
Comments suppressed due to low confidence (2)
src/libraries/System.Numerics.Tensors/tests/TensorTests.cs:2913
- Add test cases covering the
GetSpan
andTryGetSpan
overloads that acceptReadOnlySpan<NIndex>
to ensure the new NIndex-based APIs are exercised.
public static void GetSpanTest()
src/libraries/System.Numerics.Tensors/src/System/Runtime/InteropServices/TensorMarshal.cs:21
- Consider validating that
lengths.Length == strides.Length
(or providing a default stride when empty) to avoid constructing aTensorSpan
with mismatched dimension metadata.
public static TensorSpan<T> CreateTensorSpan<T>(scoped ref T data, nint dataLength, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned)
...ibraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs
Show resolved
Hide resolved
...ibraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs
Show resolved
Hide resolved
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs
Show resolved
Hide resolved
...ibraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs
Show resolved
Hide resolved
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.
If this missed the Preview 7 snap, we should backport into the branch.
/ba-g unrelated wasm timeouts |
This resolves #117373, resolves #117372, resolves #117375