Browse Source

LA: integrate iterative solvers into matrix type, leads to significant simplification

optimization-1
Christoph Ruegg 13 years ago
parent
commit
ad501d0f33
  1. 2
      src/Examples/LinearAlgebra/IterativeSolvers/BiCgStabSolver.cs
  2. 2
      src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs
  3. 2
      src/Examples/LinearAlgebra/IterativeSolvers/GpBiCgSolver.cs
  4. 2
      src/Examples/LinearAlgebra/IterativeSolvers/MlkBiCgStabSolver.cs
  5. 2
      src/Examples/LinearAlgebra/IterativeSolvers/TFQMRSolver.cs
  6. 54
      src/Numerics/LinearAlgebra/Builder.cs
  7. 68
      src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs
  8. 75
      src/Numerics/LinearAlgebra/Complex/Solvers/CompositeSolver.cs
  9. 68
      src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
  10. 73
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
  11. 68
      src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
  12. 68
      src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs
  13. 68
      src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs
  14. 75
      src/Numerics/LinearAlgebra/Complex32/Solvers/CompositeSolver.cs
  15. 68
      src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
  16. 68
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
  17. 68
      src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
  18. 68
      src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs
  19. 68
      src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs
  20. 75
      src/Numerics/LinearAlgebra/Double/Solvers/CompositeSolver.cs
  21. 68
      src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
  22. 66
      src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
  23. 68
      src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
  24. 68
      src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs
  25. 78
      src/Numerics/LinearAlgebra/Matrix.Factorization.cs
  26. 284
      src/Numerics/LinearAlgebra/Matrix.Solve.cs
  27. 68
      src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs
  28. 75
      src/Numerics/LinearAlgebra/Single/Solvers/CompositeSolver.cs
  29. 68
      src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
  30. 66
      src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
  31. 68
      src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
  32. 68
      src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs
  33. 29
      src/Numerics/LinearAlgebra/Solvers/IIterativeSolver.cs
  34. 8
      src/Numerics/LinearAlgebra/Solvers/Iterator.cs
  35. 6
      src/Numerics/Numerics.csproj
  36. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs
  37. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs
  38. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs
  39. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs
  40. 18
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs
  41. 14
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs
  42. 18
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs
  43. 18
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs
  44. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs
  45. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs
  46. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs
  47. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs
  48. 18
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs
  49. 18
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs
  50. 20
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs
  51. 18
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs

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

@ -111,7 +111,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
var solver = new BiCgStab();
// 1. Solve the matrix equation
var resultX = solver.Solve(matrixA, vectorB, monitor);
var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
Console.WriteLine(@"1. Solve the matrix equation");
Console.WriteLine();

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

@ -112,7 +112,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
var solver = new CompositeSolver(SolverSetup<double>.LoadFromAssembly(Assembly.GetExecutingAssembly()));
// 1. Solve the matrix equation
var resultX = solver.Solve(matrixA, vectorB, monitor);
var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
Console.WriteLine(@"1. Solve the matrix equation");
Console.WriteLine();

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

@ -109,7 +109,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
var solver = new GpBiCg();
// 1. Solve the matrix equation
var resultX = solver.Solve(matrixA, vectorB, monitor);
var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
Console.WriteLine(@"1. Solve the matrix equation");
Console.WriteLine();

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

@ -110,7 +110,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
var solver = new MlkBiCgStab();
// 1. Solve the matrix equation
var resultX = solver.Solve(matrixA, vectorB, monitor);
var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
Console.WriteLine(@"1. Solve the matrix equation");
Console.WriteLine();

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

@ -110,7 +110,7 @@ namespace Examples.LinearAlgebra.IterativeSolversExamples
var solver = new TFQMR();
// 1. Solve the matrix equation
var resultX = solver.Solve(matrixA, vectorB, monitor);
var resultX = matrixA.SolveIterative(vectorB, solver, monitor);
Console.WriteLine(@"1. Solve the matrix equation");
Console.WriteLine();

54
src/Numerics/LinearAlgebra/Builder.cs

@ -29,9 +29,12 @@
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Double
{
using Solvers.StopCriterium;
internal class GenericBuilder : IGenericBuilder<double>
{
public double Zero
@ -63,11 +66,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
return new SparseVector(size);
}
public IIterationStopCriterium<double>[] IterativeSolverStopCriteria(int maxIterations)
{
return new IIterationStopCriterium<double>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<double>(maxIterations),
new ResidualStopCriterium()
};
}
}
}
namespace MathNet.Numerics.LinearAlgebra.Single
{
using Solvers.StopCriterium;
internal class GenericBuilder : IGenericBuilder<float>
{
public float Zero
@ -99,11 +115,23 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
return new SparseVector(size);
}
public IIterationStopCriterium<float>[] IterativeSolverStopCriteria(int maxIterations)
{
return new IIterationStopCriterium<float>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<float>(maxIterations),
new ResidualStopCriterium()
};
}
}
}
namespace MathNet.Numerics.LinearAlgebra.Complex
{
using Solvers.StopCriterium;
#if NOSYSNUMERICS
using Complex = Numerics.Complex;
@ -142,11 +170,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
return new SparseVector(size);
}
public IIterationStopCriterium<Complex>[] IterativeSolverStopCriteria(int maxIterations)
{
return new IIterationStopCriterium<Complex>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<Complex>(maxIterations),
new ResidualStopCriterium()
};
}
}
}
namespace MathNet.Numerics.LinearAlgebra.Complex32
{
using Solvers.StopCriterium;
internal class GenericBuilder : IGenericBuilder<Numerics.Complex32>
{
public Numerics.Complex32 Zero
@ -178,6 +219,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
return new SparseVector(size);
}
public IIterationStopCriterium<Numerics.Complex32>[] IterativeSolverStopCriteria(int maxIterations)
{
return new IIterationStopCriterium<Numerics.Complex32>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<Numerics.Complex32>(maxIterations),
new ResidualStopCriterium()
};
}
}
}
@ -232,6 +284,8 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary>
/// <param name="size">The size of the vector.</param>
Vector<T> SparseVector(int size);
IIterationStopCriterium<T>[] IterativeSolverStopCriteria(int maxIterations = 1000);
}
internal static class Builder<T> where T : struct, IEquatable<T>, IFormattable

68
src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs

@ -98,7 +98,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <param name="result">The result <see cref="Vector"/>, <c>x</c>.</param>
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator, IPreconditioner<Complex> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -115,11 +115,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, result);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Complex>();
}
if (preconditioner == null)
@ -277,67 +275,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <param name="result">The result <see cref="Matrix"/>, <c>X</c></param>
public void Solve(Matrix<Complex> matrix, Matrix<Complex> input, Matrix<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="vector">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <returns>The result <see cref="Vector"/>, <c>x</c>.</returns>
public Vector<Complex> Solve(Matrix<Complex> matrix, Vector<Complex> vector, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <returns>The result <see cref="Matrix"/>, <c>X</c>.</returns>
public Matrix<Complex> Solve(Matrix<Complex> matrix, Matrix<Complex> input, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

75
src/Numerics/LinearAlgebra/Complex/Solvers/CompositeSolver.cs

@ -77,7 +77,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator, IPreconditioner<Complex> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -89,11 +89,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Complex>();
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
// Create a copy of the solution and result vectors so we can use them
@ -112,7 +115,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
iterator.Reset();
// Start the solver
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2);
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2 ?? preconditioner);
status = iterator.Status;
}
catch (Exception)
@ -151,67 +154,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
}
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Complex> matrix, Matrix<Complex> input, Matrix<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Complex> Solve(Matrix<Complex> matrix, Vector<Complex> vector, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Complex> Solve(Matrix<Complex> matrix, Matrix<Complex> input, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs

@ -161,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator, IPreconditioner<Complex> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -173,11 +173,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Complex>();
}
if (preconditioner == null)
@ -376,67 +374,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Complex> matrix, Matrix<Complex> input, Matrix<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Complex> Solve(Matrix<Complex> matrix, Vector<Complex> vector, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Complex> Solve(Matrix<Complex> matrix, Matrix<Complex> input, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

73
src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs

@ -1,73 +0,0 @@
// <copyright file="Iterator.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.Complex.Solvers.StopCriterium;
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>
/// An iterator that is used to check if an iterative calculation should continue or stop.
/// </summary>
public static class Iterator
{
// TODO: Refactor
/// <summary>
/// Creates the default stop criteria.
/// </summary>
public static IIterationStopCriterium<Complex>[] CreateDefaultStopCriteria()
{
return new IIterationStopCriterium<Complex>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<Complex>(),
new ResidualStopCriterium()
};
}
/// <summary>
/// Creates a default iterator with all the default stop criteria.
/// </summary>
public static Iterator<Complex> CreateDefault()
{
return new Iterator<Complex>(CreateDefaultStopCriteria());
}
}
}

68
src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs

@ -247,7 +247,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator, IPreconditioner<Complex> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -259,11 +259,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Complex>();
}
if (preconditioner == null)
@ -541,67 +539,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// copy the temporary result to the real result vector
xtemp.CopyTo(result);
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Complex> matrix, Matrix<Complex> input, Matrix<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Complex> Solve(Matrix<Complex> matrix, Vector<Complex> vector, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Complex> Solve(Matrix<Complex> matrix, Matrix<Complex> input, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs

@ -95,7 +95,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
public void Solve(Matrix<Complex> matrix, Vector<Complex> input, Vector<Complex> result, Iterator<Complex> iterator, IPreconditioner<Complex> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -107,11 +107,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Complex>();
}
if (preconditioner == null)
@ -277,67 +275,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Complex> matrix, Matrix<Complex> input, Matrix<Complex> result, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Complex>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Complex>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Complex> Solve(Matrix<Complex> matrix, Vector<Complex> vector, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Complex> Solve(Matrix<Complex> matrix, Matrix<Complex> input, Iterator<Complex> iterator = null, IPreconditioner<Complex> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs

@ -91,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <param name="result">The result <see cref="Vector"/>, <c>x</c>.</param>
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator, IPreconditioner<Numerics.Complex32> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -108,11 +108,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Numerics.Complex32>();
}
if (preconditioner == null)
@ -270,67 +268,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <param name="result">The result <see cref="Matrix"/>, <c>X</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Matrix<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="vector">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <returns>The result <see cref="Vector"/>, <c>x</c>.</returns>
public Vector<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> vector, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <returns>The result <see cref="Matrix"/>, <c>X</c>.</returns>
public Matrix<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

75
src/Numerics/LinearAlgebra/Complex32/Solvers/CompositeSolver.cs

@ -70,7 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator, IPreconditioner<Numerics.Complex32> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -82,11 +82,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Numerics.Complex32>();
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
// Create a copy of the solution and result vectors so we can use them
@ -105,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
iterator.Reset();
// Start the solver
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2);
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2 ?? preconditioner);
status = iterator.Status;
}
catch (Exception)
@ -144,67 +147,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
}
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Matrix<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> vector, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs

@ -154,7 +154,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator, IPreconditioner<Numerics.Complex32> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -171,11 +171,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Numerics.Complex32>();
}
if (preconditioner == null)
@ -374,67 +372,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Matrix<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> vector, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs

@ -1,68 +0,0 @@
// <copyright file="Iterator.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.Complex32.Solvers.StopCriterium;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
using Numerics;
/// <summary>
/// An iterator that is used to check if an iterative calculation should continue or stop.
/// </summary>
public static class Iterator
{
// TODO: Refactor
/// <summary>
/// Creates the default stop criteria.
/// </summary>
public static IIterationStopCriterium<Complex32>[] CreateDefaultStopCriteria()
{
return new IIterationStopCriterium<Complex32>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<Complex32>(),
new ResidualStopCriterium()
};
}
/// <summary>
/// Creates a default iterator with all the default stop criteria.
/// </summary>
public static Iterator<Complex32> CreateDefault()
{
return new Iterator<Complex32>(CreateDefaultStopCriteria());
}
}
}

68
src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs

@ -240,7 +240,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator, IPreconditioner<Numerics.Complex32> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -257,11 +257,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Numerics.Complex32>();
}
if (preconditioner == null)
@ -539,67 +537,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// copy the temporary result to the real result vector
xtemp.CopyTo(result);
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Matrix<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> vector, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs

