Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd757c03

Browse files
Add some additional Tensor APIs (#117739)
* Remove unnecessary usings from Tensor code* Add the TensorMarshal class* Fix the naming of various tensor create APIs to remove ambiguities* Add support for directly getting a contiguous span from a tensor* Update the compatibility supressions file for S.N.Tensors* Add tests for the new APIs* Fix some tests* Ensure the test calls TryGetSpan
1 parent3fb6fbb commitd757c03

File tree

59 files changed

+1558
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1558
-537
lines changed

‎src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.net9.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ void System.IDisposable.Dispose() { }
4949
System.Numerics.Tensors.ReadOnlyTensorSpan<T>System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.AsReadOnlyTensorSpan(paramsscoped System.ReadOnlySpan<System.Buffers.NRange>ranges){thrownull;}
5050
System.Numerics.Tensors.ReadOnlyTensorDimensionSpan<T>System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.GetDimensionSpan(intdimension){thrownull;}
5151
ref readonlyT System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.GetPinnableReference(){thrownull;}
52+
System.ReadOnlySpan<T>System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.GetSpan(scopedSystem.ReadOnlySpan<nint>startIndexes,intlength){thrownull;}
53+
System.ReadOnlySpan<T>System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.GetSpan(scopedSystem.ReadOnlySpan<System.Buffers.NIndex>startIndexes,intlength){thrownull;}
5254
System.Numerics.Tensors.TensorSpan<T>System.Numerics.Tensors.IReadOnlyTensor<System.Numerics.Tensors.TensorSpan<T>,T>.ToDenseTensor(){thrownull;}
5355

5456
boolSystem.Numerics.Tensors.ITensor.IsReadOnly{get{thrownull;}}
5557
object?System.Numerics.Tensors.ITensor.this[paramsscoped System.ReadOnlySpan<System.Buffers.NIndex>indexes]{get{thrownull;} set{}}
5658
object?System.Numerics.Tensors.ITensor.this[paramsscoped System.ReadOnlySpan<nint> indexes]{get{thrownull;} set{}}
5759
voidSystem.Numerics.Tensors.ITensor.Fill(objectvalue){}
58-
static System.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.Create(scopedSystem.ReadOnlySpan<nint>lengths,boolpinned){thrownull;}
59-
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.Create(scopedSystem.ReadOnlySpan<nint>lengths, scopedSystem.ReadOnlySpan<nint>strides,boolpinned){thrownull;}
60-
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateUninitialized(scopedSystem.ReadOnlySpan<nint>lengths,boolpinned){thrownull;}
61-
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateUninitialized(scopedSystem.ReadOnlySpan<nint>lengths, scopedSystem.ReadOnlySpan<nint>strides,boolpinned){thrownull;}
60+
static System.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateFromShape(scopedSystem.ReadOnlySpan<nint>lengths,boolpinned){thrownull;}
61+
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateFromShape(scopedSystem.ReadOnlySpan<nint>lengths, scopedSystem.ReadOnlySpan<nint>strides,boolpinned){thrownull;}
62+
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateFromShapeUninitialized(scopedSystem.ReadOnlySpan<nint>lengths,boolpinned){thrownull;}
63+
staticSystem.Numerics.Tensors.TensorSpan<T>ITensor<TensorSpan<T>,T>.CreateFromShapeUninitialized(scopedSystem.ReadOnlySpan<nint>lengths, scopedSystem.ReadOnlySpan<nint>strides,boolpinned){thrownull;}
6264
System.Numerics.Tensors.TensorSpan<T>System.Numerics.Tensors.ITensor<System.Numerics.Tensors.TensorSpan<T>,T>.AsTensorSpan(){thrownull;}
6365
System.Numerics.Tensors.TensorSpan<T>System.Numerics.Tensors.ITensor<System.Numerics.Tensors.TensorSpan<T>,T>.AsTensorSpan(paramsscoped System.ReadOnlySpan<nint> startIndexes){thrownull;}
6466
System.Numerics.Tensors.TensorSpan<T>System.Numerics.Tensors.ITensor<System.Numerics.Tensors.TensorSpan<T>,T>.AsTensorSpan(paramsscoped System.ReadOnlySpan<System.Buffers.NIndex>startIndexes){thrownull;}

‎src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs

Lines changed: 48 additions & 19 deletions
Large diffs are not rendered by default.

‎src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml

Lines changed: 365 additions & 1 deletion
Large diffs are not rendered by default.

‎src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<CompileInclude="System\Numerics\Tensors\netcore\TensorShape.cs" />
172172
<CompileInclude="System\Numerics\Tensors\netcore\TensorSpan_1.cs" />
173173
<CompileInclude="System\Numerics\Tensors\netcore\TensorSpanDebugView.cs" />
174+
<CompileInclude="System\Runtime\InteropServices\TensorMarshal.cs" />
174175
</ItemGroup>
175176

176177
<ItemGroupCondition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Helpers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
usingSystem.Diagnostics.CodeAnalysis;
54
usingSystem.Diagnostics;
65
usingSystem.Runtime.CompilerServices;
76
usingSystem.Runtime.InteropServices;

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
usingSystem.Runtime.CompilerServices;
5-
usingSystem.Runtime.InteropServices;
6-
74
namespaceSystem.Numerics.Tensors
85
{
96
/// <summary>Performs primitive tensor operations over spans of memory.</summary>

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Common/TensorPrimitives.IBooleanUnaryOperator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
usingSystem.Runtime.CompilerServices;
66
usingSystem.Runtime.InteropServices;
77
usingSystem.Runtime.Intrinsics;
8-
usingstaticSystem.Numerics.Tensors.TensorPrimitives;
98

109
namespaceSystem.Numerics.Tensors
1110
{

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Common/TensorPrimitives.IUnaryInputBinaryOutput.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
usingSystem.Diagnostics;
54
usingSystem.Runtime.CompilerServices;
65
usingSystem.Runtime.InteropServices;
76
usingSystem.Runtime.Intrinsics;

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/IReadOnlyTensor_1.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ public interface IReadOnlyTensor<TSelf, T> : IReadOnlyTensor
7272
/// <remarks>This method is intended to support .NET compilers and is not intended to be called by user code.</remarks>
7373
ref readonlyTGetPinnableReference();
7474

75+
/// <summary>Return a span that starts at the specified index and contains the specified number of items.</summary>
76+
/// <param name="startIndexes">The index at which the span should start.</param>
77+
/// <param name="length">The length for the span to return.</param>
78+
/// <returns>A span that consists of <paramref name="length" /> elements from the current tensor starting at <paramref name="startIndexes" />.</returns>
79+
/// <exception cref="ArgumentOutOfRangeException">
80+
/// <para><paramref name="startIndexes" /> does not contain <see cref="IReadOnlyTensor.Rank" /> elements.</para>
81+
/// -or-
82+
/// <para><paramref name="length" /> is negative, greater than <see cref="IReadOnlyTensor.FlattenedLength" />, or would cause the span to contain elements that should be skipped due to <see cref="IReadOnlyTensor.Strides" />.</para>
83+
/// </exception>
84+
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndexes" /> is not a valid index into the tensor.</exception>
85+
ReadOnlySpan<T>GetSpan(scopedReadOnlySpan<nint>startIndexes,intlength);
86+
87+
/// <inheritdoc cref="GetSpan(ReadOnlySpan{nint}, int)" />
88+
ReadOnlySpan<T>GetSpan(scopedReadOnlySpan<NIndex>startIndexes,intlength);
89+
7590
/// <summary>Forms a slice out of the current tensor that begins at a specified index.</summary>
7691
/// <param name="startIndexes">The indexes at which to begin the slice.</param>
7792
/// <returns>A tensor that consists of all elements of the current tensor from <paramref name="startIndexes" /> to the end of the tensor.</returns>
@@ -112,5 +127,17 @@ public interface IReadOnlyTensor<TSelf, T> : IReadOnlyTensor
112127
/// <para>If the <paramref name="destination" /> length is shorter than the source, no items are copied and the method returns <c>false</c>.</para>
113128
/// </remarks>
114129
boolTryFlattenTo(scopedSpan<T>destination);
130+
131+
/// <summary>Tries to return a span that starts at the specified index and contains the specified number of items.</summary>
132+
/// <param name="startIndexes">The index at which the span should start.</param>
133+
/// <param name="length">The desired length of the span to retrieve.</param>
134+
/// <param name="span">On successful return, a span that consists of <paramref name="length" /> elements from the current tensor starting at <paramref name="startIndexes" />.</param>
135+
/// <returns><c>true</c> if a span was successfully retrieved; otherwise, <c>false</c> which indicates <paramref name="length" /> was invalid.</returns>
136+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndexes" /> does not contain <see cref="IReadOnlyTensor.Rank" /> elements.</exception>
137+
/// <exception cref="IndexOutOfRangeException"><paramref name="startIndexes" /> is not a valid index into the tensor.</exception>
138+
boolTryGetSpan(scopedReadOnlySpan<nint>startIndexes,intlength,outReadOnlySpan<T>span);
139+
140+
/// <inheritdoc cref="TryGetSpan(ReadOnlySpan{nint}, int, out ReadOnlySpan{T})" />
141+
boolTryGetSpan(scopedReadOnlySpan<NIndex>startIndexes,intlength,outReadOnlySpan<T>span);
115142
}
116143
}

‎src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/ITensor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
usingSystem.Buffers;
5-
usingSystem.Diagnostics.CodeAnalysis;
65

76
namespaceSystem.Numerics.Tensors
87
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp