From bef1641d69bfc992f42eac54e5f5a5c27224f0f1 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 28 Jan 2018 20:13:37 +0100 Subject: [PATCH] Control: Describe gives an overview over the current configuration --- src/Numerics/Control.cs | 61 ++++++++++++++++++----- src/UnitTests/UseLinearAlgebraProvider.cs | 17 +------ 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs index 9ee45304..dc4e4e15 100644 --- a/src/Numerics/Control.cs +++ b/src/Numerics/Control.cs @@ -28,6 +28,10 @@ // using System; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; using System.Threading.Tasks; using MathNet.Numerics.Providers.FourierTransform; using MathNet.Numerics.Providers.LinearAlgebra; @@ -40,7 +44,6 @@ namespace MathNet.Numerics public static class Control { static int _maxDegreeOfParallelism; - static int _blockSize; static int _parallelizeOrder; static int _parallelizeElements; static string _nativeProviderHintPath; @@ -58,7 +61,6 @@ namespace MathNet.Numerics // Parallelization & Threading ThreadSafeRandomNumberGenerators = true; _maxDegreeOfParallelism = Environment.ProcessorCount; - _blockSize = 512; _parallelizeOrder = 64; _parallelizeElements = 300; TaskScheduler = TaskScheduler.Default; @@ -259,17 +261,6 @@ namespace MathNet.Numerics /// public static TaskScheduler TaskScheduler { get; set; } - /// - /// Gets or sets the block size to use for - /// the native linear algebra provider. - /// - /// The block size. Default 512, must be at least 32. - public static int BlockSize - { - get { return _blockSize; } - set { _blockSize = Math.Max(32, value); } - } - /// /// Gets or sets the order of the matrix when linear algebra provider /// must calculate multiply in parallel threads. @@ -291,5 +282,49 @@ namespace MathNet.Numerics get { return _parallelizeElements; } set { _parallelizeElements = Math.Max(3, value); } } + + 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:"); + sb.AppendLine($"Version {versionAttribute?.InformationalVersion}"); +#if NETSTANDARD1_3 + sb.AppendLine("Built for .Net Standard 1.3"); +#elif NETSTANDARD2_0 + sb.AppendLine("Built for .Net Standard 2.0"); +#elif NET40 + sb.AppendLine("Built for .Net Framework 4.0"); +#endif +#if !NATIVE + sb.AppendLine("No Native Provider Support"); +#endif + sb.AppendLine($"Linear Algebra Provider: {LinearAlgebraControl.Provider}"); + sb.AppendLine($"Fourier Transform Provider: {FourierTransformControl.Provider}"); + sb.AppendLine($"Max Degree of Parallelism: {MaxDegreeOfParallelism}"); + sb.AppendLine($"Parallelize Elements: {ParallelizeElements}"); + sb.AppendLine($"Parallelize Order: {ParallelizeOrder}"); + sb.AppendLine($"Check Distribution Parameters: {CheckDistributionParameters}"); + sb.AppendLine($"Thread-Safe RNGs: {ThreadSafeRandomNumberGenerators}"); +#if NETSTANDARD1_3 || NETSTANDARD2_0 + // This would also work in .Net 4.0, but we don't want the dependency just for that. + sb.AppendLine($"Operating System: {RuntimeInformation.OSDescription}"); + sb.AppendLine($"Operating System Architecture: {RuntimeInformation.OSArchitecture}"); + sb.AppendLine($"Framework: {RuntimeInformation.FrameworkDescription}"); + sb.AppendLine($"Process Architecture: {RuntimeInformation.ProcessArchitecture}"); +#else + sb.AppendLine($"Operating System: {Environment.OSVersion}"); + sb.AppendLine($"Framework: {Environment.Version}"); +#endif + return sb.ToString(); + } } } diff --git a/src/UnitTests/UseLinearAlgebraProvider.cs b/src/UnitTests/UseLinearAlgebraProvider.cs index b74315a6..dd139eb9 100644 --- a/src/UnitTests/UseLinearAlgebraProvider.cs +++ b/src/UnitTests/UseLinearAlgebraProvider.cs @@ -28,10 +28,6 @@ // using System; -using System.Runtime.InteropServices; - -using MathNet.Numerics.Providers.FourierTransform; -using MathNet.Numerics.Providers.LinearAlgebra; using NUnit.Framework; using NUnit.Framework.Interfaces; @@ -58,18 +54,7 @@ namespace MathNet.Numerics.UnitTests // ReSharper disable LocalizableElement Console.WriteLine(); - Console.WriteLine("Math.NET Numerics Test Configuration:"); - Console.WriteLine($"Operating System: {RuntimeInformation.OSDescription}"); - Console.WriteLine($"Framework: {RuntimeInformation.FrameworkDescription}"); - Console.WriteLine($"Operating System Architecture: {RuntimeInformation.OSArchitecture}"); - Console.WriteLine($"Process Architecture: {RuntimeInformation.ProcessArchitecture}"); - #if !NETCOREAPP1_1 - Console.WriteLine($"CLR Version: {Environment.Version}"); - Console.WriteLine($"OS Version: {Environment.OSVersion}"); - #endif - Console.WriteLine($"Linear Algebra Provider: {LinearAlgebraControl.Provider}"); - Console.WriteLine($"Fourier Transform Provider: {FourierTransformControl.Provider}"); - Console.WriteLine(); + Console.WriteLine(Control.Describe()); // ReSharper restore LocalizableElement }