@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
public void Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> input, Vector<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator, IPreconditioner<Numerics.Complex32> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -104,11 +104,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<Numerics.Complex32>();
}
if (preconditioner == null)
@ -274,67 +272,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Matrix<Numerics.Complex32> result, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix, result);
}
if (iterator == null)
{
iterator = new Iterator<Numerics.Complex32>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<Numerics.Complex32>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Vector<Numerics.Complex32> vector, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<Numerics.Complex32> Solve(Matrix<Numerics.Complex32> matrix, Matrix<Numerics.Complex32> input, Iterator<Numerics.Complex32> iterator = null, IPreconditioner<Numerics.Complex32> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs

@ -91,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <param name="result">The result <see cref="Vector"/>, <c>x</c>.</param>
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator, IPreconditioner<double> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -108,11 +108,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<double>();
}
if (preconditioner == null)
@ -270,67 +268,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <param name="result">The result <see cref="Matrix"/>, <c>X</c></param>
public void Solve(Matrix<double> matrix, Matrix<double> input, Matrix<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="vector">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <returns>The result <see cref="Vector"/>, <c>x</c>.</returns>
public Vector<double> Solve(Matrix<double> matrix, Vector<double> vector, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <returns>The result <see cref="Matrix"/>, <c>X</c>.</returns>
public Matrix<double> Solve(Matrix<double> matrix, Matrix<double> input, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

75
src/Numerics/LinearAlgebra/Double/Solvers/CompositeSolver.cs

@ -70,7 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator, IPreconditioner<double> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -82,11 +82,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<double>();
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
// Create a copy of the solution and result vectors so we can use them
@ -105,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
iterator.Reset();
// Start the solver
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2);
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2 ?? preconditioner);
status = iterator.Status;
}
catch (Exception)
@ -144,67 +147,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
}
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<double> matrix, Matrix<double> input, Matrix<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<double> Solve(Matrix<double> matrix, Vector<double> vector, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<double> Solve(Matrix<double> matrix, Matrix<double> input, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs

@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator, IPreconditioner<double> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -177,11 +177,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<double>();
}
if (preconditioner == null)
@ -380,67 +378,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<double> matrix, Matrix<double> input, Matrix<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<double> Solve(Matrix<double> matrix, Vector<double> vector, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<double> Solve(Matrix<double> matrix, Matrix<double> input, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

66
src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs

@ -1,66 +0,0 @@
// <copyright file="Iterator.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-2013 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.Double.Solvers.StopCriterium;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
{
/// <summary>
/// An iterator that is used to check if an iterative calculation should continue or stop.
/// </summary>
public static class Iterator
{
// TODO: Refactor
/// <summary>
/// Creates the default stop criteria.
/// </summary>
public static IIterationStopCriterium<double>[] CreateDefaultStopCriteria()
{
return new IIterationStopCriterium<double>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<double>(),
new ResidualStopCriterium()
};
}
/// <summary>
/// Creates a default iterator with all the default stop criteria.
/// </summary>
public static Iterator<double> CreateDefault()
{
return new Iterator<double>(CreateDefaultStopCriteria());
}
}
}

68
src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs

@ -240,7 +240,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator, IPreconditioner<double> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -257,11 +257,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<double>();
}
if (preconditioner == null)
@ -539,67 +537,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// copy the temporary result to the real result vector
xtemp.CopyTo(result);
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<double> matrix, Matrix<double> input, Matrix<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<double> Solve(Matrix<double> matrix, Vector<double> vector, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<double> Solve(Matrix<double> matrix, Matrix<double> input, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs

@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
public void Solve(Matrix<double> matrix, Vector<double> input, Vector<double> result, Iterator<double> iterator, IPreconditioner<double> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -104,11 +104,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<double>();
}
if (preconditioner == null)
@ -274,67 +272,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<double> matrix, Matrix<double> input, Matrix<double> result, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<double>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<double>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<double> Solve(Matrix<double> matrix, Vector<double> vector, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<double> Solve(Matrix<double> matrix, Matrix<double> input, Iterator<double> iterator = null, IPreconditioner<double> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

78
src/Numerics/LinearAlgebra/Matrix.Factorization.cs

@ -1,78 +0,0 @@
// <copyright file="Matrix.Factorization.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-2013 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.Factorization;
namespace MathNet.Numerics.LinearAlgebra
{
/// <summary>
/// Defines the base class for <c>Matrix</c> classes.
/// </summary>
public abstract partial class Matrix<T>
{
/// <summary>
/// Computes the Cholesky decomposition for a matrix.
/// </summary>
/// <returns>The Cholesky decomposition object.</returns>
public abstract Cholesky<T> Cholesky();
/// <summary>
/// Computes the LU decomposition for a matrix.
/// </summary>
/// <returns>The LU decomposition object.</returns>
public abstract LU<T> LU();
/// <summary>
/// Computes the QR decomposition for a matrix.
/// </summary>
/// <param name="method">The type of QR factorization to perform.</param>
/// <returns>The QR decomposition object.</returns>
public abstract QR<T> QR(QRMethod method = QRMethod.Thin);
/// <summary>
/// Computes the QR decomposition for a matrix using Modified Gram-Schmidt Orthogonalization.
/// </summary>
/// <returns>The QR decomposition object.</returns>
public abstract GramSchmidt<T> GramSchmidt();
/// <summary>
/// Computes the SVD decomposition for a matrix.
/// </summary>
/// <param name="computeVectors">Compute the singular U and VT vectors or not.</param>
/// <returns>The SVD decomposition object.</returns>
public abstract Svd<T> Svd(bool computeVectors);
/// <summary>
/// Computes the EVD decomposition for a matrix.
/// </summary>
/// <returns>The EVD decomposition object.</returns>
public abstract Evd<T> Evd();
}
}

284
src/Numerics/LinearAlgebra/Matrix.Solve.cs

@ -0,0 +1,284 @@
// <copyright file="Matrix.Solve.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-2013 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.Factorization;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra
{
/// <summary>
/// Defines the base class for <c>Matrix</c> classes.
/// </summary>
public abstract partial class Matrix<T>
{
// Factorizations
/// <summary>
/// Computes the Cholesky decomposition for a matrix.
/// </summary>
/// <returns>The Cholesky decomposition object.</returns>
public abstract Cholesky<T> Cholesky();
/// <summary>
/// Computes the LU decomposition for a matrix.
/// </summary>
/// <returns>The LU decomposition object.</returns>
public abstract LU<T> LU();
/// <summary>
/// Computes the QR decomposition for a matrix.
/// </summary>
/// <param name="method">The type of QR factorization to perform.</param>
/// <returns>The QR decomposition object.</returns>
public abstract QR<T> QR(QRMethod method = QRMethod.Thin);
/// <summary>
/// Computes the QR decomposition for a matrix using Modified Gram-Schmidt Orthogonalization.
/// </summary>
/// <returns>The QR decomposition object.</returns>
public abstract GramSchmidt<T> GramSchmidt();
/// <summary>
/// Computes the SVD decomposition for a matrix.
/// </summary>
/// <param name="computeVectors">Compute the singular U and VT vectors or not.</param>
/// <returns>The SVD decomposition object.</returns>
public abstract Svd<T> Svd(bool computeVectors);
/// <summary>
/// Computes the EVD decomposition for a matrix.
/// </summary>
/// <returns>The EVD decomposition object.</returns>
public abstract Evd<T> Evd();
// Iterative Solvers: Try
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix (this matrix), b is the solution vector and x is the unknown vector.
/// </summary>
/// <param name="input">The solution vector <c>b</c>.</param>
/// <param name="result">The result vector <c>x</c>.</param>
/// <param name="solver">The iterative solver to use.</param>
public IterationStatus TrySolveIterative(Vector<T> input, Vector<T> result, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, Iterator<T> iterator = null)
{
if (iterator == null)
{
iterator = new Iterator<T>(Builder.IterativeSolverStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<T>();
}
solver.Solve(this, input, result, iterator, preconditioner);
return iterator.Status;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix (this matrix), B is the solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="input">The solution matrix <c>B</c>.</param>
/// <param name="result">The result matrix <c>X</c></param>
/// <param name="solver">The iterative solver to use.</param>
public IterationStatus TrySolveIterative(Matrix<T> input, Matrix<T> result, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, Iterator<T> iterator = null)
{
if (RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, input, result);
}
if (iterator == null)
{
iterator = new Iterator<T>(Builder.IterativeSolverStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<T>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Builder.DenseVector(RowCount);
solver.Solve(this, input.Column(column), solution, iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
return iterator.Status;
}
public IterationStatus TrySolveIterative(Vector<T> input, Vector<T> result, IIterativeSolver<T> solver, Iterator<T> iterator)
{
var preconditioner = new UnitPreconditioner<T>();
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Matrix<T> input, Matrix<T> result, IIterativeSolver<T> solver, Iterator<T> iterator)
{
var preconditioner = new UnitPreconditioner<T>();
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Vector<T> input, Vector<T> result, IIterativeSolver<T> solver)
{
var preconditioner = new UnitPreconditioner<T>();
var iterator = new Iterator<T>(Builder.IterativeSolverStopCriteria());
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Matrix<T> input, Matrix<T> result, IIterativeSolver<T> solver)
{
var preconditioner = new UnitPreconditioner<T>();
var iterator = new Iterator<T>(Builder.IterativeSolverStopCriteria());
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Vector<T> input, Vector<T> result, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, params IIterationStopCriterium<T>[] stopCriteria)
{
var iterator = new Iterator<T>(stopCriteria.Length == 0 ? Builder.IterativeSolverStopCriteria() : stopCriteria);
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Matrix<T> input, Matrix<T> result, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, params IIterationStopCriterium<T>[] stopCriteria)
{
var iterator = new Iterator<T>(stopCriteria.Length == 0 ? Builder.IterativeSolverStopCriteria() : stopCriteria);
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Vector<T> input, Vector<T> result, IIterativeSolver<T> solver, params IIterationStopCriterium<T>[] stopCriteria)
{
var preconditioner = new UnitPreconditioner<T>();
var iterator = new Iterator<T>(stopCriteria.Length == 0 ? Builder.IterativeSolverStopCriteria() : stopCriteria);
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
public IterationStatus TrySolveIterative(Matrix<T> input, Matrix<T> result, IIterativeSolver<T> solver, params IIterationStopCriterium<T>[] stopCriteria)
{
var preconditioner = new UnitPreconditioner<T>();
var iterator = new Iterator<T>(stopCriteria.Length == 0 ? Builder.IterativeSolverStopCriteria() : stopCriteria);
return TrySolveIterative(input, result, solver, preconditioner, iterator);
}
// Iterative Solvers: Simple
public Vector<T> SolveIterative(Vector<T> input, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, Iterator<T> iterator)
{
var result = Builder.DenseVector(RowCount);
TrySolveIterative(input, result, solver, preconditioner, iterator);
return result;
}
public Matrix<T> SolveIterative(Matrix<T> input, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, Iterator<T> iterator)
{
var result = Builder.DenseMatrix(input.RowCount, input.ColumnCount);
TrySolveIterative(input, result, solver, preconditioner, iterator);
return result;
}
public Vector<T> SolveIterative(Vector<T> input, IIterativeSolver<T> solver, Iterator<T> iterator)
{
var result = Builder.DenseVector(RowCount);
TrySolveIterative(input, result, solver, iterator);
return result;
}
public Matrix<T> SolveIterative(Matrix<T> input, IIterativeSolver<T> solver, Iterator<T> iterator)
{
var result = Builder.DenseMatrix(input.RowCount, input.ColumnCount);
TrySolveIterative(input, result, solver, iterator);
return result;
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix (this matrix), b is the solution vector and x is the unknown vector.
/// </summary>
/// <param name="input">The solution vector <c>b</c>.</param>
/// <param name="solver">The iterative solver to use.</param>
/// <returns>The result vector <c>x</c>.</returns>
public Vector<T> SolveIterative(Vector<T> input, IIterativeSolver<T> solver)
{
var result = Builder.DenseVector(RowCount);
TrySolveIterative(input, result, solver);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix (this matrix), B is the solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="input">The solution matrix <c>B</c>.</param>
/// <param name="solver">The iterative solver to use.</param>
/// <returns>The result matrix <c>X</c>.</returns>
public Matrix<T> SolveIterative(Matrix<T> input, IIterativeSolver<T> solver)
{
var result = Builder.DenseMatrix(input.RowCount, input.ColumnCount);
TrySolveIterative(input, result, solver);
return result;
}
public Vector<T> SolveIterative(Vector<T> input, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, params IIterationStopCriterium<T>[] stopCriteria)
{
var result = Builder.DenseVector(RowCount);
TrySolveIterative(input, result, solver, preconditioner, stopCriteria);
return result;
}
public Matrix<T> SolveIterative(Matrix<T> input, IIterativeSolver<T> solver, IPreconditioner<T> preconditioner, params IIterationStopCriterium<T>[] stopCriteria)
{
var result = Builder.DenseMatrix(input.RowCount, input.ColumnCount);
TrySolveIterative(input, result, solver, preconditioner, stopCriteria);
return result;
}
public Vector<T> SolveIterative(Vector<T> input, IIterativeSolver<T> solver, params IIterationStopCriterium<T>[] stopCriteria)
{
var result = Builder.DenseVector(RowCount);
TrySolveIterative(input, result, solver, stopCriteria);
return result;
}
public Matrix<T> SolveIterative(Matrix<T> input, IIterativeSolver<T> solver, params IIterationStopCriterium<T>[] stopCriteria)
{
var result = Builder.DenseMatrix(input.RowCount, input.ColumnCount);
TrySolveIterative(input, result, solver, stopCriteria);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs

@ -91,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <param name="result">The result <see cref="Vector"/>, <c>x</c>.</param>
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator, IPreconditioner<float> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -108,11 +108,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<float>();
}
if (preconditioner == null)
@ -270,67 +268,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <param name="result">The result <see cref="Matrix"/>, <c>X</c></param>
public void Solve(Matrix<float> matrix, Matrix<float> input, Matrix<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="vector">The solution <see cref="Vector"/>, <c>b</c>.</param>
/// <returns>The result <see cref="Vector"/>, <c>x</c>.</returns>
public Vector<float> Solve(Matrix<float> matrix, Vector<float> vector, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient <see cref="Matrix"/>, <c>A</c>.</param>
/// <param name="input">The solution <see cref="Matrix"/>, <c>B</c>.</param>
/// <returns>The result <see cref="Matrix"/>, <c>X</c>.</returns>
public Matrix<float> Solve(Matrix<float> matrix, Matrix<float> input, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

75
src/Numerics/LinearAlgebra/Single/Solvers/CompositeSolver.cs

@ -70,7 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator, IPreconditioner<float> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -82,11 +82,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<float>();
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
// Create a copy of the solution and result vectors so we can use them
@ -105,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
iterator.Reset();
// Start the solver
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2);
solver.Item1.Solve(matrix, internalInput, internalResult, iterator, solver.Item2 ?? preconditioner);
status = iterator.Status;
}
catch (Exception)
@ -144,67 +147,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
}
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<float> matrix, Matrix<float> input, Matrix<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<float> Solve(Matrix<float> matrix, Vector<float> vector, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<float> Solve(Matrix<float> matrix, Matrix<float> input, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs

@ -154,7 +154,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator, IPreconditioner<float> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -171,11 +171,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<float>();
}
if (preconditioner == null)
@ -374,67 +372,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<float> matrix, Matrix<float> input, Matrix<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<float> Solve(Matrix<float> matrix, Vector<float> vector, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<float> Solve(Matrix<float> matrix, Matrix<float> input, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

66
src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs

@ -1,66 +0,0 @@
// <copyright file="Iterator.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.Single.Solvers.StopCriterium;
using MathNet.Numerics.LinearAlgebra.Solvers;
namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
{
/// <summary>
/// An iterator that is used to check if an iterative calculation should continue or stop.
/// </summary>
public static class Iterator
{
// TODO: Refactor
/// <summary>
/// Creates the default stop criteria.
/// </summary>
public static IIterationStopCriterium<float>[] CreateDefaultStopCriteria()
{
return new IIterationStopCriterium<float>[]
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium<float>(),
new ResidualStopCriterium()
};
}
/// <summary>
/// Creates a default iterator with all the default stop criteria.
/// </summary>
public static Iterator<float> CreateDefault()
{
return new Iterator<float>(CreateDefaultStopCriteria());
}
}
}

68
src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs

@ -243,7 +243,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator, IPreconditioner<float> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -260,11 +260,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<float>();
}
if (preconditioner == null)
@ -542,67 +540,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// copy the temporary result to the real result vector
xtemp.CopyTo(result);
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<float> matrix, Matrix<float> input, Matrix<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<float> Solve(Matrix<float> matrix, Vector<float> vector, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<float> Solve(Matrix<float> matrix, Matrix<float> input, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

68
src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs

@ -87,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
public void Solve(Matrix<float> matrix, Vector<float> input, Vector<float> result, Iterator<float> iterator, IPreconditioner<float> preconditioner)
{
if (matrix.RowCount != matrix.ColumnCount)
{
@ -104,11 +104,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
}
// Initialize the solver fields
// Set the convergence monitor
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
iterator = new Iterator<float>();
}
if (preconditioner == null)
@ -274,67 +272,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
iterationNumber++;
}
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
public void Solve(Matrix<float> matrix, Matrix<float> input, Matrix<float> result, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
if (iterator == null)
{
iterator = new Iterator<float>(Iterator.CreateDefaultStopCriteria());
}
if (preconditioner == null)
{
preconditioner = new UnitPreconditioner<float>();
}
for (var column = 0; column < input.ColumnCount; column++)
{
var solution = Solve(matrix, input.Column(column), iterator, preconditioner);
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
}
}
}
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
public Vector<float> Solve(Matrix<float> matrix, Vector<float> vector, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result, iterator, preconditioner);
return result;
}
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
public Matrix<float> Solve(Matrix<float> matrix, Matrix<float> input, Iterator<float> iterator = null, IPreconditioner<float> preconditioner = null)
{
var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result, iterator, preconditioner);
return result;
}
}
}

29
src/Numerics/LinearAlgebra/Solvers/IIterativeSolver.cs

@ -38,15 +38,6 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
/// </summary>
public interface IIterativeSolver<T> where T : struct, IEquatable<T>, IFormattable
{
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="vector">The solution vector, <c>b</c>.</param>
/// <returns>The result vector, <c>x</c>.</returns>
Vector<T> Solve(Matrix<T> matrix, Vector<T> vector, Iterator<T> iterator = null, IPreconditioner<T> preconditioner = null);
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
@ -54,24 +45,6 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
void Solve(Matrix<T> matrix, Vector<T> input, Vector<T> result, Iterator<T> iterator = null, IPreconditioner<T> preconditioner = null);
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <returns>The result matrix, <c>X</c>.</returns>
Matrix<T> Solve(Matrix<T> matrix, Matrix<T> input, Iterator<T> iterator = null, IPreconditioner<T> preconditioner = null);
/// <summary>
/// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the
/// solution matrix and X is the unknown matrix.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution matrix, <c>B</c>.</param>
/// <param name="result">The result matrix, <c>X</c></param>
void Solve(Matrix<T> matrix, Matrix<T> input, Matrix<T> result, Iterator<T> iterator = null, IPreconditioner<T> preconditioner = null);
void Solve(Matrix<T> matrix, Vector<T> input, Vector<T> result, Iterator<T> iterator, IPreconditioner<T> preconditioner);
}
}

8
src/Numerics/LinearAlgebra/Solvers/Iterator.cs

@ -51,6 +51,14 @@ namespace MathNet.Numerics.LinearAlgebra.Solvers
/// </summary>
IterationStatus _status = IterationStatus.Continue;
/// <summary>
/// Initializes a new instance of the <see cref="Iterator{T}"/> class with the default stop criteria.
/// </summary>
public Iterator()
{
_stopCriteria = new List<IIterationStopCriterium<T>>(Matrix<T>.Builder.IterativeSolverStopCriteria());
}
/// <summary>
/// Initializes a new instance of the <see cref="Iterator{T}"/> class with the specified stop criteria.
/// </summary>

6
src/Numerics/Numerics.csproj

@ -122,7 +122,7 @@
<Compile Include="Distributions\Wishart.cs" />
<Compile Include="Distributions\Zipf.cs" />
<Compile Include="LinearAlgebra\Builder.cs" />
<Compile Include="LinearAlgebra\Matrix.Factorization.cs" />
<Compile Include="LinearAlgebra\Matrix.Solve.cs" />
<Compile Include="LinearAlgebra\Solvers\CancellationStopCriterium.cs" />
<Compile Include="LinearAlgebra\Solvers\IterationStatus.cs" />
<Compile Include="LinearAlgebra\Solvers\Iterator.cs" />
@ -243,7 +243,6 @@
<Compile Include="LinearAlgebra\Complex32\Solvers\GpBiCg.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\MlkBiCgStab.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\TFQMR.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\Iterator.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\Preconditioners\Diagonal.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\Preconditioners\Ilutp.cs" />
<Compile Include="LinearAlgebra\Complex32\Solvers\Preconditioners\IlutpElementSorter.cs" />
@ -269,7 +268,6 @@
<Compile Include="LinearAlgebra\Complex\Solvers\GpBiCg.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\MlkBiCgStab.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\TFQMR.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\Iterator.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\Preconditioners\Diagonal.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\Preconditioners\Ilutp.cs" />
<Compile Include="LinearAlgebra\Complex\Solvers\Preconditioners\IlutpElementSorter.cs" />
@ -311,7 +309,6 @@
<Compile Include="LinearAlgebra\Single\Solvers\GpBiCg.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\MlkBiCgStab.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\TFQMR.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Iterator.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Preconditioners\Diagonal.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Preconditioners\Ilutp.cs" />
<Compile Include="LinearAlgebra\Single\Solvers\Preconditioners\IlutpElementSorter.cs" />
@ -340,7 +337,6 @@
<Compile Include="LinearAlgebra\Double\Solvers\GpBiCg.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\MlkBiCgStab.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\TFQMR.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\Iterator.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\Preconditioners\Diagonal.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\Preconditioners\Ilutp.cs" />
<Compile Include="LinearAlgebra\Double\Solvers\Preconditioners\IlutpElementSorter.cs" />

14
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(2);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(3);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -149,7 +149,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -227,7 +227,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -265,7 +265,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
});
var solver = new BiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -296,7 +296,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
new ResidualStopCriterium(1e-10),
});
var solver = new BiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(3);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -229,7 +229,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -267,7 +267,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
});
var solver = new GpBiCg();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -298,7 +298,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
new ResidualStopCriterium(1e-10),
});
var solver = new GpBiCg();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(2);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(3);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -228,7 +228,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -266,7 +266,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
});
var solver = new MlkBiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -297,7 +297,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
new ResidualStopCriterium(1e-10),
});
var solver = new MlkBiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -228,7 +228,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -266,7 +266,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
});
var solver = new TFQMR();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -297,7 +297,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
new ResidualStopCriterium(1e-10),
});
var solver = new TFQMR();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

