Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a few unnecessary unsafe keyword uses in TensorPrimitives #93219

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void Abs(ReadOnlySpan<float> x, Span<float> destination) =>
/// If either of the element-wise input values is equal to <see cref="float.NaN"/>, the resulting element-wise value is also NaN.
/// </para>
/// </remarks>
public static unsafe void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination) =>
public static void Add(ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination) =>
InvokeSpanSpanIntoSpan<AddOperator>(x, y, destination);

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

Expand Down Expand Up @@ -376,7 +376,7 @@ public static unsafe int IndexOfMax(ReadOnlySpan<float> x)
/// operating systems or architectures.
/// </para>
/// </remarks>
public static unsafe int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
public static int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
{
int result = -1;

Expand Down Expand Up @@ -429,7 +429,7 @@ public static unsafe int IndexOfMaxMagnitude(ReadOnlySpan<float> x)
/// operating systems or architectures.
/// </para>
/// </remarks>
public static unsafe int IndexOfMin(ReadOnlySpan<float> x)
public static int IndexOfMin(ReadOnlySpan<float> x)
{
int result = -1;

Expand Down Expand Up @@ -479,7 +479,7 @@ public static unsafe int IndexOfMin(ReadOnlySpan<float> x)
/// operating systems or architectures.
/// </para>
/// </remarks>
public static unsafe int IndexOfMinMagnitude(ReadOnlySpan<float> x)
public static int IndexOfMinMagnitude(ReadOnlySpan<float> x)
{
int result = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ private static float MinMaxCore<TMinMaxOperator>(ReadOnlySpan<float> x)

/// <summary>Performs an element-wise operation on <paramref name="x"/> and writes the results to <paramref name="destination"/>.</summary>
/// <typeparam name="TUnaryOperator">Specifies the operation to perform on each element loaded from <paramref name="x"/>.</typeparam>
private static unsafe void InvokeSpanIntoSpan<TUnaryOperator>(
private static void InvokeSpanIntoSpan<TUnaryOperator>(
ReadOnlySpan<float> x, Span<float> destination)
where TUnaryOperator : struct, IUnaryOperator
{
Expand Down Expand Up @@ -1326,7 +1326,7 @@ private static unsafe void InvokeSpanIntoSpan<TUnaryOperator>(
/// <typeparam name="TBinaryOperator">
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/> and <paramref name="y"/>.
/// </typeparam>
private static unsafe void InvokeSpanSpanIntoSpan<TBinaryOperator>(
private static void InvokeSpanSpanIntoSpan<TBinaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, Span<float> destination)
where TBinaryOperator : struct, IBinaryOperator
{
Expand Down Expand Up @@ -1456,7 +1456,7 @@ private static unsafe void InvokeSpanSpanIntoSpan<TBinaryOperator>(
/// <typeparam name="TBinaryOperator">
/// Specifies the operation to perform on each element loaded from <paramref name="x"/> with <paramref name="y"/>.
/// </typeparam>
private static unsafe void InvokeSpanScalarIntoSpan<TBinaryOperator>(
private static void InvokeSpanScalarIntoSpan<TBinaryOperator>(
ReadOnlySpan<float> x, float y, Span<float> destination)
where TBinaryOperator : struct, IBinaryOperator =>
InvokeSpanScalarIntoSpan<IdentityOperator, TBinaryOperator>(x, y, destination);
Expand All @@ -1472,7 +1472,7 @@ private static unsafe void InvokeSpanScalarIntoSpan<TBinaryOperator>(
/// <typeparam name="TBinaryOperator">
/// Specifies the operation to perform on the transformed value from <paramref name="x"/> with <paramref name="y"/>.
/// </typeparam>
private static unsafe void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryOperator>(
private static void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryOperator>(
ReadOnlySpan<float> x, float y, Span<float> destination)
where TTransformOperator : struct, IUnaryOperator
where TBinaryOperator : struct, IBinaryOperator
Expand Down Expand Up @@ -1603,7 +1603,7 @@ private static unsafe void InvokeSpanScalarIntoSpan<TTransformOperator, TBinaryO
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/>, <paramref name="y"/>,
/// and <paramref name="z"/>.
/// </typeparam>
private static unsafe void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
private static void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, ReadOnlySpan<float> z, Span<float> destination)
where TTernaryOperator : struct, ITernaryOperator
{
Expand Down Expand Up @@ -1743,7 +1743,7 @@ private static unsafe void InvokeSpanSpanSpanIntoSpan<TTernaryOperator>(
/// Specifies the operation to perform on the pair-wise elements loaded from <paramref name="x"/> and <paramref name="y"/>
/// with <paramref name="z"/>.
/// </typeparam>
private static unsafe void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
private static void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, ReadOnlySpan<float> y, float z, Span<float> destination)
where TTernaryOperator : struct, ITernaryOperator
{
Expand Down Expand Up @@ -1887,7 +1887,7 @@ private static unsafe void InvokeSpanSpanScalarIntoSpan<TTernaryOperator>(
/// Specifies the operation to perform on the pair-wise element loaded from <paramref name="x"/>, with <paramref name="y"/>,
/// and the element loaded from <paramref name="z"/>.
/// </typeparam>
private static unsafe void InvokeSpanScalarSpanIntoSpan<TTernaryOperator>(
private static void InvokeSpanScalarSpanIntoSpan<TTernaryOperator>(
ReadOnlySpan<float> x, float y, ReadOnlySpan<float> z, Span<float> destination)
where TTernaryOperator : struct, ITernaryOperator
{
Expand Down Expand Up @@ -2142,7 +2142,7 @@ private static float GetFirstNaN(Vector512<float> vector)
/// and zero for all other elements.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe Vector128<float> CreateRemainderMaskSingleVector128(int count) =>
private static Vector128<float> CreateRemainderMaskSingleVector128(int count) =>
Vector128.LoadUnsafe(
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
(uint)((count * 16) + 12)); // last four floats in the row
Expand All @@ -2152,7 +2152,7 @@ ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16
/// and zero for all other elements.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe Vector256<float> CreateRemainderMaskSingleVector256(int count) =>
private static Vector256<float> CreateRemainderMaskSingleVector256(int count) =>
Vector256.LoadUnsafe(
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
(uint)((count * 16) + 8)); // last eight floats in the row
Expand All @@ -2163,7 +2163,7 @@ ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16
/// and zero for all other elements.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe Vector512<float> CreateRemainderMaskSingleVector512(int count) =>
private static Vector512<float> CreateRemainderMaskSingleVector512(int count) =>
Vector512.LoadUnsafe(
ref Unsafe.As<uint, float>(ref MemoryMarshal.GetReference(RemainderUInt32Mask_16x16)),
(uint)(count * 16)); // all sixteen floats in the row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ ref Unsafe.As<float, Vector<float>>(
private static unsafe bool IsNegative(float f) => *(int*)&f < 0;

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

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

Expand Down