Browse Source

LA: make IIterativeSolverSetup generic & shared

pull/163/head
Christoph Ruegg 13 years ago
parent
commit
1b8cf0ec2e
  1. 2
      src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs
  2. 79
      src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolverSetup.cs
  3. 10
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
  4. 10
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
  5. 73
      src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolverSetup.cs
  6. 10
      src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
  7. 73
      src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolverSetup.cs
  8. 10
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
  9. 9
      src/Numerics/LinearAlgebra/Solvers/IIterativeSolverSetup.cs
  10. 5
      src/Numerics/Numerics.csproj

2
src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs

@ -147,7 +147,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
/// <summary>
/// Sample of user-defined solver setup
/// </summary>
public class UserBiCgStab : IIterativeSolverSetup
public class UserBiCgStab : IIterativeSolverSetup<double>
{
/// <summary>
/// Gets the type of the solver that will be created by this setup object.

79
src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolverSetup.cs

@ -1,79 +0,0 @@
// <copyright file="IIterativeSolverSetup.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 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.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
#if NOSYSNUMERICS
using Complex = Numerics.Complex;
#else
using Complex = System.Numerics.Complex;
#endif
/// <summary>
/// Defines the interface for objects that can create an iterative solver with
/// specific settings. This interface is used to pass iterative solver creation
/// setup information around.
/// </summary>
public interface IIterativeSolverSetup
{
/// <summary>
/// Gets the type of the solver that will be created by this setup object.
/// </summary>
Type SolverType { get; }
/// <summary>
/// Gets type of preconditioner, if any, that will be created by this setup object.
/// </summary>
Type PreconditionerType { get; }
/// <summary>
/// Creates a fully functional iterative solver with the default settings
/// given by this setup.
/// </summary>
/// <returns>A new <see cref="IIterativeSolver"/>.</returns>
IIterativeSolver<Complex> CreateNew();
/// <summary>
/// Gets the relative speed of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1, inclusive.</value>
double SolutionSpeed { get; }
/// <summary>
/// Gets the relative reliability of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1 inclusive.</value>
double Reliability { get; }
}
}

10
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs

