From 26ad32bd00fba1defe780e1483fc90152755088d Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 19 Dec 2021 15:48:14 +0100 Subject: [PATCH] Cleanup net40 compiler directives, fix missing handling of net48 in Control. --- .../Random/RandomSerializationTests.cs | 2 +- src/Numerics/AppSwitches.cs | 12 ----- src/Numerics/Compatibility.cs | 44 ------------------- src/Numerics/Control.cs | 19 ++------ src/Numerics/Euclid.cs | 32 -------------- src/Numerics/LinearAlgebra/Matrix.cs | 8 ---- src/Numerics/LinearAlgebra/Vector.cs | 8 ---- src/Numerics/Polynomial.cs | 8 ---- .../ManagedFourierTransformProvider.Radix2.cs | 4 -- src/Providers.CUDA/Compatibility.cs | 44 ------------------- src/Providers.MKL/Compatibility.cs | 44 ------------------- src/Providers.OpenBLAS/Compatibility.cs | 44 ------------------- 12 files changed, 5 insertions(+), 264 deletions(-) delete mode 100644 src/Numerics/Compatibility.cs delete mode 100644 src/Providers.CUDA/Compatibility.cs delete mode 100644 src/Providers.MKL/Compatibility.cs delete mode 100644 src/Providers.OpenBLAS/Compatibility.cs diff --git a/src/Numerics.Tests/Random/RandomSerializationTests.cs b/src/Numerics.Tests/Random/RandomSerializationTests.cs index f0f7f423..6b6f76b8 100644 --- a/src/Numerics.Tests/Random/RandomSerializationTests.cs +++ b/src/Numerics.Tests/Random/RandomSerializationTests.cs @@ -27,7 +27,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // -#if NET40_OR_GREATER +#if NET461_OR_GREATER // Rationale: System.Random is no longer serializable in .Net Core using System; diff --git a/src/Numerics/AppSwitches.cs b/src/Numerics/AppSwitches.cs index 430f4679..10fc5a41 100644 --- a/src/Numerics/AppSwitches.cs +++ b/src/Numerics/AppSwitches.cs @@ -46,26 +46,14 @@ namespace MathNet.Numerics const string AppSwitchDisableCudaNativeProvider = "Switch.MathNet.Numerics.Providers.DisableCudaNativeProvider"; const string AppSwitchDisableOpenBlasNativeProvider = "Switch.MathNet.Numerics.Providers.DisableOpenBlasNativeProvider"; -#if NET40 - static readonly System.Collections.Generic.Dictionary Switches = new System.Collections.Generic.Dictionary(); -#endif - static void SetSwitch(string switchName, bool isEnabled) { -#if NET40 - Switches[switchName] = isEnabled; -#else System.AppContext.SetSwitch(switchName, isEnabled); -#endif } static bool IsEnabled(string switchName) { -#if NET40 - return Switches.TryGetValue(switchName, out bool isEnabled) && isEnabled; -#else return System.AppContext.TryGetSwitch(switchName, out bool isEnabled) && isEnabled; -#endif } public static bool DisableNativeProviderProbing diff --git a/src/Numerics/Compatibility.cs b/src/Numerics/Compatibility.cs deleted file mode 100644 index 444e41cb..00000000 --- a/src/Numerics/Compatibility.cs +++ /dev/null @@ -1,44 +0,0 @@ -#if NET40 -using System.Globalization; - -namespace System.Runtime.CompilerServices -{ - internal class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] args) - { - return new FormattableString(format, args); - } - } -} - -namespace System -{ - internal class FormattableString - { - readonly string _format; - readonly object[] _args; - - public FormattableString(string format, object[] args) - { - _format = format; - _args = args; - } - - public static string Invariant(FormattableString messageFormat) - { - return messageFormat.ToString(CultureInfo.InvariantCulture); - } - - public string ToString(IFormatProvider formatProvider) - { - return string.Format(formatProvider, _format, _args); - } - - public override string ToString() - { - return string.Format(_format, _args); - } - } -} -#endif diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs index 5094a415..ada9f86d 100644 --- a/src/Numerics/Control.cs +++ b/src/Numerics/Control.cs @@ -35,11 +35,7 @@ using MathNet.Numerics.Providers.SparseSolver; using MathNet.Numerics.Providers.FourierTransform; using MathNet.Numerics.Providers.LinearAlgebra; -#if NET40 -using System.Linq; -#endif - -#if !NET40 && !NET461 +#if !NET461 using System.Runtime.InteropServices; #endif @@ -310,14 +306,7 @@ namespace MathNet.Numerics public static string Describe() { -#if NET40 - var versionAttribute = typeof(Control).Assembly - .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false) - .OfType() - .FirstOrDefault(); -#else var versionAttribute = typeof(Control).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; -#endif var sb = new StringBuilder(); sb.AppendLine("Math.NET Numerics Configuration:"); @@ -328,10 +317,10 @@ namespace MathNet.Numerics sb.AppendLine("Built for .Net 5.0+"); #elif NETSTANDARD2_0 sb.AppendLine("Built for .Net Standard 2.0"); +#elif NET48 + sb.AppendLine("Built for .Net Framework 4.8"); #elif NET461 sb.AppendLine("Built for .Net Framework 4.6.1"); -#elif NET40 - sb.AppendLine("Built for .Net Framework 4.0"); #endif sb.AppendLine($"Linear Algebra Provider: {LinearAlgebraControl.Provider}"); @@ -342,7 +331,7 @@ namespace MathNet.Numerics sb.AppendLine($"Parallelize Order: {ParallelizeOrder}"); sb.AppendLine($"Check Distribution Parameters: {CheckDistributionParameters}"); sb.AppendLine($"Thread-Safe RNGs: {ThreadSafeRandomNumberGenerators}"); -#if NET40 || NET461 +#if NET461 sb.AppendLine($"Operating System: {Environment.OSVersion}"); sb.AppendLine($"Framework: {Environment.Version}"); #else diff --git a/src/Numerics/Euclid.cs b/src/Numerics/Euclid.cs index cecb839e..0ecf4bfe 100644 --- a/src/Numerics/Euclid.cs +++ b/src/Numerics/Euclid.cs @@ -42,9 +42,7 @@ namespace MathNet.Numerics /// /// Canonical Modulus. The result has the sign of the divisor. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static double Modulus(double dividend, double divisor) { return ((dividend%divisor) + divisor)%divisor; @@ -53,9 +51,7 @@ namespace MathNet.Numerics /// /// Canonical Modulus. The result has the sign of the divisor. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static float Modulus(float dividend, float divisor) { return ((dividend%divisor) + divisor)%divisor; @@ -64,9 +60,7 @@ namespace MathNet.Numerics /// /// Canonical Modulus. The result has the sign of the divisor. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static int Modulus(int dividend, int divisor) { return ((dividend%divisor) + divisor)%divisor; @@ -75,9 +69,7 @@ namespace MathNet.Numerics /// /// Canonical Modulus. The result has the sign of the divisor. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static long Modulus(long dividend, long divisor) { return ((dividend%divisor) + divisor)%divisor; @@ -86,9 +78,7 @@ namespace MathNet.Numerics /// /// Canonical Modulus. The result has the sign of the divisor. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static BigInteger Modulus(BigInteger dividend, BigInteger divisor) { return ((dividend%divisor) + divisor)%divisor; @@ -97,9 +87,7 @@ namespace MathNet.Numerics /// /// Remainder (% operator). The result has the sign of the dividend. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static double Remainder(double dividend, double divisor) { return dividend%divisor; @@ -108,9 +96,7 @@ namespace MathNet.Numerics /// /// Remainder (% operator). The result has the sign of the dividend. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static float Remainder(float dividend, float divisor) { return dividend%divisor; @@ -119,9 +105,7 @@ namespace MathNet.Numerics /// /// Remainder (% operator). The result has the sign of the dividend. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static int Remainder(int dividend, int divisor) { return dividend%divisor; @@ -130,9 +114,7 @@ namespace MathNet.Numerics /// /// Remainder (% operator). The result has the sign of the dividend. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static long Remainder(long dividend, long divisor) { return dividend%divisor; @@ -141,9 +123,7 @@ namespace MathNet.Numerics /// /// Remainder (% operator). The result has the sign of the dividend. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static BigInteger Remainder(BigInteger dividend, BigInteger divisor) { return dividend%divisor; @@ -154,9 +134,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's even. /// True if and only if it is an even number. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsEven(this int number) { return (number & 0x1) == 0x0; @@ -167,9 +145,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's even. /// True if and only if it is an even number. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsEven(this long number) { return (number & 0x1) == 0x0; @@ -180,9 +156,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's odd. /// True if and only if it is an odd number. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsOdd(this int number) { return (number & 0x1) == 0x1; @@ -193,9 +167,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's odd. /// True if and only if it is an odd number. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsOdd(this long number) { return (number & 0x1) == 0x1; @@ -206,9 +178,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's a power of two. /// True if and only if it is a power of two. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsPowerOfTwo(this int number) { return number > 0 && (number & (number - 1)) == 0x0; @@ -219,9 +189,7 @@ namespace MathNet.Numerics /// /// The number to very whether it's a power of two. /// True if and only if it is a power of two. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif public static bool IsPowerOfTwo(this long number) { return number > 0 && (number & (number - 1)) == 0x0; diff --git a/src/Numerics/LinearAlgebra/Matrix.cs b/src/Numerics/LinearAlgebra/Matrix.cs index 3497e2fb..4fb2d37f 100644 --- a/src/Numerics/LinearAlgebra/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Matrix.cs @@ -88,15 +88,11 @@ namespace MathNet.Numerics.LinearAlgebra /// to get and set values without range checking. public T this[int row, int column] { -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] get { return Storage[row, column]; } -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] set { Storage[row, column] = value; } } @@ -113,9 +109,7 @@ namespace MathNet.Numerics.LinearAlgebra /// /// The requested element. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public T At(int row, int column) { @@ -134,9 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra /// /// The value to set the element to. /// -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public void At(int row, int column, T value) { diff --git a/src/Numerics/LinearAlgebra/Vector.cs b/src/Numerics/LinearAlgebra/Vector.cs index 08c7d952..38607cb6 100644 --- a/src/Numerics/LinearAlgebra/Vector.cs +++ b/src/Numerics/LinearAlgebra/Vector.cs @@ -72,15 +72,11 @@ namespace MathNet.Numerics.LinearAlgebra /// greater than the size of the vector. public T this[int index] { -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] get { return Storage[index]; } -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] set { Storage[index] = value; } } @@ -88,9 +84,7 @@ namespace MathNet.Numerics.LinearAlgebra /// Gets the value at the given without range checking.. /// The index of the value to get or set. /// The value of the vector at the given . -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public T At(int index) { @@ -100,9 +94,7 @@ namespace MathNet.Numerics.LinearAlgebra /// Sets the at the given without range checking.. /// The index of the value to get or set. /// The value to set. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public void At(int index, T value) { diff --git a/src/Numerics/Polynomial.cs b/src/Numerics/Polynomial.cs index 54a1d7fb..31f4f6bb 100644 --- a/src/Numerics/Polynomial.cs +++ b/src/Numerics/Polynomial.cs @@ -64,11 +64,7 @@ namespace MathNet.Numerics /// public Polynomial() { -#if NET40 - Coefficients = new double[0]; -#else Coefficients = Array.Empty(); -#endif } /// @@ -80,11 +76,7 @@ namespace MathNet.Numerics { if (coefficient == 0.0) { -#if NET40 - Coefficients = new double[0]; -#else Coefficients = Array.Empty(); -#endif } else { diff --git a/src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs b/src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs index fe6c453f..04944878 100644 --- a/src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs +++ b/src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs @@ -70,9 +70,7 @@ namespace MathNet.Numerics.Providers.FourierTransform /// Fourier series exponent sign. /// Level Group Size. /// Index inside of the level. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k) { // Twiddle Factor @@ -96,9 +94,7 @@ namespace MathNet.Numerics.Providers.FourierTransform /// Fourier series exponent sign. /// Level Group Size. /// Index inside of the level. -#if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif static void Radix2Step(Complex[] samples, int exponentSign, int levelSize, int k) { // Twiddle Factor diff --git a/src/Providers.CUDA/Compatibility.cs b/src/Providers.CUDA/Compatibility.cs deleted file mode 100644 index 444e41cb..00000000 --- a/src/Providers.CUDA/Compatibility.cs +++ /dev/null @@ -1,44 +0,0 @@ -#if NET40 -using System.Globalization; - -namespace System.Runtime.CompilerServices -{ - internal class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] args) - { - return new FormattableString(format, args); - } - } -} - -namespace System -{ - internal class FormattableString - { - readonly string _format; - readonly object[] _args; - - public FormattableString(string format, object[] args) - { - _format = format; - _args = args; - } - - public static string Invariant(FormattableString messageFormat) - { - return messageFormat.ToString(CultureInfo.InvariantCulture); - } - - public string ToString(IFormatProvider formatProvider) - { - return string.Format(formatProvider, _format, _args); - } - - public override string ToString() - { - return string.Format(_format, _args); - } - } -} -#endif diff --git a/src/Providers.MKL/Compatibility.cs b/src/Providers.MKL/Compatibility.cs deleted file mode 100644 index 444e41cb..00000000 --- a/src/Providers.MKL/Compatibility.cs +++ /dev/null @@ -1,44 +0,0 @@ -#if NET40 -using System.Globalization; - -namespace System.Runtime.CompilerServices -{ - internal class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] args) - { - return new FormattableString(format, args); - } - } -} - -namespace System -{ - internal class FormattableString - { - readonly string _format; - readonly object[] _args; - - public FormattableString(string format, object[] args) - { - _format = format; - _args = args; - } - - public static string Invariant(FormattableString messageFormat) - { - return messageFormat.ToString(CultureInfo.InvariantCulture); - } - - public string ToString(IFormatProvider formatProvider) - { - return string.Format(formatProvider, _format, _args); - } - - public override string ToString() - { - return string.Format(_format, _args); - } - } -} -#endif diff --git a/src/Providers.OpenBLAS/Compatibility.cs b/src/Providers.OpenBLAS/Compatibility.cs deleted file mode 100644 index 444e41cb..00000000 --- a/src/Providers.OpenBLAS/Compatibility.cs +++ /dev/null @@ -1,44 +0,0 @@ -#if NET40 -using System.Globalization; - -namespace System.Runtime.CompilerServices -{ - internal class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] args) - { - return new FormattableString(format, args); - } - } -} - -namespace System -{ - internal class FormattableString - { - readonly string _format; - readonly object[] _args; - - public FormattableString(string format, object[] args) - { - _format = format; - _args = args; - } - - public static string Invariant(FormattableString messageFormat) - { - return messageFormat.ToString(CultureInfo.InvariantCulture); - } - - public string ToString(IFormatProvider formatProvider) - { - return string.Format(formatProvider, _format, _args); - } - - public override string ToString() - { - return string.Format(_format, _args); - } - } -} -#endif