Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d008dd89abdc417254f5b7a0bafe91c53abb7f3e3dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| 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}) |
| 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 | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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?