From 1d8645c15e2466bbc1e82c6e51aba8afb9c10d84 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Wed, 16 Sep 2009 14:05:57 +0800 Subject: [PATCH] Removed the Algorithm factory, now just registering the providers in the Control class Made the managed provider public --- src/Numerics/Algorithms/AlgorithmFactory.cs | 130 ------------------ ...arAlgebra.cs => ILinearAlgebraProvider.cs} | 2 +- ...bra.cs => ManagedLinearAlgebraProvider.cs} | 2 +- src/Numerics/Control.cs | 11 ++ .../LinearAlgebra/Double/DenseVector.cs | 11 +- src/Numerics/Numerics.csproj | 5 +- src/Numerics/Threading/Task.cs | 2 +- 7 files changed, 19 insertions(+), 144 deletions(-) delete mode 100644 src/Numerics/Algorithms/AlgorithmFactory.cs rename src/Numerics/Algorithms/LinearAlgebra/{ILinearAlgebra.cs => ILinearAlgebraProvider.cs} (98%) rename src/Numerics/Algorithms/LinearAlgebra/{ManagedLinearAlgebra.cs => ManagedLinearAlgebraProvider.cs} (97%) diff --git a/src/Numerics/Algorithms/AlgorithmFactory.cs b/src/Numerics/Algorithms/AlgorithmFactory.cs deleted file mode 100644 index 4b32719f..00000000 --- a/src/Numerics/Algorithms/AlgorithmFactory.cs +++ /dev/null @@ -1,130 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://mathnet.opensourcedotnet.info -// Copyright (c) 2009 Math.NET -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -using System; -using MathNet.Numerics.Algorithms.LinearAlgebra; - -namespace MathNet.Numerics.Algorithms -{ - /// - /// Enumerates the linear algebra providers. - /// - public enum LinearAlgebraProvider - { - /// - /// Managed provider - /// - Managed, - - /// - /// User defined provider - /// - UserDefined - -/* /// - /// Intel's Math Kernel Library (MKL) Provider - /// - Mkl, - - /// - /// Automatically Tuned Linear Algebra Software (ATLAS) Provider - /// - Atlas, - - /// - /// AMD Core Math Library (ACML) Provider - /// - Acml, - - /// - /// NVIDIA Compute Unified Device Architecture (CUDA) Provider - /// - Cuda, - */ - } - - /// - /// Lets users choose which algorithm providers to use. - /// - public static class AlgorithmFactory - { - /// - /// The current linear algebra provider - starts as the managed provider. - /// - private static Type _linearAlgebraProvider = typeof(ManagedLinearAlgebra); - - /// - /// The type of the user defined linear algebra provider. - /// - private static Type _userLinearAlgebraProvider; - - /// - /// Gets the linear algebra provider. - /// - /// The linear algebra provider. - public static ILinearAlgebra LinearAlgebra - { - get { return (ILinearAlgebra) Activator.CreateInstance(_linearAlgebraProvider); } - } - - /// - /// Sets the linear algebra provider to use. - /// - /// - /// The linear algebra provider to use. - /// - public static void SetLinearAlgebraProvider(LinearAlgebraProvider provider) - { - switch (provider) - { - case LinearAlgebraProvider.Managed: - _linearAlgebraProvider = typeof(ManagedLinearAlgebra); - break; - case LinearAlgebraProvider.UserDefined: - if (_userLinearAlgebraProvider == null) - { - throw new ArgumentException(); - } - - _linearAlgebraProvider = _userLinearAlgebraProvider; - break; - } - } - - /// - /// Registers the user defined linear algebra provider. - /// - /// - /// The user defined provider. - /// - public static void RegisterLinearAlgebraProvider(Type provider) - { - if (provider == null) - { - throw new ArgumentNullException("provider"); - } - - _userLinearAlgebraProvider = provider; - } - } -} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs similarity index 98% rename from src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs rename to src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs index eb7d43eb..2875df6a 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs @@ -27,7 +27,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// Interface to linear algebra algorithms that work off 1-D arrays. /// - public interface ILinearAlgebra + public interface ILinearAlgebraProvider { /// /// Adds a scaled vector to another: y += alpha*x. diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs similarity index 97% rename from src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs rename to src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs index e87fdb33..258cd7c1 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs @@ -29,7 +29,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// The managed linear algebra provider. /// - internal class ManagedLinearAlgebra : ILinearAlgebra + public class ManagedLinearAlgebraProvider : ILinearAlgebraProvider { /// /// Adds a scaled vector to another: y += alpha*x. diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs index 89418049..e762d4b3 100644 --- a/src/Numerics/Control.cs +++ b/src/Numerics/Control.cs @@ -28,6 +28,7 @@ namespace MathNet.Numerics { + using Algorithms.LinearAlgebra; using Threading; /// @@ -43,6 +44,7 @@ namespace MathNet.Numerics CheckDistributionParameters = true; ThreadSafeRandomNumberGenerators = true; DisableParallelization = false; + LinearAlgebraProvider = new ManagedLinearAlgebraProvider(); } /// @@ -75,5 +77,14 @@ namespace MathNet.Numerics /// Gets or sets a value indicating whether parallelization shall be disabled globally. /// public static bool DisableParallelization { get; set; } + + /// + /// Gets or sets the linear algebra provider. + /// + /// The linear algebra provider. + public static ILinearAlgebraProvider LinearAlgebraProvider + { + get; set; + } } } diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs index ebf0c501..a1c168e2 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs @@ -42,11 +42,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// public class DenseVector : Vector { - /// - /// The linear algebra provider. - /// - private readonly ILinearAlgebra _linearAlgebra = AlgorithmFactory.LinearAlgebra; - /// /// Initializes a new instance of the class with a given size. /// @@ -283,7 +278,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double } else { - _linearAlgebra.AddVectorToScaledVector(Data, 1.0, denseVector.Data); + Control.LinearAlgebraProvider.AddVectorToScaledVector(Data, 1.0, denseVector.Data); } } @@ -436,7 +431,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double } else { - _linearAlgebra.AddVectorToScaledVector(Data, -1.0, denseVector.Data); + Control.LinearAlgebraProvider.AddVectorToScaledVector(Data, -1.0, denseVector.Data); } } @@ -548,7 +543,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double return; } - _linearAlgebra.ScaleArray(scalar, Data); + Control.LinearAlgebraProvider.ScaleArray(scalar, Data); } #region Vector Norms diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 9200e049..08307a18 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -44,9 +44,8 @@ - - - + + diff --git a/src/Numerics/Threading/Task.cs b/src/Numerics/Threading/Task.cs index c0a5ca12..97ffd43a 100644 --- a/src/Numerics/Threading/Task.cs +++ b/src/Numerics/Threading/Task.cs @@ -120,7 +120,7 @@ namespace MathNet.Numerics.Threading { while (!IsCompleted && !IsFaulted) { - Thread.Sleep(100); + Thread.Sleep(0); } } }