-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Tensor<T> select. Iteration along dimensions #113697
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d008dd8
base code in place
michaelgsharp 9abdc41
enum tests
michaelgsharp 7254f5b
Merge remote-tracking branch 'dotnet/main' into tensor-select
tannergooding 7a0bafe
Update to match the approved API refinements
tannergooding 91c53ab
Update the suppression file
tannergooding b7f3e3d
Update reference assembly and suppressions
ericstj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 128 additions & 95 deletions
223
src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs
Large diffs are not rendered by default.
Oops, something went wrong.
278 changes: 27 additions & 251 deletions
278
src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml
Large diffs are not rendered by default.
Oops, something went wrong.
51 changes: 49 additions & 2 deletions
51
src/libraries/System.Numerics.Tensors/src/ReferenceAssemblyExclusions.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,49 @@ | ||
| M:System.Numerics.Tensors.TensorPrimitives.ConvertToHalf(System.ReadOnlySpan{System.Single},System.Span{System.Half}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.ConvertToSingle(System.ReadOnlySpan{System.Half},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Abs(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Add(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Add(System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.AddMultiply(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.AddMultiply(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.AddMultiply(System.ReadOnlySpan{System.Single},System.Single,System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Cosh(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.CosineSimilarity(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Distance(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Divide(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Divide(System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Dot(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Exp(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.IndexOfMax(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.IndexOfMaxMagnitude(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.IndexOfMin(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.IndexOfMinMagnitude(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Log(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Log2(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Max(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Max(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MaxMagnitude(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MaxMagnitude(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Min(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Min(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MinMagnitude(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MinMagnitude(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Multiply(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Multiply(System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MultiplyAdd(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MultiplyAdd(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.MultiplyAdd(System.ReadOnlySpan{System.Single},System.Single,System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Negate(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Norm(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Product(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.ProductOfDifferences(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.ProductOfSums(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Sigmoid(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Sinh(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.SoftMax(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Subtract(System.ReadOnlySpan{System.Single},System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Subtract(System.ReadOnlySpan{System.Single},System.Single,System.Span{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Sum(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.SumOfMagnitudes(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.SumOfSquares(System.ReadOnlySpan{System.Single}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.Tanh(System.ReadOnlySpan{System.Single},System.Span{System.Single}) | ||
|
|
||
| M:System.Numerics.Tensors.TensorPrimitives.ConvertToIntegerNative``2(System.ReadOnlySpan{``0},System.Span{``1}) | ||
| M:System.Numerics.Tensors.TensorPrimitives.ConvertToInteger``2(System.ReadOnlySpan{``0},System.Span{``1}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...tem.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Numerics.Tensors | ||
| { | ||
| /// <summary>Represents the slices that exist within a dimension of a tensor span.</summary> | ||
| /// <typeparam name="T">The type of the elements within the tensor span.</typeparam> | ||
| public readonly ref struct ReadOnlyTensorDimensionSpan<T> | ||
| { | ||
| private readonly ReadOnlyTensorSpan<T> _tensor; | ||
| private readonly nint _length; | ||
| private readonly int _dimension; | ||
| private readonly TensorShape _sliceShape; | ||
|
|
||
| internal ReadOnlyTensorDimensionSpan(ReadOnlyTensorSpan<T> tensor, int dimension) | ||
| { | ||
| if ((uint)dimension >= tensor.Rank) | ||
| { | ||
| ThrowHelper.ThrowArgumentOutOfRangeException(); | ||
| } | ||
| dimension += 1; | ||
|
|
||
| _tensor = tensor; | ||
| _length = TensorPrimitives.Product(tensor.Lengths[..dimension]); | ||
| _dimension = dimension; | ||
| _sliceShape = TensorShape.Create((dimension != tensor.Rank) ? tensor.Lengths[dimension..] : [1], tensor.Strides[dimension..]); | ||
| } | ||
|
|
||
| /// <summary>Gets the length of the tensor dimension span.</summary> | ||
| public nint Length => _length; | ||
|
|
||
| /// <summary>Gets the tensor span representing a slice of the tracked dimension using the specified index.</summary> | ||
| /// <param name="index">The index of the tensor span slice to retrieve within the tracked dimension.</param> | ||
| /// <returns>The tensor span representing a slice of the tracked dimension using <paramref name="index" />.</returns> | ||
| public ReadOnlyTensorSpan<T> this[nint index] | ||
| { | ||
| get | ||
| { | ||
| if ((nuint)index >= (nuint)_length) | ||
| { | ||
| ThrowHelper.ThrowArgumentOutOfRangeException(); | ||
| } | ||
|
|
||
| nint linearOffset = _tensor._shape.GetLinearOffset(index, _dimension); | ||
| return new ReadOnlyTensorSpan<T>(ref Unsafe.Add(ref _tensor._reference, linearOffset), _sliceShape); | ||
| } | ||
| } | ||
|
|
||
| /// <summary>Gets an enumerator for the readonly tensor dimension span.</summary> | ||
| public Enumerator GetEnumerator() => new Enumerator(this); | ||
|
|
||
| /// <summary>Enumerates the spans of a tensor dimension span.</summary> | ||
| public ref struct Enumerator | ||
| #if NET9_0_OR_GREATER | ||
| : IEnumerator<ReadOnlyTensorSpan<T>> | ||
| #endif | ||
| { | ||
| private readonly ReadOnlyTensorDimensionSpan<T> _span; | ||
| private nint _index; | ||
|
|
||
| internal Enumerator(ReadOnlyTensorDimensionSpan<T> span) | ||
| { | ||
| _span = span; | ||
| _index = -1; | ||
| } | ||
|
|
||
| /// <summary>Gets the span at the current position of the enumerator.</summary> | ||
| public readonly ReadOnlyTensorSpan<T> Current => _span[_index]; | ||
|
|
||
| /// <summary>Advances the enumerator to the next element of the tensor span.</summary> | ||
| public bool MoveNext() | ||
| { | ||
| nint index = _index + 1; | ||
|
|
||
| if (index < _span.Length) | ||
| { | ||
| _index = index; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /// <summary>Sets the enumerator to its initial position, which is before the first element in the tensor span.</summary> | ||
| public void Reset() | ||
| { | ||
| _index = -1; | ||
| } | ||
|
|
||
| #if NET9_0_OR_GREATER | ||
| // | ||
| // IDisposable | ||
| // | ||
|
|
||
| void IDisposable.Dispose() { } | ||
|
|
||
| // | ||
| // IEnumerator | ||
| // | ||
|
|
||
| readonly object? IEnumerator.Current => throw new NotSupportedException(); | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this implement other interfaces in older TFMs?
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.
What other interfaces would it implement?