18
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(2);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(3);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -149,7 +149,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -227,7 +227,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -269,9 +269,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
});
var solver = new BiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -311,9 +311,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new BiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

14
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(3);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -229,7 +229,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -267,9 +267,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
});
var solver = new GpBiCg();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

18
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(2);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(3);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -228,7 +228,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -266,9 +266,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
});
var solver = new MlkBiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -308,9 +308,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new MlkBiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

18
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs

@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -150,7 +150,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -228,7 +228,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -266,9 +266,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
});
var solver = new TFQMR();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -308,9 +308,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new TFQMR();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

14
src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(2);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(3);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -147,7 +147,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -225,7 +225,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -267,7 +267,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
});
var solver = new BiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -297,7 +297,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
new ResidualStopCriterium(1e-10)
});
var solver = new BiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(3);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -227,7 +227,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -269,7 +269,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
});
var solver = new GpBiCg();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -299,7 +299,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
new ResidualStopCriterium(1e-10)
});
var solver = new GpBiCg();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(2);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(3);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -103,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -226,7 +226,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -268,7 +268,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
});
var solver = new MlkBiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -298,7 +298,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
new ResidualStopCriterium(1e-10)
});
var solver = new MlkBiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

14
src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -103,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -226,7 +226,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -264,7 +264,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
});
var solver = new TFQMR();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA*resultx;
@ -294,7 +294,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
new ResidualStopCriterium(1e-10)
});
var solver = new TFQMR();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

