Skip to content
Closed
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
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Intrinsics;

namespace System.Numerics.Tensors
Expand Down Expand Up @@ -29,11 +30,65 @@ public static void Acos<T>(ReadOnlySpan<T> x, Span<T> destination)
private readonly struct AcosOperator<T> : IUnaryOperator<T, T>
where T : ITrigonometricFunctions<T>
{
public static bool Vectorizable => false; // TODO: Vectorize
#if NET11_0_OR_GREATER
public static bool Vectorizable => (typeof(T) == typeof(float))
|| (typeof(T) == typeof(double));
#else
public static bool Vectorizable => false;
#endif

public static T Invoke(T x) => T.Acos(x);
public static Vector128<T> Invoke(Vector128<T> x) => throw new NotSupportedException();
public static Vector256<T> Invoke(Vector256<T> x) => throw new NotSupportedException();
public static Vector512<T> Invoke(Vector512<T> x) => throw new NotSupportedException();

public static Vector128<T> Invoke(Vector128<T> x)
{
#if NET11_0_OR_GREATER
Comment thread
stephentoub marked this conversation as resolved.
if (typeof(T) == typeof(double))
{
return Vector128.Acos(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector128.Acos(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector256<T> Invoke(Vector256<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector256.Acos(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector256.Acos(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector512<T> Invoke(Vector512<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector512.Acos(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector512.Acos(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Intrinsics;

namespace System.Numerics.Tensors
Expand All @@ -26,14 +27,68 @@ public static void Acosh<T>(ReadOnlySpan<T> x, Span<T> destination)
InvokeSpanIntoSpan<T, AcoshOperator<T>>(x, destination);

/// <summary>T.Acosh(x)</summary>
private readonly struct AcoshOperator<T> : IUnaryOperator<T, T>
internal readonly struct AcoshOperator<T> : IUnaryOperator<T, T>
where T : IHyperbolicFunctions<T>
{
public static bool Vectorizable => false; // TODO: Vectorize
#if NET11_0_OR_GREATER
public static bool Vectorizable => (typeof(T) == typeof(float))
|| (typeof(T) == typeof(double));
#else
public static bool Vectorizable => false;
#endif

public static T Invoke(T x) => T.Acosh(x);
public static Vector128<T> Invoke(Vector128<T> x) => throw new NotSupportedException();
public static Vector256<T> Invoke(Vector256<T> x) => throw new NotSupportedException();
public static Vector512<T> Invoke(Vector512<T> x) => throw new NotSupportedException();

public static Vector128<T> Invoke(Vector128<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector128.Acosh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector128.Acosh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector256<T> Invoke(Vector256<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector256.Acosh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector256.Acosh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector512<T> Invoke(Vector512<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector512.Acosh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector512.Acosh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Intrinsics;

namespace System.Numerics.Tensors
Expand Down Expand Up @@ -29,11 +30,65 @@ public static void Asinh<T>(ReadOnlySpan<T> x, Span<T> destination)
internal readonly struct AsinhOperator<T> : IUnaryOperator<T, T>
where T : IHyperbolicFunctions<T>
{
public static bool Vectorizable => false; // TODO: Vectorize
#if NET11_0_OR_GREATER
public static bool Vectorizable => (typeof(T) == typeof(float))
|| (typeof(T) == typeof(double));
#else
public static bool Vectorizable => false;
#endif

public static T Invoke(T x) => T.Asinh(x);
public static Vector128<T> Invoke(Vector128<T> x) => throw new NotSupportedException();
public static Vector256<T> Invoke(Vector256<T> x) => throw new NotSupportedException();
public static Vector512<T> Invoke(Vector512<T> x) => throw new NotSupportedException();

public static Vector128<T> Invoke(Vector128<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector128.Asinh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector128.Asinh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector256<T> Invoke(Vector256<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector256.Asinh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector256.Asinh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector512<T> Invoke(Vector512<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector512.Asinh(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector512.Asinh(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Intrinsics;

namespace System.Numerics.Tensors
Expand Down Expand Up @@ -29,11 +30,65 @@ public static void Atan<T>(ReadOnlySpan<T> x, Span<T> destination)
internal readonly struct AtanOperator<T> : IUnaryOperator<T, T>
where T : ITrigonometricFunctions<T>
{
public static bool Vectorizable => false; // TODO: Vectorize
#if NET11_0_OR_GREATER
public static bool Vectorizable => (typeof(T) == typeof(float))
|| (typeof(T) == typeof(double));
#else
public static bool Vectorizable => false;
#endif

public static T Invoke(T x) => T.Atan(x);
public static Vector128<T> Invoke(Vector128<T> x) => throw new NotSupportedException();
public static Vector256<T> Invoke(Vector256<T> x) => throw new NotSupportedException();
public static Vector512<T> Invoke(Vector512<T> x) => throw new NotSupportedException();

public static Vector128<T> Invoke(Vector128<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector128.Atan(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector128.Atan(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector256<T> Invoke(Vector256<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector256.Atan(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector256.Atan(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector512<T> Invoke(Vector512<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector512.Atan(x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector512.Atan(x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.Intrinsics;

namespace System.Numerics.Tensors
Expand Down Expand Up @@ -70,11 +71,65 @@ public static void Atan2<T>(T y, ReadOnlySpan<T> x, Span<T> destination)
private readonly struct Atan2Operator<T> : IBinaryOperator<T>
where T : IFloatingPointIeee754<T>
{
public static bool Vectorizable => false; // TODO: Vectorize
#if NET11_0_OR_GREATER
public static bool Vectorizable => (typeof(T) == typeof(float))
|| (typeof(T) == typeof(double));
#else
public static bool Vectorizable => false;
#endif

public static T Invoke(T y, T x) => T.Atan2(y, x);
public static Vector128<T> Invoke(Vector128<T> y, Vector128<T> x) => throw new NotSupportedException();
public static Vector256<T> Invoke(Vector256<T> y, Vector256<T> x) => throw new NotSupportedException();
public static Vector512<T> Invoke(Vector512<T> y, Vector512<T> x) => throw new NotSupportedException();

public static Vector128<T> Invoke(Vector128<T> y, Vector128<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector128.Atan2(y.AsDouble(), x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector128.Atan2(y.AsSingle(), x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector256<T> Invoke(Vector256<T> y, Vector256<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector256.Atan2(y.AsDouble(), x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector256.Atan2(y.AsSingle(), x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}

public static Vector512<T> Invoke(Vector512<T> y, Vector512<T> x)
{
#if NET11_0_OR_GREATER
if (typeof(T) == typeof(double))
{
return Vector512.Atan2(y.AsDouble(), x.AsDouble()).As<double, T>();
}
else
{
Debug.Assert(typeof(T) == typeof(float));
return Vector512.Atan2(y.AsSingle(), x.AsSingle()).As<float, T>();
}
#else
throw new NotSupportedException();
#endif
}
}
}
}
Loading
Loading