Skip to content

Commit a42e97f

Browse files
authored
Remove a few unnecessary unsafe keyword uses in TensorPrimitives (#93219)
1 parent 4f77a1b commit a42e97f

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void Abs(ReadOnlySpan<float> x, Span<float> destination) =>
4545
/// If either of the element-wise input values is equal to <see cref="float.NaN"/>, the resulting element-wise value is also NaN.
4646
/// </para>
4747
/// </remarks>
48-
public static unsafe void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination) =>
48+
public static void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination) =>
4949
InvokeSpanSpanIntoSpan<AddOperator>(x, y, destination);
5050

5151
/// <summary>Computes the element-wise addition of single-precision floating-point numbers in the specified tensors.</summary>
@@ -326,7 +326,7 @@ public static void Exp(ReadOnlySpan<float> x, Span<float> destination) =>
326326
/// operating systems or architectures.
327327
/// </para>
328328
/// </remarks>
329-
public static unsafe int IndexOfMax(ReadOnlySpan<float> x)
329+
public static int IndexOfMax(ReadOnlySpan<float> x)
330330
{
331331
int result = -1;
332332

@@ -376,7 +376,7 @@ public static unsafe int IndexOfMax(ReadOnlySpan<float> x)
376376
/// operating systems or architectures.
377377
/// </para>
378378
/// </remarks>
379-
public static unsafe int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
379+
public static int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
380380
{
381381
int result = -1;
382382

@@ -429,7 +429,7 @@ public static unsafe int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
429429
/// operating systems or architectures.
430430
/// </para>
431431
/// </remarks>
432-
public static unsafe int IndexOfMin(ReadOnlySpan<float> x)
432+
public static int IndexOfMin(ReadOnlySpan<float> x)
433433
{
434434
int result = -1;
435435

@@ -479,7 +479,7 @@ public static unsafe int IndexOfMin(ReadOnlySpan<float> x)
479479
/// operating systems or architectures.
480480
/// </para>
481481
/// </remarks>
482-
public static unsafe int IndexOfMinMagnitude(ReadOnlySpan<float> x)
482+
public static int IndexOfMinMagnitude(ReadOnlySpan<float> x)
483483
{
484484
int result = -1;
485485

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ private static float MinMaxCore<TMinMaxOperator>(ReadOnlySpan<float> x)
12101210

12111211
/// <summary>Performs an element-wise operation on <paramref name="x"/> and writes the results to <paramref name="destination"/>.</summary>
12121212
/// <typeparam name="TUnaryOperator">Specifies the operation to perform on each element loaded from <paramref name="x"/>.</typeparam>
1213-
private static unsafe void InvokeSpanIntoSpan<TUnaryOperator>(
1213+
private static void InvokeSpanIntoSpan<TUnaryOperator>(
12141214
ReadOnlySpan<float> x, Span<float> destination)
12151215
where TUnaryOperator : struct, IUnaryOperator
12161216
{
@@ -1326,7 +1326,7 @@ private static unsafe void InvokeSpanIntoSpan<TUnaryOperator>(
13261326
/// <typeparam name="TBinaryOperator">
13271327
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/> and <paramref name="y"/>.
13281328
/// </typeparam>
1329-
private static unsafe void InvokeSpanSpanIntoSpan<TBinaryOperator>(
1329+
private static void InvokeSpanSpanIntoSpan<TBinaryOperator>(
13301330
ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination)
13311331
where TBinaryOperator : struct, IBinaryOperator
13321332
{
@@ -1456,7 +1456,7 @@ private static unsafe void InvokeSpanSpanIntoSpan<TBinaryOperator>(
14561456
/// <typeparam name="TBinaryOperator">
14571457
/// Specifies the operation to perform on each element loaded from <paramref name="x"/> with <paramref name="y"/>.
14581458
/// </typeparam>
1459-
private static unsafe void InvokeSpanScalarIntoSpan<TBinaryOperator>(
1459+
private static void InvokeSpanScalarIntoSpan<TBinaryOperator>(
14601460
ReadOnlySpan<float> x, float y, Span<float> destination)
14611461
where TBinaryOperator : struct, IBinaryOperator =>
14621462
InvokeSpanScalarIntoSpan<IdentityOperator, TBinaryOperator>(x, y, destination);
@@ -1472,7 +1472,7 @@ private static unsafe void InvokeSpanScalarIntoSpan<TBinaryOperator>(
14721472
/// <typeparam name="TBinaryOperator">
14731473
/// Specifies the operation to perform on the transformed value from <paramref name="x"/> with <paramref name="y"/>.
14741474
/// </typeparam>
1475-
private static unsafe void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryOperator>(
1475+
private static void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryOperator>(
14761476
ReadOnlySpan<float> x, float y, Span<float> destination)
14771477
where TTransformOperator : struct, IUnaryOperator
14781478
where TBinaryOperator : struct, IBinaryOperator
@@ -1603,7 +1603,7 @@ private static unsafe void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryO
16031603
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/>, <paramref name="y"/>,
16041604
/// and <paramref name="z"/>.
16051605
/// </typeparam>
1606-
private static unsafe void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
1606+
private static void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
16071607
ReadOnlySpan<float> x, ReadOnlySpan<float> y, ReadOnlySpan<float> z, Span<float> destination)
16081608
where TTernaryOperator : struct, ITernaryOperator
16091609
{
@@ -1743,7 +1743,7 @@ private static unsafe void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
17431743
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/> and <paramref name="y"/>
17441744
/// with <paramref name="z"/>.
17451745
/// </typeparam>
1746-
private static unsafe void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
1746+
private static void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
17471747
ReadOnlySpan<float> x, ReadOnlySpan<float> y, float z, Span<float> destination)
17481748
where TTernaryOperator : struct, ITernaryOperator
17491749
{
@@ -1887,7 +1887,7 @@ private static unsafe void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
18871887
/// Specifies the operation to perform on the pair-wise element loaded from <paramref name="x"/>, with <paramref name="y"/>,
18881888
/// and the element loaded from <paramref name="z"/>.
18891889
/// </typeparam>
1890-
private static unsafe void InvokeSpanScalarSpanIntoSpan<TTernaryOperator>(
1890+
private static void InvokeSpanScalarSpanIntoSpan<TTernaryOperator>(
18911891
ReadOnlySpan<float> x, float y, ReadOnlySpan<float> z, Span<float> destination)
18921892
where TTernaryOperator : struct, ITernaryOperator
18931893
{
@@ -2142,7 +2142,7 @@ private static float GetFirstNaN(Vector512<float> vector)
21422142
/// and zero for all other elements.
21432143
/// </summary>
21442144
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2145-
private static unsafe Vector128<float> CreateRemainderMaskSingleVector128(int count) =>
2145+
private static Vector128<float> CreateRemainderMaskSingleVector128(int count) =>
21462146
Vector128.LoadUnsafe(
21472147
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
21482148
(uint)((count * 16) + 12)); // last four floats in the row
@@ -2152,7 +2152,7 @@ ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16
21522152
/// and zero for all other elements.
21532153
/// </summary>
21542154
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2155-
private static unsafe Vector256<float> CreateRemainderMaskSingleVector256(int count) =>
2155+
private static Vector256<float> CreateRemainderMaskSingleVector256(int count) =>
21562156
Vector256.LoadUnsafe(
21572157
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
21582158
(uint)((count * 16) + 8)); // last eight floats in the row
@@ -2163,7 +2163,7 @@ ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16
21632163
/// and zero for all other elements.
21642164
/// </summary>
21652165
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2166-
private static unsafe Vector512<float> CreateRemainderMaskSingleVector512(int count) =>
2166+
private static Vector512<float> CreateRemainderMaskSingleVector512(int count) =>
21672167
Vector512.LoadUnsafe(
21682168
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
21692169
(uint)(count * 16)); // all sixteen floats in the row

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.netstandard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ ref Unsafe.As<float, Vector<float>>(
750750
private static unsafe bool IsNegative(float f) => *(int*)&f < 0;
751751

752752
/// <summary>Gets whether each specified <see cref="float"/> is negative.</summary>
753-
private static unsafe Vector<float> IsNegative(Vector<float> f) =>
753+
private static Vector<float> IsNegative(Vector<float> f) =>
754754
(Vector<float>)Vector.LessThan((Vector<int>)f, Vector<int>.Zero);
755755

756756
/// <summary>Gets the base 2 logarithm of <paramref name="x"/>.</summary>
@@ -760,7 +760,7 @@ private static unsafe Vector<float> IsNegative(Vector<float> f) =>
760760
/// Gets a vector mask that will be all-ones-set for the last <paramref name="count"/> elements
761761
/// and zero for all other elements.
762762
/// </summary>
763-
private static unsafe Vector<float> CreateRemainderMaskSingleVector(int count)
763+
private static Vector<float> CreateRemainderMaskSingleVector(int count)
764764
{
765765
Debug.Assert(Vector<float>.Count is 4 or 8 or 16);
766766

0 commit comments

Comments
 (0)