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 f488813caf6cda..69a05a12b81567 100644 --- a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml @@ -1,132 +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 - CP0002 M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.#ctor(`0[],System.Index,System.ReadOnlySpan{System.IntPtr},System.ReadOnlySpan{System.IntPtr}) @@ -339,7 +213,7 @@ CP0006 - M:System.Numerics.Tensors.IReadOnlyTensor`2.ToDenseTensor + M:System.Numerics.Tensors.IReadOnlyTensor`2.GetDimensionSpan(System.Int32) lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true @@ -347,153 +221,118 @@ CP0006 M:System.Numerics.Tensors.IReadOnlyTensor`2.ToDenseTensor - lib/net9.0/System.Numerics.Tensors.dll - lib/net9.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NRange})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.IntPtr})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.Buffers.NIndex})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll - true - - - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.Buffers.NRange})$0 lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true - CP0017 - M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.IntPtr})$0 + 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 - CP0017 - M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll + 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 - CP0017 - M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.Buffers.NRange})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll + CP0006 + M:System.Numerics.Tensors.IReadOnlyTensor`2.ToDenseTensor + lib/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll true - CP0017 - M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.IntPtr})$0 - lib/net8.0/System.Numerics.Tensors.dll - lib/net8.0/System.Numerics.Tensors.dll + 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 CP0017 - M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.Slice(System.ReadOnlySpan{System.Buffers.NIndex})$0 + M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true CP0017 - M:System.Numerics.Tensors.Tensor.Create``1(System.Collections.Generic.IEnumerable{``0},System.ReadOnlySpan{System.IntPtr},System.Boolean)$0 + M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NRange})$0 lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true CP0017 - M:System.Numerics.Tensors.Tensor.Create``1(System.Collections.Generic.IEnumerable{``0},System.ReadOnlySpan{System.IntPtr},System.ReadOnlySpan{System.IntPtr},System.Boolean)$0 + M:System.Numerics.Tensors.IReadOnlyTensor`2.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.IntPtr})$0 lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true CP0017 - M:System.Numerics.Tensors.Tensor.GreaterThanOrEqualAll``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,``0)$0 + M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.Buffers.NIndex})$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 + M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.Buffers.NRange})$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 + M:System.Numerics.Tensors.IReadOnlyTensor`2.Slice(System.ReadOnlySpan{System.IntPtr})$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)$0 + M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$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 + M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.Buffers.NRange})$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)$0 + M:System.Numerics.Tensors.ITensor`2.AsTensorSpan(System.ReadOnlySpan{System.IntPtr})$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 + M:System.Numerics.Tensors.ReadOnlyTensorSpan`1.Slice(System.ReadOnlySpan{System.Buffers.NIndex})$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)$0 + M:System.Numerics.Tensors.Tensor.Create``1(System.Collections.Generic.IEnumerable{``0},System.ReadOnlySpan{System.IntPtr},System.Boolean)$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 + M:System.Numerics.Tensors.Tensor.Create``1(System.Collections.Generic.IEnumerable{``0},System.ReadOnlySpan{System.IntPtr},System.ReadOnlySpan{System.IntPtr},System.Boolean)$0 lib/net8.0/System.Numerics.Tensors.dll lib/net8.0/System.Numerics.Tensors.dll true @@ -673,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 7202c69d6ab762..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 @@ -36,9 +37,11 @@ + + @@ -167,7 +170,7 @@ - + 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/ReadOnlyTensorSpan_1.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ReadOnlyTensorSpan_1.cs index 56c2d1a1469ade..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); 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 41219fe5aa351a..7c8aec0244ebe7 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/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/TensorShape.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorShape.cs index 7d0e39571d350d..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 { @@ -614,6 +612,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) { @@ -1104,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; @@ -1185,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) @@ -1297,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)] @@ -1309,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.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorSpan_1.cs similarity index 98% 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 55663994c96e7a..d1d3ee856502ba 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 @@ -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); 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 b4841b44557ab8..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 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..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 @@ + diff --git a/src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs new file mode 100644 index 00000000000000..3906407b54b074 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/tests/TensorDimensionSpanTests.cs @@ -0,0 +1,391 @@ +using Xunit; + +namespace System.Numerics.Tensors.Tests +{ + public class TensorDimensionSpanTests + { + [Fact] + 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.GetDimensionSpan(1); + + // Assert + 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[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // Act + dimensionView = tensor.GetDimensionSpan(0); + + // Assert + 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[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.GetDimensionSpan(0); + + // Assert + 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[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); + Assert.Equal([3], sliceData); + + 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.GetDimensionSpan(0); + + // Assert + 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.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.GetDimensionSpan(1); + + // Assert + Assert.Equal(4, dimensionView.Length); + for (int i = 0; i < dimensionView.Length; i++) + { + TensorSpan slice = dimensionView[i]; + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([2], slice.Lengths.ToArray()); + Assert.Equal([(i * 2), (i * 2) + 1], sliceData); + } + + // Act + dimensionView = tensor.GetDimensionSpan(2); + + // Assert + Assert.Equal(8, dimensionView.Length); + for (int i = 0; i < 8; i++) + { + TensorSpan slice = dimensionView[i]; + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([1], slice.Lengths.ToArray()); + Assert.Equal([i], sliceData); + } + } + + [Fact] + 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.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.GetDimensionSpan(-1)); + Assert.Throws(() => tensor.GetDimensionSpan(1)); + } + + [Fact] + 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.GetDimensionSpan(1)[-1]; }); + Assert.Throws(() => { _ = tensor.GetDimensionSpan(1)[4]; }); + } + + [Fact] + 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().GetDimensionSpan(1); + + // Assert + 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[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); + Assert.Equal([3], sliceData); + + dimensionView[3].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[3].Lengths.ToArray()); + Assert.Equal([4], sliceData); + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(0); + + // Assert + 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[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().GetDimensionSpan(0); + + // Assert + 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[1].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[1].Lengths.ToArray()); + Assert.Equal([2], sliceData); + + dimensionView[2].FlattenTo(sliceData); + Assert.Equal([1], dimensionView[2].Lengths.ToArray()); + Assert.Equal([3], sliceData); + + 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().GetDimensionSpan(0); + + // Assert + 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.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().GetDimensionSpan(1); + + // Assert + Assert.Equal(4, dimensionView.Length); + for (int i = 0; i < dimensionView.Length; i++) + { + ReadOnlyTensorSpan slice = dimensionView[i]; + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([2], slice.Lengths.ToArray()); + Assert.Equal([(i * 2), (i * 2) + 1], sliceData); + } + + // Act + dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(2); + + // Assert + Assert.Equal(8, dimensionView.Length); + for (int i = 0; i < 8; i++) + { + ReadOnlyTensorSpan slice = dimensionView[i]; + sliceData = new int[slice.FlattenedLength]; + slice.FlattenTo(sliceData); + Assert.Equal([1], slice.Lengths.ToArray()); + Assert.Equal([i], sliceData); + } + } + + [Fact] + 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().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().GetDimensionSpan(-1)); + Assert.Throws(() => tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1)); + } + + [Fact] + 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().GetDimensionSpan(1)[-1]; }); + Assert.Throws(() => { _ = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(1)[4]; }); + } + + [Fact] + public void TensorDimensionSpan_Enumerator_EnumeratesCorrectly() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + var dimensionView = tensor.GetDimensionSpan(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 ReadOnlyTensorDimensionSpan_Enumerator_EnumeratesCorrectly() + { + // Arrange + var tensor = Tensor.Create(new int[] { 1, 2, 3, 4 }, new nint[] { 2, 2 }); + var dimensionView = tensor.AsReadOnlyTensorSpan().GetDimensionSpan(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 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.GetDimensionSpan(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 + } + } +}