Browse Source

Cleanup net40 compiler directives, fix missing handling of net48 in Control.

pull/506/merge
Christoph Ruegg 5 years ago
parent
commit
26ad32bd00
  1. 2
      src/Numerics.Tests/Random/RandomSerializationTests.cs
  2. 12
      src/Numerics/AppSwitches.cs
  3. 44
      src/Numerics/Compatibility.cs
  4. 19
      src/Numerics/Control.cs
  5. 32
      src/Numerics/Euclid.cs
  6. 8
      src/Numerics/LinearAlgebra/Matrix.cs
  7. 8
      src/Numerics/LinearAlgebra/Vector.cs
  8. 8
      src/Numerics/Polynomial.cs
  9. 4
      src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs
  10. 44
      src/Providers.CUDA/Compatibility.cs
  11. 44
      src/Providers.MKL/Compatibility.cs
  12. 44
      src/Providers.OpenBLAS/Compatibility.cs

2
src/Numerics.Tests/Random/RandomSerializationTests.cs

@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
#if NET40_OR_GREATER
#if NET461_OR_GREATER
// Rationale: System.Random is no longer serializable in .Net Core
using System;

12
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<string, bool> Switches = new System.Collections.Generic.Dictionary<string, bool>();
#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

44
src/Numerics/Compatibility.cs

@ -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

19
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<AssemblyInformationalVersionAttribute>()
.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

32
src/Numerics/Euclid.cs

@ -42,9 +42,7 @@ namespace MathNet.Numerics
/// <summary>
/// Canonical Modulus. The result has the sign of the divisor.
/// </summary>
#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
/// <summary>
/// Canonical Modulus. The result has the sign of the divisor.
/// </summary>
#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
/// <summary>
/// Canonical Modulus. The result has the sign of the divisor.
/// </summary>
#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
/// <summary>
/// Canonical Modulus. The result has the sign of the divisor.
/// </summary>
#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
/// <summary>
/// Canonical Modulus. The result has the sign of the divisor.
/// </summary>
#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
/// <summary>
/// Remainder (% operator). The result has the sign of the dividend.
/// </summary>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static double Remainder(double dividend, double divisor)
{
return dividend%divisor;
@ -108,9 +96,7 @@ namespace MathNet.Numerics
/// <summary>
/// Remainder (% operator). The result has the sign of the dividend.
/// </summary>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static float Remainder(float dividend, float divisor)
{
return dividend%divisor;
@ -119,9 +105,7 @@ namespace MathNet.Numerics
/// <summary>
/// Remainder (% operator). The result has the sign of the dividend.
/// </summary>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static int Remainder(int dividend, int divisor)
{
return dividend%divisor;
@ -130,9 +114,7 @@ namespace MathNet.Numerics
/// <summary>
/// Remainder (% operator). The result has the sign of the dividend.
/// </summary>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static long Remainder(long dividend, long divisor)
{
return dividend%divisor;
@ -141,9 +123,7 @@ namespace MathNet.Numerics
/// <summary>
/// Remainder (% operator). The result has the sign of the dividend.
/// </summary>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static BigInteger Remainder(BigInteger dividend, BigInteger divisor)
{
return dividend%divisor;
@ -154,9 +134,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="number">The number to very whether it's even.</param>
/// <returns>True if and only if it is an even number.</returns>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool IsEven(this int number)
{
return (number & 0x1) == 0x0;
@ -167,9 +145,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="number">The number to very whether it's even.</param>
/// <returns>True if and only if it is an even number.</returns>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool IsEven(this long number)
{
return (number & 0x1) == 0x0;
@ -180,9 +156,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="number">The number to very whether it's odd.</param>
/// <returns>True if and only if it is an odd number.</returns>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool IsOdd(this int number)
{
return (number & 0x1) == 0x1;
@ -193,9 +167,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="number">The number to very whether it's odd.</param>
/// <returns>True if and only if it is an odd number.</returns>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool IsOdd(this long number)
{
return (number & 0x1) == 0x1;
@ -206,9 +178,7 @@ namespace MathNet.Numerics
/// </summary>
/// <param name="number">The number to very whether it's a power of two.</param>
/// <returns>True if and only if it is a power of two.</returns>
#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
/// </summary>
/// <param name="number">The number to very whether it's a power of two.</param>
/// <returns>True if and only if it is a power of two.</returns>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static bool IsPowerOfTwo(this long number)
{
return number > 0 && (number & (number - 1)) == 0x0;

8
src/Numerics/LinearAlgebra/Matrix.cs

@ -88,15 +88,11 @@ namespace MathNet.Numerics.LinearAlgebra
/// to get and set values without range checking.</remarks>
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
/// <returns>
/// The requested element.
/// </returns>
#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
/// <param name="value">
/// The value to set the element to.
/// </param>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public void At(int row, int column, T value)
{

8
src/Numerics/LinearAlgebra/Vector.cs

@ -72,15 +72,11 @@ namespace MathNet.Numerics.LinearAlgebra
/// greater than the size of the vector.</exception>
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
/// <summary>Gets the value at the given <paramref name="index"/> without range checking..</summary>
/// <param name="index">The index of the value to get or set.</param>
/// <returns>The value of the vector at the given <paramref name="index"/>.</returns>
#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
/// <summary>Sets the <paramref name="value"/> at the given <paramref name="index"/> without range checking..</summary>
/// <param name="index">The index of the value to get or set.</param>
/// <param name="value">The value to set.</param>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public void At(int index, T value)
{

8
src/Numerics/Polynomial.cs

@ -64,11 +64,7 @@ namespace MathNet.Numerics
/// </summary>
public Polynomial()
{
#if NET40
Coefficients = new double[0];
#else
Coefficients = Array.Empty<double>();
#endif
}
/// <summary>
@ -80,11 +76,7 @@ namespace MathNet.Numerics
{
if (coefficient == 0.0)
{
#if NET40
Coefficients = new double[0];
#else
Coefficients = Array.Empty<double>();
#endif
}
else
{

4
src/Numerics/Providers/FourierTransform/ManagedFourierTransformProvider.Radix2.cs

@ -70,9 +70,7 @@ namespace MathNet.Numerics.Providers.FourierTransform
/// <param name="exponentSign">Fourier series exponent sign.</param>
/// <param name="levelSize">Level Group Size.</param>
/// <param name="k">Index inside of the level.</param>
#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
/// <param name="exponentSign">Fourier series exponent sign.</param>
/// <param name="levelSize">Level Group Size.</param>
/// <param name="k">Index inside of the level.</param>
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
static void Radix2Step(Complex[] samples, int exponentSign, int levelSize, int k)
{
// Twiddle Factor

44
src/Providers.CUDA/Compatibility.cs

@ -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

44
src/Providers.MKL/Compatibility.cs

@ -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

44
src/Providers.OpenBLAS/Compatibility.cs

@ -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
Loading…
Cancel
Save