Skip to content

Commit 7dce8f6

Browse files
Mark some Tensor extension methods as scoped (#115575)
* Removing extension methods * Use `this scoped in` so APIs can remain extension methods --------- Co-authored-by: Tanner Gooding <tagoo@outlook.com>
1 parent 1c06dfa commit 7dce8f6

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ public static void BroadcastTo<T>(this System.Numerics.Tensors.Tensor<T> source,
469469
public static ref readonly System.Numerics.Tensors.TensorSpan<T> RadiansToDegrees<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, in System.Numerics.Tensors.TensorSpan<T> destination) where T : System.Numerics.ITrigonometricFunctions<T> { throw null; }
470470
public static System.Numerics.Tensors.Tensor<T> Reciprocal<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x) where T : System.Numerics.IFloatingPoint<T> { throw null; }
471471
public static ref readonly System.Numerics.Tensors.TensorSpan<T> Reciprocal<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, in System.Numerics.Tensors.TensorSpan<T> destination) where T : System.Numerics.IFloatingPoint<T> { throw null; }
472-
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Reshape<T>(this in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, scoped System.ReadOnlySpan<nint> lengths) { throw null; }
473-
public static System.Numerics.Tensors.TensorSpan<T> Reshape<T>(this in System.Numerics.Tensors.TensorSpan<T> tensor, scoped System.ReadOnlySpan<nint> lengths) { throw null; }
472+
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Reshape<T>(this scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, scoped System.ReadOnlySpan<nint> lengths) { throw null; }
473+
public static System.Numerics.Tensors.TensorSpan<T> Reshape<T>(this scoped in System.Numerics.Tensors.TensorSpan<T> tensor, scoped System.ReadOnlySpan<nint> lengths) { throw null; }
474474
public static System.Numerics.Tensors.Tensor<T> Reshape<T>(this System.Numerics.Tensors.Tensor<T> tensor, scoped System.ReadOnlySpan<nint> lengths) { throw null; }
475475
public static void ResizeTo<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, in System.Numerics.Tensors.TensorSpan<T> destination) { }
476476
public static void ResizeTo<T>(scoped in System.Numerics.Tensors.TensorSpan<T> tensor, in System.Numerics.Tensors.TensorSpan<T> destination) { }
@@ -511,11 +511,11 @@ public static void ResizeTo<T>(scoped in System.Numerics.Tensors.Tensor<T> tenso
511511
public static System.Numerics.Tensors.Tensor<T>[] Split<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, int splitCount, nint dimension) { throw null; }
512512
public static System.Numerics.Tensors.Tensor<T> Sqrt<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x) where T : System.Numerics.IRootFunctions<T> { throw null; }
513513
public static ref readonly System.Numerics.Tensors.TensorSpan<T> Sqrt<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, in System.Numerics.Tensors.TensorSpan<T> destination) where T : System.Numerics.IRootFunctions<T> { throw null; }
514-
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> SqueezeDimension<T>(this in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, int dimension) { throw null; }
515-
public static System.Numerics.Tensors.TensorSpan<T> SqueezeDimension<T>(this in System.Numerics.Tensors.TensorSpan<T> tensor, int dimension) { throw null; }
514+
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> SqueezeDimension<T>(this scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, int dimension) { throw null; }
515+
public static System.Numerics.Tensors.TensorSpan<T> SqueezeDimension<T>(this scoped in System.Numerics.Tensors.TensorSpan<T> tensor, int dimension) { throw null; }
516516
public static System.Numerics.Tensors.Tensor<T> SqueezeDimension<T>(this System.Numerics.Tensors.Tensor<T> tensor, int dimension) { throw null; }
517-
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Squeeze<T>(this in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor) { throw null; }
518-
public static System.Numerics.Tensors.TensorSpan<T> Squeeze<T>(this in System.Numerics.Tensors.TensorSpan<T> tensor) { throw null; }
517+
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Squeeze<T>(this scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor) { throw null; }
518+
public static System.Numerics.Tensors.TensorSpan<T> Squeeze<T>(this scoped in System.Numerics.Tensors.TensorSpan<T> tensor) { throw null; }
519519
public static System.Numerics.Tensors.Tensor<T> Squeeze<T>(this System.Numerics.Tensors.Tensor<T> tensor) { throw null; }
520520
public static System.Numerics.Tensors.Tensor<T> StackAlongDimension<T>(int dimension, params scoped System.ReadOnlySpan<System.Numerics.Tensors.Tensor<T>> tensors) { throw null; }
521521
public static ref readonly System.Numerics.Tensors.TensorSpan<T> StackAlongDimension<T>(scoped System.ReadOnlySpan<System.Numerics.Tensors.Tensor<T>> tensors, in System.Numerics.Tensors.TensorSpan<T> destination, int dimension) { throw null; }
@@ -546,8 +546,8 @@ public static void ResizeTo<T>(scoped in System.Numerics.Tensors.Tensor<T> tenso
546546
public static bool TryBroadcastTo<T>(this in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, in System.Numerics.Tensors.TensorSpan<T> destination) { throw null; }
547547
public static bool TryBroadcastTo<T>(this in System.Numerics.Tensors.TensorSpan<T> tensor, in System.Numerics.Tensors.TensorSpan<T> destination) { throw null; }
548548
public static bool TryBroadcastTo<T>(this System.Numerics.Tensors.Tensor<T> tensor, in System.Numerics.Tensors.TensorSpan<T> destination) { throw null; }
549-
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Unsqueeze<T>(this in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, int dimension) { throw null; }
550-
public static System.Numerics.Tensors.TensorSpan<T> Unsqueeze<T>(this in System.Numerics.Tensors.TensorSpan<T> tensor, int dimension) { throw null; }
549+
public static System.Numerics.Tensors.ReadOnlyTensorSpan<T> Unsqueeze<T>(this scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> tensor, int dimension) { throw null; }
550+
public static System.Numerics.Tensors.TensorSpan<T> Unsqueeze<T>(this scoped in System.Numerics.Tensors.TensorSpan<T> tensor, int dimension) { throw null; }
551551
public static System.Numerics.Tensors.Tensor<T> Unsqueeze<T>(this System.Numerics.Tensors.Tensor<T> tensor, int dimension) { throw null; }
552552
public static System.Numerics.Tensors.Tensor<T> Xor<T>(in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, in System.Numerics.Tensors.ReadOnlyTensorSpan<T> y) where T : System.Numerics.IBitwiseOperators<T, T, T> { throw null; }
553553
public static ref readonly System.Numerics.Tensors.TensorSpan<T> Xor<T>(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan<T> y, in System.Numerics.Tensors.TensorSpan<T> destination) where T : System.Numerics.IBitwiseOperators<T, T, T> { throw null; }

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ public static Tensor<T> Reshape<T>(this Tensor<T> tensor, ReadOnlySpan<nint> len
15081508
/// </summary>
15091509
/// <param name="tensor"><see cref="TensorSpan{T}"/> you want to reshape.</param>
15101510
/// <param name="lengths"><see cref="ReadOnlySpan{T}"/> with the new dimensions.</param>
1511-
public static TensorSpan<T> Reshape<T>(in this TensorSpan<T> tensor, scoped ReadOnlySpan<nint> lengths)
1511+
public static TensorSpan<T> Reshape<T>(this scoped in TensorSpan<T> tensor, scoped ReadOnlySpan<nint> lengths)
15121512
{
15131513
if (tensor.Lengths.SequenceEqual(lengths))
15141514
return tensor;
@@ -1584,7 +1584,7 @@ public static TensorSpan<T> Reshape<T>(in this TensorSpan<T> tensor, scoped Read
15841584
/// </summary>
15851585
/// <param name="tensor"><see cref="TensorSpan{T}"/> you want to reshape.</param>
15861586
/// <param name="lengths"><see cref="ReadOnlySpan{T}"/> with the new dimensions.</param>
1587-
public static ReadOnlyTensorSpan<T> Reshape<T>(in this ReadOnlyTensorSpan<T> tensor, scoped ReadOnlySpan<nint> lengths)
1587+
public static ReadOnlyTensorSpan<T> Reshape<T>(this scoped in ReadOnlyTensorSpan<T> tensor, scoped ReadOnlySpan<nint> lengths)
15881588
{
15891589
if (tensor.Lengths.SequenceEqual(lengths))
15901590
return tensor;
@@ -1983,7 +1983,7 @@ public static Tensor<T> SqueezeDimension<T>(this Tensor<T> tensor, int dimension
19831983
/// Removes all dimensions of length one from the <paramref name="tensor"/>.
19841984
/// </summary>
19851985
/// <param name="tensor">The <see cref="TensorSpan{T}"/> to remove all dimensions of length 1.</param>
1986-
public static TensorSpan<T> Squeeze<T>(in this TensorSpan<T> tensor)
1986+
public static TensorSpan<T> Squeeze<T>(this scoped in TensorSpan<T> tensor)
19871987
{
19881988
return SqueezeDimension(tensor, -1);
19891989
}
@@ -1994,7 +1994,7 @@ public static TensorSpan<T> Squeeze<T>(in this TensorSpan<T> tensor)
19941994
/// </summary>
19951995
/// <param name="tensor">The <see cref="TensorSpan{T}"/> to remove dimension of length 1.</param>
19961996
/// <param name="dimension">The dimension to remove.</param>
1997-
public static TensorSpan<T> SqueezeDimension<T>(in this TensorSpan<T> tensor, int dimension)
1997+
public static TensorSpan<T> SqueezeDimension<T>(this scoped in TensorSpan<T> tensor, int dimension)
19981998
{
19991999
if (dimension >= tensor.Rank || dimension < -1)
20002000
ThrowHelper.ThrowArgument_AxisLargerThanRank();
@@ -2065,7 +2065,7 @@ public static TensorSpan<T> SqueezeDimension<T>(in this TensorSpan<T> tensor, in
20652065
/// Removes all dimensions of length one from the <paramref name="tensor"/>.
20662066
/// </summary>
20672067
/// <param name="tensor">The <see cref="ReadOnlyTensorSpan{T}"/> to remove all dimensions of length 1.</param>
2068-
public static ReadOnlyTensorSpan<T> Squeeze<T>(in this ReadOnlyTensorSpan<T> tensor)
2068+
public static ReadOnlyTensorSpan<T> Squeeze<T>(this scoped in ReadOnlyTensorSpan<T> tensor)
20692069
{
20702070
return SqueezeDimension(tensor, -1);
20712071
}
@@ -2076,7 +2076,7 @@ public static ReadOnlyTensorSpan<T> Squeeze<T>(in this ReadOnlyTensorSpan<T> ten
20762076
/// </summary>
20772077
/// <param name="tensor">The <see cref="ReadOnlyTensorSpan{T}"/> to remove dimension of length 1.</param>
20782078
/// <param name="dimension">The dimension to remove.</param>
2079-
public static ReadOnlyTensorSpan<T> SqueezeDimension<T>(in this ReadOnlyTensorSpan<T> tensor, int dimension)
2079+
public static ReadOnlyTensorSpan<T> SqueezeDimension<T>(this scoped in ReadOnlyTensorSpan<T> tensor, int dimension)
20802080
{
20812081
if (dimension >= tensor.Rank || dimension < -1)
20822082
ThrowHelper.ThrowArgument_AxisLargerThanRank();
@@ -2467,7 +2467,7 @@ public static Tensor<T> Unsqueeze<T>(this Tensor<T> tensor, int dimension)
24672467
/// </summary>
24682468
/// <param name="tensor">The <see cref="TensorSpan{T}"/> to add a dimension of length 1.</param>
24692469
/// <param name="dimension">The index of the dimension to add.</param>
2470-
public static TensorSpan<T> Unsqueeze<T>(in this TensorSpan<T> tensor, int dimension)
2470+
public static TensorSpan<T> Unsqueeze<T>(this scoped in TensorSpan<T> tensor, int dimension)
24712471
{
24722472
if (dimension > tensor.Lengths.Length)
24732473
ThrowHelper.ThrowArgument_AxisLargerThanRank();
@@ -2504,7 +2504,7 @@ public static TensorSpan<T> Unsqueeze<T>(in this TensorSpan<T> tensor, int dimen
25042504
/// </summary>
25052505
/// <param name="tensor">The <see cref="ReadOnlyTensorSpan{T}"/> to add a dimension of length 1.</param>
25062506
/// <param name="dimension">The index of the dimension to add.</param>
2507-
public static ReadOnlyTensorSpan<T> Unsqueeze<T>(in this ReadOnlyTensorSpan<T> tensor, int dimension)
2507+
public static ReadOnlyTensorSpan<T> Unsqueeze<T>(this scoped in ReadOnlyTensorSpan<T> tensor, int dimension)
25082508
{
25092509
if (dimension > tensor.Lengths.Length)
25102510
ThrowHelper.ThrowArgument_AxisLargerThanRank();

0 commit comments

Comments
 (0)