@ -108,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// The collection of iterative solver setups. Stored based on the
/// ratio between the relative speed and relative accuracy.
/// </summary>
private static readonly SortedList<double, List<IIterativeSolverSetup>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup>>(new DoubleComparer());
private static readonly SortedList<double, List<IIterativeSolverSetup<Complex>>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup<Complex>>>(new DoubleComparer());
#endif
#region Solver information loading methods
@ -273,18 +273,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
interfaceTypes.Clear();
interfaceTypes.AddRange(type.GetInterfaces());
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match)))
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup<Complex>).IsAssignableFrom(match)))
{
continue;
}
// See if we actually want this type of iterative solver
IIterativeSolverSetup setup;
IIterativeSolverSetup<Complex> setup;
try
{
// If something goes wrong we just ignore it and move on with the next type.
// There should probably be a log somewhere indicating that something went wrong?
setup = (IIterativeSolverSetup)Activator.CreateInstance(type);
setup = (IIterativeSolverSetup<Complex>)Activator.CreateInstance(type);
}
catch (ArgumentException)
{
@ -327,7 +327,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
var ratio = setup.SolutionSpeed / setup.Reliability;
if (!SolverSetups.ContainsKey(ratio))
{
SolverSetups.Add(ratio, new List<IIterativeSolverSetup>());
SolverSetups.Add(ratio, new List<IIterativeSolverSetup<Complex>>());
}
var list = SolverSetups[ratio];

10
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs

@ -103,7 +103,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// The collection of iterative solver setups. Stored based on the
/// ratio between the relative speed and relative accuracy.
/// </summary>
private static readonly SortedList<double, List<IIterativeSolverSetup>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup>>(new DoubleComparer());
private static readonly SortedList<double, List<IIterativeSolverSetup<Complex32>>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup<Complex32>>>(new DoubleComparer());
#endif
#region Solver information loading methods
@ -268,18 +268,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
{
interfaceTypes.Clear();
interfaceTypes.AddRange(type.GetInterfaces());
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match)))
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup<Complex32>).IsAssignableFrom(match)))
{
continue;
}
// See if we actually want this type of iterative solver
IIterativeSolverSetup setup;
IIterativeSolverSetup<Complex32> setup;
try
{
// If something goes wrong we just ignore it and move on with the next type.
// There should probably be a log somewhere indicating that something went wrong?
setup = (IIterativeSolverSetup)Activator.CreateInstance(type);
setup = (IIterativeSolverSetup<Complex32>)Activator.CreateInstance(type);
}
catch (ArgumentException)
{
@ -322,7 +322,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
var ratio = setup.SolutionSpeed / setup.Reliability;
if (!SolverSetups.ContainsKey(ratio))
{
SolverSetups.Add(ratio, new List<IIterativeSolverSetup>());
SolverSetups.Add(ratio, new List<IIterativeSolverSetup<Complex32>>());
}
var list = SolverSetups[ratio];

73
src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolverSetup.cs

@ -1,73 +0,0 @@
// <copyright file="IIterativeSolverSetup.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 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 MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
{
using System;
/// <summary>
/// Defines the interface for objects that can create an iterative solver with
/// specific settings. This interface is used to pass iterative solver creation
/// setup information around.
/// </summary>
public interface IIterativeSolverSetup
{
/// <summary>
/// Gets the type of the solver that will be created by this setup object.
/// </summary>
Type SolverType { get; }
/// <summary>
/// Gets type of preconditioner, if any, that will be created by this setup object.
/// </summary>
Type PreconditionerType { get; }
/// <summary>
/// Creates a fully functional iterative solver with the default settings
/// given by this setup.
/// </summary>
/// <returns>A new <see cref="IIterativeSolver"/>.</returns>
IIterativeSolver<double> CreateNew();
/// <summary>
/// Gets the relative speed of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1, inclusive.</value>
double SolutionSpeed { get; }
/// <summary>
/// Gets the relative reliability of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1 inclusive.</value>
double Reliability { get; }
}
}

10
src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs

@ -98,7 +98,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// The collection of iterative solver setups. Stored based on the
/// ratio between the relative speed and relative accuracy.
/// </summary>
private static readonly SortedList<double, List<IIterativeSolverSetup>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup>>(new DoubleComparer());
private static readonly SortedList<double, List<IIterativeSolverSetup<double>>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup<double>>>(new DoubleComparer());
#endif
#region Solver information loading methods
@ -263,18 +263,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
{
interfaceTypes.Clear();
interfaceTypes.AddRange(type.GetInterfaces());
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match)))
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup<double>).IsAssignableFrom(match)))
{
continue;
}
// See if we actually want this type of iterative solver
IIterativeSolverSetup setup;
IIterativeSolverSetup<double> setup;
try
{
// If something goes wrong we just ignore it and move on with the next type.
// There should probably be a log somewhere indicating that something went wrong?
setup = (IIterativeSolverSetup)Activator.CreateInstance(type);
setup = (IIterativeSolverSetup<double>)Activator.CreateInstance(type);
}
catch (ArgumentException)
{
@ -317,7 +317,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
var ratio = setup.SolutionSpeed / setup.Reliability;
if (!SolverSetups.ContainsKey(ratio))
{
SolverSetups.Add(ratio, new List<IIterativeSolverSetup>());
SolverSetups.Add(ratio, new List<IIterativeSolverSetup<double>>());
}
var list = SolverSetups[ratio];

73
src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolverSetup.cs

@ -1,73 +0,0 @@
// <copyright file="IIterativeSolverSetup.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 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 MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
{
using System;
/// <summary>
/// Defines the interface for objects that can create an iterative solver with
/// specific settings. This interface is used to pass iterative solver creation
/// setup information around.
/// </summary>
public interface IIterativeSolverSetup
{
/// <summary>
/// Gets the type of the solver that will be created by this setup object.
/// </summary>
Type SolverType { get; }
/// <summary>
/// Gets type of preconditioner, if any, that will be created by this setup object.
/// </summary>
Type PreconditionerType { get; }
/// <summary>
/// Creates a fully functional iterative solver with the default settings
/// given by this setup.
/// </summary>
/// <returns>A new <see cref="IIterativeSolver"/>.</returns>
IIterativeSolver<float> CreateNew();
/// <summary>
/// Gets the relative speed of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1, inclusive.</value>
double SolutionSpeed { get; }
/// <summary>
/// Gets the relative reliability of the solver.
/// </summary>
/// <value>Returns a value between 0 and 1 inclusive.</value>
double Reliability { get; }
}
}

10
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs

@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// The collection of iterative solver setups. Stored based on the
/// ratio between the relative speed and relative accuracy.
/// </summary>
private static readonly SortedList<double, List<IIterativeSolverSetup>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup>>(new DoubleComparer());
private static readonly SortedList<double, List<IIterativeSolverSetup<float>>> SolverSetups = new SortedList<double, List<IIterativeSolverSetup<float>>>(new DoubleComparer());
#endif
#region Solver information loading methods
@ -266,18 +266,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
{
interfaceTypes.Clear();
interfaceTypes.AddRange(type.GetInterfaces());
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match)))
if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup<float>).IsAssignableFrom(match)))
{
continue;
}
// See if we actually want this type of iterative solver
IIterativeSolverSetup setup;
IIterativeSolverSetup<float> setup;
try
{
// If something goes wrong we just ignore it and move on with the next type.
// There should probably be a log somewhere indicating that something went wrong?
setup = (IIterativeSolverSetup)Activator.CreateInstance(type);
setup = (IIterativeSolverSetup<float>)Activator.CreateInstance(type);
}
catch (ArgumentException)
{
@ -320,7 +320,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
var ratio = setup.SolutionSpeed / setup.Reliability;
if (!SolverSetups.ContainsKey(ratio))
{
SolverSetups.Add(ratio, new List<IIterativeSolverSetup>());
SolverSetups.Add(ratio, new List<IIterativeSolverSetup<float>>());
}
var list = SolverSetups[ratio];

9
src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolverSetup.cs → src/Numerics/LinearAlgebra/Solvers/IIterativeSolverSetup.cs

@ -29,18 +29,15 @@
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
namespace MathNet.Numerics.LinearAlgebra.Solvers
{
using Numerics;
/// <summary>
/// Defines the interface for objects that can create an iterative solver with
/// specific settings. This interface is used to pass iterative solver creation
/// setup information around.
/// </summary>
public interface IIterativeSolverSetup
public interface IIterativeSolverSetup<T> where T : struct, IEquatable<T>, IFormattable
{
/// <summary>
/// Gets the type of the solver that will be created by this setup object.
@ -57,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// given by this setup.
/// </summary>
/// <returns>A new <see cref="IIterativeSolver{T}"/>.</returns>
IIterativeSolver<Complex32> CreateNew();
IIterativeSolver<T> CreateNew();
/// <summary>
/// Gets the relative speed of the solver.

5
src/Numerics/Numerics.csproj

@ -190,7 +190,6 @@
<Compile Include="LinearAlgebra\Complex32\Factorization\QR.cs" />
<Compile Include="LinearAlgebra\Complex32\Factorization\Svd.cs" />
<Compile Include="LinearAlgebra\Complex32\Matrix.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\IIterativeSolverSetup.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\Preconditioners\IPreConditioner.cs" />
<Compile Include="LinearAlgebra\Complex32\SparseMatrix.cs" />
<Compile Include="LinearAlgebra\Complex32\Vector.cs" />
@ -207,7 +206,6 @@
<Compile Include="LinearAlgebra\Complex\Factorization\QR.cs" />
<Compile Include="LinearAlgebra\Complex\Factorization\Svd.cs" />
<Compile Include="LinearAlgebra\Complex\Matrix.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\IIterativeSolverSetup.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\Preconditioners\IPreConditioner.cs" />
<Compile Include="LinearAlgebra\Complex\SparseMatrix.cs" />
<Compile Include="LinearAlgebra\Complex\Vector.cs" />
@ -222,7 +220,7 @@
<Compile Include="LinearAlgebra\Double\Factorization\LU.cs" />
<Compile Include="LinearAlgebra\Double\Matrix.cs" />
<Compile Include="LinearAlgebra\Solvers\IIterativeSolver.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\IIterativeSolverSetup.cs" />
<Compile Include="LinearAlgebra\Solvers\IIterativeSolverSetup.cs" />
<Compile Include="LinearAlgebra\Solvers\IIterator.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\Preconditioners\IPreConditioner.cs" />
<Compile Include="LinearAlgebra\Solvers\StopCriterium\IIterationStopCriterium.cs" />
@ -312,7 +310,6 @@
<Compile Include="LinearAlgebra\Single\Factorization\UserQR.cs" />
<Compile Include="LinearAlgebra\Single\Factorization\UserSvd.cs" />
<Compile Include="LinearAlgebra\Single\Matrix.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\IIterativeSolverSetup.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\BiCgStab.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\CompositeSolver.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterative\GpBiCg.cs" />

Loading…
Cancel
Save