18
src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(2);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(3);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -147,7 +147,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -225,7 +225,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new BiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -264,9 +264,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new BiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -305,9 +305,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new BiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

18
src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(3);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -227,7 +227,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new GpBiCg();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -266,9 +266,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new GpBiCg();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -307,9 +307,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new GpBiCg();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

20
src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs

@ -64,7 +64,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(2);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -77,7 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(3);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -149,7 +149,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new MlkBiCgStab();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -234,14 +234,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
Vector<float> x;
try
{
x = solver.Solve(matrix, y, monitor);
x = matrix.SolveIterative(y, solver, monitor);
}
catch (Exception)
{
continue;
}
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
continue;
}
@ -283,9 +283,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new MlkBiCgStab();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -326,9 +326,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new MlkBiCgStab();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

18
src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
/// <summary>
@ -103,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -226,7 +226,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
var solver = new TFQMR();
// Solve equation Ax = y
var x = solver.Solve(matrix, y, monitor);
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
@ -265,9 +265,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new TFQMR();
var resultx = solver.Solve(matrixA, vectorb, monitor);
var resultx = matrixA.SolveIterative(vectorb, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;
@ -306,9 +306,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
});
var solver = new TFQMR();
var matrixX = solver.Solve(matrixA, matrixB, monitor);
var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);
if (!(monitor.Status == IterationStatus.Converged))
if (monitor.Status != IterationStatus.Converged)
{
// Solution was not found, try again downgrading convergence boundary
continue;

Loading…
Cancel
Save