From d008dd848ec4739139c3d938b758c83d6a1379e2 Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Wed, 7 May 2025 16:20:12 -0600 Subject: [PATCH 1/5] base code in place --- .../src/System.Numerics.Tensors.csproj | 3 + .../netcore/ReadOnlyTensorDimensionView_1.cs | 146 +++++++++++++++ .../System/Numerics/Tensors/netcore/Tensor.cs | 21 +-- .../Tensors/netcore/TensorDimensionView_1.cs | 171 ++++++++++++++++++ .../Numerics/Tensors/netcore/TensorShape.cs | 18 ++ .../Numerics/Tensors/netcore/Tensor_1.cs | 8 + .../System.Numerics.Tensors.Tests.csproj | 1 + .../tests/TensorGetDimensionTests.cs | 72 ++++++++ 8 files changed, 421 insertions(+), 19 deletions(-) create mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs create mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs create mode 100644 src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index 7202c69d6ab762..1b813b3c901fc8 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -8,6 +8,7 @@ ReferenceAssemblyExclusions.txt $(NoWarn);SYSLIB5001 + false @@ -40,6 +41,8 @@ + + diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs new file mode 100644 index 00000000000000..d58fdb53161519 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs @@ -0,0 +1,146 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Text; +using static System.Numerics.Tensors.TensorOperation; + +namespace System.Numerics.Tensors +{ + /// + /// Represents a read-only view of a tensor dimension. + /// + /// + public readonly ref struct ReadOnlyTensorDimensionView + { + private readonly ReadOnlyTensorSpan _tensor; + private readonly int _dimension; + private readonly nint _count; + //private readonly + + internal ReadOnlyTensorDimensionView(ReadOnlyTensorSpan tensor, int dimension) + { + if (dimension < 0 || dimension >= tensor.Rank) + { + ThrowHelper.ThrowArgument_InvalidDimension(); + } + + _tensor = tensor; + _dimension = dimension; + _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, tensor.Rank - dimension)); + } + + /// + /// The length of the dimension + /// + public nint Count => _count; + + /// + /// Returns a tensor that represents the slice of the tensor at the specified index. + /// + /// + /// + public ReadOnlyTensorSpan GetSlice(int index) + { + // This is not optimized, but it is a correct one. + scoped Span indexes = RentedBuffer.CreateUninitialized(_tensor.Rank, out RentedBuffer rentedBuffer); + + indexes.Fill(NRange.All); + for (int i = 0; i < _dimension; i++) + { + indexes[i] = 0..1; + } + indexes[_dimension] = -1..0; + for (int i = 0; i < index; i++) + { + TensorShape.AdjustToNextIndex(indexes, _dimension, _tensor.Lengths); + } + ReadOnlyTensorSpan slice = _tensor[indexes]; + rentedBuffer.Dispose(); + return slice; + } + + /// + /// Gets an enumerator that iterates through the dimension. + /// + /// + public Enumerator GetEnumerator() + { + return new Enumerator(_tensor, _dimension); + } + + /// + /// Enumerates the slices of the tensor dimension. + /// + public ref struct Enumerator +#if NET9_0_OR_GREATER + : IEnumerator> +#endif + { + private readonly ReadOnlyTensorSpan _tensor; + private readonly int _dimension; + private readonly NRange[] _rentedBuffer; + private readonly Span _indexes; + + internal Enumerator(ReadOnlyTensorSpan tensor, int dimension) + { + _tensor = tensor; + _dimension = dimension; + _rentedBuffer = ArrayPool.Shared.Rent(tensor.Rank); + + _indexes = _rentedBuffer.AsSpan(0, tensor.Rank); + _indexes.Clear(); + + _indexes.Fill(NRange.All); + Reset(); + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + /// if the enumerator moved, otherwise. + public bool MoveNext() => TensorShape.AdjustToNextIndex(_indexes, _dimension, _tensor.Lengths); + + /// + /// Resets the enumerator to the beginning of the span. + /// + public void Reset() + { + for (int i = 0; i < _dimension; i++) + { + _indexes[i] = 0..1; + } + _indexes[_dimension] = -1..0; + } + + /// + /// Disposes of the enumerator. + /// + public void Dispose() + { + ArrayPool.Shared.Return(_rentedBuffer); + } + + /// + /// Current value of the + /// + public ReadOnlyTensorSpan Current => _tensor[_indexes]; + +#if NET9_0_OR_GREATER + // This will always just throw but needs to be here. + //TODO: What error do we throw for this Tanner? + object IEnumerator.Current => throw new NotImplementedException(); + + ReadOnlyTensorSpan IEnumerator>.Current + { + get => Current; + } +#endif + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs index 8d4a670a1bd9b6..4533569a8b4ce5 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs @@ -272,31 +272,14 @@ public static ref readonly TensorSpan ConcatenateOnDimension(int dimension TensorOperation.Invoke, T, T>(slice, dstSpan); dstSpan = dstSpan.Slice((int)slice.FlattenedLength); } - hasMore = IncrementIndexes(ranges, dimension, destination.Lengths); + // We do dimension - 1 because we want to include the dimension we concatenated on. + hasMore = TensorShape.AdjustToNextIndex(ranges, dimension - 1, destination.Lengths); } rentedBuffer.Dispose(); } return ref destination; } - private static bool IncrementIndexes(Span ranges, int dimension, ReadOnlySpan lengths) - { - NRange curRange = ranges[dimension - 1]; - ranges[dimension - 1] = new NRange(curRange.Start.Value + 1, curRange.End.Value + 1); - - for (int i = dimension - 1; i >= 0; i--) - { - if (ranges[i].Start.Value >= lengths[i]) - { - ranges[i] = 0..1; - if (i == 0) - return false; - ranges[i - 1] = new NRange(ranges[i - 1].Start.Value + 1, ranges[i - 1].End.Value + 1); - } - } - return true; - } - private static nint CalculateCopyLength(ReadOnlySpan lengths, int startingAxis) { // When starting axis is -1 we want all the data at once same as if starting axis is 0 diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs new file mode 100644 index 00000000000000..12cfd35f1cf376 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs @@ -0,0 +1,171 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Buffers; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using static System.Numerics.Tensors.TensorOperation; + +namespace System.Numerics.Tensors +{ + /// + /// Represents a read-only view of a tensor dimension. + /// + /// + public readonly ref struct TensorDimensionView + { + private readonly TensorSpan _tensor; + private readonly int _dimension; + private readonly nint _count; + //private readonly + + internal TensorDimensionView(TensorSpan tensor, int dimension) + { + if (dimension < 0 || dimension >= tensor.Rank) + { + ThrowHelper.ThrowArgument_InvalidDimension(); + } + + _tensor = tensor; + _dimension = dimension; + // Span.Slice is based on length (so 1 based) and the dimension is an index (so 0 based) + // So we need to add 1 to the dimension to reconcile this. + _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, dimension + 1)); + } + + /// + /// The length of the dimension + /// + public nint Count => _count; + + /// + /// Returns a tensor that represents the slice of the tensor at the specified index. + /// + /// + /// + public TensorSpan GetSlice(int index) + { + if (index < 0 || index >= _count) + { + ThrowHelper.ThrowIndexOutOfRangeException(); + } + + // This is not optimized, but it is a correct one. + scoped Span indexes = RentedBuffer.CreateUninitialized(_tensor.Rank, out RentedBuffer rentedBuffer); + + indexes.Fill(NRange.All); + for (int i = 0; i <= _dimension; i++) + { + indexes[i] = 0..1; + } + + // Starting at 0..1 so our loop is strictly less than the index since index is a valid index and we are already on the first one. + for (int i = 0; i < index; i++) + { + TensorShape.AdjustToNextIndex(indexes, _dimension, _tensor.Lengths); + } + TensorSpan slice = _tensor[indexes]; + rentedBuffer.Dispose(); + return slice; + } + + /// + /// Gets an enumerator that iterates through the dimension. + /// + /// + public Enumerator GetEnumerator() + { + return new Enumerator(_tensor, _dimension); + } + + /// + /// Enumerates the slices of the tensor dimension. + /// + public ref struct Enumerator +#if NET9_0_OR_GREATER + : IEnumerator> +#endif + { + private readonly TensorSpan _tensor; + private readonly int _dimension; + private readonly NRange[] _rentedBuffer; + private readonly Span _indexes; + + internal Enumerator(TensorSpan tensor, int dimension) + { + _tensor = tensor; + _dimension = dimension; + _rentedBuffer = ArrayPool.Shared.Rent(tensor.Rank); + + _indexes = _rentedBuffer.AsSpan(0, tensor.Rank); + _indexes.Clear(); + + _indexes.Fill(NRange.All); + Reset(); + } + + /// + /// Advances the enumerator to the next element of the collection. + /// + /// if the enumerator moved, otherwise. + public bool MoveNext() => TensorShape.AdjustToNextIndex(_indexes, _dimension, _tensor.Lengths); + + /// + /// Resets the enumerator to the beginning of the span. + /// + public void Reset() + { + for (int i = 0; i < _dimension; i++) + { + _indexes[i] = 0..1; + } + _indexes[_dimension] = 0..0; + } + + /// + /// Disposes of the enumerator. + /// + public void Dispose() + { + ArrayPool.Shared.Return(_rentedBuffer); + } + + /// + /// Current value of the + /// + public TensorSpan Current + { + get + { + scoped TensorSpan slice = _tensor[_indexes]; + for (Int128 i = 0; i < _dimension; i++) + { + slice = slice.SqueezeDimension(0); + } + if ( _dimension == 0) + { + slice = slice.SqueezeDimension(0); + } + + return slice; + } + } + +#if NET9_0_OR_GREATER + // This will always just throw but needs to be here. + //TODO: What error do we throw for this Tanner? + object IEnumerator.Current => throw new NotImplementedException(); + + TensorSpan IEnumerator>.Current + { + get => Current; + } +#endif + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs index 9cf04855e93d5d..4a926b0a407105 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs @@ -587,6 +587,24 @@ public nint AdjustToPreviousIndex(in TensorShape destinationShape, nint linearOf return 0; } + public static bool AdjustToNextIndex(Span ranges, int dimension, ReadOnlySpan lengths) + { + NRange curRange = ranges[dimension]; + ranges[dimension] = new NRange(curRange.Start.Value + 1, curRange.End.Value + 1); + + for (int i = dimension; i >= 0; i--) + { + if (ranges[i].Start.Value >= lengths[i]) + { + ranges[i] = 0..1; + if (i == 0) + return false; + ranges[i - 1] = new NRange(ranges[i - 1].Start.Value + 1, ranges[i - 1].End.Value + 1); + } + } + return true; + } + // Answer the question: Can shape2 turn into shape1 or vice-versa if allowBidirectional? public static bool AreCompatible(in TensorShape shape1, in TensorShape shape2, bool allowBidirectional) { diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs index a2417ae57f1afe..d7012441c0757a 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs @@ -447,5 +447,13 @@ readonly void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } + + /// + /// Slices the tensor along the specified dimension. + /// + /// The dimension to slice along. + /// The tensor sliced to the given + public TensorDimensionView GetDimension(int dimension) => new TensorDimensionView(this, dimension); + } } diff --git a/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj b/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj index 89c744dc04a7ba..9f564fa2c07821 100644 --- a/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj +++ b/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj @@ -27,6 +27,7 @@ + diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs new file mode 100644 index 00000000000000..113d38e451c712 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs @@ -0,0 +1,72 @@ +using Xunit; + +namespace System.Numerics.Tensors.Tests +{ + public class TensorGetDimensionTests + { + [Fact] + public void GetDimension_ValidDimension_ReturnsCorrectView() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act + var dimensionView = tensor.GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + int[] slice = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(slice); + Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1], slice); + + dimensionView.GetSlice(1).FlattenTo(slice); + Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([2], slice); + + dimensionView.GetSlice(2).FlattenTo(slice); + Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + Assert.Equal([3], slice); + + dimensionView.GetSlice(3).FlattenTo(slice); + Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + Assert.Equal([4], slice); + + // Act + dimensionView = tensor.GetDimension(0); + + // Assert + Assert.Equal(2, dimensionView.Count); + slice = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(slice); + Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1, 2], slice); + + dimensionView.GetSlice(1).FlattenTo(slice); + Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([3, 4], slice); + } + + [Fact] + public void GetDimension_InvalidDimension_ThrowsArgumentException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.GetDimension(-1)); + Assert.Throws(() => tensor.GetDimension(3)); + } + + [Fact] + public void GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.GetDimension(1).GetSlice(-1)); + Assert.Throws(() => tensor.GetDimension(1).GetSlice(4)); + } + } +} From 9abdc41955f8847a9407768d82df03f82760200a Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Thu, 8 May 2025 17:13:14 -0600 Subject: [PATCH 2/5] enum tests --- .../netcore/ReadOnlyTensorDimensionView_1.cs | 35 +- .../Tensors/netcore/ReadOnlyTensorSpan_1.cs | 7 + .../Tensors/netcore/TensorDimensionView_1.cs | 6 +- .../{TensorSpan.cs => TensorSpan_1.cs} | 7 + .../Numerics/Tensors/netcore/Tensor_1.cs | 1 - .../tests/TensorDimensionViewTests.cs | 391 ++++++++++++++++++ .../tests/TensorGetDimensionTests.cs | 72 ---- 7 files changed, 438 insertions(+), 81 deletions(-) rename src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/{TensorSpan.cs => TensorSpan_1.cs} (97%) create mode 100644 src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs delete mode 100644 src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs index d58fdb53161519..adb0362497b65d 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs @@ -8,6 +8,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; +using System.Threading; using static System.Numerics.Tensors.TensorOperation; namespace System.Numerics.Tensors @@ -32,7 +33,9 @@ internal ReadOnlyTensorDimensionView(ReadOnlyTensorSpan tensor, int dimension _tensor = tensor; _dimension = dimension; - _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, tensor.Rank - dimension)); + // Span.Slice is based on length (so 1 based) and the dimension is an index (so 0 based) + // So we need to add 1 to the dimension to reconcile this. + _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, dimension + 1)); } /// @@ -47,15 +50,21 @@ internal ReadOnlyTensorDimensionView(ReadOnlyTensorSpan tensor, int dimension /// public ReadOnlyTensorSpan GetSlice(int index) { + if (index < 0 || index >= _count) + { + ThrowHelper.ThrowIndexOutOfRangeException(); + } + // This is not optimized, but it is a correct one. scoped Span indexes = RentedBuffer.CreateUninitialized(_tensor.Rank, out RentedBuffer rentedBuffer); indexes.Fill(NRange.All); - for (int i = 0; i < _dimension; i++) + for (int i = 0; i <= _dimension; i++) { indexes[i] = 0..1; } - indexes[_dimension] = -1..0; + + // Starting at 0..1 so our loop is strictly less than the index since index is a valid index and we are already on the first one. for (int i = 0; i < index; i++) { TensorShape.AdjustToNextIndex(indexes, _dimension, _tensor.Lengths); @@ -115,7 +124,7 @@ public void Reset() { _indexes[i] = 0..1; } - _indexes[_dimension] = -1..0; + _indexes[_dimension] = 0..0; } /// @@ -129,7 +138,23 @@ public void Dispose() /// /// Current value of the /// - public ReadOnlyTensorSpan Current => _tensor[_indexes]; + public ReadOnlyTensorSpan Current + { + get + { + ReadOnlyTensorSpan slice = _tensor[_indexes]; + for (int i = 0; i < _dimension; i++) + { + slice = slice.SqueezeDimension(0); + } + if (_dimension == 0) + { + slice = slice.SqueezeDimension(0); + } + + return slice; + } + } #if NET9_0_OR_GREATER // This will always just throw but needs to be here. diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs index 36452121c96ebd..25250ef25b72e5 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs @@ -520,5 +520,12 @@ void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } + + /// + /// Slices the tensor along the specified dimension. + /// + /// The dimension to slice along. + /// The tensor sliced to the given + public ReadOnlyTensorDimensionView GetDimension(int dimension) => new ReadOnlyTensorDimensionView(this, dimension); } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs index 12cfd35f1cf376..08e6dc53c6b9bc 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs @@ -142,12 +142,12 @@ public TensorSpan Current { get { - scoped TensorSpan slice = _tensor[_indexes]; - for (Int128 i = 0; i < _dimension; i++) + TensorSpan slice = _tensor[_indexes]; + for (int i = 0; i < _dimension; i++) { slice = slice.SqueezeDimension(0); } - if ( _dimension == 0) + if (_dimension == 0) { slice = slice.SqueezeDimension(0); } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs similarity index 97% rename from src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan.cs rename to src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs index 093a922f2f3789..14a7beef199cc2 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs @@ -400,5 +400,12 @@ void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } + + /// + /// Slices the tensor along the specified dimension. + /// + /// The dimension to slice along. + /// The tensor sliced to the given + public TensorDimensionView GetDimension(int dimension) => new TensorDimensionView(this, dimension); } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs index d7012441c0757a..1faeafe74609bb 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs @@ -454,6 +454,5 @@ readonly void IDisposable.Dispose() { } /// The dimension to slice along. /// The tensor sliced to the given public TensorDimensionView GetDimension(int dimension) => new TensorDimensionView(this, dimension); - } } diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs new file mode 100644 index 00000000000000..47ef029cff3aa5 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs @@ -0,0 +1,391 @@ +using Xunit; + +namespace System.Numerics.Tensors.Tests +{ + public class TensorGetDimensionTests + { + [Fact] + public void TensorDimensionView_GetDimension_ValidDimension_ReturnsCorrectView() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act + var dimensionView = tensor.GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + int[] sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView.GetSlice(2).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView.GetSlice(3).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // Act + dimensionView = tensor.GetDimension(0); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1, 2], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([3, 4], sliceData); + + // check tensor with 1 dimension + tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); + + // Act + dimensionView = tensor.GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView.GetSlice(2).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView.GetSlice(3).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // check tensor with 3 dimensions + tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); + + // Act + dimensionView = tensor.GetDimension(0); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([0, 1, 2, 3], sliceData); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(1).FlattenedLength]; + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([4, 5, 6, 7], sliceData); + + // Act + dimensionView = tensor.GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + for (int i = 0; i < dimensionView.Count; i+=2) + { + TensorSpan slice = dimensionView.GetSlice(i); + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([2], slice.Lengths.ToArray()); + Assert.Equal([i, i + 1], sliceData); + } + + // Act + dimensionView = tensor.GetDimension(2); + + // Assert + Assert.Equal(8, dimensionView.Count); + for (int i = 0; i < 8; i++) + { + TensorSpan slice = dimensionView.GetSlice(i); + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([1], slice.Lengths.ToArray()); + Assert.Equal([i], sliceData); + } + } + + [Fact] + public void TensorDimensionView_GetDimension_InvalidDimension_ThrowsArgumentException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.GetDimension(-1)); + Assert.Throws(() => tensor.GetDimension(2)); + + // Arrange + tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); + + // Act & Assert + Assert.Throws(() => tensor.GetDimension(-1)); + Assert.Throws(() => tensor.GetDimension(1)); + } + + [Fact] + public void TensorDimensionView_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.GetDimension(1).GetSlice(-1)); + Assert.Throws(() => tensor.GetDimension(1).GetSlice(4)); + } + + [Fact] + public void ReadOnlyTensorDimensionView_GetDimension_ValidDimension_ReturnsCorrectView() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act + var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + int[] sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView.GetSlice(2).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView.GetSlice(3).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(0); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1, 2], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([3, 4], sliceData); + + // check tensor with 1 dimension + tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([1], sliceData); + + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView.GetSlice(2).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView.GetSlice(3).FlattenTo(sliceData); + Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // check tensor with 3 dimensions + tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(0); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; + dimensionView.GetSlice(0).FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([0, 1, 2, 3], sliceData); + + // Assert + Assert.Equal(2, dimensionView.Count); + sliceData = new int[dimensionView.GetSlice(1).FlattenedLength]; + dimensionView.GetSlice(1).FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal([4, 5, 6, 7], sliceData); + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + + // Assert + Assert.Equal(4, dimensionView.Count); + for (int i = 0; i < dimensionView.Count; i += 2) + { + ReadOnlyTensorSpan slice = dimensionView.GetSlice(i); + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([2], slice.Lengths.ToArray()); + Assert.Equal([i, i + 1], sliceData); + } + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(2); + + // Assert + Assert.Equal(8, dimensionView.Count); + for (int i = 0; i < 8; i++) + { + ReadOnlyTensorSpan slice = dimensionView.GetSlice(i); + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([1], slice.Lengths.ToArray()); + Assert.Equal([i], sliceData); + } + } + + [Fact] + public void ReadOnlyTensorDimensionView_GetDimension_InvalidDimension_ThrowsArgumentException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(2)); + + // Arrange + tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); + + // Act & Assert + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1)); + } + + [Fact] + public void ReadOnlyTensorDimensionView_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + + // Act & Assert + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1).GetSlice(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1).GetSlice(4)); + } + + [Fact] + public void TensorDimensionView_Enumerator_EnumeratesCorrectly() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + var dimensionView = tensor.GetDimension(1); + + // Act & Assert + int index = 0; + int[][] expectedSlices = new int[][] { new int[] { 1 }, new int[] { 2 }, new int[] { 3 }, new int[] { 4 } }; + + foreach (var slice in dimensionView) + { + int[] sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal(expectedSlices[index], sliceData); + index++; + } + + Assert.Equal(4, index); // Verify we got all slices + + // Test enumeration with explicit enumerator + index = 0; + var enumerator = dimensionView.GetEnumerator(); + while (enumerator.MoveNext()) + { + var slice = enumerator.Current; + int[] sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal(expectedSlices[index], sliceData); + index++; + } + + Assert.Equal(4, index); + } + + [Fact] + public void ReadOnlyTensorDimensionView_Enumerator_EnumeratesCorrectly() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + + // Act & Assert + int index = 0; + int[][] expectedSlices = new int[][] { new int[] { 1 }, new int[] { 2 }, new int[] { 3 }, new int[] { 4 } }; + + foreach (var slice in dimensionView) + { + int[] sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal(expectedSlices[index], sliceData); + index++; + } + + Assert.Equal(4, index); // Verify we got all slices + + // Test enumeration with explicit enumerator + index = 0; + var enumerator = dimensionView.GetEnumerator(); + while (enumerator.MoveNext()) + { + var slice = enumerator.Current; + int[] sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal(expectedSlices[index], sliceData); + index++; + } + + Assert.Equal(4, index); + } + + [Fact] + public void TensorDimensionView_Enumerator_MultidimensionalTensor() + { + // Arrange - using a 3D tensor + var tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); + var dimensionView = tensor.GetDimension(0); + + // Act & Assert + int index = 0; + int[][] expectedSlices = new int[][] { new int[] { 0, 1, 2, 3 }, new int[] { 4, 5, 6, 7 } }; + + foreach (var slice in dimensionView) + { + int[] sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal(expectedSlices[index], sliceData); + index++; + } + + Assert.Equal(2, index); // Verify we got all slices + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs deleted file mode 100644 index 113d38e451c712..00000000000000 --- a/src/libraries/System.Numerics.Tensors/tests/TensorGetDimensionTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -using Xunit; - -namespace System.Numerics.Tensors.Tests -{ - public class TensorGetDimensionTests - { - [Fact] - public void GetDimension_ValidDimension_ReturnsCorrectView() - { - // Arrange - var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); - - // Act - var dimensionView = tensor.GetDimension(1); - - // Assert - Assert.Equal(4, dimensionView.Count); - int[] slice = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(slice); - Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); - Assert.Equal([1], slice); - - dimensionView.GetSlice(1).FlattenTo(slice); - Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); - Assert.Equal([2], slice); - - dimensionView.GetSlice(2).FlattenTo(slice); - Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); - Assert.Equal([3], slice); - - dimensionView.GetSlice(3).FlattenTo(slice); - Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); - Assert.Equal([4], slice); - - // Act - dimensionView = tensor.GetDimension(0); - - // Assert - Assert.Equal(2, dimensionView.Count); - slice = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(slice); - Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); - Assert.Equal([1, 2], slice); - - dimensionView.GetSlice(1).FlattenTo(slice); - Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); - Assert.Equal([3, 4], slice); - } - - [Fact] - public void GetDimension_InvalidDimension_ThrowsArgumentException() - { - // Arrange - var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); - - // Act & Assert - Assert.Throws(() => tensor.GetDimension(-1)); - Assert.Throws(() => tensor.GetDimension(3)); - } - - [Fact] - public void GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() - { - // Arrange - var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); - - // Act & Assert - Assert.Throws(() => tensor.GetDimension(1).GetSlice(-1)); - Assert.Throws(() => tensor.GetDimension(1).GetSlice(4)); - } - } -} From 7a0bafe7b1c6114ac7cb3af03e1109a520a7b18e Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 11 Jun 2025 11:28:52 -0700 Subject: [PATCH 3/5] Update to match the approved API refinements --- .../src/System.Numerics.Tensors.csproj | 4 +- .../Tensors/netcore/IReadOnlyTensor_1.cs | 5 + .../Numerics/Tensors/netcore/ITensor_1.cs | 3 + .../netcore/ReadOnlyTensorDimensionSpan_1.cs | 109 ++++++++ .../netcore/ReadOnlyTensorDimensionView_1.cs | 171 ------------- .../Tensors/netcore/ReadOnlyTensorSpan_1.cs | 11 +- .../Tensors/netcore/TensorDimensionSpan_1.cs | 108 ++++++++ .../Tensors/netcore/TensorDimensionView_1.cs | 171 ------------- .../Numerics/Tensors/netcore/TensorShape.cs | 70 ++++-- .../Numerics/Tensors/netcore/TensorSpan_1.cs | 11 +- .../Numerics/Tensors/netcore/Tensor_1.cs | 15 +- .../System.Numerics.Tensors.Tests.csproj | 2 +- ...ewTests.cs => TensorDimensionSpanTests.cs} | 234 +++++++++--------- 13 files changed, 404 insertions(+), 510 deletions(-) create mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs delete mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs create mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionSpan_1.cs delete mode 100644 src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs rename src/libraries/System.Numerics.Tensors/tests/{TensorDimensionViewTests.cs => TensorDimensionSpanTests.cs} (52%) diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index fead715eed182c..2a14c9c09d25c8 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -37,12 +37,12 @@ + + - - diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/IReadOnlyTensor_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/IReadOnlyTensor_1.cs index 5a6a3cbc10e735..f14635deafb564 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/IReadOnlyTensor_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/IReadOnlyTensor_1.cs @@ -62,6 +62,11 @@ public interface IReadOnlyTensor : IReadOnlyTensor, IEnumerable /// This method copies all of the source tensor to even if they overlap. void FlattenTo(scoped Span destination); + /// Returns a span that can be used to access the flattened elements for a given dimension. + /// The dimension for which the span should be created. + /// A span that can be used to access the flattened elements for a given dimension. + ReadOnlyTensorDimensionSpan GetDimensionSpan(int dimension); + /// Returns a reference to an object of type that can be used for pinning. /// A reference to the element of the tensor at index 0, or null if the tensor is empty. /// This method is intended to support .NET compilers and is not intended to be called by user code. diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ITensor_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ITensor_1.cs index 8be1445275e3fb..c7b0ab8b1d60da 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ITensor_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ITensor_1.cs @@ -87,6 +87,9 @@ public interface ITensor : ITensor, IReadOnlyTensor /// void Fill(T value); + /// + new TensorDimensionSpan GetDimensionSpan(int dimension); + /// new ref T GetPinnableReference(); } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs new file mode 100644 index 00000000000000..32d3374acf459f --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionSpan_1.cs @@ -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 +{ + /// Represents the slices that exist within a dimension of a tensor span. + /// The type of the elements within the tensor span. + public readonly ref struct ReadOnlyTensorDimensionSpan + { + private readonly ReadOnlyTensorSpan _tensor; + private readonly nint _length; + private readonly int _dimension; + private readonly TensorShape _sliceShape; + + internal ReadOnlyTensorDimensionSpan(ReadOnlyTensorSpan 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..]); + } + + /// Gets the length of the tensor dimension span. + public nint Length => _length; + + /// Gets the tensor span representing a slice of the tracked dimension using the specified index. + /// The index of the tensor span slice to retrieve within the tracked dimension. + /// The tensor span representing a slice of the tracked dimension using . + public ReadOnlyTensorSpan this[nint index] + { + get + { + if ((nuint)index >= (nuint)_length) + { + ThrowHelper.ThrowArgumentOutOfRangeException(); + } + + nint linearOffset = _tensor._shape.GetLinearOffset(index, _dimension); + return new ReadOnlyTensorSpan(ref Unsafe.Add(ref _tensor._reference, linearOffset), _sliceShape); + } + } + + /// Gets an enumerator for the readonly tensor dimension span. + public Enumerator GetEnumerator() => new Enumerator(this); + + /// Enumerates the spans of a tensor dimension span. + public ref struct Enumerator +#if NET9_0_OR_GREATER + : IEnumerator> +#endif + { + private readonly ReadOnlyTensorDimensionSpan _span; + private nint _index; + + internal Enumerator(ReadOnlyTensorDimensionSpan span) + { + _span = span; + _index = -1; + } + + /// Gets the span at the current position of the enumerator. + public readonly ReadOnlyTensorSpan Current => _span[_index]; + + /// Advances the enumerator to the next element of the tensor span. + public bool MoveNext() + { + nint index = _index + 1; + + if (index < _span.Length) + { + _index = index; + return true; + } + return false; + } + + /// Sets the enumerator to its initial position, which is before the first element in the tensor span. + public void Reset() + { + _index = -1; + } + +#if NET9_0_OR_GREATER + // + // IDisposable + // + + void IDisposable.Dispose() { } + + // + // IEnumerator + // + + readonly object? IEnumerator.Current => throw new NotSupportedException(); +#endif + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs deleted file mode 100644 index adb0362497b65d..00000000000000 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorDimensionView_1.cs +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using static System.Numerics.Tensors.TensorOperation; - -namespace System.Numerics.Tensors -{ - /// - /// Represents a read-only view of a tensor dimension. - /// - /// - public readonly ref struct ReadOnlyTensorDimensionView - { - private readonly ReadOnlyTensorSpan _tensor; - private readonly int _dimension; - private readonly nint _count; - //private readonly - - internal ReadOnlyTensorDimensionView(ReadOnlyTensorSpan tensor, int dimension) - { - if (dimension < 0 || dimension >= tensor.Rank) - { - ThrowHelper.ThrowArgument_InvalidDimension(); - } - - _tensor = tensor; - _dimension = dimension; - // Span.Slice is based on length (so 1 based) and the dimension is an index (so 0 based) - // So we need to add 1 to the dimension to reconcile this. - _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, dimension + 1)); - } - - /// - /// The length of the dimension - /// - public nint Count => _count; - - /// - /// Returns a tensor that represents the slice of the tensor at the specified index. - /// - /// - /// - public ReadOnlyTensorSpan GetSlice(int index) - { - if (index < 0 || index >= _count) - { - ThrowHelper.ThrowIndexOutOfRangeException(); - } - - // This is not optimized, but it is a correct one. - scoped Span indexes = RentedBuffer.CreateUninitialized(_tensor.Rank, out RentedBuffer rentedBuffer); - - indexes.Fill(NRange.All); - for (int i = 0; i <= _dimension; i++) - { - indexes[i] = 0..1; - } - - // Starting at 0..1 so our loop is strictly less than the index since index is a valid index and we are already on the first one. - for (int i = 0; i < index; i++) - { - TensorShape.AdjustToNextIndex(indexes, _dimension, _tensor.Lengths); - } - ReadOnlyTensorSpan slice = _tensor[indexes]; - rentedBuffer.Dispose(); - return slice; - } - - /// - /// Gets an enumerator that iterates through the dimension. - /// - /// - public Enumerator GetEnumerator() - { - return new Enumerator(_tensor, _dimension); - } - - /// - /// Enumerates the slices of the tensor dimension. - /// - public ref struct Enumerator -#if NET9_0_OR_GREATER - : IEnumerator> -#endif - { - private readonly ReadOnlyTensorSpan _tensor; - private readonly int _dimension; - private readonly NRange[] _rentedBuffer; - private readonly Span _indexes; - - internal Enumerator(ReadOnlyTensorSpan tensor, int dimension) - { - _tensor = tensor; - _dimension = dimension; - _rentedBuffer = ArrayPool.Shared.Rent(tensor.Rank); - - _indexes = _rentedBuffer.AsSpan(0, tensor.Rank); - _indexes.Clear(); - - _indexes.Fill(NRange.All); - Reset(); - } - - /// - /// Advances the enumerator to the next element of the collection. - /// - /// if the enumerator moved, otherwise. - public bool MoveNext() => TensorShape.AdjustToNextIndex(_indexes, _dimension, _tensor.Lengths); - - /// - /// Resets the enumerator to the beginning of the span. - /// - public void Reset() - { - for (int i = 0; i < _dimension; i++) - { - _indexes[i] = 0..1; - } - _indexes[_dimension] = 0..0; - } - - /// - /// Disposes of the enumerator. - /// - public void Dispose() - { - ArrayPool.Shared.Return(_rentedBuffer); - } - - /// - /// Current value of the - /// - public ReadOnlyTensorSpan Current - { - get - { - ReadOnlyTensorSpan slice = _tensor[_indexes]; - for (int i = 0; i < _dimension; i++) - { - slice = slice.SqueezeDimension(0); - } - if (_dimension == 0) - { - slice = slice.SqueezeDimension(0); - } - - return slice; - } - } - -#if NET9_0_OR_GREATER - // This will always just throw but needs to be here. - //TODO: What error do we throw for this Tanner? - object IEnumerator.Current => throw new NotImplementedException(); - - ReadOnlyTensorSpan IEnumerator>.Current - { - get => Current; - } -#endif - } - } -} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs index 9f5d64ceb5b5cb..74e6d6c0423517 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs @@ -18,6 +18,7 @@ namespace System.Numerics.Tensors /// Represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed /// or native memory, or to memory allocated on the stack. It is type-safe and memory-safe. /// + /// The type of the elements within the tensor span. [DebuggerTypeProxy(typeof(TensorSpanDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] [Experimental(Experimentals.TensorTDiagId, UrlFormat = Experimentals.SharedUrlFormat)] @@ -382,6 +383,9 @@ public void FlattenTo(scoped Span destination) } } + /// + public ReadOnlyTensorDimensionSpan GetDimensionSpan(int dimension) => new ReadOnlyTensorDimensionSpan(this, dimension); + /// Gets an enumerator for the readonly tensor span. public Enumerator GetEnumerator() => new Enumerator(this); @@ -524,12 +528,5 @@ void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } - - /// - /// Slices the tensor along the specified dimension. - /// - /// The dimension to slice along. - /// The tensor sliced to the given - public ReadOnlyTensorDimensionView GetDimension(int dimension) => new ReadOnlyTensorDimensionView(this, dimension); } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionSpan_1.cs new file mode 100644 index 00000000000000..78622c79c59f09 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionSpan_1.cs @@ -0,0 +1,108 @@ +// 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; + +namespace System.Numerics.Tensors +{ + /// Represents the slices that exist within a dimension of a tensor span. + /// The type of the elements within the tensor span. + public readonly ref struct TensorDimensionSpan + { + private readonly TensorSpan _tensor; + private readonly nint _length; + private readonly int _dimension; + private readonly TensorShape _sliceShape; + + internal TensorDimensionSpan(TensorSpan 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..]); + } + + /// Gets the length of the tensor dimension span. + public nint Length => _length; + + /// Gets the tensor span representing a slice of the tracked dimension using the specified index. + /// The index of the tensor span slice to retrieve within the tracked dimension. + /// The tensor span representing a slice of the tracked dimension using . + public TensorSpan this[nint index] + { + get + { + if ((nuint)index >= (nuint)_length) + { + ThrowHelper.ThrowArgumentOutOfRangeException(); + } + + nint linearOffset = _tensor._shape.GetLinearOffset(index, _dimension); + return new TensorSpan(ref Unsafe.Add(ref _tensor._reference, linearOffset), _sliceShape); + } + } + + /// Gets an enumerator for the readonly tensor dimension span. + public Enumerator GetEnumerator() => new Enumerator(this); + + /// Enumerates the spans of a tensor dimension span. + public ref struct Enumerator +#if NET9_0_OR_GREATER + : IEnumerator> +#endif + { + private readonly TensorDimensionSpan _span; + private nint _index; + + internal Enumerator(TensorDimensionSpan span) + { + _span = span; + _index = -1; + } + + /// Gets the span at the current position of the enumerator. + public readonly TensorSpan Current => _span[_index]; + + /// Advances the enumerator to the next element of the tensor span. + public bool MoveNext() + { + nint index = _index + 1; + + if (index < _span.Length) + { + _index = index; + return true; + } + return false; + } + + /// Sets the enumerator to its initial position, which is before the first element in the tensor span. + public void Reset() + { + _index = -1; + } + +#if NET9_0_OR_GREATER + // + // IDisposable + // + + void IDisposable.Dispose() { } + + // + // IEnumerator + // + + readonly object? IEnumerator.Current => throw new NotSupportedException(); +#endif + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs deleted file mode 100644 index 08e6dc53c6b9bc..00000000000000 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorDimensionView_1.cs +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using static System.Numerics.Tensors.TensorOperation; - -namespace System.Numerics.Tensors -{ - /// - /// Represents a read-only view of a tensor dimension. - /// - /// - public readonly ref struct TensorDimensionView - { - private readonly TensorSpan _tensor; - private readonly int _dimension; - private readonly nint _count; - //private readonly - - internal TensorDimensionView(TensorSpan tensor, int dimension) - { - if (dimension < 0 || dimension >= tensor.Rank) - { - ThrowHelper.ThrowArgument_InvalidDimension(); - } - - _tensor = tensor; - _dimension = dimension; - // Span.Slice is based on length (so 1 based) and the dimension is an index (so 0 based) - // So we need to add 1 to the dimension to reconcile this. - _count = TensorPrimitives.Product(tensor.Lengths.Slice(0, dimension + 1)); - } - - /// - /// The length of the dimension - /// - public nint Count => _count; - - /// - /// Returns a tensor that represents the slice of the tensor at the specified index. - /// - /// - /// - public TensorSpan GetSlice(int index) - { - if (index < 0 || index >= _count) - { - ThrowHelper.ThrowIndexOutOfRangeException(); - } - - // This is not optimized, but it is a correct one. - scoped Span indexes = RentedBuffer.CreateUninitialized(_tensor.Rank, out RentedBuffer rentedBuffer); - - indexes.Fill(NRange.All); - for (int i = 0; i <= _dimension; i++) - { - indexes[i] = 0..1; - } - - // Starting at 0..1 so our loop is strictly less than the index since index is a valid index and we are already on the first one. - for (int i = 0; i < index; i++) - { - TensorShape.AdjustToNextIndex(indexes, _dimension, _tensor.Lengths); - } - TensorSpan slice = _tensor[indexes]; - rentedBuffer.Dispose(); - return slice; - } - - /// - /// Gets an enumerator that iterates through the dimension. - /// - /// - public Enumerator GetEnumerator() - { - return new Enumerator(_tensor, _dimension); - } - - /// - /// Enumerates the slices of the tensor dimension. - /// - public ref struct Enumerator -#if NET9_0_OR_GREATER - : IEnumerator> -#endif - { - private readonly TensorSpan _tensor; - private readonly int _dimension; - private readonly NRange[] _rentedBuffer; - private readonly Span _indexes; - - internal Enumerator(TensorSpan tensor, int dimension) - { - _tensor = tensor; - _dimension = dimension; - _rentedBuffer = ArrayPool.Shared.Rent(tensor.Rank); - - _indexes = _rentedBuffer.AsSpan(0, tensor.Rank); - _indexes.Clear(); - - _indexes.Fill(NRange.All); - Reset(); - } - - /// - /// Advances the enumerator to the next element of the collection. - /// - /// if the enumerator moved, otherwise. - public bool MoveNext() => TensorShape.AdjustToNextIndex(_indexes, _dimension, _tensor.Lengths); - - /// - /// Resets the enumerator to the beginning of the span. - /// - public void Reset() - { - for (int i = 0; i < _dimension; i++) - { - _indexes[i] = 0..1; - } - _indexes[_dimension] = 0..0; - } - - /// - /// Disposes of the enumerator. - /// - public void Dispose() - { - ArrayPool.Shared.Return(_rentedBuffer); - } - - /// - /// Current value of the - /// - public TensorSpan Current - { - get - { - TensorSpan slice = _tensor[_indexes]; - for (int i = 0; i < _dimension; i++) - { - slice = slice.SqueezeDimension(0); - } - if (_dimension == 0) - { - slice = slice.SqueezeDimension(0); - } - - return slice; - } - } - -#if NET9_0_OR_GREATER - // This will always just throw but needs to be here. - //TODO: What error do we throw for this Tanner? - object IEnumerator.Current => throw new NotImplementedException(); - - TensorSpan IEnumerator>.Current - { - get => Current; - } -#endif - } - } -} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs index 06d55f3fc0a48d..d77e749dcecb59 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs @@ -7,8 +7,6 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.VisualBasic; namespace System.Numerics.Tensors { @@ -1122,11 +1120,33 @@ public nint GetLinearOffset(ReadOnlySpan state) for (int i = 0; i < state.Length; i++) { - nint length = lengths[i]; - nint stride = strides[i]; + nint offset = TGetOffsetAndLength.GetOffset(state[i], lengths[i]); + linearOffset += (offset * strides[i]); + } + + return linearOffset; + } + + public nint GetLinearOffset(nint index, int dimension) + { + ReadOnlySpan lengths = Lengths; + ReadOnlySpan strides = Strides; + + if ((uint)dimension > (uint)lengths.Length) + { + ThrowHelper.ThrowArgumentOutOfRangeException(); + } + + nint linearOffset = 0; + + for (int i = 0; i < dimension; i++) + { + int rankIndex = dimension - (i + 1); + + nint length = lengths[rankIndex]; + (index, nint remainder) = nint.DivRem(index, length); - nint offset = TGetOffsetAndLength.GetOffset(state, i, length); - linearOffset += (offset * stride); + linearOffset += (remainder * strides[rankIndex]); } return linearOffset; @@ -1203,7 +1223,7 @@ public TensorShape Slice(ReadOnlySpan state, out nint nint previousLength = previousLengths[linearRankIndex]; nint previousStride = previousStrides[linearRankIndex]; - (nint offset, nint length) = TGetOffsetAndLength.GetOffsetAndLength(state, linearRankIndex, previousLength); + (nint offset, nint length) = TGetOffsetAndLength.GetOffsetAndLength(state[linearRankIndex], previousLength); nint stride = (length > 1) ? previousStride : 0; if (stride != 0) @@ -1315,8 +1335,8 @@ private static bool CalculateHasAnyDenseDimensions(ReadOnlySpan lengths, R public interface IGetOffsetAndLength { - static abstract nint GetOffset(ReadOnlySpan state, int rankIndex, nint previousLength); - static abstract (nint Offset, nint Length) GetOffsetAndLength(ReadOnlySpan state, int rankIndex, nint previousLength); + static abstract nint GetOffset(T state, nint length); + static abstract (nint Offset, nint Length) GetOffsetAndLength(T state, nint length); } [InlineArray(MaxInlineRank)] @@ -1327,54 +1347,54 @@ public struct InlineBuffer public readonly struct GetOffsetAndLengthForNInt : IGetOffsetAndLength { - public static nint GetOffset(ReadOnlySpan indexes, int rankIndex, nint previousLength) + public static nint GetOffset(nint index, nint length) { - nint offset = indexes[rankIndex]; + nint offset = index; - if ((offset < 0) || (offset >= previousLength)) + if ((offset < 0) || (offset >= length)) { ThrowHelper.ThrowIndexOutOfRangeException(); } return offset; } - public static (nint Offset, nint Length) GetOffsetAndLength(ReadOnlySpan indexes, int rankIndex, nint previousLength) + public static (nint Offset, nint Length) GetOffsetAndLength(nint index, nint length) { - nint offset = GetOffset(indexes, rankIndex, previousLength); - return (offset, previousLength - offset); + nint offset = GetOffset(index, length); + return (offset, length - offset); } } public readonly struct GetOffsetAndLengthForNIndex : IGetOffsetAndLength { - public static nint GetOffset(ReadOnlySpan indexes, int rankIndex, nint previousLength) + public static nint GetOffset(NIndex index, nint length) { - nint offset = indexes[rankIndex].GetOffset(previousLength); + nint offset = index.GetOffset(length); - if ((offset < 0) || (offset >= previousLength)) + if ((offset < 0) || (offset >= length)) { ThrowHelper.ThrowIndexOutOfRangeException(); } return offset; } - public static (nint Offset, nint Length) GetOffsetAndLength(ReadOnlySpan indexes, int rankIndex, nint previousLength) + public static (nint Offset, nint Length) GetOffsetAndLength(NIndex index, nint length) { - nint offset = GetOffset(indexes, rankIndex, previousLength); - return (offset, previousLength - offset); + nint offset = GetOffset(index, length); + return (offset, length - offset); } } public readonly struct GetOffsetAndLengthForNRange : IGetOffsetAndLength { - public static nint GetOffset(ReadOnlySpan ranges, int rankIndex, nint previousLength) + public static nint GetOffset(NRange range, nint length) { - return ranges[rankIndex].Start.GetOffset(previousLength); + return range.Start.GetOffset(length); } - public static (nint Offset, nint Length) GetOffsetAndLength(ReadOnlySpan ranges, int rankIndex, nint previousLength) + public static (nint Offset, nint Length) GetOffsetAndLength(NRange range, nint length) { - return ranges[rankIndex].GetOffsetAndLength(previousLength); + return range.GetOffsetAndLength(length); } } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs index da108366dbd809..d1d3ee856502ba 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs @@ -18,6 +18,7 @@ namespace System.Numerics.Tensors /// Represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed /// or native memory, or to memory allocated on the stack. It is type-safe and memory-safe. /// + /// The type of the elements within the tensor span. [DebuggerTypeProxy(typeof(TensorSpanDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] [Experimental(Experimentals.TensorTDiagId, UrlFormat = Experimentals.SharedUrlFormat)] @@ -282,6 +283,9 @@ public void FlattenTo(scoped Span destination) } } + /// + public TensorDimensionSpan GetDimensionSpan(int dimension) => new TensorDimensionSpan(this, dimension); + /// Gets an enumerator for the tensor span. public Enumerator GetEnumerator() => new Enumerator(this); @@ -404,12 +408,5 @@ void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } - - /// - /// Slices the tensor along the specified dimension. - /// - /// The dimension to slice along. - /// The tensor sliced to the given - public TensorDimensionView GetDimension(int dimension) => new TensorDimensionView(this, dimension); } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs index 9da126d14ed0e0..b209109eba8374 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor_1.cs @@ -226,6 +226,9 @@ public void FlattenTo(scoped Span destination) } } + /// + public TensorDimensionSpan GetDimensionSpan(int dimension) => AsTensorSpan().GetDimensionSpan(dimension); + /// Gets an enumerator for the readonly tensor. public Enumerator GetEnumerator() => new Enumerator(this); @@ -358,7 +361,8 @@ public string ToString(params ReadOnlySpan maximumLengths) ref readonly T IReadOnlyTensor, T>.this[params ReadOnlySpan indexes] => ref this[indexes]; - [EditorBrowsable(EditorBrowsableState.Never)] + ReadOnlyTensorDimensionSpan IReadOnlyTensor, T>.GetDimensionSpan(int dimension) => AsReadOnlyTensorSpan().GetDimensionSpan(dimension); + ref readonly T IReadOnlyTensor, T>.GetPinnableReference() => ref GetPinnableReference(); // @@ -451,7 +455,7 @@ public void Reset() // IDisposable // - readonly void IDisposable.Dispose() { } + void IDisposable.Dispose() { } // // IEnumerator @@ -465,12 +469,5 @@ readonly void IDisposable.Dispose() { } readonly T IEnumerator.Current => Current; } - - /// - /// Slices the tensor along the specified dimension. - /// - /// The dimension to slice along. - /// The tensor sliced to the given - public TensorDimensionView GetDimension(int dimension) => new TensorDimensionView(this, dimension); } } diff --git a/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj b/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj index 9f564fa2c07821..366c2a83688a2e 100644 --- a/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj +++ b/src/libraries/System.Numerics.Tensors/tests/System.Numerics.Tensors.Tests.csproj @@ -19,6 +19,7 @@ + @@ -27,7 +28,6 @@ - diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs similarity index 52% rename from src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs rename to src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs index 47ef029cff3aa5..3906407b54b074 100644 --- a/src/libraries/System.Numerics.Tensors/tests/TensorDimensionViewTests.cs +++ b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs @@ -2,117 +2,117 @@ namespace System.Numerics.Tensors.Tests { - public class TensorGetDimensionTests + public class TensorDimensionSpanTests { [Fact] - public void TensorDimensionView_GetDimension_ValidDimension_ReturnsCorrectView() + public void TensorDimensionSpan_GetDimension_ValidDimension_ReturnsCorrectView() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act - var dimensionView = tensor.GetDimension(1); + var dimensionView = tensor.GetDimensionSpan(1); // Assert - Assert.Equal(4, dimensionView.Count); - int[] sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(4, dimensionView.Length); + int[] sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[0].Lengths.ToArray()); Assert.Equal([1], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); Assert.Equal([2], sliceData); - dimensionView.GetSlice(2).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); Assert.Equal([3], sliceData); - dimensionView.GetSlice(3).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); Assert.Equal([4], sliceData); // Act - dimensionView = tensor.GetDimension(0); + dimensionView = tensor.GetDimensionSpan(0); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([2], dimensionView[0].Lengths.ToArray()); Assert.Equal([1, 2], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([2], dimensionView[1].Lengths.ToArray()); Assert.Equal([3, 4], sliceData); // check tensor with 1 dimension tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); // Act - dimensionView = tensor.GetDimension(1); + dimensionView = tensor.GetDimensionSpan(0); // Assert - Assert.Equal(4, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(4, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[0].Lengths.ToArray()); Assert.Equal([1], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); Assert.Equal([2], sliceData); - dimensionView.GetSlice(2).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); Assert.Equal([3], sliceData); - dimensionView.GetSlice(3).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); Assert.Equal([4], sliceData); // check tensor with 3 dimensions tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); // Act - dimensionView = tensor.GetDimension(0); + dimensionView = tensor.GetDimensionSpan(0); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView[0].Lengths.ToArray()); Assert.Equal([0, 1, 2, 3], sliceData); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(1).FlattenedLength]; - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[1].FlattenedLength]; + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView[0].Lengths.ToArray()); Assert.Equal([4, 5, 6, 7], sliceData); // Act - dimensionView = tensor.GetDimension(1); + dimensionView = tensor.GetDimensionSpan(1); // Assert - Assert.Equal(4, dimensionView.Count); - for (int i = 0; i < dimensionView.Count; i+=2) + Assert.Equal(4, dimensionView.Length); + for (int i = 0; i < dimensionView.Length; i++) { - TensorSpan slice = dimensionView.GetSlice(i); + TensorSpan slice = dimensionView[i]; sliceData = new int[slice.FlattenedLength]; slice.FlattenTo(sliceData); Assert.Equal([2], slice.Lengths.ToArray()); - Assert.Equal([i, i + 1], sliceData); + Assert.Equal([(i * 2), (i * 2) + 1], sliceData); } // Act - dimensionView = tensor.GetDimension(2); + dimensionView = tensor.GetDimensionSpan(2); // Assert - Assert.Equal(8, dimensionView.Count); + Assert.Equal(8, dimensionView.Length); for (int i = 0; i < 8; i++) { - TensorSpan slice = dimensionView.GetSlice(i); + TensorSpan slice = dimensionView[i]; sliceData = new int[slice.FlattenedLength]; slice.FlattenTo(sliceData); Assert.Equal([1], slice.Lengths.ToArray()); @@ -121,143 +121,143 @@ public void TensorDimensionView_GetDimension_ValidDimension_ReturnsCorrectView() } [Fact] - public void TensorDimensionView_GetDimension_InvalidDimension_ThrowsArgumentException() + public void TensorDimensionSpan_GetDimension_InvalidDimension_ThrowsArgumentOutOfRangeException() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act & Assert - Assert.Throws(() => tensor.GetDimension(-1)); - Assert.Throws(() => tensor.GetDimension(2)); + Assert.Throws(() => tensor.GetDimensionSpan(-1)); + Assert.Throws(() => tensor.GetDimensionSpan(2)); // Arrange tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); // Act & Assert - Assert.Throws(() => tensor.GetDimension(-1)); - Assert.Throws(() => tensor.GetDimension(1)); + Assert.Throws(() => tensor.GetDimensionSpan(-1)); + Assert.Throws(() => tensor.GetDimensionSpan(1)); } [Fact] - public void TensorDimensionView_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() + public void TensorDimensionSpan_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act & Assert - Assert.Throws(() => tensor.GetDimension(1).GetSlice(-1)); - Assert.Throws(() => tensor.GetDimension(1).GetSlice(4)); + Assert.Throws(() => { _ = tensor.GetDimensionSpan(1)[-1]; }); + Assert.Throws(() => { _ = tensor.GetDimensionSpan(1)[4]; }); } [Fact] - public void ReadOnlyTensorDimensionView_GetDimension_ValidDimension_ReturnsCorrectView() + public void ReadOnlyTensorDimensionSpan_GetDimension_ValidDimension_ReturnsCorrectView() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act - var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1); // Assert - Assert.Equal(4, dimensionView.Count); - int[] sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(4, dimensionView.Length); + int[] sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[0].Lengths.ToArray()); Assert.Equal([1], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); Assert.Equal([2], sliceData); - dimensionView.GetSlice(2).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); Assert.Equal([3], sliceData); - dimensionView.GetSlice(3).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); Assert.Equal([4], sliceData); // Act - dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(0); + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(0); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([2], dimensionView[0].Lengths.ToArray()); Assert.Equal([1, 2], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([2], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([2], dimensionView[1].Lengths.ToArray()); Assert.Equal([3, 4], sliceData); // check tensor with 1 dimension tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); // Act - dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(0); // Assert - Assert.Equal(4, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(4, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[0].Lengths.ToArray()); Assert.Equal([1], sliceData); - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(1).Lengths.ToArray()); + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); Assert.Equal([2], sliceData); - dimensionView.GetSlice(2).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(2).Lengths.ToArray()); + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); Assert.Equal([3], sliceData); - dimensionView.GetSlice(3).FlattenTo(sliceData); - Assert.Equal([1], dimensionView.GetSlice(3).Lengths.ToArray()); + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); Assert.Equal([4], sliceData); // check tensor with 3 dimensions tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); // Act - dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(0); + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(0); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(0).FlattenedLength]; - dimensionView.GetSlice(0).FlattenTo(sliceData); - Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[0].FlattenedLength]; + dimensionView[0].FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView[0].Lengths.ToArray()); Assert.Equal([0, 1, 2, 3], sliceData); // Assert - Assert.Equal(2, dimensionView.Count); - sliceData = new int[dimensionView.GetSlice(1).FlattenedLength]; - dimensionView.GetSlice(1).FlattenTo(sliceData); - Assert.Equal([2, 2], dimensionView.GetSlice(0).Lengths.ToArray()); + Assert.Equal(2, dimensionView.Length); + sliceData = new int[dimensionView[1].FlattenedLength]; + dimensionView[1].FlattenTo(sliceData); + Assert.Equal([2, 2], dimensionView[0].Lengths.ToArray()); Assert.Equal([4, 5, 6, 7], sliceData); // Act - dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1); // Assert - Assert.Equal(4, dimensionView.Count); - for (int i = 0; i < dimensionView.Count; i += 2) + Assert.Equal(4, dimensionView.Length); + for (int i = 0; i < dimensionView.Length; i++) { - ReadOnlyTensorSpan slice = dimensionView.GetSlice(i); + ReadOnlyTensorSpan slice = dimensionView[i]; sliceData = new int[slice.FlattenedLength]; slice.FlattenTo(sliceData); Assert.Equal([2], slice.Lengths.ToArray()); - Assert.Equal([i, i + 1], sliceData); + Assert.Equal([(i * 2), (i * 2) + 1], sliceData); } // Act - dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(2); + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(2); // Assert - Assert.Equal(8, dimensionView.Count); + Assert.Equal(8, dimensionView.Length); for (int i = 0; i < 8; i++) { - ReadOnlyTensorSpan slice = dimensionView.GetSlice(i); + ReadOnlyTensorSpan slice = dimensionView[i]; sliceData = new int[slice.FlattenedLength]; slice.FlattenTo(sliceData); Assert.Equal([1], slice.Lengths.ToArray()); @@ -266,40 +266,40 @@ public void ReadOnlyTensorDimensionView_GetDimension_ValidDimension_ReturnsCorre } [Fact] - public void ReadOnlyTensorDimensionView_GetDimension_InvalidDimension_ThrowsArgumentException() + public void ReadOnlyTensorDimensionSpan_GetDimension_InvalidDimension_ThrowsArgumentOutOfRangeException() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act & Assert - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(-1)); - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(2)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimensionSpan(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimensionSpan(2)); // Arrange tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 4 }); // Act & Assert - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(-1)); - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimensionSpan(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1)); } [Fact] - public void ReadOnlyTensorDimensionView_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() + public void ReadOnlyTensorDimensionSpan_GetDimension_GetSlice_InvalidIndex_ThrowsArgumentOutOfRangeException() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); // Act & Assert - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1).GetSlice(-1)); - Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimension(1).GetSlice(4)); + Assert.Throws(() => { _ = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1)[-1]; }); + Assert.Throws(() => { _ = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1)[4]; }); } [Fact] - public void TensorDimensionView_Enumerator_EnumeratesCorrectly() + public void TensorDimensionSpan_Enumerator_EnumeratesCorrectly() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); - var dimensionView = tensor.GetDimension(1); + var dimensionView = tensor.GetDimensionSpan(1); // Act & Assert int index = 0; @@ -331,11 +331,11 @@ public void TensorDimensionView_Enumerator_EnumeratesCorrectly() } [Fact] - public void ReadOnlyTensorDimensionView_Enumerator_EnumeratesCorrectly() + public void ReadOnlyTensorDimensionSpan_Enumerator_EnumeratesCorrectly() { // Arrange var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); - var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimension(1); + var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1); // Act & Assert int index = 0; @@ -367,11 +367,11 @@ public void ReadOnlyTensorDimensionView_Enumerator_EnumeratesCorrectly() } [Fact] - public void TensorDimensionView_Enumerator_MultidimensionalTensor() + public void TensorDimensionSpan_Enumerator_MultidimensionalTensor() { // Arrange - using a 3D tensor var tensor = Tensor.Create(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, new nint[] { 2, 2, 2 }); - var dimensionView = tensor.GetDimension(0); + var dimensionView = tensor.GetDimensionSpan(0); // Act & Assert int index = 0; From 91c53ab9bf66699315a73692be94cb49fd8b04a5 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 13 Jun 2025 08:21:01 -0700 Subject: [PATCH 4/5] Update the suppression file --- .../src/CompatibilitySuppressions.xml | 166 ++++++++++++++++++ .../src/System.Numerics.Tensors.csproj | 1 - 2 files changed, 166 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml index f488813caf6cda..53804a48af133e 100644 --- a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml @@ -127,6 +127,42 @@ lib/netstandard2.0/System.Numerics.Tensors.dll true + + CP0001 + T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0001 + T:System.Numerics.Tensors.TensorDimensionSpan`1 + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0001 + T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0001 + T:System.Numerics.Tensors.TensorDimensionSpan`1 + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0001 + T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0001 + T:System.Numerics.Tensors.TensorDimensionSpan`1 + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + CP0002 M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.#ctor(`0[],System.Index,System.ReadOnlySpan{System.IntPtr},System.ReadOnlySpan{System.IntPtr}) @@ -337,6 +373,103 @@ lib/net9.0/System.Numerics.Tensors.dll true + + CP0002 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0002 + M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + + + CP0006 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + lib/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + true + CP0006 M:System.Numerics.Tensors.IReadOnlyTensor`2.ToDenseTensor @@ -344,6 +477,20 @@ lib/net8.0/System.Numerics.Tensors.dll true + + CP0006 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + lib/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + true + + + CP0006 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + lib/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + true + CP0006 M:System.Numerics.Tensors.IReadOnlyTensor`2.ToDenseTensor @@ -351,6 +498,25 @@ lib/net9.0/System.Numerics.Tensors.dll true + + CP0006 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + lib/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + true + + + CP0006 + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0006 + M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + CP0017 M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index 2a14c9c09d25c8..3698e82ecdab9b 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -8,7 +8,6 @@ ReferenceAssemblyExclusions.txt $(NoWarn);SYSLIB5001 - false From b7f3e3de2084c880474ea8c60159f3b34d00a884 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Fri, 13 Jun 2025 14:46:14 -0700 Subject: [PATCH 5/5] Update reference assembly and suppressions --- eng/resolveContract.targets | 2 +- .../ref/System.Numerics.Tensors.csproj | 4 +- .../ref/System.Numerics.Tensors.net9.cs | 16 + .../ref/System.Numerics.Tensors.netcore.cs | 223 +++++----- .../src/CompatibilitySuppressions.xml | 390 ------------------ .../src/ReferenceAssemblyExclusions.txt | 51 ++- .../src/System.Numerics.Tensors.csproj | 1 + 7 files changed, 198 insertions(+), 489 deletions(-) diff --git a/eng/resolveContract.targets b/eng/resolveContract.targets index 907d690f5def7b..14bf17e8ed4f93 100644 --- a/eng/resolveContract.targets +++ b/eng/resolveContract.targets @@ -126,7 +126,7 @@ $(RepositoryEngineeringDir)DefaultGenApiDocIds.txt $(RepositoryEngineeringDir)LicenseHeader.txt - $([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs')) + $([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs')) $(LangVersion) $(CoreLibProject) diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj index b29997b584e52d..3f78270ba33f08 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.csproj @@ -3,6 +3,8 @@ $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) true + + $(NoWarn);SYSLIB5001 @@ -21,4 +23,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs index 268bd7c0731890..74f068d61918d3 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs @@ -11,4 +11,20 @@ public static partial class TensorPrimitives public static void ConvertToIntegerNative(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.IFloatingPoint where TTo : System.Numerics.IBinaryInteger { } public static void ConvertToInteger(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.IFloatingPoint where TTo : System.Numerics.IBinaryInteger { } } + public readonly ref partial struct ReadOnlyTensorDimensionSpan + { + public ref partial struct Enumerator : System.Collections.Generic.IEnumerator>, System.Collections.IEnumerator, System.IDisposable + { + readonly object? System.Collections.IEnumerator.Current { get { throw null; } } + void System.IDisposable.Dispose() { } + } + } + public readonly ref partial struct TensorDimensionSpan + { + public ref partial struct Enumerator : System.Collections.Generic.IEnumerator>, System.Collections.IEnumerator, System.IDisposable + { + readonly object? System.Collections.IEnumerator.Current { get { throw null; } } + void System.IDisposable.Dispose() { } + } + } } diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs index 038b107fd80e94..a91431b35fcf0e 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs @@ -6,7 +6,7 @@ namespace System.Buffers { - [System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public readonly partial struct NIndex : System.IEquatable { private readonly int _dummyPrimitive; @@ -30,7 +30,7 @@ namespace System.Buffers public System.Index ToIndexUnchecked() { throw null; } public override string ToString() { throw null; } } - [System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public readonly partial struct NRange : System.IEquatable { private readonly int _dummyPrimitive; @@ -63,8 +63,8 @@ public partial interface IReadOnlyTensor bool IsDense { get; } bool IsEmpty { get; } bool IsPinned { get; } - object this[params scoped System.ReadOnlySpan indexes] { get; } - object this[params scoped System.ReadOnlySpan indexes] { get; } + object? this[params scoped System.ReadOnlySpan indexes] { get; } + object? this[params scoped System.ReadOnlySpan indexes] { get; } [System.Diagnostics.CodeAnalysis.UnscopedRefAttribute] System.ReadOnlySpan Lengths { get; } int Rank { get; } @@ -75,39 +75,40 @@ public partial interface IReadOnlyTensor [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public partial interface IReadOnlyTensor : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Numerics.Tensors.IReadOnlyTensor where TSelf : System.Numerics.Tensors.IReadOnlyTensor { - static abstract TSelf? Empty { get; } - new T this[params scoped System.ReadOnlySpan indexes] { get; } + static abstract TSelf Empty { get; } + new ref readonly T this[params scoped System.ReadOnlySpan indexes] { get; } TSelf this[params scoped System.ReadOnlySpan ranges] { get; } - new T this[params scoped System.ReadOnlySpan indexes] { get; } + new ref readonly T this[params scoped System.ReadOnlySpan indexes] { get; } System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(); System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan startIndexes); System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan ranges); System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan startIndexes); - void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination); + void CopyTo(scoped in System.Numerics.Tensors.TensorSpan destination); void FlattenTo(scoped System.Span destination); + System.Numerics.Tensors.ReadOnlyTensorDimensionSpan GetDimensionSpan(int dimension); ref readonly T GetPinnableReference(); TSelf Slice(params scoped System.ReadOnlySpan startIndexes); TSelf Slice(params scoped System.ReadOnlySpan ranges); TSelf Slice(params scoped System.ReadOnlySpan startIndexes); TSelf ToDenseTensor(); - bool TryCopyTo(scoped System.Numerics.Tensors.TensorSpan destination); + bool TryCopyTo(scoped in System.Numerics.Tensors.TensorSpan destination); bool TryFlattenTo(scoped System.Span destination); } [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public partial interface ITensor : System.Numerics.Tensors.IReadOnlyTensor { bool IsReadOnly { get; } - new object this[params scoped System.ReadOnlySpan indexes] { get; set; } - new object this[params scoped System.ReadOnlySpan indexes] { get; set; } + new object? this[params scoped System.ReadOnlySpan indexes] { get; set; } + new object? this[params scoped System.ReadOnlySpan indexes] { get; set; } void Clear(); void Fill(object value); } [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public partial interface ITensor : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Numerics.Tensors.IReadOnlyTensor, System.Numerics.Tensors.IReadOnlyTensor, System.Numerics.Tensors.ITensor where TSelf : System.Numerics.Tensors.ITensor { - new T this[params scoped System.ReadOnlySpan indexes] { get; set; } + new ref T this[params scoped System.ReadOnlySpan indexes] { get; } new TSelf this[params scoped System.ReadOnlySpan ranges] { get; set; } - new T this[params scoped System.ReadOnlySpan indexes] { get; set; } + new ref T this[params scoped System.ReadOnlySpan indexes] { get; } System.Numerics.Tensors.TensorSpan AsTensorSpan(); System.Numerics.Tensors.TensorSpan AsTensorSpan(params scoped System.ReadOnlySpan startIndexes); System.Numerics.Tensors.TensorSpan AsTensorSpan(params scoped System.ReadOnlySpan ranges); @@ -117,9 +118,26 @@ public partial interface ITensor : System.Collections.Generic.IEnumera static abstract TSelf CreateUninitialized(scoped System.ReadOnlySpan lengths, bool pinned = false); static abstract TSelf CreateUninitialized(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned = false); void Fill(T value); + new System.Numerics.Tensors.TensorDimensionSpan GetDimensionSpan(int dimension); new ref T GetPinnableReference(); } - [System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + public readonly ref partial struct ReadOnlyTensorDimensionSpan + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public System.Numerics.Tensors.ReadOnlyTensorSpan this[nint index] { get { throw null; } } + public nint Length { get { throw null; } } + public System.Numerics.Tensors.ReadOnlyTensorDimensionSpan.Enumerator GetEnumerator() { throw null; } + public ref partial struct Enumerator + { + private object _dummy; + private int _dummyPrimitive; + public readonly System.Numerics.Tensors.ReadOnlyTensorSpan Current { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { } + } + } + [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public readonly ref partial struct ReadOnlyTensorSpan { private readonly object _dummy; @@ -136,9 +154,9 @@ public readonly ref partial struct ReadOnlyTensorSpan [System.CLSCompliantAttribute(false)] public unsafe ReadOnlyTensorSpan(T* data, nint dataLength, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public ReadOnlyTensorSpan(T[]? array) { throw null; } - public ReadOnlyTensorSpan(T[]? array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } - public ReadOnlyTensorSpan(T[]? array, scoped System.ReadOnlySpan lengths) { throw null; } public ReadOnlyTensorSpan(T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } + public ReadOnlyTensorSpan(T[]? array, scoped System.ReadOnlySpan lengths) { throw null; } + public ReadOnlyTensorSpan(T[]? array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.ReadOnlyTensorSpan Empty { get { throw null; } } public nint FlattenedLength { get { throw null; } } public bool HasAnyDenseDimensions { get { throw null; } } @@ -152,13 +170,15 @@ public readonly ref partial struct ReadOnlyTensorSpan public int Rank { get { throw null; } } [System.Diagnostics.CodeAnalysis.UnscopedRefAttribute] public System.ReadOnlySpan Strides { get { throw null; } } - public static System.Numerics.Tensors.ReadOnlyTensorSpan CastUp(System.Numerics.Tensors.ReadOnlyTensorSpan items) where TDerived : class?, T? { throw null; } - public void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { } + public static System.Numerics.Tensors.ReadOnlyTensorSpan CastUp(in System.Numerics.Tensors.ReadOnlyTensorSpan items) where TDerived : class?, T? { throw null; } + public void CopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("Equals() on ReadOnlyTensorSpan will always throw an exception. Use the equality operator instead.")] #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member public override bool Equals(object? obj) { throw null; } #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member + public void FlattenTo(scoped System.Span destination) { } + public System.Numerics.Tensors.ReadOnlyTensorDimensionSpan GetDimensionSpan(int dimension) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan.Enumerator GetEnumerator() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("GetHashCode() on ReadOnlyTensorSpan will always throw an exception.")] @@ -167,29 +187,28 @@ public void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { } #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public ref readonly T GetPinnableReference() { throw null; } - public static bool operator ==(System.Numerics.Tensors.ReadOnlyTensorSpan left, System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static bool operator ==(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } public static implicit operator System.Numerics.Tensors.ReadOnlyTensorSpan (T[]? array) { throw null; } - public static bool operator !=(System.Numerics.Tensors.ReadOnlyTensorSpan left, System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static bool operator !=(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan Slice(params scoped System.ReadOnlySpan startIndexes) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan Slice(params scoped System.ReadOnlySpan ranges) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan Slice(params scoped System.ReadOnlySpan startIndexes) { throw null; } public override string ToString() { throw null; } - public bool TryCopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { throw null; } + public bool TryCopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { throw null; } public bool TryFlattenTo(scoped System.Span destination) { throw null; } - public void FlattenTo(scoped System.Span destination) { throw null; } - public ref partial struct Enumerator : System.Collections.Generic.IEnumerator + public ref partial struct Enumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.IDisposable { private object _dummy; private int _dummyPrimitive; public readonly ref readonly T Current { get { throw null; } } - public bool MoveNext() { throw null; } - public void Reset() { throw null; } - void System.IDisposable.Dispose() { throw null; } - readonly object? System.Collections.IEnumerator.Current { get { throw null; } } readonly T System.Collections.Generic.IEnumerator.Current { get { throw null; } } + readonly object? System.Collections.IEnumerator.Current { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { } + void System.IDisposable.Dispose() { } } } - [System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public static partial class Tensor { public static System.Numerics.Tensors.Tensor Abs(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.INumberBase { throw null; } @@ -211,13 +230,13 @@ public static partial class Tensor public static System.Numerics.Tensors.Tensor Asin(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Asin(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(this T[]? array) { throw null; } + public static System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(this T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(this T[]? array, scoped System.ReadOnlySpan lengths) { throw null; } public static System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(this T[]? array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } - public static System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(this T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.TensorSpan AsTensorSpan(this T[]? array) { throw null; } + public static System.Numerics.Tensors.TensorSpan AsTensorSpan(this T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.TensorSpan AsTensorSpan(this T[]? array, scoped System.ReadOnlySpan lengths) { throw null; } public static System.Numerics.Tensors.TensorSpan AsTensorSpan(this T[]? array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } - public static System.Numerics.Tensors.TensorSpan AsTensorSpan(this T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.Tensor Atan2Pi(in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.ReadOnlyTensorSpan y) where T : System.Numerics.IFloatingPointIeee754 { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Atan2Pi(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IFloatingPointIeee754 { throw null; } public static System.Numerics.Tensors.Tensor Atan2Pi(in System.Numerics.Tensors.ReadOnlyTensorSpan x, T y) where T : System.Numerics.IFloatingPointIeee754 { throw null; } @@ -287,9 +306,9 @@ public static void BroadcastTo(this System.Numerics.Tensors.Tensor source, public static System.Numerics.Tensors.Tensor Create(scoped System.ReadOnlySpan lengths, bool pinned = false) { throw null; } public static System.Numerics.Tensors.Tensor Create(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned = false) { throw null; } public static System.Numerics.Tensors.Tensor Create(T[] array) { throw null; } + public static System.Numerics.Tensors.Tensor Create(T[] array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.Tensor Create(T[] array, scoped System.ReadOnlySpan lengths) { throw null; } public static System.Numerics.Tensors.Tensor Create(T[] array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } - public static System.Numerics.Tensors.Tensor Create(T[] array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.Tensor DegreesToRadians(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan DegreesToRadians(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static T Distance(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y) where T : System.Numerics.IRootFunctions { throw null; } @@ -455,7 +474,7 @@ public static void BroadcastTo(this System.Numerics.Tensors.Tensor source, public static T Norm(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IRootFunctions { throw null; } public static System.Numerics.Tensors.Tensor OnesComplement(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IBitwiseOperators { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan OnesComplement(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBitwiseOperators { throw null; } - public static System.Numerics.Tensors.Tensor PermuteDimensions(this System.Numerics.Tensors.Tensor tensor, scoped System.ReadOnlySpan dimensions) { throw null; } + public static System.Numerics.Tensors.Tensor PermuteDimensions(this System.Numerics.Tensors.Tensor tensor, System.ReadOnlySpan dimensions) { throw null; } public static System.Numerics.Tensors.Tensor PopCount(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IBinaryInteger { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan PopCount(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBinaryInteger { throw null; } public static System.Numerics.Tensors.Tensor Pow(in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.ReadOnlyTensorSpan y) where T : System.Numerics.IPowerFunctions { throw null; } @@ -471,7 +490,7 @@ public static void BroadcastTo(this System.Numerics.Tensors.Tensor source, public static ref readonly System.Numerics.Tensors.TensorSpan Reciprocal(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IFloatingPoint { throw null; } public static System.Numerics.Tensors.ReadOnlyTensorSpan Reshape(this scoped in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, scoped System.ReadOnlySpan lengths) { throw null; } public static System.Numerics.Tensors.TensorSpan Reshape(this scoped in System.Numerics.Tensors.TensorSpan tensor, scoped System.ReadOnlySpan lengths) { throw null; } - public static System.Numerics.Tensors.Tensor Reshape(this System.Numerics.Tensors.Tensor tensor, scoped System.ReadOnlySpan lengths) { throw null; } + public static System.Numerics.Tensors.Tensor Reshape(this System.Numerics.Tensors.Tensor tensor, System.ReadOnlySpan lengths) { throw null; } public static void ResizeTo(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, in System.Numerics.Tensors.TensorSpan destination) { } public static void ResizeTo(scoped in System.Numerics.Tensors.TensorSpan tensor, in System.Numerics.Tensors.TensorSpan destination) { } public static void ResizeTo(scoped in System.Numerics.Tensors.Tensor tensor, in System.Numerics.Tensors.TensorSpan destination) { } @@ -535,9 +554,9 @@ public static void ResizeTo(scoped in System.Numerics.Tensors.Tensor tenso public static ref readonly System.Numerics.Tensors.TensorSpan TanPi(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static System.Numerics.Tensors.Tensor Tan(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Tan(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.ITrigonometricFunctions { throw null; } - public static string ToString(this in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, scoped System.ReadOnlySpan maximumLengths) { throw null; } - public static string ToString(this in System.Numerics.Tensors.TensorSpan tensor, scoped System.ReadOnlySpan maximumLengths) { throw null; } - public static string ToString(this System.Numerics.Tensors.Tensor tensor, scoped System.ReadOnlySpan maximumLengths) { throw null; } + public static string ToString(this in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, System.ReadOnlySpan maximumLengths) { throw null; } + public static string ToString(this in System.Numerics.Tensors.TensorSpan tensor, System.ReadOnlySpan maximumLengths) { throw null; } + public static string ToString(this System.Numerics.Tensors.Tensor tensor, System.ReadOnlySpan maximumLengths) { throw null; } public static System.Numerics.Tensors.Tensor TrailingZeroCount(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IBinaryInteger { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan TrailingZeroCount(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBinaryInteger { throw null; } public static System.Numerics.Tensors.Tensor Transpose(System.Numerics.Tensors.Tensor tensor) { throw null; } @@ -554,6 +573,22 @@ public static void ResizeTo(scoped in System.Numerics.Tensors.Tensor tenso public static System.Numerics.Tensors.Tensor Xor(in System.Numerics.Tensors.ReadOnlyTensorSpan x, T y) where T : System.Numerics.IBitwiseOperators { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Xor(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, T y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBitwiseOperators { throw null; } } + public readonly ref partial struct TensorDimensionSpan + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public System.Numerics.Tensors.TensorSpan this[nint index] { get { throw null; } } + public nint Length { get { throw null; } } + public System.Numerics.Tensors.TensorDimensionSpan.Enumerator GetEnumerator() { throw null; } + public ref partial struct Enumerator + { + private object _dummy; + private int _dummyPrimitive; + public readonly System.Numerics.Tensors.TensorSpan Current { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { } + } + } public static partial class TensorPrimitives { public static void Abs(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.INumberBase { } @@ -595,15 +630,15 @@ public static void Clamp(T x, System.ReadOnlySpan min, T max, System.Span< public static void Clamp(T x, T min, System.ReadOnlySpan max, System.Span destination) where T : System.Numerics.INumber { } public static void ConvertChecked(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.INumberBase where TTo : System.Numerics.INumberBase { } public static void ConvertSaturating(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.INumberBase where TTo : System.Numerics.INumberBase { } - public static void ConvertTruncating(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.INumberBase where TTo : System.Numerics.INumberBase { } public static void ConvertToHalf(System.ReadOnlySpan source, System.Span destination) { } public static void ConvertToSingle(System.ReadOnlySpan source, System.Span destination) { } + public static void ConvertTruncating(System.ReadOnlySpan source, System.Span destination) where TFrom : System.Numerics.INumberBase where TTo : System.Numerics.INumberBase { } public static void CopySign(System.ReadOnlySpan x, System.ReadOnlySpan sign, System.Span destination) where T : System.Numerics.INumber { } public static void CopySign(System.ReadOnlySpan x, T sign, System.Span destination) where T : System.Numerics.INumber { } - public static void CosPi(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ITrigonometricFunctions { } - public static void Cos(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ITrigonometricFunctions { } public static void Cosh(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IHyperbolicFunctions { } public static T CosineSimilarity(System.ReadOnlySpan x, System.ReadOnlySpan y) where T : System.Numerics.IRootFunctions { throw null; } + public static void CosPi(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ITrigonometricFunctions { } + public static void Cos(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ITrigonometricFunctions { } public static void Decrement(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IDecrementOperators { } public static void DegreesToRadians(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ITrigonometricFunctions { } public static T Distance(System.ReadOnlySpan x, System.ReadOnlySpan y) where T : System.Numerics.IRootFunctions { throw null; } @@ -614,18 +649,18 @@ public static void DivRem(System.ReadOnlySpan x, System.ReadOnlySpan y, public static void DivRem(System.ReadOnlySpan x, T y, System.Span quotientDestination, System.Span remainderDestination) where T : System.Numerics.IBinaryInteger { } public static void DivRem(T x, System.ReadOnlySpan y, System.Span quotientDestination, System.Span remainderDestination) where T : System.Numerics.IBinaryInteger { } public static T Dot(System.ReadOnlySpan x, System.ReadOnlySpan y) where T : System.Numerics.IAdditionOperators, System.Numerics.IAdditiveIdentity, System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity { throw null; } - public static void Exp(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void Exp10M1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void Exp10(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void Exp2M1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void Exp2(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void ExpM1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } + public static void Exp(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IExponentialFunctions { } public static void Floor(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IFloatingPoint { } public static void FusedMultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } public static void FusedMultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, T addend, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } public static void FusedMultiplyAdd(System.ReadOnlySpan x, T y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } + public static long HammingBitDistance(System.ReadOnlySpan x, System.ReadOnlySpan y) where T : System.Numerics.IBinaryInteger { throw null; } public static int HammingDistance(System.ReadOnlySpan x, System.ReadOnlySpan y) { throw null; } - public static long HammingBitDistance(System.ReadOnlySpan x, System.ReadOnlySpan y) where T : IBinaryInteger { throw null; } public static void Hypot(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.IRootFunctions { } public static void Ieee754Remainder(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } public static void Ieee754Remainder(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } @@ -694,44 +729,44 @@ public static void LeadingZeroCount(System.ReadOnlySpan x, System.Span public static void Lerp(System.ReadOnlySpan x, System.ReadOnlySpan y, System.ReadOnlySpan amount, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } public static void Lerp(System.ReadOnlySpan x, System.ReadOnlySpan y, T amount, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } public static void Lerp(System.ReadOnlySpan x, T y, System.ReadOnlySpan amount, System.Span destination) where T : System.Numerics.IFloatingPointIeee754 { } - public static void Log2(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } + public static void Log10P1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } + public static void Log10(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } public static void Log2P1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } + public static void Log2(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } public static void LogP1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } public static void Log(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } - public static void Log(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } public static void Log(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } - public static void Log10P1(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } - public static void Log10(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } - public static T MaxMagnitude(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } - public static void MaxMagnitude(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } - public static void MaxMagnitude(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } + public static void Log(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.ILogarithmicFunctions { } public static T MaxMagnitudeNumber(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } public static void MaxMagnitudeNumber(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } public static void MaxMagnitudeNumber(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } - public static T Max(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } - public static void Max(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } - public static void Max(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } + public static T MaxMagnitude(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } + public static void MaxMagnitude(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } + public static void MaxMagnitude(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } public static T MaxNumber(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } public static void MaxNumber(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } public static void MaxNumber(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } - public static T MinMagnitude(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } - public static void MinMagnitude(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } - public static void MinMagnitude(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } + public static T Max(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } + public static void Max(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } + public static void Max(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } public static T MinMagnitudeNumber(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } public static void MinMagnitudeNumber(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } public static void MinMagnitudeNumber(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } - public static T Min(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } - public static void Min(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } - public static void Min(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } + public static T MinMagnitude(System.ReadOnlySpan x) where T : System.Numerics.INumberBase { throw null; } + public static void MinMagnitude(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumberBase { } + public static void MinMagnitude(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumberBase { } public static T MinNumber(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } public static void MinNumber(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } public static void MinNumber(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } - public static void MultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } - public static void MultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, T addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } - public static void MultiplyAdd(System.ReadOnlySpan x, T y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } + public static T Min(System.ReadOnlySpan x) where T : System.Numerics.INumber { throw null; } + public static void Min(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.INumber { } + public static void Min(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.INumber { } public static void MultiplyAddEstimate(System.ReadOnlySpan x, System.ReadOnlySpan y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.INumberBase { } public static void MultiplyAddEstimate(System.ReadOnlySpan x, System.ReadOnlySpan y, T addend, System.Span destination) where T : System.Numerics.INumberBase { } public static void MultiplyAddEstimate(System.ReadOnlySpan x, T y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.INumberBase { } + public static void MultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } + public static void MultiplyAdd(System.ReadOnlySpan x, System.ReadOnlySpan y, T addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } + public static void MultiplyAdd(System.ReadOnlySpan x, T y, System.ReadOnlySpan addend, System.Span destination) where T : System.Numerics.IAdditionOperators, System.Numerics.IMultiplyOperators { } public static void Multiply(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity { } public static void Multiply(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity { } public static void Negate(System.ReadOnlySpan x, System.Span destination) where T : System.Numerics.IUnaryNegationOperators { } @@ -788,7 +823,7 @@ public static void Truncate(System.ReadOnlySpan x, System.Span destinat public static void Xor(System.ReadOnlySpan x, System.ReadOnlySpan y, System.Span destination) where T : System.Numerics.IBitwiseOperators { } public static void Xor(System.ReadOnlySpan x, T y, System.Span destination) where T : System.Numerics.IBitwiseOperators { } } - [System.Diagnostics.CodeAnalysis.Experimental("SYSLIB5001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] + [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] public readonly ref partial struct TensorSpan { private readonly object _dummy; @@ -805,9 +840,9 @@ public readonly ref partial struct TensorSpan [System.CLSCompliantAttribute(false)] public unsafe TensorSpan(T* data, nint dataLength, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public TensorSpan(T[]? array) { throw null; } + public TensorSpan(T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public TensorSpan(T[]? array, scoped System.ReadOnlySpan lengths) { throw null; } public TensorSpan(T[]? array, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } - public TensorSpan(T[]? array, int start, scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides) { throw null; } public static System.Numerics.Tensors.TensorSpan Empty { get { throw null; } } public nint FlattenedLength { get { throw null; } } public bool HasAnyDenseDimensions { get { throw null; } } @@ -826,7 +861,7 @@ public readonly ref partial struct TensorSpan public System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan ranges) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan startIndexes) { throw null; } public void Clear() { } - public void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { } + public void CopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("Equals() on TensorSpan will always throw an exception. Use the equality operator instead.")] #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member @@ -834,6 +869,7 @@ public void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { } #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member public void Fill(T value) { } public void FlattenTo(scoped System.Span destination) { } + public System.Numerics.Tensors.TensorDimensionSpan GetDimensionSpan(int dimension) { throw null; } public System.Numerics.Tensors.TensorSpan.Enumerator GetEnumerator() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("GetHashCode() on TensorSpan will always throw an exception.")] @@ -842,26 +878,26 @@ public void FlattenTo(scoped System.Span destination) { } #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public ref T GetPinnableReference() { throw null; } - public static bool operator ==(System.Numerics.Tensors.TensorSpan left, System.Numerics.Tensors.TensorSpan right) { throw null; } - public static implicit operator System.Numerics.Tensors.ReadOnlyTensorSpan (System.Numerics.Tensors.TensorSpan tensor) { throw null; } + public static bool operator ==(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static implicit operator System.Numerics.Tensors.ReadOnlyTensorSpan (scoped in System.Numerics.Tensors.TensorSpan tensor) { throw null; } public static implicit operator System.Numerics.Tensors.TensorSpan (T[]? array) { throw null; } - public static bool operator !=(System.Numerics.Tensors.TensorSpan left, System.Numerics.Tensors.TensorSpan right) { throw null; } + public static bool operator !=(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } public System.Numerics.Tensors.TensorSpan Slice(params scoped System.ReadOnlySpan startIndexes) { throw null; } public System.Numerics.Tensors.TensorSpan Slice(params scoped System.ReadOnlySpan ranges) { throw null; } public System.Numerics.Tensors.TensorSpan Slice(params scoped System.ReadOnlySpan startIndexes) { throw null; } public override string ToString() { throw null; } - public bool TryCopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { throw null; } + public bool TryCopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { throw null; } public bool TryFlattenTo(scoped System.Span destination) { throw null; } - public ref partial struct Enumerator : System.Collections.Generic.IEnumerator + public ref partial struct Enumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.IDisposable { private object _dummy; private int _dummyPrimitive; public readonly ref T Current { get { throw null; } } - public bool MoveNext() { throw null; } - public void Reset() { throw null; } - void System.IDisposable.Dispose() { throw null; } - readonly object? System.Collections.IEnumerator.Current { get { throw null; } } readonly T System.Collections.Generic.IEnumerator.Current { get { throw null; } } + readonly object? System.Collections.IEnumerator.Current { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { } + void System.IDisposable.Dispose() { } } } [System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5001", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] @@ -880,18 +916,13 @@ internal Tensor() { } public System.ReadOnlySpan Lengths { get { throw null; } } public int Rank { get { throw null; } } public System.ReadOnlySpan Strides { get { throw null; } } - object System.Numerics.Tensors.IReadOnlyTensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } - object System.Numerics.Tensors.IReadOnlyTensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } - System.ReadOnlySpan System.Numerics.Tensors.IReadOnlyTensor.Lengths { get { throw null; } } - System.ReadOnlySpan System.Numerics.Tensors.IReadOnlyTensor.Strides { get { throw null; } } - T System.Numerics.Tensors.IReadOnlyTensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } - System.Numerics.Tensors.Tensor System.Numerics.Tensors.IReadOnlyTensor, T>.this[params scoped System.ReadOnlySpan ranges] { get { throw null; } } - T System.Numerics.Tensors.IReadOnlyTensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } + object? System.Numerics.Tensors.IReadOnlyTensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } + object? System.Numerics.Tensors.IReadOnlyTensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } + ref readonly T System.Numerics.Tensors.IReadOnlyTensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } + ref readonly T System.Numerics.Tensors.IReadOnlyTensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } } bool System.Numerics.Tensors.ITensor.IsReadOnly { get { throw null; } } - object System.Numerics.Tensors.ITensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } - object System.Numerics.Tensors.ITensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } - T System.Numerics.Tensors.ITensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } - T System.Numerics.Tensors.ITensor, T>.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } + object? System.Numerics.Tensors.ITensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } + object? System.Numerics.Tensors.ITensor.this[params scoped System.ReadOnlySpan indexes] { get { throw null; } set { } } public System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan() { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan startIndexes) { throw null; } public System.Numerics.Tensors.ReadOnlyTensorSpan AsReadOnlyTensorSpan(params scoped System.ReadOnlySpan ranges) { throw null; } @@ -901,11 +932,11 @@ internal Tensor() { } public System.Numerics.Tensors.TensorSpan AsTensorSpan(params scoped System.ReadOnlySpan ranges) { throw null; } public System.Numerics.Tensors.TensorSpan AsTensorSpan(params scoped System.ReadOnlySpan startIndexes) { throw null; } public void Clear() { } - public void CopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { } + public void CopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { } public void Fill(T value) { } public void FlattenTo(scoped System.Span destination) { } - public Enumerator GetEnumerator() { throw null; } - public override int GetHashCode() { throw null; } + public System.Numerics.Tensors.TensorDimensionSpan GetDimensionSpan(int dimension) { throw null; } + public System.Numerics.Tensors.Tensor.Enumerator GetEnumerator() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public ref T GetPinnableReference() { throw null; } public System.Buffers.MemoryHandle GetPinnedHandle() { throw null; } @@ -917,27 +948,29 @@ public void FlattenTo(scoped System.Span destination) { } public System.Numerics.Tensors.Tensor Slice(params scoped System.ReadOnlySpan startIndexes) { throw null; } System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + void System.Numerics.Tensors.IReadOnlyTensor, T>.CopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { } + System.Numerics.Tensors.ReadOnlyTensorDimensionSpan System.Numerics.Tensors.IReadOnlyTensor, T>.GetDimensionSpan(int dimension) { throw null; } ref readonly T System.Numerics.Tensors.IReadOnlyTensor, T>.GetPinnableReference() { throw null; } + bool System.Numerics.Tensors.IReadOnlyTensor, T>.TryCopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { throw null; } void System.Numerics.Tensors.ITensor.Fill(object value) { } static System.Numerics.Tensors.Tensor System.Numerics.Tensors.ITensor, T>.Create(scoped System.ReadOnlySpan lengths, bool pinned) { throw null; } static System.Numerics.Tensors.Tensor System.Numerics.Tensors.ITensor, T>.Create(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned) { throw null; } static System.Numerics.Tensors.Tensor System.Numerics.Tensors.ITensor, T>.CreateUninitialized(scoped System.ReadOnlySpan lengths, bool pinned) { throw null; } static System.Numerics.Tensors.Tensor System.Numerics.Tensors.ITensor, T>.CreateUninitialized(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned) { throw null; } - public Tensor ToDenseTensor() { throw null; } - public string ToString(scoped System.ReadOnlySpan maximumLengths) { throw null; } - public bool TryCopyTo(scoped System.Numerics.Tensors.TensorSpan destination) { throw null; } + public System.Numerics.Tensors.Tensor ToDenseTensor() { throw null; } + public string ToString(params scoped System.ReadOnlySpan maximumLengths) { throw null; } + public bool TryCopyTo(scoped in System.Numerics.Tensors.TensorSpan destination) { throw null; } public bool TryFlattenTo(scoped System.Span destination) { throw null; } - public partial struct Enumerator : System.Collections.Generic.IEnumerator + public partial struct Enumerator : System.Collections.Generic.IEnumerator, System.Collections.IEnumerator, System.IDisposable { private object _dummy; private int _dummyPrimitive; public readonly ref T Current { get { throw null; } } - public bool MoveNext() { throw null; } - public void Reset() { throw null; } - void System.IDisposable.Dispose() { throw null; } - readonly object? System.Collections.IEnumerator.Current { get { throw null; } } readonly T System.Collections.Generic.IEnumerator.Current { get { throw null; } } + readonly object? System.Collections.IEnumerator.Current { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { } + void System.IDisposable.Dispose() { } } } } diff --git a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml index 53804a48af133e..69a05a12b81567 100644 --- a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml @@ -1,168 +1,6 @@  - - CP0001 - T:System.Numerics.Tensors.ArrayTensorExtensions - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.CompressedSparseTensor`1 - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.DenseTensor`1 - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.SparseTensor`1 - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor`1 - lib/net462/System.Numerics.Tensors.dll - lib/net462/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.ArrayTensorExtensions - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.CompressedSparseTensor`1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.DenseTensor`1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.SparseTensor`1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor`1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.ArrayTensorExtensions - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.CompressedSparseTensor`1 - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.DenseTensor`1 - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.SparseTensor`1 - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.Tensor`1 - lib/netstandard2.0/System.Numerics.Tensors.dll - lib/netstandard2.0/System.Numerics.Tensors.dll - true - - - CP0001 - T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0001 - T:System.Numerics.Tensors.TensorDimensionSpan`1 - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0001 - T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0001 - T:System.Numerics.Tensors.TensorDimensionSpan`1 - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0001 - T:System.Numerics.Tensors.ReadOnlyTensorDimensionSpan`1 - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - - - CP0001 - T:System.Numerics.Tensors.TensorDimensionSpan`1 - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - CP0002 M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.#ctor(`0[],System.Index,System.ReadOnlySpan{System.IntPtr},System.ReadOnlySpan{System.IntPtr}) @@ -373,96 +211,6 @@ lib/net9.0/System.Numerics.Tensors.dll true - - CP0002 - M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) - ref/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.GetDimensionSpan(System.Int32) - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.Tensor`1.GetDimensionSpan(System.Int32) - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - - - CP0002 - M:System.Numerics.Tensors.TensorSpan`1.GetDimensionSpan(System.Int32) - ref/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - CP0006 M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) @@ -505,18 +253,6 @@ lib/net9.0/System.Numerics.Tensors.dll true - - CP0006 - M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - - - CP0006 - M:System.Numerics.Tensors.ITensor`2.GetDimensionSpan(System.Int32) - ref/net10.0/System.Numerics.Tensors.dll - lib/net10.0/System.Numerics.Tensors.dll - CP0017 M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 @@ -601,69 +337,6 @@ lib/net8.0/System.Numerics.Tensors.dll true - - CP0017 - M:System.Numerics.Tensors.Tensor.GreaterThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - CP0017 M:System.Numerics.Tensors.Tensor`1.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 @@ -839,69 +512,6 @@ lib/net9.0/System.Numerics.Tensors.dll true - - CP0017 - M:System.Numerics.Tensors.Tensor.GreaterThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.Tensor.LessThanOrEqualAny``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$1 - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - CP0017 M:System.Numerics.Tensors.Tensor`1.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 diff --git a/src/libraries/System.Numerics.Tensors/src/ReferenceAssemblyExclusions.txt b/src/libraries/System.Numerics.Tensors/src/ReferenceAssemblyExclusions.txt index a8f2d0192cfec9..5236ee6e89cb2e 100644 --- a/src/libraries/System.Numerics.Tensors/src/ReferenceAssemblyExclusions.txt +++ b/src/libraries/System.Numerics.Tensors/src/ReferenceAssemblyExclusions.txt @@ -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}) \ No newline at end of file +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}) diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index 3698e82ecdab9b..5fa3946074f6d1 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -6,6 +6,7 @@ true Provides support for operating over tensors. ReferenceAssemblyExclusions.txt + $([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).netcore.cs')) $(NoWarn);SYSLIB5001