Browse Source

Removed the Algorithm factory, now just registering the providers in the Control class

Made the managed provider public
la-knuth
Marcus Cuda 17 years ago
parent
commit
1d8645c15e
  1. 130
      src/Numerics/Algorithms/AlgorithmFactory.cs
  2. 2
      src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs
  3. 2
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs
  4. 11
      src/Numerics/Control.cs
  5. 11
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  6. 5
      src/Numerics/Numerics.csproj
  7. 2
      src/Numerics/Threading/Task.cs

130
src/Numerics/Algorithms/AlgorithmFactory.cs

@ -1,130 +0,0 @@
// <copyright file="AlgorithmFactory.cs" company="Math.NET">
// 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.
// </copyright>
using System;
using MathNet.Numerics.Algorithms.LinearAlgebra;
namespace MathNet.Numerics.Algorithms
{
/// <summary>
/// Enumerates the linear algebra providers.
/// </summary>
public enum LinearAlgebraProvider
{
/// <summary>
/// Managed provider
/// </summary>
Managed,
/// <summary>
/// User defined provider
/// </summary>
UserDefined
/* /// <summary>
/// Intel's Math Kernel Library (MKL) Provider
/// </summary>
Mkl,
/// <summary>
/// Automatically Tuned Linear Algebra Software (ATLAS) Provider
/// </summary>
Atlas,
/// <summary>
/// AMD Core Math Library (ACML) Provider
/// </summary>
Acml,
/// <summary>
/// NVIDIA Compute Unified Device Architecture (CUDA) Provider
/// </summary>
Cuda,
*/
}
/// <summary>
/// Lets users choose which algorithm providers to use.
/// </summary>
public static class AlgorithmFactory
{
/// <summary>
/// The current linear algebra provider - starts as the managed provider.
/// </summary>
private static Type _linearAlgebraProvider = typeof(ManagedLinearAlgebra);
/// <summary>
/// The type of the user defined linear algebra provider.
/// </summary>
private static Type _userLinearAlgebraProvider;
/// <summary>
/// Gets the linear algebra provider.
/// </summary>
/// <value>The linear algebra provider.</value>
public static ILinearAlgebra LinearAlgebra
{
get { return (ILinearAlgebra) Activator.CreateInstance(_linearAlgebraProvider); }
}
/// <summary>
/// Sets the linear algebra provider to use.
/// </summary>
/// <param name="provider">
/// The linear algebra provider to use.
/// </param>
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;
}
}
/// <summary>
/// Registers the user defined linear algebra provider.
/// </summary>
/// <param name="provider">
/// The user defined provider.
/// </param>
public static void RegisterLinearAlgebraProvider(Type provider)
{
if (provider == null)
{
throw new ArgumentNullException("provider");
}
_userLinearAlgebraProvider = provider;
}
}
}

2
src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebra.cs → src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs

@ -27,7 +27,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <summary>
/// Interface to linear algebra algorithms that work off 1-D arrays.
/// </summary>
public interface ILinearAlgebra
public interface ILinearAlgebraProvider
{
/// <summary>
/// Adds a scaled vector to another: <c>y += alpha*x</c>.

2
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebra.cs → src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs

@ -29,7 +29,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <summary>
/// The managed linear algebra provider.
/// </summary>
internal class ManagedLinearAlgebra : ILinearAlgebra
public class ManagedLinearAlgebraProvider : ILinearAlgebraProvider
{
/// <summary>
/// Adds a scaled vector to another: <c>y += alpha*x</c>.

11
src/Numerics/Control.cs

@ -28,6 +28,7 @@
namespace MathNet.Numerics
{
using Algorithms.LinearAlgebra;
using Threading;
/// <summary>
@ -43,6 +44,7 @@ namespace MathNet.Numerics
CheckDistributionParameters = true;
ThreadSafeRandomNumberGenerators = true;
DisableParallelization = false;
LinearAlgebraProvider = new ManagedLinearAlgebraProvider();
}
/// <summary>
@ -75,5 +77,14 @@ namespace MathNet.Numerics
/// Gets or sets a value indicating whether parallelization shall be disabled globally.
/// </summary>
public static bool DisableParallelization { get; set; }
/// <summary>
/// Gets or sets the linear algebra provider.
/// </summary>
/// <value>The linear algebra provider.</value>
public static ILinearAlgebraProvider LinearAlgebraProvider
{
get; set;
}
}
}

11
src/Numerics/LinearAlgebra/Double/DenseVector.cs

@ -42,11 +42,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
public class DenseVector : Vector
{
/// <summary>
/// The linear algebra provider.
/// </summary>
private readonly ILinearAlgebra _linearAlgebra = AlgorithmFactory.LinearAlgebra;
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size.
/// </summary>
@ -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

5
src/Numerics/Numerics.csproj

@ -44,9 +44,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Algorithms\AlgorithmFactory.cs" />
<Compile Include="Algorithms\LinearAlgebra\ILinearAlgebra.cs" />
<Compile Include="Algorithms\LinearAlgebra\ManagedLinearAlgebra.cs" />
<Compile Include="Algorithms\LinearAlgebra\ILinearAlgebraProvider.cs" />
<Compile Include="Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.cs" />
<Compile Include="Combinatorics.cs" />
<Compile Include="Complex.cs" />
<Compile Include="Constants.cs" />

2
src/Numerics/Threading/Task.cs

@ -120,7 +120,7 @@ namespace MathNet.Numerics.Threading
{
while (!IsCompleted && !IsFaulted)
{
Thread.Sleep(100);
Thread.Sleep(0);
}
}
}

Loading…
Cancel
Save