diff --git a/src/Examples/LinearAlgebra/IterativeSolvers/BiCgStabSolver.cs b/src/Examples/LinearAlgebra/IterativeSolvers/BiCgStabSolver.cs index 48fa620f..bdcb6bba 100644 --- a/src/Examples/LinearAlgebra/IterativeSolvers/BiCgStabSolver.cs +++ b/src/Examples/LinearAlgebra/IterativeSolvers/BiCgStabSolver.cs @@ -32,7 +32,6 @@ namespace Examples.LinearAlgebra.IterativeSolvers using MathNet.Numerics.LinearAlgebra.Double.Solvers; using MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative; using MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium; /// /// BiCGStab Iterative solver @@ -102,7 +101,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers var residualStopCriterium = new ResidualStopCriterium(1e-10); // Create monitor with defined stop criteriums - var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); + var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); // Create Bi-Conjugate Gradient Stabilized solver var solver = new BiCgStab(monitor); diff --git a/src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs b/src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs index 4864de07..7101506f 100644 --- a/src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs +++ b/src/Examples/LinearAlgebra/IterativeSolvers/CompositeSolverExample.cs @@ -33,11 +33,9 @@ namespace Examples.LinearAlgebra.IterativeSolvers using MathNet.Numerics.LinearAlgebra.Double.Solvers; using MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative; using MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium; /// - /// Сomposite matrix solver + /// Composite matrix solver /// public class CompositeSolverExample : IExample { @@ -102,7 +100,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers var residualStopCriterium = new ResidualStopCriterium(1e-10); // Create monitor with defined stop criteriums - var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); + var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); // Load all suitable solvers from current assembly. Below in this example, there is user-defined solver // "class UserBiCgStab : IIterativeSolverSetup" which uses regular BiCgStab solver. But user may create any other solver @@ -147,7 +145,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers /// /// Sample of user-defined solver setup /// - public class UserBiCgStab : IIterativeSolverSetup + public class UserBiCgStab : IIterativeSolverSetup { /// /// Gets the type of the solver that will be created by this setup object. @@ -175,8 +173,8 @@ namespace Examples.LinearAlgebra.IterativeSolvers /// Creates a fully functional iterative solver with the default settings /// given by this setup. /// - /// A new . - public IIterativeSolver CreateNew() + /// A new . + public IIterativeSolver CreateNew() { return new BiCgStab(); } diff --git a/src/Examples/LinearAlgebra/IterativeSolvers/GpBiCgSolver.cs b/src/Examples/LinearAlgebra/IterativeSolvers/GpBiCgSolver.cs index 675b6a8f..8d97da9b 100644 --- a/src/Examples/LinearAlgebra/IterativeSolvers/GpBiCgSolver.cs +++ b/src/Examples/LinearAlgebra/IterativeSolvers/GpBiCgSolver.cs @@ -32,7 +32,6 @@ namespace Examples.LinearAlgebra.IterativeSolvers using MathNet.Numerics.LinearAlgebra.Double.Solvers; using MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative; using MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium; /// /// GpBiCg Iterative solver @@ -100,7 +99,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers var residualStopCriterium = new ResidualStopCriterium(1e-10); // Create monitor with defined stop criteriums - var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); + var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); // Create Generalized Product Bi-Conjugate Gradient solver var solver = new GpBiCg(monitor); diff --git a/src/Examples/LinearAlgebra/IterativeSolvers/MlkBiCgStabSolver.cs b/src/Examples/LinearAlgebra/IterativeSolvers/MlkBiCgStabSolver.cs index 8a56f3bf..1f526215 100644 --- a/src/Examples/LinearAlgebra/IterativeSolvers/MlkBiCgStabSolver.cs +++ b/src/Examples/LinearAlgebra/IterativeSolvers/MlkBiCgStabSolver.cs @@ -32,7 +32,6 @@ namespace Examples.LinearAlgebra.IterativeSolvers using MathNet.Numerics.LinearAlgebra.Double.Solvers; using MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative; using MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium; /// /// Multiple-Lanczos Bi-Conjugate Gradient stabilized Iterative solver @@ -101,7 +100,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers var residualStopCriterium = new ResidualStopCriterium(1e-10); // Create monitor with defined stop criteriums - var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); + var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); // Create Multiple-Lanczos Bi-Conjugate Gradient Stabilized solver var solver = new MlkBiCgStab(monitor); diff --git a/src/Examples/LinearAlgebra/IterativeSolvers/TFQMRSolver.cs b/src/Examples/LinearAlgebra/IterativeSolvers/TFQMRSolver.cs index 4938acb8..79d8643a 100644 --- a/src/Examples/LinearAlgebra/IterativeSolvers/TFQMRSolver.cs +++ b/src/Examples/LinearAlgebra/IterativeSolvers/TFQMRSolver.cs @@ -32,7 +32,6 @@ namespace Examples.LinearAlgebra.IterativeSolvers using MathNet.Numerics.LinearAlgebra.Double.Solvers; using MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative; using MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium; - using MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium; /// /// Transpose Free Quasi-Minimal Residual iterative solver @@ -101,7 +100,7 @@ namespace Examples.LinearAlgebra.IterativeSolvers var residualStopCriterium = new ResidualStopCriterium(1e-10); // Create monitor with defined stop criteriums - var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); + var monitor = new Iterator(new IIterationStopCriterium[] { iterationCountStopCriterium, residualStopCriterium }); // Create Transpose Free Quasi-Minimal Residual solver var solver = new TFQMR(monitor); diff --git a/src/MathNet.Numerics.5.1.ReSharper b/src/MathNet.Numerics.5.1.ReSharper index a11bfa15..46415860 100644 --- a/src/MathNet.Numerics.5.1.ReSharper +++ b/src/MathNet.Numerics.5.1.ReSharper @@ -10,7 +10,12 @@ en-US false - + Criterium +cancelled +pre +preconditioner +Preconditioners +indetermined @@ -238,7 +243,7 @@ - false + true Any diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs similarity index 80% rename from src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolver.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs index 6b32c05c..3f4fbe7e 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolver.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs @@ -28,18 +28,15 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers +namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers { - using System; - using System.Numerics; - using Status; + using Generic.Solvers.Status; /// - /// Defines the interface for classes that solve the matrix equation Ax = b in + /// Defines the interface for classes that solve the matrix equation Ax = b in /// an iterative manner. /// - /// Supported data types are double, single, , and . - public interface IIterativeSolver where T : struct, IEquatable, IFormattable + public interface IIterativeSolver { /// /// Stops the solve process. @@ -50,10 +47,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers void StopSolve(); /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - void SetIterator(IIterator iterator); + void SetIterator(IIterator iterator); /// /// Gets the status of the iteration once the calculation is finished. @@ -67,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - Vector Solve(Matrix matrix, Vector vector); + Vector Solve(Matrix matrix, Vector vector); /// /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the @@ -76,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - void Solve(Matrix matrix, Vector input, Vector result); + void Solve(Matrix matrix, Vector input, Vector result); /// /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the @@ -85,7 +82,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - Matrix Solve(Matrix matrix, Matrix input); + Matrix Solve(Matrix matrix, Matrix input); /// /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the @@ -94,6 +91,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - void Solve(Matrix matrix, Matrix input, Matrix result); + void Solve(Matrix matrix, Matrix input, Matrix result); } } diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolverSetup.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolverSetup.cs similarity index 85% rename from src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolverSetup.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolverSetup.cs index da37cdc2..50bf1783 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterativeSolverSetup.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolverSetup.cs @@ -28,18 +28,16 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers +namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers { using System; - using System.Numerics; /// /// Defines the interface for objects that can create an iterative solver with /// specific settings. This interface is used to pass iterative solver creation /// setup information around. /// - /// Supported data types are double, single, , and . - public interface IIterativeSolverSetup where T : struct, IEquatable, IFormattable + public interface IIterativeSolverSetup { /// /// Gets the type of the solver that will be created by this setup object. @@ -55,8 +53,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// Creates a fully functional iterative solver with the default settings /// given by this setup. /// - /// A new . - IIterativeSolver CreateNew(); + /// A new . + IIterativeSolver CreateNew(); /// /// Gets the relative speed of the solver. diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs similarity index 76% rename from src/Numerics/LinearAlgebra/Generic/Solvers/IIterator.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs index a226a43c..99ffad1c 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/IIterator.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs @@ -28,44 +28,41 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers +namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers { using System; - using System.Numerics; - using Status; + using Generic.Solvers.Status; using StopCriterium; /// /// Defines the base interface for iterators that help control an iterative calculation. /// - /// Supported data types are double, single, , and . - public interface IIterator + public interface IIterator #if !SILVERLIGHT - : ICloneable + : ICloneable #endif - where T : struct, IEquatable, IFormattable { /// - /// Adds an to the internal collection of stop-criteria. Only a + /// Adds an to the internal collection of stop-criteria. Only a /// single stop criterium of each type can be stored. /// /// The stop criterium to add. /// Thrown if is . /// Thrown if is of the same type as an already stored criterium. - void Add(IIterationStopCriterium stopCriterium); + void Add(IIterationStopCriterium stopCriterium); /// - /// Removes the from the internal collection. + /// Removes the from the internal collection. /// /// The stop criterium that must be removed. - void Remove(IIterationStopCriterium stopCriterium); + void Remove(IIterationStopCriterium stopCriterium); /// - /// Indicates if the specific stop criterium is stored by the . + /// Indicates if the specific stop criterium is stored by the . /// /// The stop criterium. - /// true if the contains the stop criterium; otherwise false. - bool Contains(IIterationStopCriterium stopCriterium); + /// true if the contains the stop criterium; otherwise false. + bool Contains(IIterationStopCriterium stopCriterium); /// /// Indicates to the iterator that the iterative process has been cancelled. @@ -75,7 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Status is set to Status field of current object. + /// by the current . Status is set to Status field of current object. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -86,7 +83,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); /// /// Gets the current calculation status. @@ -95,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers ICalculationStatus Status { get; } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// /// /// Note to implementers: Invoking this method should not clear the user defined @@ -105,7 +102,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers void ResetToPrecalculationState(); #if SILVERLIGHT - IIterator Clone(); + IIterator Clone(); #endif } } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs index ca2f2d06..14fe6014 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs @@ -33,8 +33,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative using System; using System.Numerics; using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -68,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// solver. /// /// - public sealed class BiCgStab : IIterativeSolver + public sealed class BiCgStab : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -80,12 +78,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -96,7 +94,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public BiCgStab() : this(null, null) @@ -111,18 +109,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public BiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public BiCgStab(IIterator iterator) : this(null, iterator) { } @@ -130,11 +128,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -143,38 +141,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public BiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public BiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -205,17 +203,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public Vector Solve(Matrix matrix, Vector vector) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -224,10 +222,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public void Solve(Matrix matrix, Vector input, Vector result) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -282,7 +280,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // Compute r_0 = b - Ax_0 for some initial guess x_0 // In this case we take x_0 = vector // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, result, input); // Choose r~ (for example, r~ = r_0) @@ -291,13 +289,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // create seven temporary vectors needed to hold temporary // coefficients. All vectors are mangled in each iteration. // These are defined here to prevent stressing the garbage collector - Vector vecP = new DenseVector(residuals.Count); - Vector vecPdash = new DenseVector(residuals.Count); - Vector nu = new DenseVector(residuals.Count); - Vector vecS = new DenseVector(residuals.Count); - Vector vecSdash = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector vecP = new DenseVector(residuals.Count); + Vector vecPdash = new DenseVector(residuals.Count); + Vector nu = new DenseVector(residuals.Count); + Vector vecS = new DenseVector(residuals.Count); + Vector vecSdash = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); // create some temporary double variables that are needed // to hold values in between iterations @@ -429,13 +427,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -451,11 +449,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -476,10 +474,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X. - public Matrix Solve(Matrix matrix, Matrix input) + /// The coefficient , A. + /// The solution , B. + /// The result , X. + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -491,7 +489,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -500,10 +498,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X - public void Solve(Matrix matrix, Matrix input, Matrix result) + /// The coefficient , A. + /// The solution , B. + /// The result , X + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -527,7 +525,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs index e70c5a95..133c7325 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs @@ -56,7 +56,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Note that if an iterator is passed to this solver it will be used for all the sub-solvers. /// /// - public sealed class CompositeSolver : IIterativeSolver + public sealed class CompositeSolver : IIterativeSolver { #region Internal class - DoubleComparer /// @@ -97,19 +97,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative private static readonly ICalculationStatus RunningStatus = new CalculationRunning(); #if SILVERLIGHT - private static readonly Dictionary>> SolverSetups = new Dictionary>>(); + private static readonly Dictionary> SolverSetups = new Dictionary>(); #else /// /// The collection of iterative solver setups. Stored based on the /// ratio between the relative speed and relative accuracy. /// - private static readonly SortedList>> SolverSetups = new SortedList>>(new DoubleComparer()); + private static readonly SortedList> SolverSetups = new SortedList>(new DoubleComparer()); #endif #region Solver information loading methods /// - /// Loads all the available objects from the MathNet.Numerics assembly. + /// Loads all the available objects from the MathNet.Numerics assembly. /// public static void LoadSolverInformation() { @@ -117,16 +117,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the MathNet.Numerics assembly. + /// Loads the available objects from the MathNet.Numerics assembly. /// - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformation(Type[] typesToExclude) { LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude); } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. public static void LoadSolverInformationFromAssembly(string assemblyLocation) @@ -135,10 +135,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(string assemblyLocation, params Type[] typesToExclude) { if (assemblyLocation == null) @@ -173,7 +173,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName) @@ -182,10 +182,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName, params Type[] typesToExclude) { if (assemblyName == null) @@ -205,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. public static void LoadSolverInformationFromAssembly(Type typeInAssembly) @@ -214,10 +214,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Type typeInAssembly, params Type[] typesToExclude) { if (typeInAssembly == null) @@ -229,7 +229,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. public static void LoadSolverInformationFromAssembly(Assembly assembly) @@ -238,10 +238,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Assembly assembly, params Type[] typesToExclude) { if (assembly == null) @@ -266,18 +266,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative { interfaceTypes.Clear(); interfaceTypes.AddRange(type.GetInterfaces()); - if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) + if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) { continue; } // See if we actually want this type of iterative solver - IIterativeSolverSetup setup; + IIterativeSolverSetup setup; try { // If something goes wrong we just ignore it and move on with the next type. // There should probably be a log somewhere indicating that something went wrong? - setup = (IIterativeSolverSetup)Activator.CreateInstance(type); + setup = (IIterativeSolverSetup)Activator.CreateInstance(type); } catch (ArgumentException) { @@ -318,7 +318,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative var ratio = setup.SolutionSpeed / setup.Reliability; if (!SolverSetups.ContainsKey(ratio)) { - SolverSetups.Add(ratio, new List>()); + SolverSetups.Add(ratio, new List()); } var list = SolverSetups[ratio]; @@ -331,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// The collection of solvers that will be used to /// - private readonly List> _solvers = new List>(); + private readonly List _solvers = new List(); /// /// The status of the calculation. @@ -341,7 +341,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// The iterator that is used to control the iteration process. /// - private IIterator _iterator; + private IIterator _iterator; /// /// A flag indicating if the solver has been stopped or not. @@ -352,7 +352,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The solver that is currently running. Reference is used to be able to stop the /// solver if the user cancels the solve process. /// - private IIterativeSolver _currentSolver; + private IIterativeSolver _currentSolver; /// /// Initializes a new instance of the class with the default iterator. @@ -365,7 +365,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class with the specified iterator. /// /// The iterator that will be used to control the iteration process. - public CompositeSolver(IIterator iterator) + public CompositeSolver(IIterator iterator) { _iterator = iterator; } @@ -374,7 +374,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Sets the IIterator that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -412,14 +412,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -431,7 +431,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -481,8 +481,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // Create a copy of the solution and result vectors so we can use them // later on - var internalInput = input.Clone(); - var internalResult = result.Clone(); + var internalInput = (Vector)input.Clone(); + var internalResult = (Vector)result.Clone(); foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped)) { @@ -573,7 +573,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -585,7 +585,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -597,7 +597,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -621,7 +621,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs index 58c70cea..53b7e650 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs @@ -32,9 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative { using System; using System.Numerics; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -66,7 +63,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// solver. /// /// - public sealed class GpBiCg : IIterativeSolver + public sealed class GpBiCg : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -78,12 +75,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The preconditioner that will be used. Can be set to null, in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates the number of BiCGStab steps should be taken @@ -106,7 +103,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public GpBiCg() : this(null, null) @@ -121,18 +118,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public GpBiCg(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public GpBiCg(IIterator iterator) : this(null, iterator) { } @@ -140,11 +137,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -153,19 +150,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public GpBiCg(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public GpBiCg(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -216,19 +213,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -263,14 +260,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -282,7 +279,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -336,11 +333,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // x_0 is initial guess // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars @@ -349,26 +346,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // Define the temporary vectors // rDash_0 = r_0 - Vector rdash = new DenseVector(residuals); + Vector rdash = new DenseVector(residuals); // t_-1 = 0 - Vector t = new DenseVector(residuals.Count); - Vector t0 = new DenseVector(residuals.Count); + Vector t = new DenseVector(residuals.Count); + Vector t0 = new DenseVector(residuals.Count); // w_-1 = 0 - Vector w = new DenseVector(residuals.Count); + Vector w = new DenseVector(residuals.Count); // Define the remaining temporary vectors - Vector c = new DenseVector(residuals.Count); - Vector p = new DenseVector(residuals.Count); - Vector s = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector y = new DenseVector(residuals.Count); - Vector z = new DenseVector(residuals.Count); + Vector c = new DenseVector(residuals.Count); + Vector p = new DenseVector(residuals.Count); + Vector s = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector y = new DenseVector(residuals.Count); + Vector z = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); - Vector temp3 = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); + Vector temp3 = new DenseVector(residuals.Count); // for (k = 0, 1, .... ) var iterationNumber = 0; @@ -525,13 +522,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -545,11 +542,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -590,7 +587,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -602,7 +599,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -614,7 +611,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -638,7 +635,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs index 7671217d..d0b086b7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs @@ -38,8 +38,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative using Distributions; using Generic; using Generic.Factorization; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -67,7 +65,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// solver. /// /// - public sealed class MlkBiCgStab : IIterativeSolver + public sealed class MlkBiCgStab : IIterativeSolver { /// /// The default number of starting vectors. @@ -84,17 +82,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// The collection of starting vectors which are used as the basis for the Krylov sub-space. /// - private IList> _startingVectors; + private IList _startingVectors; /// /// The number of starting vectors used by the algorithm @@ -110,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public MlkBiCgStab() : this(null, null) @@ -125,18 +123,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IIterator iterator) : this(null, iterator) { } @@ -144,11 +142,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -157,19 +155,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -211,19 +209,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -232,7 +230,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Gets or sets a series of orthonormal vectors which will be used as basis for the /// Krylov sub-space. /// - public IList> StartingVectors + public IList StartingVectors { [DebuggerStepThrough] get @@ -284,14 +282,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -303,7 +301,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -357,7 +355,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // Choose an initial guess x_0 // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // Choose k vectors q_1, q_2, ..., q_k // Build a new set if: @@ -386,24 +384,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary values var c = new Complex[k]; // Define the temporary vectors - Vector gtemp = new DenseVector(residuals.Count); + Vector gtemp = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector utemp = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp1 = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector utemp = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp1 = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); - Vector zd = new DenseVector(residuals.Count); - Vector zg = new DenseVector(residuals.Count); - Vector zw = new DenseVector(residuals.Count); + Vector zd = new DenseVector(residuals.Count); + Vector zg = new DenseVector(residuals.Count); + Vector zw = new DenseVector(residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count); @@ -647,7 +645,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// the is smaller than /// the . /// - private static IList> CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) + private static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) { // Create no more starting vectors than the size of the problem - 1 // Get random values and then orthogonalize them with @@ -658,7 +656,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative // mean = 0 and sd = 1 var distribution = new Normal(); - Matrix matrix = new DenseMatrix(numberOfVariables, count); + Matrix matrix = new DenseMatrix(numberOfVariables, count); for (var i = 0; i < matrix.ColumnCount; i++) { var samples = new Complex[matrix.RowCount]; @@ -678,10 +676,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative var orthogonalMatrix = gs.Q; // Now transfer this to vectors - var result = new List>(); + var result = new List(); for (var i = 0; i < orthogonalMatrix.ColumnCount; i++) { - result.Add(orthogonalMatrix.Column(i)); + result.Add((Vector)orthogonalMatrix.Column(i)); // Normalize the result vector result[i].Multiply(1 / result[i].Norm(2), result[i]); @@ -696,9 +694,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Number of vectors /// Size of each vector /// Array of random vectors - private static Vector[] CreateVectorArray(int arraySize, int vectorSize) + private static Vector[] CreateVectorArray(int arraySize, int vectorSize) { - var result = new Vector[arraySize]; + var result = new Vector[arraySize]; for (var i = 0; i < result.Length; i++) { result[i] = new DenseVector(vectorSize); @@ -708,13 +706,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Source A. - /// Residual data. - /// x data. - /// b data. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Source A. + /// Residual data. + /// x data. + /// b data. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -728,11 +726,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -756,7 +754,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -768,7 +766,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -780,7 +778,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -804,7 +802,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs index b8efc344..4d024c83 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs @@ -32,9 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative { using System; using System.Numerics; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -56,7 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// solver. /// /// - public sealed class TFQMR : IIterativeSolver + public sealed class TFQMR : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -68,12 +65,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -84,7 +81,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public TFQMR() : this(null, null) @@ -99,18 +96,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public TFQMR(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public TFQMR(IIterator iterator) : this(null, iterator) { } @@ -118,11 +115,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -131,38 +128,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public TFQMR(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public TFQMR(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -196,14 +193,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -215,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -427,13 +424,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -447,11 +444,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -485,7 +482,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -497,7 +494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -509,7 +506,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -533,7 +530,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs index 81c4c76e..c4c75eeb 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs @@ -33,18 +33,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers using System; using System.Collections.Generic; using System.Linq; - using System.Numerics; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; - using Generic.Solvers.StopCriterium; using Properties; using StopCriterium; /// /// An iterator that is used to check if an iterative calculation should continue or stop. /// - public sealed class Iterator : IIterator + public sealed class Iterator : IIterator { /// /// The default status for the iterator. @@ -52,10 +48,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers private static readonly ICalculationStatus DefaultStatus = new CalculationIndetermined(); /// - /// Creates a default iterator with all the objects. + /// Creates a default iterator with all the objects. /// - /// A new object. - public static IIterator CreateDefault() + /// A new object. + public static IIterator CreateDefault() { var iterator = new Iterator(); iterator.Add(new FailureStopCriterium()); @@ -70,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// The collection that holds all the stop criteria and the flag indicating if they should be added /// to the child iterators. /// - private readonly Dictionary> _stopCriterias = new Dictionary>(); + private readonly Dictionary _stopCriterias = new Dictionary(); /// /// The status of the iterator. @@ -97,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// of the stop criteria will be passed on to child iterators. /// /// Thrown if contains multiple stop criteria of the same type. - public Iterator(IEnumerable> stopCriteria) + public Iterator(IEnumerable stopCriteria) { // Add the stop criteria if (stopCriteria == null) @@ -112,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers } /// - /// Adds an to the internal collection of stop-criteria. Only a + /// Adds an to the internal collection of stop-criteria. Only a /// single stop criterium of each type can be stored. /// /// The stop criterium to add. @@ -121,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// Thrown if is of the same type as an already /// stored criterium. /// - public void Add(IIterationStopCriterium stopCriterium) + public void Add(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -138,10 +134,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers } /// - /// Removes the from the internal collection. + /// Removes the from the internal collection. /// /// The stop criterium that must be removed. - public void Remove(IIterationStopCriterium stopCriterium) + public void Remove(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -158,11 +154,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers } /// - /// Indicates if the specific stop criterium is stored by the . + /// Indicates if the specific stop criterium is stored by the . /// /// The stop criterium. - /// true if the contains the stop criterium; otherwise false. - public bool Contains(IIterationStopCriterium stopCriterium) + /// true if the contains the stop criterium; otherwise false. + public bool Contains(IIterationStopCriterium stopCriterium) { return stopCriterium != null && _stopCriterias.ContainsKey(stopCriterium.GetType()); } @@ -183,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// Gets an IEnumerator that enumerates over all the stored stop criteria. /// /// Used for testing only. - internal IEnumerator> StoredStopCriteria + internal IEnumerator StoredStopCriteria { get { @@ -216,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (_stopCriterias.Count == 0) { @@ -288,7 +284,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -309,9 +305,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers /// Creates a deep clone of the current iterator. /// /// The deep clone of the current iterator. - public IIterator Clone() + public IIterator Clone() { - var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); + var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); return new Iterator(stopCriteria); } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs index 5f5ea777..3a985957 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs @@ -32,15 +32,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners { using System; using System.Numerics; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreConditioner + public sealed class Diagonal : IPreConditioner { /// /// The inverse of the matrix diagonal. @@ -66,10 +64,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. + /// The upon which this preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -93,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -110,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -120,7 +118,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/Preconditioners/IPreConditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs similarity index 86% rename from src/Numerics/LinearAlgebra/Generic/Solvers/Preconditioners/IPreConditioner.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs index 70fc8e0c..b542ceac 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/Preconditioners/IPreConditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs @@ -28,11 +28,8 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.Preconditioners +namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners { - using System; - using System.Numerics; - /// /// The base interface for preconditioner classes. /// @@ -51,27 +48,26 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.Preconditioners /// if the changes occur after creating the preconditioner. /// /// - /// Supported data types are double, single, , and . - public interface IPreConditioner where T : struct, IEquatable, IFormattable + public interface IPreConditioner { /// /// Initializes the preconditioner and loads the internal data structures. /// /// The matrix on which the preconditioner is based. - void Initialize(Matrix matrix); + void Initialize(Matrix matrix); /// /// Approximates the solution to the matrix equation Mx = b. /// /// The right hand side vector. /// The left hand side vector. - Vector Approximate(Vector rhs); + Vector Approximate(Vector rhs); /// /// Approximates the solution to the matrix equation Mx = b. /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - void Approximate(Vector rhs, Vector lhs); + void Approximate(Vector rhs, Vector lhs); } } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs index e13fd38b..8cc07747 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs @@ -33,8 +33,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners using System; using System.Collections.Generic; using System.Numerics; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -54,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreConditioner + public sealed class Ilutp : IPreConditioner { /// /// The default fill level. @@ -258,9 +256,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { - return _upper.Clone(); + return (Matrix)_upper.Clone(); } /// @@ -270,9 +268,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { - return _lower.Clone(); + return (Matrix)_lower.Clone(); } /// @@ -298,13 +296,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. Note that the + /// The upon which this preconditioner is based. Note that the /// method takes a general matrix type. However internally the data is stored /// as a sparse matrix. Therefore it is not recommended to pass a dense matrix. /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -376,8 +374,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners _pivots[i] = i; } - Vector workVector = new DenseVector(sparseMatrix.RowCount); - Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); + Vector workVector = new DenseVector(sparseMatrix.RowCount); + Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); var indexSorting = new int[sparseMatrix.RowCount]; // spaceLeft = lfilNnz * nnz(A) @@ -532,8 +530,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// Pivot elements in the according to internal pivot array /// - /// Row to pivot in - private void PivotRow(Vector row) + /// Row to pivot in + private void PivotRow(Vector row) { var knownPivots = new Dictionary(); @@ -580,12 +578,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners } /// - /// Swap columns in the + /// Swap columns in the /// - /// Source . + /// Source . /// First column index to swap /// Second column index to swap - private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) + private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) { for (var i = 0; i < matrix.RowCount; i++) { @@ -601,8 +599,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Start sort form /// Sort till upper bound /// Array with sorted vector indicies - /// Source - private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// Source + private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Copy the indices for the values into the array for (var i = 0; i < upperBound + 1 - lowerBound; i++) @@ -627,7 +625,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -644,7 +642,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -654,7 +652,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -679,7 +677,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners // Solve equation here // Pivot(vector, result); // Solve L*Y = B(piv,:) - Vector rowValues = new DenseVector(_lower.RowCount); + Vector rowValues = new DenseVector(_lower.RowCount); for (var i = 0; i < _lower.RowCount; i++) { _lower.Row(i, rowValues); @@ -709,17 +707,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners // We have a column pivot so we only need to pivot the // end result not the incoming right hand side vector - var temp = lhs.Clone(); + var temp = (Vector)lhs.Clone(); Pivot(temp, lhs); } /// - /// Pivot elements in accoring to internal pivot array + /// Pivot elements in according to internal pivot array /// - /// Source . - /// Result after pivoting. - private void Pivot(Vector vector, Vector result) + /// Source . + /// Result after pivoting. + private void Pivot(Vector vector, Vector result) { for (var i = 0; i < _pivots.Length; i++) { diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs index b073af57..fa06ddd4 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs @@ -95,7 +95,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Build heap for double indicies ///
/// Root position - /// Lenght of + /// Length of /// Indicies of /// Target private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) @@ -113,15 +113,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Indicies of /// Target /// Root position - /// Lenght of + /// Length of private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) { var root = begin; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) { child += 1; @@ -171,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// Target values array /// Root position - /// Lenght of + /// Length of private static void BuildHeap(int[] values, int start, int count) { while (start >= 0) @@ -186,15 +185,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// Target value array /// Root position - /// Lenght of + /// Length of private static void Sift(int[] values, int start, int count) { var root = start; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[child] > values[child + 1])) { child += 1; @@ -216,8 +214,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Exchange values in array /// /// Target values array - /// First value to exchanghe - /// Second value to exchanghe + /// First value to exchange + /// Second value to exchange private static void Exchange(int[] values, int first, int second) { var t = values[first]; diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs index ce41969b..b9357ee7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs @@ -32,8 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners { using System; using System.Numerics; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -45,7 +43,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreConditioner + public sealed class IncompleteLU : IPreConditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The @@ -57,7 +55,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Returns the upper triagonal matrix that was created during the LU decomposition. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -75,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Returns the lower triagonal matrix that was created during the LU decomposition. ///
/// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -102,7 +100,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// The matrix upon which the preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -164,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -181,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -191,7 +189,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -221,7 +219,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners // z_i = l_ii^-1 * (y_i - SUM_(j rowValues = new DenseVector(_decompositionLU.RowCount); + Vector rowValues = new DenseVector(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) { // Clear the rowValues diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/UnitPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/UnitPreconditioner.cs index 8520a3a5..fafa0b23 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/UnitPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/UnitPreconditioner.cs @@ -31,18 +31,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners { using System; - using System.Numerics; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Properties; /// /// A unit preconditioner. This preconditioner does not actually do anything - /// it is only used when running an without + /// it is only used when running an without /// a preconditioner. /// - internal sealed class UnitPreconditioner : IPreConditioner + internal sealed class UnitPreconditioner : IPreConditioner { /// /// The coefficient matrix on which this preconditioner operates. @@ -58,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -91,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// If the size of is different the number of rows of the coefficient matrix. /// /// - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -120,7 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// /// If the size of is different the number of rows of the coefficient matrix. /// - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -132,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentMatrixDimensions); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs index d34600b0..3f0cc784 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs @@ -32,15 +32,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium { using System; using System.Diagnostics; - using System.Numerics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// /// Monitors an iterative calculation for signs of divergence. /// - public sealed class DivergenceStopCriterium : IIterationStopCriterium + public sealed class DivergenceStopCriterium : IIterationStopCriterium { /// /// Default value for the maximum relative increase that the @@ -208,7 +206,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -219,7 +217,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -302,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium } /// - /// Gets required history lenght + /// Gets required history Length /// private int RequiredHistoryLength { @@ -348,7 +346,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -359,7 +357,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -375,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs index f6f6fc39..176280ba 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium { using System; using System.Diagnostics; - using System.Numerics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals for NaN's. + /// Defines an that monitors residuals for NaN's. /// - public sealed class FailureStopCriterium : IIterationStopCriterium + public sealed class FailureStopCriterium : IIterationStopCriterium { /// /// Defines the default last iteration number. Set to -1 because iterations normally @@ -66,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -77,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -157,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -167,7 +165,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -183,7 +181,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new FailureStopCriterium(); } diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs similarity index 79% rename from src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/IIterationStopCriterium.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs index cc1c5893..90237143 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/IIterationStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs @@ -24,36 +24,34 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium +namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium { using System; - using System.Numerics; - using Status; + using Generic.Solvers.Status; + using Generic.Solvers.StopCriterium; /// /// The base interface for classes that provide stop criteria for iterative calculations. /// - /// Supported data types are double, single, , and . - public interface IIterationStopCriterium + public interface IIterationStopCriterium #if !SILVERLIGHT - : ICloneable + : ICloneable #endif - where T : struct, IEquatable, IFormattable { /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Status is set to Status field of current object. + /// by the current . Status is set to Status field of current object. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. /// The right hand side vector. /// The vector containing the current residual vectors. - /// + /// /// The individual stop criteria may internally track the progress of the calculation based /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); /// /// Gets the current calculation status. @@ -62,7 +60,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium ICalculationStatus Status { get; } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// /// To implementers: Invoking this method should not clear the user defined /// property values, only the state that is used to track the progress of the @@ -71,12 +69,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// StopLevel StopLevel { get; } #if SILVERLIGHT - IIterationStopCriterium Clone(); + IIterationStopCriterium Clone(); #endif } } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs index 7199b686..1ecabc32 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium { using System; using System.Diagnostics; - using System.Numerics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// - /// Defines an that monitors the numbers of iteration + /// Defines an that monitors the numbers of iteration /// steps as stop criterium. /// - public sealed class IterationCountStopCriterium : IIterationStopCriterium + public sealed class IterationCountStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum number of iterations the process is allowed @@ -132,7 +130,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -209,7 +207,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new IterationCountStopCriterium(_maximumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs index 153e1806..15471b3e 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium { using System; using System.Diagnostics; - using System.Numerics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals as stop criterium. + /// Defines an that monitors residuals as stop criterium. /// - public sealed class ResidualStopCriterium : IIterationStopCriterium + public sealed class ResidualStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum value of the residual. @@ -213,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -224,7 +222,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -364,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -375,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -391,7 +389,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum); } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs new file mode 100644 index 00000000..865cc5b2 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs @@ -0,0 +1,96 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers +{ + using Generic.Solvers.Status; + + /// + /// Defines the interface for classes that solve the matrix equation Ax = b in + /// an iterative manner. + /// + public interface IIterativeSolver + { + /// + /// Stops the solve process. + /// + /// + /// Note that it may take an indetermined amount of time for the solver to actually stop the process. + /// + void StopSolve(); + + /// + /// Sets the that will be used to track the iterative process. + /// + /// The iterator. + void SetIterator(IIterator iterator); + + /// + /// Gets the status of the iteration once the calculation is finished. + /// + ICalculationStatus IterationResult { get; } + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b. + /// The result vector, x. + Vector Solve(Matrix matrix, Vector vector); + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b + /// The result vector, x + void Solve(Matrix matrix, Vector input, Vector result); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X. + Matrix Solve(Matrix matrix, Matrix input); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X + void Solve(Matrix matrix, Matrix input, Matrix result); + } +} diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolverSetup.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolverSetup.cs new file mode 100644 index 00000000..f98f5de3 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolverSetup.cs @@ -0,0 +1,71 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers +{ + using System; + + /// + /// Defines the interface for objects that can create an iterative solver with + /// specific settings. This interface is used to pass iterative solver creation + /// setup information around. + /// + public interface IIterativeSolverSetup + { + /// + /// Gets the type of the solver that will be created by this setup object. + /// + Type SolverType { get; } + + /// + /// Gets type of preconditioner, if any, that will be created by this setup object. + /// + Type PreconditionerType { get; } + + /// + /// Creates a fully functional iterative solver with the default settings + /// given by this setup. + /// + /// A new . + IIterativeSolver CreateNew(); + + /// + /// Gets the relative speed of the solver. + /// + /// Returns a value between 0 and 1, inclusive. + double SolutionSpeed { get; } + + /// + /// Gets the relative reliability of the solver. + /// + /// Returns a value between 0 and 1 inclusive. + double Reliability { get; } + } +} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs new file mode 100644 index 00000000..23b0c110 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs @@ -0,0 +1,108 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers +{ + using System; + using Generic.Solvers.Status; + using StopCriterium; + + /// + /// Defines the base interface for iterators that help control an iterative calculation. + /// + public interface IIterator +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Adds an to the internal collection of stop-criteria. Only a + /// single stop criterium of each type can be stored. + /// + /// The stop criterium to add. + /// Thrown if is . + /// Thrown if is of the same type as an already stored criterium. + void Add(IIterationStopCriterium stopCriterium); + + /// + /// Removes the from the internal collection. + /// + /// The stop criterium that must be removed. + void Remove(IIterationStopCriterium stopCriterium); + + /// + /// Indicates if the specific stop criterium is stored by the . + /// + /// The stop criterium. + /// true if the contains the stop criterium; otherwise false. + bool Contains(IIterationStopCriterium stopCriterium); + + /// + /// Indicates to the iterator that the iterative process has been cancelled. + /// + /// Does not reset the stop-criteria. + void IterationCancelled(); + + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual iterators may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation.. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// + /// Note to implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + /// + void ResetToPrecalculationState(); + +#if SILVERLIGHT + IIterator Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs index 3f832752..b359f19d 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Numerics; using Preconditioners; @@ -68,7 +65,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// solver. /// /// - public sealed class BiCgStab : IIterativeSolver + public sealed class BiCgStab : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -80,12 +77,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -96,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public BiCgStab() : this(null, null) @@ -111,18 +108,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public BiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public BiCgStab(IIterator iterator) : this(null, iterator) { } @@ -130,11 +127,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -143,38 +140,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public BiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public BiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -205,17 +202,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public Vector Solve(Matrix matrix, Vector vector) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -224,10 +221,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public void Solve(Matrix matrix, Vector input, Vector result) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -282,7 +279,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // Compute r_0 = b - Ax_0 for some initial guess x_0 // In this case we take x_0 = vector // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, result, input); // Choose r~ (for example, r~ = r_0) @@ -291,13 +288,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // create seven temporary vectors needed to hold temporary // coefficients. All vectors are mangled in each iteration. // These are defined here to prevent stressing the garbage collector - Vector vecP = new DenseVector(residuals.Count); - Vector vecPdash = new DenseVector(residuals.Count); - Vector nu = new DenseVector(residuals.Count); - Vector vecS = new DenseVector(residuals.Count); - Vector vecSdash = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector vecP = new DenseVector(residuals.Count); + Vector vecPdash = new DenseVector(residuals.Count); + Vector nu = new DenseVector(residuals.Count); + Vector vecS = new DenseVector(residuals.Count); + Vector vecSdash = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); // create some temporary float variables that are needed // to hold values in between iterations @@ -429,13 +426,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -451,11 +448,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -476,10 +473,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X. - public Matrix Solve(Matrix matrix, Matrix input) + /// The coefficient , A. + /// The solution , B. + /// The result , X. + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -491,7 +488,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -500,10 +497,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X - public void Solve(Matrix matrix, Matrix input, Matrix result) + /// The coefficient , A. + /// The solution , B. + /// The result , X + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -527,7 +524,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs index 47fcdde7..22f868cf 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs @@ -35,10 +35,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative using System.IO; using System.Linq; using System.Reflection; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; - using Numerics; using Properties; /// @@ -56,7 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Note that if an iterator is passed to this solver it will be used for all the sub-solvers. /// /// - public sealed class CompositeSolver : IIterativeSolver + public sealed class CompositeSolver : IIterativeSolver { #region Internal class - DoubleComparer /// @@ -97,19 +94,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative private static readonly ICalculationStatus RunningStatus = new CalculationRunning(); #if SILVERLIGHT - private static readonly Dictionary>> SolverSetups = new Dictionary>>(); + private static readonly Dictionary> SolverSetups = new Dictionary>(); #else /// /// The collection of iterative solver setups. Stored based on the /// ratio between the relative speed and relative accuracy. /// - private static readonly SortedList>> SolverSetups = new SortedList>>(new DoubleComparer()); + private static readonly SortedList> SolverSetups = new SortedList>(new DoubleComparer()); #endif #region Solver information loading methods /// - /// Loads all the available objects from the MathNet.Numerics assembly. + /// Loads all the available objects from the MathNet.Numerics assembly. /// public static void LoadSolverInformation() { @@ -117,16 +114,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the MathNet.Numerics assembly. + /// Loads the available objects from the MathNet.Numerics assembly. /// - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformation(Type[] typesToExclude) { LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude); } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. public static void LoadSolverInformationFromAssembly(string assemblyLocation) @@ -135,10 +132,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(string assemblyLocation, params Type[] typesToExclude) { if (assemblyLocation == null) @@ -173,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName) @@ -182,10 +179,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName, params Type[] typesToExclude) { if (assemblyName == null) @@ -205,7 +202,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. public static void LoadSolverInformationFromAssembly(Type typeInAssembly) @@ -214,10 +211,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Type typeInAssembly, params Type[] typesToExclude) { if (typeInAssembly == null) @@ -229,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. public static void LoadSolverInformationFromAssembly(Assembly assembly) @@ -238,10 +235,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Assembly assembly, params Type[] typesToExclude) { if (assembly == null) @@ -266,18 +263,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative { interfaceTypes.Clear(); interfaceTypes.AddRange(type.GetInterfaces()); - if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) + if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) { continue; } // See if we actually want this type of iterative solver - IIterativeSolverSetup setup; + IIterativeSolverSetup setup; try { // If something goes wrong we just ignore it and move on with the next type. // There should probably be a log somewhere indicating that something went wrong? - setup = (IIterativeSolverSetup)Activator.CreateInstance(type); + setup = (IIterativeSolverSetup)Activator.CreateInstance(type); } catch (ArgumentException) { @@ -318,7 +315,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative var ratio = setup.SolutionSpeed / setup.Reliability; if (!SolverSetups.ContainsKey(ratio)) { - SolverSetups.Add(ratio, new List>()); + SolverSetups.Add(ratio, new List()); } var list = SolverSetups[ratio]; @@ -331,7 +328,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// The collection of solvers that will be used to /// - private readonly List> _solvers = new List>(); + private readonly List _solvers = new List(); /// /// The status of the calculation. @@ -341,7 +338,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// The iterator that is used to control the iteration process. /// - private IIterator _iterator; + private IIterator _iterator; /// /// A flag indicating if the solver has been stopped or not. @@ -352,7 +349,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The solver that is currently running. Reference is used to be able to stop the /// solver if the user cancels the solve process. /// - private IIterativeSolver _currentSolver; + private IIterativeSolver _currentSolver; /// /// Initializes a new instance of the class with the default iterator. @@ -365,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class with the specified iterator. /// /// The iterator that will be used to control the iteration process. - public CompositeSolver(IIterator iterator) + public CompositeSolver(IIterator iterator) { _iterator = iterator; } @@ -374,7 +371,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Sets the IIterator that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -412,14 +409,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -431,7 +428,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -481,8 +478,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // Create a copy of the solution and result vectors so we can use them // later on - var internalInput = input.Clone(); - var internalResult = result.Clone(); + var internalInput = (Vector)input.Clone(); + var internalResult = (Vector)result.Clone(); foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped)) { @@ -573,7 +570,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -585,7 +582,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -597,7 +594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -621,7 +618,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs index 26e35eb8..5451a75b 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Numerics; using Preconditioners; @@ -66,7 +63,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// solver. /// /// - public sealed class GpBiCg : IIterativeSolver + public sealed class GpBiCg : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -78,12 +75,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The preconditioner that will be used. Can be set to null, in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates the number of BiCGStab steps should be taken @@ -106,7 +103,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public GpBiCg() : this(null, null) @@ -121,18 +118,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public GpBiCg(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public GpBiCg(IIterator iterator) : this(null, iterator) { } @@ -140,11 +137,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -153,19 +150,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public GpBiCg(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public GpBiCg(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -216,19 +213,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -263,14 +260,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -282,7 +279,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -336,11 +333,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // x_0 is initial guess // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars @@ -349,26 +346,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // Define the temporary vectors // rDash_0 = r_0 - Vector rdash = new DenseVector(residuals); + Vector rdash = new DenseVector(residuals); // t_-1 = 0 - Vector t = new DenseVector(residuals.Count); - Vector t0 = new DenseVector(residuals.Count); + Vector t = new DenseVector(residuals.Count); + Vector t0 = new DenseVector(residuals.Count); // w_-1 = 0 - Vector w = new DenseVector(residuals.Count); + Vector w = new DenseVector(residuals.Count); // Define the remaining temporary vectors - Vector c = new DenseVector(residuals.Count); - Vector p = new DenseVector(residuals.Count); - Vector s = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector y = new DenseVector(residuals.Count); - Vector z = new DenseVector(residuals.Count); + Vector c = new DenseVector(residuals.Count); + Vector p = new DenseVector(residuals.Count); + Vector s = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector y = new DenseVector(residuals.Count); + Vector z = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); - Vector temp3 = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); + Vector temp3 = new DenseVector(residuals.Count); // for (k = 0, 1, .... ) var iterationNumber = 0; @@ -525,13 +522,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -545,11 +542,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -590,7 +587,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -602,7 +599,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -614,7 +611,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -638,7 +635,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs index 81ee45fb..ed1649e9 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs @@ -35,10 +35,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative using System.Diagnostics; using System.Linq; using Distributions; - using Generic; using Generic.Factorization; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Numerics; using Preconditioners; @@ -67,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// solver. /// /// - public sealed class MlkBiCgStab : IIterativeSolver + public sealed class MlkBiCgStab : IIterativeSolver { /// /// The default number of starting vectors. @@ -84,17 +81,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// The collection of starting vectors which are used as the basis for the Krylov sub-space. /// - private IList> _startingVectors; + private IList _startingVectors; /// /// The number of starting vectors used by the algorithm @@ -110,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public MlkBiCgStab() : this(null, null) @@ -125,18 +122,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IIterator iterator) : this(null, iterator) { } @@ -144,11 +141,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -157,19 +154,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -211,19 +208,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -232,7 +229,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Gets or sets a series of orthonormal vectors which will be used as basis for the /// Krylov sub-space. /// - public IList> StartingVectors + public IList StartingVectors { [DebuggerStepThrough] get @@ -284,14 +281,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -303,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -357,7 +354,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // Choose an initial guess x_0 // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // Choose k vectors q_1, q_2, ..., q_k // Build a new set if: @@ -386,24 +383,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary values var c = new Complex32[k]; // Define the temporary vectors - Vector gtemp = new DenseVector(residuals.Count); + Vector gtemp = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector utemp = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp1 = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector utemp = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp1 = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); - Vector zd = new DenseVector(residuals.Count); - Vector zg = new DenseVector(residuals.Count); - Vector zw = new DenseVector(residuals.Count); + Vector zd = new DenseVector(residuals.Count); + Vector zg = new DenseVector(residuals.Count); + Vector zw = new DenseVector(residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count); @@ -647,7 +644,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// the is smaller than /// the . /// - private static IList> CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) + private static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) { // Create no more starting vectors than the size of the problem - 1 // Get random values and then orthogonalize them with @@ -658,7 +655,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative // mean = 0 and sd = 1 var distribution = new Normal(); - Matrix matrix = new DenseMatrix(numberOfVariables, count); + Matrix matrix = new DenseMatrix(numberOfVariables, count); for (var i = 0; i < matrix.ColumnCount; i++) { var samples = new Complex32[matrix.RowCount]; @@ -678,10 +675,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative var orthogonalMatrix = gs.Q; // Now transfer this to vectors - var result = new List>(); + var result = new List(); for (var i = 0; i < orthogonalMatrix.ColumnCount; i++) { - result.Add(orthogonalMatrix.Column(i)); + result.Add((Vector)orthogonalMatrix.Column(i)); // Normalize the result vector result[i].Multiply(1 / result[i].Norm(2).Real, result[i]); @@ -691,14 +688,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Create random vecrors array + /// Create random vectors array /// /// Number of vectors /// Size of each vector /// Array of random vectors - private static Vector[] CreateVectorArray(int arraySize, int vectorSize) + private static Vector[] CreateVectorArray(int arraySize, int vectorSize) { - var result = new Vector[arraySize]; + var result = new Vector[arraySize]; for (var i = 0; i < result.Length; i++) { result[i] = new DenseVector(vectorSize); @@ -708,13 +705,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Source A. - /// Residual data. - /// x data. - /// b data. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Source A. + /// Residual data. + /// x data. + /// b data. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -728,11 +725,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -756,7 +753,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -768,7 +765,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -780,7 +777,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -804,7 +801,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs index 1a2ca2cf..06af4ffd 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Numerics; using Preconditioners; @@ -56,7 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// solver. /// /// - public sealed class TFQMR : IIterativeSolver + public sealed class TFQMR : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -68,12 +65,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -84,7 +81,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public TFQMR() : this(null, null) @@ -99,18 +96,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public TFQMR(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public TFQMR(IIterator iterator) : this(null, iterator) { } @@ -118,11 +115,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -131,38 +128,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public TFQMR(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public TFQMR(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -196,14 +193,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -215,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -427,13 +424,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -447,11 +444,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -485,7 +482,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -497,7 +494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -509,7 +506,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -533,7 +530,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs index 44dbc648..008091fb 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs @@ -33,18 +33,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers using System; using System.Collections.Generic; using System.Linq; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; - using Generic.Solvers.StopCriterium; - using Numerics; using Properties; using StopCriterium; /// /// An iterator that is used to check if an iterative calculation should continue or stop. /// - public sealed class Iterator : IIterator + public sealed class Iterator : IIterator { /// /// The default status for the iterator. @@ -52,10 +48,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers private static readonly ICalculationStatus DefaultStatus = new CalculationIndetermined(); /// - /// Creates a default iterator with all the objects. + /// Creates a default iterator with all the objects. /// - /// A new object. - public static IIterator CreateDefault() + /// A new object. + public static IIterator CreateDefault() { var iterator = new Iterator(); iterator.Add(new FailureStopCriterium()); @@ -70,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// The collection that holds all the stop criteria and the flag indicating if they should be added /// to the child iterators. /// - private readonly Dictionary> _stopCriterias = new Dictionary>(); + private readonly Dictionary _stopCriterias = new Dictionary(); /// /// The status of the iterator. @@ -97,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// of the stop criteria will be passed on to child iterators. /// /// Thrown if contains multiple stop criteria of the same type. - public Iterator(IEnumerable> stopCriteria) + public Iterator(IEnumerable stopCriteria) { // Add the stop criteria if (stopCriteria == null) @@ -112,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers } /// - /// Adds an to the internal collection of stop-criteria. Only a + /// Adds an to the internal collection of stop-criteria. Only a /// single stop criterium of each type can be stored. /// /// The stop criterium to add. @@ -121,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// Thrown if is of the same type as an already /// stored criterium. /// - public void Add(IIterationStopCriterium stopCriterium) + public void Add(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -138,10 +134,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers } /// - /// Removes the from the internal collection. + /// Removes the from the internal collection. /// /// The stop criterium that must be removed. - public void Remove(IIterationStopCriterium stopCriterium) + public void Remove(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -158,11 +154,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers } /// - /// Indicates if the specific stop criterium is stored by the . + /// Indicates if the specific stop criterium is stored by the . /// /// The stop criterium. - /// true if the contains the stop criterium; otherwise false. - public bool Contains(IIterationStopCriterium stopCriterium) + /// true if the contains the stop criterium; otherwise false. + public bool Contains(IIterationStopCriterium stopCriterium) { return stopCriterium != null && _stopCriterias.ContainsKey(stopCriterium.GetType()); } @@ -183,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// Gets an IEnumerator that enumerates over all the stored stop criteria. /// /// Used for testing only. - internal IEnumerator> StoredStopCriteria + internal IEnumerator StoredStopCriteria { get { @@ -216,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (_stopCriterias.Count == 0) { @@ -288,7 +284,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -309,9 +305,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers /// Creates a deep clone of the current iterator. /// /// The deep clone of the current iterator. - public IIterator Clone() + public IIterator Clone() { - var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); + var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); return new Iterator(stopCriteria); } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs index db39acef..c9c87171 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs @@ -31,8 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Numerics; using Properties; @@ -40,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreConditioner + public sealed class Diagonal : IPreConditioner { /// /// The inverse of the matrix diagonal. @@ -66,10 +64,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. + /// The upon which this preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -93,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -110,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -120,7 +118,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IPreConditioner.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IPreConditioner.cs new file mode 100644 index 00000000..0c34892e --- /dev/null +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IPreConditioner.cs @@ -0,0 +1,73 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners +{ + /// + /// The base interface for preconditioner classes. + /// + /// + /// + /// Preconditioners are used by iterative solvers to improve the convergence + /// speed of the solving process. Increase in convergence speed + /// is related to the number of iterations necessary to get a converged solution. + /// So while in general the use of a preconditioner means that the iterative + /// solver will perform fewer iterations it does not guarantee that the actual + /// solution time decreases given that some preconditioners can be expensive to + /// setup and run. + /// + /// + /// Note that in general changes to the matrix will invalidate the preconditioner + /// if the changes occur after creating the preconditioner. + /// + /// + public interface IPreConditioner + { + /// + /// Initializes the preconditioner and loads the internal data structures. + /// + /// The matrix on which the preconditioner is based. + void Initialize(Matrix matrix); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. + Vector Approximate(Vector rhs); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. Also known as the result vector. + void Approximate(Vector rhs, Vector lhs); + } +} diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs index 18cc82f7..e75179b9 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs @@ -32,8 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners { using System; using System.Collections.Generic; - using Generic; - using Generic.Solvers.Preconditioners; using Numerics; using Properties; @@ -54,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreConditioner + public sealed class Ilutp : IPreConditioner { /// /// The default fill level. @@ -258,9 +256,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { - return _upper.Clone(); + return (Matrix)_upper.Clone(); } /// @@ -270,9 +268,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { - return _lower.Clone(); + return (Matrix)_lower.Clone(); } /// @@ -298,13 +296,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. Note that the + /// The upon which this preconditioner is based. Note that the /// method takes a general matrix type. However internally the data is stored /// as a sparse matrix. Therefore it is not recommended to pass a dense matrix. /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -376,8 +374,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners _pivots[i] = i; } - Vector workVector = new DenseVector(sparseMatrix.RowCount); - Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); + Vector workVector = new DenseVector(sparseMatrix.RowCount); + Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); var indexSorting = new int[sparseMatrix.RowCount]; // spaceLeft = lfilNnz * nnz(A) @@ -532,8 +530,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// Pivot elements in the according to internal pivot array /// - /// Row to pivot in - private void PivotRow(Vector row) + /// Row to pivot in + private void PivotRow(Vector row) { var knownPivots = new Dictionary(); @@ -580,12 +578,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners } /// - /// Swap columns in the + /// Swap columns in the /// - /// Source . + /// Source . /// First column index to swap /// Second column index to swap - private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) + private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) { for (var i = 0; i < matrix.RowCount; i++) { @@ -601,8 +599,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Start sort form /// Sort till upper bound /// Array with sorted vector indicies - /// Source - private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// Source + private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Copy the indices for the values into the array for (var i = 0; i < upperBound + 1 - lowerBound; i++) @@ -627,7 +625,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -644,7 +642,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -654,7 +652,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -679,7 +677,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners // Solve equation here // Pivot(vector, result); // Solve L*Y = B(piv,:) - Vector rowValues = new DenseVector(_lower.RowCount); + Vector rowValues = new DenseVector(_lower.RowCount); for (var i = 0; i < _lower.RowCount; i++) { _lower.Row(i, rowValues); @@ -709,17 +707,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners // We have a column pivot so we only need to pivot the // end result not the incoming right hand side vector - var temp = lhs.Clone(); + var temp = (Vector)lhs.Clone(); Pivot(temp, lhs); } /// - /// Pivot elements in accoring to internal pivot array + /// Pivot elements in according to internal pivot array /// - /// Source . - /// Result after pivoting. - private void Pivot(Vector vector, Vector result) + /// Source . + /// Result after pivoting. + private void Pivot(Vector vector, Vector result) { for (var i = 0; i < _pivots.Length; i++) { diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs index b84e7571..cf2ee5cc 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs @@ -30,9 +30,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners { - using Generic; - using Numerics; - /// /// An element sort algorithm for the class. /// @@ -49,8 +46,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Move all the indices that we're interested in to the beginning of the // array. Ignore the rest of the indices. @@ -75,8 +72,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; var end = (upperBound - lowerBound + 1) - 1 + lowerBound; @@ -95,10 +92,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Build heap for double indicies /// /// Root position - /// Lenght of + /// Length of /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) { while (start >= 0) { @@ -111,17 +108,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Sift double indicies /// /// Indicies of - /// Target + /// Target /// Root position - /// Lenght of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) { var root = begin; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) { child += 1; @@ -171,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// Target values array /// Root position - /// Lenght of + /// Length of private static void BuildHeap(int[] values, int start, int count) { while (start >= 0) @@ -186,15 +182,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// Target value array /// Root position - /// Lenght of + /// Length of private static void Sift(int[] values, int start, int count) { var root = start; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[child] > values[child + 1])) { child += 1; @@ -216,8 +211,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Exchange values in array /// /// Target values array - /// First value to exchanghe - /// Second value to exchanghe + /// First value to exchange + /// Second value to exchange private static void Exchange(int[] values, int first, int second) { var t = values[first]; diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs index 016e65ff..7c908554 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs @@ -31,8 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Numerics; using Properties; @@ -45,7 +43,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreConditioner + public sealed class IncompleteLU : IPreConditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The @@ -57,7 +55,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Returns the upper triagonal matrix that was created during the LU decomposition. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -75,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Returns the lower triagonal matrix that was created during the LU decomposition. /// /// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -102,7 +100,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// The matrix upon which the preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -164,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -181,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -191,7 +189,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -221,7 +219,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners // z_i = l_ii^-1 * (y_i - SUM_(j rowValues = new DenseVector(_decompositionLU.RowCount); + Vector rowValues = new DenseVector(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) { // Clear the rowValues diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/UnitPreconditioner.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/UnitPreconditioner.cs index 19dac74b..cfdae773 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/UnitPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/UnitPreconditioner.cs @@ -31,18 +31,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; - using Numerics; using Properties; /// /// A unit preconditioner. This preconditioner does not actually do anything - /// it is only used when running an without + /// it is only used when running an without /// a preconditioner. /// - internal sealed class UnitPreconditioner : IPreConditioner + internal sealed class UnitPreconditioner : IPreConditioner { /// /// The coefficient matrix on which this preconditioner operates. @@ -58,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -91,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// If the size of is different the number of rows of the coefficient matrix. /// /// - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -120,7 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// /// If the size of is different the number of rows of the coefficient matrix. /// - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -132,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentMatrixDimensions); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs index 165e9575..cbe6f37e 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs @@ -32,15 +32,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; - using Numerics; /// /// Monitors an iterative calculation for signs of divergence. /// - public sealed class DivergenceStopCriterium : IIterationStopCriterium + public sealed class DivergenceStopCriterium : IIterationStopCriterium { /// /// Default value for the maximum relative increase that the @@ -208,7 +206,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -219,7 +217,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -302,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium } /// - /// Gets required history lenght + /// Gets required history Length /// private int RequiredHistoryLength { @@ -348,7 +346,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -359,7 +357,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -375,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs index d3d1d0a7..8ab3a39f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; - using Numerics; using Properties; /// - /// Defines an that monitors residuals for NaN's. + /// Defines an that monitors residuals for NaN's. /// - public sealed class FailureStopCriterium : IIterationStopCriterium + public sealed class FailureStopCriterium : IIterationStopCriterium { /// /// Defines the default last iteration number. Set to -1 because iterations normally @@ -66,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -77,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -157,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -167,7 +165,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -183,7 +181,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new FailureStopCriterium(); } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs new file mode 100644 index 00000000..8853629a --- /dev/null +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs @@ -0,0 +1,80 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium +{ + using System; + using Generic.Solvers.Status; + using Generic.Solvers.StopCriterium; + + /// + /// The base interface for classes that provide stop criteria for iterative calculations. + /// + public interface IIterationStopCriterium +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual stop criteria may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// To implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + void ResetToPrecalculationState(); + + /// + /// Gets the which indicates what sort of stop criterium this + /// monitors. + /// + StopLevel StopLevel { get; } + +#if SILVERLIGHT + IIterationStopCriterium Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs index 0fd95d0b..451fcb32 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; - using Numerics; /// - /// Defines an that monitors the numbers of iteration + /// Defines an that monitors the numbers of iteration /// steps as stop criterium. /// - public sealed class IterationCountStopCriterium : IIterationStopCriterium + public sealed class IterationCountStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum number of iterations the process is allowed @@ -132,7 +130,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -209,7 +207,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new IterationCountStopCriterium(_maximumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs index 906e6046..1ada26d7 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs @@ -32,16 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; - using Numerics; using Properties; /// - /// Defines an that monitors residuals as stop criterium. + /// Defines an that monitors residuals as stop criterium. /// - public sealed class ResidualStopCriterium : IIterationStopCriterium + public sealed class ResidualStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum value of the residual. @@ -213,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -224,7 +222,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -364,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -375,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -391,7 +389,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum); } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs new file mode 100644 index 00000000..9c3ed963 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs @@ -0,0 +1,96 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Double.Solvers +{ + using Generic.Solvers.Status; + + /// + /// Defines the interface for classes that solve the matrix equation Ax = b in + /// an iterative manner. + /// + public interface IIterativeSolver + { + /// + /// Stops the solve process. + /// + /// + /// Note that it may take an indetermined amount of time for the solver to actually stop the process. + /// + void StopSolve(); + + /// + /// Sets the that will be used to track the iterative process. + /// + /// The iterator. + void SetIterator(IIterator iterator); + + /// + /// Gets the status of the iteration once the calculation is finished. + /// + ICalculationStatus IterationResult { get; } + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b. + /// The result vector, x. + Vector Solve(Matrix matrix, Vector vector); + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b + /// The result vector, x + void Solve(Matrix matrix, Vector input, Vector result); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X. + Matrix Solve(Matrix matrix, Matrix input); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X + void Solve(Matrix matrix, Matrix input, Matrix result); + } +} diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolverSetup.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolverSetup.cs new file mode 100644 index 00000000..86ec59f4 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolverSetup.cs @@ -0,0 +1,71 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Double.Solvers +{ + using System; + + /// + /// Defines the interface for objects that can create an iterative solver with + /// specific settings. This interface is used to pass iterative solver creation + /// setup information around. + /// + public interface IIterativeSolverSetup + { + /// + /// Gets the type of the solver that will be created by this setup object. + /// + Type SolverType { get; } + + /// + /// Gets type of preconditioner, if any, that will be created by this setup object. + /// + Type PreconditionerType { get; } + + /// + /// Creates a fully functional iterative solver with the default settings + /// given by this setup. + /// + /// A new . + IIterativeSolver CreateNew(); + + /// + /// Gets the relative speed of the solver. + /// + /// Returns a value between 0 and 1, inclusive. + double SolutionSpeed { get; } + + /// + /// Gets the relative reliability of the solver. + /// + /// Returns a value between 0 and 1 inclusive. + double Reliability { get; } + } +} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs new file mode 100644 index 00000000..3f68df69 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs @@ -0,0 +1,108 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Double.Solvers +{ + using System; + using Generic.Solvers.Status; + using StopCriterium; + + /// + /// Defines the base interface for iterators that help control an iterative calculation. + /// + public interface IIterator +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Adds an to the internal collection of stop-criteria. Only a + /// single stop criterium of each type can be stored. + /// + /// The stop criterium to add. + /// Thrown if is . + /// Thrown if is of the same type as an already stored criterium. + void Add(IIterationStopCriterium stopCriterium); + + /// + /// Removes the from the internal collection. + /// + /// The stop criterium that must be removed. + void Remove(IIterationStopCriterium stopCriterium); + + /// + /// Indicates if the specific stop criterium is stored by the . + /// + /// The stop criterium. + /// true if the contains the stop criterium; otherwise false. + bool Contains(IIterationStopCriterium stopCriterium); + + /// + /// Indicates to the iterator that the iterative process has been cancelled. + /// + /// Does not reset the stop-criteria. + void IterationCancelled(); + + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual iterators may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation.. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// + /// Note to implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + /// + void ResetToPrecalculationState(); + +#if SILVERLIGHT + IIterator Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs index cfc20bb5..7fcb67de 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -67,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// solver. /// /// - public sealed class BiCgStab : IIterativeSolver + public sealed class BiCgStab : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -79,12 +76,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -95,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public BiCgStab() : this(null, null) @@ -110,18 +107,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public BiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public BiCgStab(IIterator iterator) : this(null, iterator) { } @@ -129,11 +126,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -142,38 +139,38 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public BiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public BiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -193,7 +190,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Stops the solve process. /// /// - /// Note that it may take an indetermined amount of time for the solver to actually stop the process. + /// It may take an indetermined amount of time for the solver to actually stop the process. /// public void StopSolve() { @@ -204,17 +201,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public Vector Solve(Matrix matrix, Vector vector) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + var result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -223,10 +220,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public void Solve(Matrix matrix, Vector input, Vector result) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -281,7 +278,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // Compute r_0 = b - Ax_0 for some initial guess x_0 // In this case we take x_0 = vector // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, result, input); // Choose r~ (for example, r~ = r_0) @@ -290,13 +287,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // create seven temporary vectors needed to hold temporary // coefficients. All vectors are mangled in each iteration. // These are defined here to prevent stressing the garbage collector - Vector vecP = new DenseVector(residuals.Count); - Vector vecPdash = new DenseVector(residuals.Count); - Vector nu = new DenseVector(residuals.Count); - Vector vecS = new DenseVector(residuals.Count); - Vector vecSdash = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector vecP = new DenseVector(residuals.Count); + Vector vecPdash = new DenseVector(residuals.Count); + Vector nu = new DenseVector(residuals.Count); + Vector vecS = new DenseVector(residuals.Count); + Vector vecSdash = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); // create some temporary double variables that are needed // to hold values in between iterations @@ -428,13 +425,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -450,11 +447,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -475,10 +472,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X. - public Matrix Solve(Matrix matrix, Matrix input) + /// The coefficient , A. + /// The solution , B. + /// The result , X. + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -490,7 +487,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -499,10 +496,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X - public void Solve(Matrix matrix, Matrix input, Matrix result) + /// The coefficient , A. + /// The solution , B. + /// The result , X + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -526,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs index e102458b..dd9bddb1 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs @@ -31,12 +31,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { using System; + using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; using Properties; @@ -55,15 +54,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Note that if an iterator is passed to this solver it will be used for all the sub-solvers. /// /// - public sealed class CompositeSolver : IIterativeSolver + public sealed class CompositeSolver : IIterativeSolver { #region Internal class - DoubleComparer /// /// An IComparer used to compare double precision floating points. /// - /// NOTE: The instance of this class is used only in . If C# suppports interface inheritence - /// NOTE: and methods in anonymous types, then this class should be deleted and anonymous type implemented with IComaprer support - /// NOTE: in constructor public sealed class DoubleComparer : IComparer { /// @@ -96,19 +92,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative private static readonly ICalculationStatus RunningStatus = new CalculationRunning(); #if SILVERLIGHT - private static readonly Dictionary>> SolverSetups = new Dictionary>>(); + private static readonly Dictionary> SolverSetups = new Dictionary>(); #else /// /// The collection of iterative solver setups. Stored based on the /// ratio between the relative speed and relative accuracy. /// - private static readonly SortedList>> SolverSetups = new SortedList>>(new DoubleComparer()); + private static readonly SortedList> SolverSetups = new SortedList>(new DoubleComparer()); #endif #region Solver information loading methods /// - /// Loads all the available objects from the MathNet.Numerics assembly. + /// Loads all the available objects from the MathNet.Numerics assembly. /// public static void LoadSolverInformation() { @@ -116,16 +112,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the MathNet.Numerics assembly. + /// Loads the available objects from the MathNet.Numerics assembly. /// - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformation(Type[] typesToExclude) { LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude); } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. public static void LoadSolverInformationFromAssembly(string assemblyLocation) @@ -134,10 +130,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(string assemblyLocation, params Type[] typesToExclude) { if (assemblyLocation == null) @@ -172,7 +168,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName) @@ -181,10 +177,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName, params Type[] typesToExclude) { if (assemblyName == null) @@ -204,7 +200,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. public static void LoadSolverInformationFromAssembly(Type typeInAssembly) @@ -213,10 +209,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Type typeInAssembly, params Type[] typesToExclude) { if (typeInAssembly == null) @@ -228,7 +224,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. public static void LoadSolverInformationFromAssembly(Assembly assembly) @@ -237,10 +233,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Assembly assembly, params Type[] typesToExclude) { if (assembly == null) @@ -265,18 +261,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { interfaceTypes.Clear(); interfaceTypes.AddRange(type.GetInterfaces()); - if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) + if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) { continue; } // See if we actually want this type of iterative solver - IIterativeSolverSetup setup; + IIterativeSolverSetup setup; try { // If something goes wrong we just ignore it and move on with the next type. // There should probably be a log somewhere indicating that something went wrong? - setup = (IIterativeSolverSetup)Activator.CreateInstance(type); + setup = (IIterativeSolverSetup)Activator.CreateInstance(type); } catch (ArgumentException) { @@ -317,7 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative var ratio = setup.SolutionSpeed / setup.Reliability; if (!SolverSetups.ContainsKey(ratio)) { - SolverSetups.Add(ratio, new List>()); + SolverSetups.Add(ratio, new List()); } var list = SolverSetups[ratio]; @@ -330,7 +326,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// The collection of solvers that will be used to /// - private readonly List> _solvers = new List>(); + private readonly List _solvers = new List(); /// /// The status of the calculation. @@ -340,7 +336,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// The iterator that is used to control the iteration process. /// - private IIterator _iterator; + private IIterator _iterator; /// /// A flag indicating if the solver has been stopped or not. @@ -351,7 +347,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The solver that is currently running. Reference is used to be able to stop the /// solver if the user cancels the solve process. /// - private IIterativeSolver _currentSolver; + private IIterativeSolver _currentSolver; /// /// Initializes a new instance of the class with the default iterator. @@ -364,16 +360,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class with the specified iterator. /// /// The iterator that will be used to control the iteration process. - public CompositeSolver(IIterator iterator) + public CompositeSolver(IIterator iterator) { _iterator = iterator; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -411,14 +407,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -430,7 +426,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -480,8 +476,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // Create a copy of the solution and result vectors so we can use them // later on - var internalInput = input.Clone(); - var internalResult = result.Clone(); + var internalInput = (Vector)input.Clone(); + var internalResult = (Vector)result.Clone(); foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped)) { @@ -572,7 +568,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -584,7 +580,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -596,7 +592,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -620,7 +616,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs index 13bb7ba1..40241d64 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -65,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// solver. /// /// - public sealed class GpBiCg : IIterativeSolver + public sealed class GpBiCg : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -77,12 +74,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The preconditioner that will be used. Can be set to null, in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates the number of BiCGStab steps should be taken @@ -105,7 +102,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public GpBiCg() : this(null, null) @@ -120,18 +117,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public GpBiCg(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public GpBiCg(IIterator iterator) : this(null, iterator) { } @@ -139,11 +136,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -152,19 +149,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public GpBiCg(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public GpBiCg(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -215,19 +212,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -262,14 +259,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -281,7 +278,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -335,11 +332,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // x_0 is initial guess // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars @@ -348,26 +345,26 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // Define the temporary vectors // rDash_0 = r_0 - Vector rdash = new DenseVector(residuals); + Vector rdash = new DenseVector(residuals); // t_-1 = 0 - Vector t = new DenseVector(residuals.Count); - Vector t0 = new DenseVector(residuals.Count); + Vector t = new DenseVector(residuals.Count); + Vector t0 = new DenseVector(residuals.Count); // w_-1 = 0 - Vector w = new DenseVector(residuals.Count); + Vector w = new DenseVector(residuals.Count); // Define the remaining temporary vectors - Vector c = new DenseVector(residuals.Count); - Vector p = new DenseVector(residuals.Count); - Vector s = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector y = new DenseVector(residuals.Count); - Vector z = new DenseVector(residuals.Count); + Vector c = new DenseVector(residuals.Count); + Vector p = new DenseVector(residuals.Count); + Vector s = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector y = new DenseVector(residuals.Count); + Vector z = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); - Vector temp3 = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); + Vector temp3 = new DenseVector(residuals.Count); // for (k = 0, 1, .... ) var iterationNumber = 0; @@ -526,11 +523,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -544,11 +541,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -589,7 +586,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -601,7 +598,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -613,7 +610,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -637,7 +634,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs index d4920723..a87e5046 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs @@ -37,8 +37,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative using Distributions; using Generic; using Generic.Factorization; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -66,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// solver. /// /// - public sealed class MlkBiCgStab : IIterativeSolver + public sealed class MlkBiCgStab : IIterativeSolver { /// /// The default number of starting vectors. @@ -83,17 +81,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// The collection of starting vectors which are used as the basis for the Krylov sub-space. /// - private IList> _startingVectors; + private IList _startingVectors; /// /// The number of starting vectors used by the algorithm @@ -109,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public MlkBiCgStab() : this(null, null) @@ -124,18 +122,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IIterator iterator) : this(null, iterator) { } @@ -143,11 +141,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -156,19 +154,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -210,19 +208,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -231,7 +229,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Gets or sets a series of orthonormal vectors which will be used as basis for the /// Krylov sub-space. /// - public IList> StartingVectors + public IList StartingVectors { [DebuggerStepThrough] get @@ -283,14 +281,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -302,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -356,7 +354,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // Choose an initial guess x_0 // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // Choose k vectors q_1, q_2, ..., q_k // Build a new set if: @@ -385,24 +383,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars var c = new double[k]; // Define the temporary vectors - Vector gtemp = new DenseVector(residuals.Count); + Vector gtemp = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector utemp = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp1 = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector utemp = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp1 = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); - Vector zd = new DenseVector(residuals.Count); - Vector zg = new DenseVector(residuals.Count); - Vector zw = new DenseVector(residuals.Count); + Vector zd = new DenseVector(residuals.Count); + Vector zg = new DenseVector(residuals.Count); + Vector zw = new DenseVector(residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count); @@ -646,7 +644,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// the is smaller than /// the . /// - private static IList> CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) + private static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) { // Create no more starting vectors than the size of the problem - 1 // Get random values and then orthogonalize them with @@ -657,7 +655,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative // mean = 0 and sd = 1 var distribution = new Normal(); - Matrix matrix = new DenseMatrix(numberOfVariables, count); + Matrix matrix = new DenseMatrix(numberOfVariables, count); for (var i = 0; i < matrix.ColumnCount; i++) { var samples = distribution.Samples().Take(matrix.RowCount).ToArray(); @@ -671,10 +669,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative var orthogonalMatrix = gs.Q; // Now transfer this to vectors - var result = new List>(); + var result = new List(); for (var i = 0; i < orthogonalMatrix.ColumnCount; i++) { - result.Add(orthogonalMatrix.Column(i)); + result.Add((Vector)orthogonalMatrix.Column(i)); // Normalize the result vector result[i].Multiply(1 / result[i].Norm(2), result[i]); @@ -689,9 +687,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Number of vectors /// Size of each vector /// Array of random vectors - private static Vector[] CreateVectorArray(int arraySize, int vectorSize) + private static Vector[] CreateVectorArray(int arraySize, int vectorSize) { - var result = new Vector[arraySize]; + var result = new Vector[arraySize]; for (var i = 0; i < result.Length; i++) { result[i] = new DenseVector(vectorSize); @@ -703,11 +701,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Source A. - /// Residual data. - /// x data. - /// b data. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Source A. + /// Residual data. + /// x data. + /// b data. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -721,11 +719,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -749,7 +747,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -761,7 +759,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -773,7 +771,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -797,7 +795,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs index 2b9d1c38..02d68401 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -55,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// solver. /// /// - public sealed class TFQMR : IIterativeSolver + public sealed class TFQMR : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -67,12 +64,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -83,7 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public TFQMR() : this(null, null) @@ -98,18 +95,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public TFQMR(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public TFQMR(IIterator iterator) : this(null, iterator) { } @@ -117,11 +114,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -130,38 +127,38 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public TFQMR(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public TFQMR(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -195,14 +192,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -214,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -426,13 +423,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -446,11 +443,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -484,7 +481,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -496,7 +493,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -508,7 +505,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -532,7 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs index a5f05f52..98361b7e 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs @@ -33,17 +33,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers using System; using System.Collections.Generic; using System.Linq; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; - using Generic.Solvers.StopCriterium; using Properties; using StopCriterium; /// /// An iterator that is used to check if an iterative calculation should continue or stop. /// - public sealed class Iterator : IIterator + public sealed class Iterator : IIterator { /// /// The default status for the iterator. @@ -51,10 +48,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers private static readonly ICalculationStatus DefaultStatus = new CalculationIndetermined(); /// - /// Creates a default iterator with all the objects. + /// Creates a default iterator with all the objects. /// - /// A new object. - public static IIterator CreateDefault() + /// A new object. + public static IIterator CreateDefault() { var iterator = new Iterator(); iterator.Add(new FailureStopCriterium()); @@ -69,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// The collection that holds all the stop criteria and the flag indicating if they should be added /// to the child iterators. /// - private readonly Dictionary> _stopCriterias = new Dictionary>(); + private readonly Dictionary _stopCriterias = new Dictionary(); /// /// The status of the iterator. @@ -77,7 +74,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers private ICalculationStatus _status = DefaultStatus; /// - /// Indicates if the iteration was cancelled. + /// Indicates if the iteration was canceled. /// private bool _wasIterationCancelled; @@ -96,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// of the stop criteria will be passed on to child iterators. /// /// Thrown if contains multiple stop criteria of the same type. - public Iterator(IEnumerable> stopCriteria) + public Iterator(IEnumerable stopCriteria) { // Add the stop criteria if (stopCriteria == null) @@ -111,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers } /// - /// Adds an to the internal collection of stop-criteria. Only a + /// Adds an to the internal collection of stop-criteria. Only a /// single stop criterium of each type can be stored. /// /// The stop criterium to add. @@ -120,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// Thrown if is of the same type as an already /// stored criterium. /// - public void Add(IIterationStopCriterium stopCriterium) + public void Add(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -137,10 +134,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers } /// - /// Removes the from the internal collection. + /// Removes the from the internal collection. /// /// The stop criterium that must be removed. - public void Remove(IIterationStopCriterium stopCriterium) + public void Remove(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -157,11 +154,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers } /// - /// Indicates if the specific stop criterium is stored by the . + /// Indicates if the specific stop criterium is stored by the . /// /// The stop criterium. - /// true if the contains the stop criterium; otherwise false. - public bool Contains(IIterationStopCriterium stopCriterium) + /// true if the contains the stop criterium; otherwise false. + public bool Contains(IIterationStopCriterium stopCriterium) { return stopCriterium != null && _stopCriterias.ContainsKey(stopCriterium.GetType()); } @@ -182,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// Gets an IEnumerator that enumerates over all the stored stop criteria. /// /// Used for testing only. - internal IEnumerator> StoredStopCriteria + internal IEnumerator StoredStopCriteria { get { @@ -204,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -215,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (_stopCriterias.Count == 0) { @@ -287,7 +284,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -308,9 +305,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers /// Creates a deep clone of the current iterator. /// /// The deep clone of the current iterator. - public IIterator Clone() + public IIterator Clone() { - var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); + var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); return new Iterator(stopCriteria); } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs index 32f318f9..9dccb70a 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs @@ -31,15 +31,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreConditioner + public sealed class Diagonal : IPreConditioner { /// /// The inverse of the matrix diagonal. @@ -65,10 +63,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. + /// The upon which this preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -92,7 +90,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -109,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -119,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IPreConditioner.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IPreConditioner.cs new file mode 100644 index 00000000..e6534041 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IPreConditioner.cs @@ -0,0 +1,73 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners +{ + /// + /// The base interface for preconditioner classes. + /// + /// + /// + /// Preconditioners are used by iterative solvers to improve the convergence + /// speed of the solving process. Increase in convergence speed + /// is related to the number of iterations necessary to get a converged solution. + /// So while in general the use of a preconditioner means that the iterative + /// solver will perform fewer iterations it does not guarantee that the actual + /// solution time decreases given that some preconditioners can be expensive to + /// setup and run. + /// + /// + /// Note that in general changes to the matrix will invalidate the preconditioner + /// if the changes occur after creating the preconditioner. + /// + /// + public interface IPreConditioner + { + /// + /// Initializes the preconditioner and loads the internal data structures. + /// + /// The matrix on which the preconditioner is based. + void Initialize(Matrix matrix); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. + Vector Approximate(Vector rhs); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. Also known as the result vector. + void Approximate(Vector rhs, Vector lhs); + } +} diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs index 709b5987..330a6336 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs @@ -32,8 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners { using System; using System.Collections.Generic; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -53,7 +51,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreConditioner + public sealed class Ilutp : IPreConditioner { /// /// The default fill level. @@ -257,9 +255,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { - return _upper.Clone(); + return (Matrix)_upper.Clone(); } /// @@ -269,9 +267,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { - return _lower.Clone(); + return (Matrix)_lower.Clone(); } /// @@ -297,13 +295,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. Note that the + /// The upon which this preconditioner is based. Note that the /// method takes a general matrix type. However internally the data is stored /// as a sparse matrix. Therefore it is not recommended to pass a dense matrix. /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -375,8 +373,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners _pivots[i] = i; } - Vector workVector = new DenseVector(sparseMatrix.RowCount); - Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); + Vector workVector = new DenseVector(sparseMatrix.RowCount); + Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); var indexSorting = new int[sparseMatrix.RowCount]; // spaceLeft = lfilNnz * nnz(A) @@ -531,8 +529,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// Pivot elements in the according to internal pivot array /// - /// Row to pivot in - private void PivotRow(Vector row) + /// Row to pivot in + private void PivotRow(Vector row) { var knownPivots = new Dictionary(); @@ -579,12 +577,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners } /// - /// Swap columns in the + /// Swap columns in the /// - /// Source . + /// Source . /// First column index to swap /// Second column index to swap - private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) + private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) { for (var i = 0; i < matrix.RowCount; i++) { @@ -600,8 +598,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Start sort form /// Sort till upper bound /// Array with sorted vector indicies - /// Source - private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// Source + private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Copy the indices for the values into the array for (var i = 0; i < upperBound + 1 - lowerBound; i++) @@ -626,7 +624,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -643,7 +641,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -653,7 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -678,7 +676,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners // Solve equation here // Pivot(vector, result); // Solve L*Y = B(piv,:) - Vector rowValues = new DenseVector(_lower.RowCount); + Vector rowValues = new DenseVector(_lower.RowCount); for (var i = 0; i < _lower.RowCount; i++) { _lower.Row(i, rowValues); @@ -708,17 +706,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners // We have a column pivot so we only need to pivot the // end result not the incoming right hand side vector - var temp = lhs.Clone(); + var temp = (Vector)lhs.Clone(); Pivot(temp, lhs); } /// - /// Pivot elements in accoring to internal pivot array + /// Pivot elements in according to internal pivot array /// - /// Source . - /// Result after pivoting. - private void Pivot(Vector vector, Vector result) + /// Source . + /// Result after pivoting. + private void Pivot(Vector vector, Vector result) { for (var i = 0; i < _pivots.Length; i++) { diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs index 5698cd67..4371c911 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs @@ -30,8 +30,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners { - using Generic; - /// /// An element sort algorithm for the class. /// @@ -48,8 +46,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Move all the indices that we're interested in to the beginning of the // array. Ignore the rest of the indices. @@ -74,8 +72,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; var end = (upperBound - lowerBound + 1) - 1 + lowerBound; @@ -94,10 +92,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Build heap for double indicies ///
/// Root position - /// Lenght of + /// Length of /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) { while (start >= 0) { @@ -110,17 +108,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Sift double indicies /// /// Indicies of - /// Target + /// Target /// Root position - /// Lenght of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) { var root = begin; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) { child += 1; @@ -170,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// Target values array /// Root position - /// Lenght of + /// Length of private static void BuildHeap(int[] values, int start, int count) { while (start >= 0) @@ -185,15 +182,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// Target value array /// Root position - /// Lenght of + /// Length of private static void Sift(int[] values, int start, int count) { var root = start; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[child] > values[child + 1])) { child += 1; @@ -215,8 +211,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Exchange values in array /// /// Target values array - /// First value to exchanghe - /// Second value to exchanghe + /// First value to exchange + /// Second value to exchange private static void Exchange(int[] values, int first, int second) { var t = values[first]; diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs index 4b3862df..ba592e70 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs @@ -31,8 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -44,7 +42,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreConditioner + public sealed class IncompleteLU : IPreConditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The @@ -56,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Returns the upper triagonal matrix that was created during the LU decomposition. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -74,7 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Returns the lower triagonal matrix that was created during the LU decomposition. ///
/// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -101,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// The matrix upon which the preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -163,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -180,7 +178,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -190,7 +188,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -220,7 +218,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners // z_i = l_ii^-1 * (y_i - SUM_(j rowValues = new DenseVector(_decompositionLU.RowCount); + Vector rowValues = new DenseVector(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) { // Clear the rowValues diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/UnitPreconditioner.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/UnitPreconditioner.cs index b9d6390f..9f586f76 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/UnitPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/UnitPreconditioner.cs @@ -31,17 +31,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Properties; /// /// A unit preconditioner. This preconditioner does not actually do anything - /// it is only used when running an without + /// it is only used when running an without /// a preconditioner. /// - internal sealed class UnitPreconditioner : IPreConditioner + internal sealed class UnitPreconditioner : IPreConditioner { /// /// The coefficient matrix on which this preconditioner operates. @@ -57,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -90,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// If the size of is different the number of rows of the coefficient matrix. /// /// - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -119,7 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// If the size of is different the number of rows of the coefficient matrix. /// - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -131,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentMatrixDimensions); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs index ba49e98d..5356827a 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs @@ -32,14 +32,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// /// Monitors an iterative calculation for signs of divergence. /// - public sealed class DivergenceStopCriterium : IIterationStopCriterium + public sealed class DivergenceStopCriterium : IIterationStopCriterium { /// /// Default value for the maximum relative increase that the @@ -207,7 +206,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -218,7 +217,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -301,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium } /// - /// Gets required history lenght + /// Gets required history Length /// private int RequiredHistoryLength { @@ -347,7 +346,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -358,7 +357,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -374,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs index fc400b6a..dd52ce1e 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals for NaN's. + /// Defines an that monitors residuals for NaN's. /// - public sealed class FailureStopCriterium : IIterationStopCriterium + public sealed class FailureStopCriterium : IIterationStopCriterium { /// /// Defines the default last iteration number. Set to -1 because iterations normally @@ -65,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -76,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -156,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -166,7 +165,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -182,7 +181,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new FailureStopCriterium(); } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs new file mode 100644 index 00000000..95a9824d --- /dev/null +++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs @@ -0,0 +1,80 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium +{ + using System; + using Generic.Solvers.Status; + using Generic.Solvers.StopCriterium; + + /// + /// The base interface for classes that provide stop criteria for iterative calculations. + /// + public interface IIterationStopCriterium +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual stop criteria may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// To implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + void ResetToPrecalculationState(); + + /// + /// Gets the which indicates what sort of stop criterium this + /// monitors. + /// + StopLevel StopLevel { get; } + +#if SILVERLIGHT + IIterationStopCriterium Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs index 01dfd691..8331418a 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// - /// Defines an that monitors the numbers of iteration + /// Defines an that monitors the numbers of iteration /// steps as stop criterium. /// - public sealed class IterationCountStopCriterium : IIterationStopCriterium + public sealed class IterationCountStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum number of iterations the process is allowed @@ -131,7 +130,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -208,7 +207,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new IterationCountStopCriterium(_maximumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs index 9976b52a..e4549885 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals as stop criterium. + /// Defines an that monitors residuals as stop criterium. /// - public sealed class ResidualStopCriterium : IIterationStopCriterium + public sealed class ResidualStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum value of the residual. @@ -212,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -223,7 +222,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -363,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -374,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -390,7 +389,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum); } diff --git a/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/StopLevel.cs b/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/StopLevel.cs index 48e5b847..b9f71763 100644 --- a/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/StopLevel.cs +++ b/src/Numerics/LinearAlgebra/Generic/Solvers/StopCriterium/StopLevel.cs @@ -27,29 +27,28 @@ namespace MathNet.Numerics.LinearAlgebra.Generic.Solvers.StopCriterium { /// - /// Indicates what an monitors for stop criteria. + /// Iteration stop criteria. /// public enum StopLevel { /// - /// The monitors calculation failures in the - /// iterative calculation. + /// Monitor calculation failures in the iterative calculation. /// CalculationFailure, /// - /// The monitors the calculation for signs of divergence. + /// Monitor the calculation for signs of divergence. /// Divergence, /// - /// The guards the calculation against unlimited continuation + /// Guard the calculation against unlimited continuation /// by monitoring user specified limits, e.g. the maximum number of iterations. /// StoppedWithoutConvergence, /// - /// The monitors the calculation for convergence, usually + /// Monitor the calculation for convergence, usually /// based on the residuals of the calculation. /// Convergence diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs new file mode 100644 index 00000000..ebd06d3c --- /dev/null +++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs @@ -0,0 +1,96 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Single.Solvers +{ + using Generic.Solvers.Status; + + /// + /// Defines the interface for classes that solve the matrix equation Ax = b in + /// an iterative manner. + /// + public interface IIterativeSolver + { + /// + /// Stops the solve process. + /// + /// + /// Note that it may take an indetermined amount of time for the solver to actually stop the process. + /// + void StopSolve(); + + /// + /// Sets the that will be used to track the iterative process. + /// + /// The iterator. + void SetIterator(IIterator iterator); + + /// + /// Gets the status of the iteration once the calculation is finished. + /// + ICalculationStatus IterationResult { get; } + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b. + /// The result vector, x. + Vector Solve(Matrix matrix, Vector vector); + + /// + /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the + /// solution vector and x is the unknown vector. + /// + /// The coefficient matrix, A. + /// The solution vector, b + /// The result vector, x + void Solve(Matrix matrix, Vector input, Vector result); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X. + Matrix Solve(Matrix matrix, Matrix input); + + /// + /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the + /// solution matrix and X is the unknown matrix. + /// + /// The coefficient matrix, A. + /// The solution matrix, B. + /// The result matrix, X + void Solve(Matrix matrix, Matrix input, Matrix result); + } +} diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolverSetup.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolverSetup.cs new file mode 100644 index 00000000..5a77d291 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolverSetup.cs @@ -0,0 +1,71 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Single.Solvers +{ + using System; + + /// + /// Defines the interface for objects that can create an iterative solver with + /// specific settings. This interface is used to pass iterative solver creation + /// setup information around. + /// + public interface IIterativeSolverSetup + { + /// + /// Gets the type of the solver that will be created by this setup object. + /// + Type SolverType { get; } + + /// + /// Gets type of preconditioner, if any, that will be created by this setup object. + /// + Type PreconditionerType { get; } + + /// + /// Creates a fully functional iterative solver with the default settings + /// given by this setup. + /// + /// A new . + IIterativeSolver CreateNew(); + + /// + /// Gets the relative speed of the solver. + /// + /// Returns a value between 0 and 1, inclusive. + double SolutionSpeed { get; } + + /// + /// Gets the relative reliability of the solver. + /// + /// Returns a value between 0 and 1 inclusive. + double Reliability { get; } + } +} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs new file mode 100644 index 00000000..446a02ed --- /dev/null +++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs @@ -0,0 +1,108 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Single.Solvers +{ + using System; + using Generic.Solvers.Status; + using StopCriterium; + + /// + /// Defines the base interface for iterators that help control an iterative calculation. + /// + public interface IIterator +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Adds an to the internal collection of stop-criteria. Only a + /// single stop criterium of each type can be stored. + /// + /// The stop criterium to add. + /// Thrown if is . + /// Thrown if is of the same type as an already stored criterium. + void Add(IIterationStopCriterium stopCriterium); + + /// + /// Removes the from the internal collection. + /// + /// The stop criterium that must be removed. + void Remove(IIterationStopCriterium stopCriterium); + + /// + /// Indicates if the specific stop criterium is stored by the . + /// + /// The stop criterium. + /// true if the contains the stop criterium; otherwise false. + bool Contains(IIterationStopCriterium stopCriterium); + + /// + /// Indicates to the iterator that the iterative process has been cancelled. + /// + /// Does not reset the stop-criteria. + void IterationCancelled(); + + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual iterators may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation.. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// + /// Note to implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + /// + void ResetToPrecalculationState(); + +#if SILVERLIGHT + IIterator Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs index 3b2c7a63..712c6548 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -67,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// solver. /// /// - public sealed class BiCgStab : IIterativeSolver + public sealed class BiCgStab : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -79,12 +76,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -95,7 +92,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public BiCgStab() : this(null, null) @@ -110,18 +107,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public BiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public BiCgStab(IIterator iterator) : this(null, iterator) { } @@ -129,11 +126,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public BiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -142,38 +139,38 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public BiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public BiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -204,17 +201,17 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public Vector Solve(Matrix matrix, Vector vector) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -223,10 +220,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the /// solution vector and x is the unknown vector. /// - /// The coefficient , A. - /// The solution , b. - /// The result , x. - public void Solve(Matrix matrix, Vector input, Vector result) + /// The coefficient , A. + /// The solution , b. + /// The result , x. + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -281,7 +278,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // Compute r_0 = b - Ax_0 for some initial guess x_0 // In this case we take x_0 = vector // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, result, input); // Choose r~ (for example, r~ = r_0) @@ -290,13 +287,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // create seven temporary vectors needed to hold temporary // coefficients. All vectors are mangled in each iteration. // These are defined here to prevent stressing the garbage collector - Vector vecP = new DenseVector(residuals.Count); - Vector vecPdash = new DenseVector(residuals.Count); - Vector nu = new DenseVector(residuals.Count); - Vector vecS = new DenseVector(residuals.Count); - Vector vecSdash = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector vecP = new DenseVector(residuals.Count); + Vector vecPdash = new DenseVector(residuals.Count); + Vector nu = new DenseVector(residuals.Count); + Vector vecS = new DenseVector(residuals.Count); + Vector vecSdash = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); // create some temporary float variables that are needed // to hold values in between iterations @@ -428,13 +425,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -450,11 +447,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -475,10 +472,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X. - public Matrix Solve(Matrix matrix, Matrix input) + /// The coefficient , A. + /// The solution , B. + /// The result , X. + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -490,7 +487,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -499,10 +496,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Solves the matrix equation AX = B, where A is the coefficient matrix, B is the /// solution matrix and X is the unknown matrix. /// - /// The coefficient , A. - /// The solution , B. - /// The result , X - public void Solve(Matrix matrix, Matrix input, Matrix result) + /// The coefficient , A. + /// The solution , B. + /// The result , X + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -526,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs index 5dbb7d69..3252c28d 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs @@ -35,8 +35,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative using System.IO; using System.Linq; using System.Reflection; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; using Properties; @@ -55,7 +53,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Note that if an iterator is passed to this solver it will be used for all the sub-solvers. /// /// - public sealed class CompositeSolver : IIterativeSolver + public sealed class CompositeSolver : IIterativeSolver { #region Internal class - DoubleComparer /// @@ -96,19 +94,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative private static readonly ICalculationStatus RunningStatus = new CalculationRunning(); #if SILVERLIGHT - private static readonly Dictionary>> SolverSetups = new Dictionary>>(); + private static readonly Dictionary> SolverSetups = new Dictionary>(); #else /// /// The collection of iterative solver setups. Stored based on the /// ratio between the relative speed and relative accuracy. /// - private static readonly SortedList>> SolverSetups = new SortedList>>(new DoubleComparer()); + private static readonly SortedList> SolverSetups = new SortedList>(new DoubleComparer()); #endif #region Solver information loading methods /// - /// Loads all the available objects from the MathNet.Numerics assembly. + /// Loads all the available objects from the MathNet.Numerics assembly. /// public static void LoadSolverInformation() { @@ -116,16 +114,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the MathNet.Numerics assembly. + /// Loads the available objects from the MathNet.Numerics assembly. /// - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformation(Type[] typesToExclude) { LoadSolverInformationFromAssembly(Assembly.GetExecutingAssembly(), typesToExclude); } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. public static void LoadSolverInformationFromAssembly(string assemblyLocation) @@ -134,10 +132,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the file location. + /// Loads the available objects from the assembly specified by the file location. /// /// The fully qualified path to the assembly. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(string assemblyLocation, params Type[] typesToExclude) { if (assemblyLocation == null) @@ -172,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName) @@ -181,10 +179,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the assembly name. + /// Loads the available objects from the assembly specified by the assembly name. /// /// The of the assembly that should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(AssemblyName assemblyName, params Type[] typesToExclude) { if (assemblyName == null) @@ -204,7 +202,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. public static void LoadSolverInformationFromAssembly(Type typeInAssembly) @@ -213,10 +211,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the assembly specified by the type. + /// Loads the available objects from the assembly specified by the type. /// /// The type in the assembly which should be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Type typeInAssembly, params Type[] typesToExclude) { if (typeInAssembly == null) @@ -228,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. public static void LoadSolverInformationFromAssembly(Assembly assembly) @@ -237,10 +235,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Loads the available objects from the specified assembly. + /// Loads the available objects from the specified assembly. /// /// The assembly which will be searched for setup objects. - /// The types that should not be loaded. + /// The types that should not be loaded. public static void LoadSolverInformationFromAssembly(Assembly assembly, params Type[] typesToExclude) { if (assembly == null) @@ -265,18 +263,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative { interfaceTypes.Clear(); interfaceTypes.AddRange(type.GetInterfaces()); - if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) + if (!interfaceTypes.Any(match => typeof(IIterativeSolverSetup).IsAssignableFrom(match))) { continue; } // See if we actually want this type of iterative solver - IIterativeSolverSetup setup; + IIterativeSolverSetup setup; try { // If something goes wrong we just ignore it and move on with the next type. // There should probably be a log somewhere indicating that something went wrong? - setup = (IIterativeSolverSetup)Activator.CreateInstance(type); + setup = (IIterativeSolverSetup)Activator.CreateInstance(type); } catch (ArgumentException) { @@ -317,7 +315,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative var ratio = setup.SolutionSpeed / setup.Reliability; if (!SolverSetups.ContainsKey(ratio)) { - SolverSetups.Add(ratio, new List>()); + SolverSetups.Add(ratio, new List()); } var list = SolverSetups[ratio]; @@ -330,7 +328,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// The collection of solvers that will be used to /// - private readonly List> _solvers = new List>(); + private readonly List _solvers = new List(); /// /// The status of the calculation. @@ -340,7 +338,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// The iterator that is used to control the iteration process. /// - private IIterator _iterator; + private IIterator _iterator; /// /// A flag indicating if the solver has been stopped or not. @@ -351,7 +349,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The solver that is currently running. Reference is used to be able to stop the /// solver if the user cancels the solve process. /// - private IIterativeSolver _currentSolver; + private IIterativeSolver _currentSolver; /// /// Initializes a new instance of the class with the default iterator. @@ -364,16 +362,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class with the specified iterator. /// /// The iterator that will be used to control the iteration process. - public CompositeSolver(IIterator iterator) + public CompositeSolver(IIterator iterator) { _iterator = iterator; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -411,14 +409,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -430,7 +428,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -480,8 +478,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // Create a copy of the solution and result vectors so we can use them // later on - var internalInput = input.Clone(); - var internalResult = result.Clone(); + var internalInput = (Vector)input.Clone(); + var internalResult = (Vector)result.Clone(); foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped)) { @@ -572,7 +570,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -584,7 +582,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -596,7 +594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -620,7 +618,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs index 0e8e52ed..b7f9a4d9 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -65,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// solver. /// /// - public sealed class GpBiCg : IIterativeSolver + public sealed class GpBiCg : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -77,12 +74,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The preconditioner that will be used. Can be set to null, in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates the number of BiCGStab steps should be taken @@ -105,7 +102,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public GpBiCg() : this(null, null) @@ -120,18 +117,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public GpBiCg(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public GpBiCg(IIterator iterator) : this(null, iterator) { } @@ -139,11 +136,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public GpBiCg(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -152,19 +149,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public GpBiCg(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public GpBiCg(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -215,19 +212,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -262,14 +259,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -281,7 +278,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -335,11 +332,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // x_0 is initial guess // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars @@ -348,26 +345,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // Define the temporary vectors // rDash_0 = r_0 - Vector rdash = new DenseVector(residuals); + Vector rdash = new DenseVector(residuals); // t_-1 = 0 - Vector t = new DenseVector(residuals.Count); - Vector t0 = new DenseVector(residuals.Count); + Vector t = new DenseVector(residuals.Count); + Vector t0 = new DenseVector(residuals.Count); // w_-1 = 0 - Vector w = new DenseVector(residuals.Count); + Vector w = new DenseVector(residuals.Count); // Define the remaining temporary vectors - Vector c = new DenseVector(residuals.Count); - Vector p = new DenseVector(residuals.Count); - Vector s = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector y = new DenseVector(residuals.Count); - Vector z = new DenseVector(residuals.Count); + Vector c = new DenseVector(residuals.Count); + Vector p = new DenseVector(residuals.Count); + Vector s = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector y = new DenseVector(residuals.Count); + Vector z = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); - Vector temp3 = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); + Vector temp3 = new DenseVector(residuals.Count); // for (k = 0, 1, .... ) var iterationNumber = 0; @@ -524,13 +521,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -544,11 +541,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -589,7 +586,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -601,7 +598,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -613,7 +610,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -637,7 +634,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs index 08688999..7da752d9 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs @@ -34,10 +34,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative using System.Collections.Generic; using System.Diagnostics; using Distributions; - using Generic; using Generic.Factorization; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -65,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// solver. /// /// - public sealed class MlkBiCgStab : IIterativeSolver + public sealed class MlkBiCgStab : IIterativeSolver { /// /// The default number of starting vectors. @@ -82,17 +79,17 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// The collection of starting vectors which are used as the basis for the Krylov sub-space. /// - private IList> _startingVectors; + private IList _startingVectors; /// /// The number of starting vectors used by the algorithm @@ -108,7 +105,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public MlkBiCgStab() : this(null, null) @@ -123,18 +120,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IIterator iterator) : this(null, iterator) { } @@ -142,11 +139,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public MlkBiCgStab(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -155,19 +152,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public MlkBiCgStab(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; @@ -209,19 +206,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -230,7 +227,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Gets or sets a series of orthonormal vectors which will be used as basis for the /// Krylov sub-space. /// - public IList> StartingVectors + public IList StartingVectors { [DebuggerStepThrough] get @@ -282,14 +279,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -301,7 +298,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -355,7 +352,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // Choose an initial guess x_0 // Take x_0 = 0 - Vector xtemp = new DenseVector(input.Count); + Vector xtemp = new DenseVector(input.Count); // Choose k vectors q_1, q_2, ..., q_k // Build a new set if: @@ -384,24 +381,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // r_0 = b - Ax_0 // This is basically a SAXPY so it could be made a lot faster - Vector residuals = new DenseVector(matrix.RowCount); + Vector residuals = new DenseVector(matrix.RowCount); CalculateTrueResidual(matrix, residuals, xtemp, input); // Define the temporary scalars var c = new float[k]; // Define the temporary vectors - Vector gtemp = new DenseVector(residuals.Count); + Vector gtemp = new DenseVector(residuals.Count); - Vector u = new DenseVector(residuals.Count); - Vector utemp = new DenseVector(residuals.Count); - Vector temp = new DenseVector(residuals.Count); - Vector temp1 = new DenseVector(residuals.Count); - Vector temp2 = new DenseVector(residuals.Count); + Vector u = new DenseVector(residuals.Count); + Vector utemp = new DenseVector(residuals.Count); + Vector temp = new DenseVector(residuals.Count); + Vector temp1 = new DenseVector(residuals.Count); + Vector temp2 = new DenseVector(residuals.Count); - Vector zd = new DenseVector(residuals.Count); - Vector zg = new DenseVector(residuals.Count); - Vector zw = new DenseVector(residuals.Count); + Vector zd = new DenseVector(residuals.Count); + Vector zg = new DenseVector(residuals.Count); + Vector zw = new DenseVector(residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count); @@ -645,7 +642,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// the is smaller than /// the . /// - private static IList> CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) + private static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables) { // Create no more starting vectors than the size of the problem - 1 // Get random values and then orthogonalize them with @@ -656,7 +653,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative // mean = 0 and sd = 1 var distribution = new Normal(); - Matrix matrix = new DenseMatrix(numberOfVariables, count); + Matrix matrix = new DenseMatrix(numberOfVariables, count); for (var i = 0; i < matrix.ColumnCount; i++) { var samples = new float[matrix.RowCount]; @@ -674,27 +671,27 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative var orthogonalMatrix = gs.Q; // Now transfer this to vectors - var result = new List>(); + var result = new List(); for (var i = 0; i < orthogonalMatrix.ColumnCount; i++) { - result.Add(orthogonalMatrix.Column(i)); + result.Add((Vector)orthogonalMatrix.Column(i)); // Normalize the result vector - result[i].Multiply(1 / (float)result[i].Norm(2), result[i]); + result[i].Multiply(1 / result[i].Norm(2), result[i]); } return result; } /// - /// Create random vecrors array + /// Create random vectors array /// /// Number of vectors /// Size of each vector /// Array of random vectors - private static Vector[] CreateVectorArray(int arraySize, int vectorSize) + private static Vector[] CreateVectorArray(int arraySize, int vectorSize) { - var result = new Vector[arraySize]; + var result = new Vector[arraySize]; for (var i = 0; i < result.Length; i++) { result[i] = new DenseVector(vectorSize); @@ -704,13 +701,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Source A. - /// Residual data. - /// x data. - /// b data. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Source A. + /// Residual data. + /// x data. + /// b data. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -724,11 +721,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -752,7 +749,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -764,7 +761,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -776,7 +773,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -800,7 +797,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs index f5191cc5..f8d48d91 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs @@ -31,9 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Generic.Solvers.Status; using Preconditioners; using Properties; @@ -55,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// solver. /// /// - public sealed class TFQMR : IIterativeSolver + public sealed class TFQMR : IIterativeSolver { /// /// The status used if there is no status, i.e. the solver hasn't run yet and there is no @@ -67,12 +64,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The preconditioner that will be used. Can be set to , in which case the default /// pre-conditioner will be used. /// - private IPreConditioner _preconditioner; + private IPreConditioner _preconditioner; /// /// The iterative process controller. /// - private IIterator _iterator; + private IIterator _iterator; /// /// Indicates if the user has stopped the solver. @@ -83,7 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings and a default preconditioner. /// public TFQMR() : this(null, null) @@ -98,18 +95,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// When using this constructor the solver will use a default preconditioner. /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to monitor the iterative process. - public TFQMR(IIterator iterator) : this(null, iterator) + /// The that will be used to monitor the iterative process. + public TFQMR(IIterator iterator) : this(null, iterator) { } @@ -117,11 +114,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Initializes a new instance of the class. /// /// - /// When using this constructor the solver will use the with + /// When using this constructor the solver will use the with /// the standard settings. /// - /// The that will be used to precondition the matrix equation. - public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) + /// The that will be used to precondition the matrix equation. + public TFQMR(IPreConditioner preconditioner) : this(preconditioner, null) { } @@ -130,38 +127,38 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// /// /// - /// The main advantages of using a user defined are: + /// The main advantages of using a user defined are: /// /// It is possible to set the desired convergence limits. /// /// It is possible to check the reason for which the solver finished - /// the iterative procedure by calling the property. + /// the iterative procedure by calling the property. /// /// /// /// - /// The that will be used to precondition the matrix equation. - /// The that will be used to monitor the iterative process. - public TFQMR(IPreConditioner preconditioner, IIterator iterator) + /// The that will be used to precondition the matrix equation. + /// The that will be used to monitor the iterative process. + public TFQMR(IPreConditioner preconditioner, IIterator iterator) { _iterator = iterator; _preconditioner = preconditioner; } /// - /// Sets the that will be used to precondition the iterative process. + /// Sets the that will be used to precondition the iterative process. /// /// The preconditioner. - public void SetPreconditioner(IPreConditioner preconditioner) + public void SetPreconditioner(IPreConditioner preconditioner) { _preconditioner = preconditioner; } /// - /// Sets the that will be used to track the iterative process. + /// Sets the that will be used to track the iterative process. /// /// The iterator. - public void SetIterator(IIterator iterator) + public void SetIterator(IIterator iterator) { _iterator = iterator; } @@ -195,14 +192,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b. /// The result vector, x. - public Vector Solve(Matrix matrix, Vector vector) + public Vector Solve(Matrix matrix, Vector vector) { if (vector == null) { throw new ArgumentNullException(); } - Vector result = new DenseVector(matrix.RowCount); + Vector result = new DenseVector(matrix.RowCount); Solve(matrix, vector, result); return result; } @@ -214,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution vector, b /// The result vector, x - public void Solve(Matrix matrix, Vector input, Vector result) + public void Solve(Matrix matrix, Vector input, Vector result) { // If we were stopped before, we are no longer // We're doing this at the start of the method to ensure @@ -285,7 +282,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative var temp2 = new DenseVector(input.Count); // Initialize - var startNorm = (float)input.Norm(2); + var startNorm = input.Norm(2); // Define the scalars float alpha = 0; @@ -351,7 +348,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative yinternal.Add(temp, d); // theta = ||pseudoResiduals||_2 / tau - theta = (float)pseudoResiduals.Norm(2) / tau; + theta = pseudoResiduals.Norm(2) / tau; var c = 1 / (float)Math.Sqrt(1 + (theta * theta)); // tau = tau * theta * c @@ -426,13 +423,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative } /// - /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax + /// Calculates the true residual of the matrix equation Ax = b according to: residual = b - Ax /// - /// Instance of the A. - /// Residual values in . - /// Instance of the x. - /// Instance of the b. - private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) + /// Instance of the A. + /// Residual values in . + /// Instance of the x. + /// Instance of the b. + private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b) { // -Ax = residual matrix.Multiply(x, residual); @@ -446,11 +443,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// Determine if calculation should continue /// /// Number of iterations passed - /// Result . - /// Source . - /// Residual . + /// Result . + /// Source . + /// Residual . /// true if continue, otherwise false - private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) + private bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals) { if (_hasBeenStopped) { @@ -484,7 +481,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X. - public Matrix Solve(Matrix matrix, Matrix input) + public Matrix Solve(Matrix matrix, Matrix input) { if (matrix == null) { @@ -496,7 +493,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative throw new ArgumentNullException("input"); } - var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount); + var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount); Solve(matrix, input, result); return result; } @@ -508,7 +505,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative /// The coefficient matrix, A. /// The solution matrix, B. /// The result matrix, X - public void Solve(Matrix matrix, Matrix input, Matrix result) + public void Solve(Matrix matrix, Matrix input, Matrix result) { if (matrix == null) { @@ -532,7 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative for (var column = 0; column < input.ColumnCount; column++) { - var solution = Solve(matrix, input.Column(column)); + var solution = Solve(matrix, (Vector)input.Column(column)); foreach (var element in solution.GetIndexedEnumerator()) { result.At(element.Key, column, element.Value); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs index a9667cc6..ad01b5fa 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs @@ -33,17 +33,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers using System; using System.Collections.Generic; using System.Linq; - using Generic; - using Generic.Solvers; using Generic.Solvers.Status; - using Generic.Solvers.StopCriterium; using Properties; using StopCriterium; /// /// An iterator that is used to check if an iterative calculation should continue or stop. /// - public sealed class Iterator : IIterator + public sealed class Iterator : IIterator { /// /// The default status for the iterator. @@ -51,10 +48,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers private static readonly ICalculationStatus DefaultStatus = new CalculationIndetermined(); /// - /// Creates a default iterator with all the objects. + /// Creates a default iterator with all the objects. /// - /// A new object. - public static IIterator CreateDefault() + /// A new object. + public static IIterator CreateDefault() { var iterator = new Iterator(); iterator.Add(new FailureStopCriterium()); @@ -69,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// The collection that holds all the stop criteria and the flag indicating if they should be added /// to the child iterators. /// - private readonly Dictionary> _stopCriterias = new Dictionary>(); + private readonly Dictionary _stopCriterias = new Dictionary(); /// /// The status of the iterator. @@ -96,7 +93,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// of the stop criteria will be passed on to child iterators. /// /// Thrown if contains multiple stop criteria of the same type. - public Iterator(IEnumerable> stopCriteria) + public Iterator(IEnumerable stopCriteria) { // Add the stop criteria if (stopCriteria == null) @@ -111,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers } /// - /// Adds an to the internal collection of stop-criteria. Only a + /// Adds an to the internal collection of stop-criteria. Only a /// single stop criterium of each type can be stored. /// /// The stop criterium to add. @@ -120,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// Thrown if is of the same type as an already /// stored criterium. /// - public void Add(IIterationStopCriterium stopCriterium) + public void Add(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -137,10 +134,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers } /// - /// Removes the from the internal collection. + /// Removes the from the internal collection. /// /// The stop criterium that must be removed. - public void Remove(IIterationStopCriterium stopCriterium) + public void Remove(IIterationStopCriterium stopCriterium) { if (stopCriterium == null) { @@ -157,11 +154,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers } /// - /// Indicates if the specific stop criterium is stored by the . + /// Indicates if the specific stop criterium is stored by the . /// /// The stop criterium. - /// true if the contains the stop criterium; otherwise false. - public bool Contains(IIterationStopCriterium stopCriterium) + /// true if the contains the stop criterium; otherwise false. + public bool Contains(IIterationStopCriterium stopCriterium) { return stopCriterium != null && _stopCriterias.ContainsKey(stopCriterium.GetType()); } @@ -182,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// Gets an IEnumerator that enumerates over all the stored stop criteria. /// /// Used for testing only. - internal IEnumerator> StoredStopCriteria + internal IEnumerator StoredStopCriteria { get { @@ -204,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -215,7 +212,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (_stopCriterias.Count == 0) { @@ -287,7 +284,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -308,9 +305,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers /// Creates a deep clone of the current iterator. /// /// The deep clone of the current iterator. - public IIterator Clone() + public IIterator Clone() { - var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); + var stopCriteria = _stopCriterias.Select(pair => pair.Value).Select(stopCriterium => (IIterationStopCriterium)stopCriterium.Clone()).ToList(); return new Iterator(stopCriteria); } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs index 65a3d750..f9006655 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs @@ -31,15 +31,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreConditioner + public sealed class Diagonal : IPreConditioner { /// /// The inverse of the matrix diagonal. @@ -65,10 +63,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. + /// The upon which this preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -92,7 +90,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -109,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -119,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IPreConditioner.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IPreConditioner.cs new file mode 100644 index 00000000..1680f989 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IPreConditioner.cs @@ -0,0 +1,73 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners +{ + /// + /// The base interface for preconditioner classes. + /// + /// + /// + /// Preconditioners are used by iterative solvers to improve the convergence + /// speed of the solving process. Increase in convergence speed + /// is related to the number of iterations necessary to get a converged solution. + /// So while in general the use of a preconditioner means that the iterative + /// solver will perform fewer iterations it does not guarantee that the actual + /// solution time decreases given that some preconditioners can be expensive to + /// setup and run. + /// + /// + /// Note that in general changes to the matrix will invalidate the preconditioner + /// if the changes occur after creating the preconditioner. + /// + /// + public interface IPreConditioner + { + /// + /// Initializes the preconditioner and loads the internal data structures. + /// + /// The matrix on which the preconditioner is based. + void Initialize(Matrix matrix); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. + Vector Approximate(Vector rhs); + + /// + /// Approximates the solution to the matrix equation Mx = b. + /// + /// The right hand side vector. + /// The left hand side vector. Also known as the result vector. + void Approximate(Vector rhs, Vector lhs); + } +} diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs index 2042270e..0bb12ef7 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs @@ -32,8 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners { using System; using System.Collections.Generic; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -53,7 +51,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreConditioner + public sealed class Ilutp : IPreConditioner { /// /// The default fill level. @@ -257,9 +255,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { - return _upper.Clone(); + return (Matrix)_upper.Clone(); } /// @@ -269,9 +267,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// This method is used for debugging purposes only and should normally not be used. /// /// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { - return _lower.Clone(); + return (Matrix)_lower.Clone(); } /// @@ -297,13 +295,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Initializes the preconditioner and loads the internal data structures. /// /// - /// The upon which this preconditioner is based. Note that the + /// The upon which this preconditioner is based. Note that the /// method takes a general matrix type. However internally the data is stored /// as a sparse matrix. Therefore it is not recommended to pass a dense matrix. /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -375,8 +373,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners _pivots[i] = i; } - Vector workVector = new DenseVector(sparseMatrix.RowCount); - Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); + Vector workVector = new DenseVector(sparseMatrix.RowCount); + Vector rowVector = new DenseVector(sparseMatrix.ColumnCount); var indexSorting = new int[sparseMatrix.RowCount]; // spaceLeft = lfilNnz * nnz(A) @@ -531,8 +529,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// Pivot elements in the according to internal pivot array /// - /// Row to pivot in - private void PivotRow(Vector row) + /// Row to pivot in + private void PivotRow(Vector row) { var knownPivots = new Dictionary(); @@ -579,12 +577,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners } /// - /// Swap columns in the + /// Swap columns in the /// - /// Source . + /// Source . /// First column index to swap /// Second column index to swap - private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) + private static void SwapColumns(Matrix matrix, int firstColumn, int secondColumn) { for (var i = 0; i < matrix.RowCount; i++) { @@ -600,8 +598,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Start sort form /// Sort till upper bound /// Array with sorted vector indicies - /// Source - private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// Source + private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Copy the indices for the values into the array for (var i = 0; i < upperBound + 1 - lowerBound; i++) @@ -626,7 +624,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -643,7 +641,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -653,7 +651,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -678,7 +676,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners // Solve equation here // Pivot(vector, result); // Solve L*Y = B(piv,:) - Vector rowValues = new DenseVector(_lower.RowCount); + Vector rowValues = new DenseVector(_lower.RowCount); for (var i = 0; i < _lower.RowCount; i++) { _lower.Row(i, rowValues); @@ -708,17 +706,17 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners // We have a column pivot so we only need to pivot the // end result not the incoming right hand side vector - var temp = lhs.Clone(); + var temp = (Vector)lhs.Clone(); Pivot(temp, lhs); } /// - /// Pivot elements in accoring to internal pivot array + /// Pivot elements in according to internal pivot array /// - /// Source . - /// Result after pivoting. - private void Pivot(Vector vector, Vector result) + /// Source . + /// Result after pivoting. + private void Pivot(Vector vector, Vector result) { for (var i = 0; i < _pivots.Length; i++) { diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs index fd6c40bf..ba66386e 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs @@ -30,8 +30,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners { - using Generic; - /// /// An element sort algorithm for the class. /// @@ -48,8 +46,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { // Move all the indices that we're interested in to the beginning of the // array. Ignore the rest of the indices. @@ -74,8 +72,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// The starting index. /// The stopping index. /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) { var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; var end = (upperBound - lowerBound + 1) - 1 + lowerBound; @@ -94,10 +92,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Build heap for double indicies ///
/// Root position - /// Lenght of + /// Length of /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) { while (start >= 0) { @@ -110,17 +108,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Sift double indicies /// /// Indicies of - /// Target + /// Target /// Root position - /// Lenght of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) { var root = begin; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) { child += 1; @@ -170,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// Target values array /// Root position - /// Lenght of + /// Length of private static void BuildHeap(int[] values, int start, int count) { while (start >= 0) @@ -185,15 +182,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// Target value array /// Root position - /// Lenght of + /// Length of private static void Sift(int[] values, int start, int count) { var root = start; - int child; while (root * 2 < count) { - child = root * 2; + var child = root * 2; if ((child < count - 1) && (values[child] > values[child + 1])) { child += 1; @@ -215,8 +211,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Exchange values in array /// /// Target values array - /// First value to exchanghe - /// Second value to exchanghe + /// First value to exchange + /// Second value to exchange private static void Exchange(int[] values, int first, int second) { var t = values[first]; diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs index 22cec0da..ade5f1ba 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs @@ -31,8 +31,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers.Preconditioners; using Properties; /// @@ -44,7 +42,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreConditioner + public sealed class IncompleteLU : IPreConditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The @@ -56,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Returns the upper triagonal matrix that was created during the LU decomposition. /// /// A new matrix containing the upper triagonal elements. - internal Matrix UpperTriangle() + internal Matrix UpperTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -74,7 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Returns the lower triagonal matrix that was created during the LU decomposition. ///
/// A new matrix containing the lower triagonal elements. - internal Matrix LowerTriangle() + internal Matrix LowerTriangle() { var result = new SparseMatrix(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) @@ -101,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// The matrix upon which the preconditioner is based. /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -163,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -180,7 +178,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs"); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } @@ -190,7 +188,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// The right hand side vector. /// The left hand side vector. Also known as the result vector. - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -220,7 +218,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners // z_i = l_ii^-1 * (y_i - SUM_(j rowValues = new DenseVector(_decompositionLU.RowCount); + Vector rowValues = new DenseVector(_decompositionLU.RowCount); for (var i = 0; i < _decompositionLU.RowCount; i++) { // Clear the rowValues diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/UnitPreconditioner.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/UnitPreconditioner.cs index da0644c8..c665e4d8 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/UnitPreconditioner.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/UnitPreconditioner.cs @@ -31,17 +31,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners { using System; - using Generic; - using Generic.Solvers; - using Generic.Solvers.Preconditioners; using Properties; /// /// A unit preconditioner. This preconditioner does not actually do anything - /// it is only used when running an without + /// it is only used when running an without /// a preconditioner. /// - internal sealed class UnitPreconditioner : IPreConditioner + internal sealed class UnitPreconditioner : IPreConditioner { /// /// The coefficient matrix on which this preconditioner operates. @@ -57,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// If is . /// If is not a square matrix. - public void Initialize(Matrix matrix) + public void Initialize(Matrix matrix) { if (matrix == null) { @@ -90,7 +87,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// If the size of is different the number of rows of the coefficient matrix. /// /// - public void Approximate(Vector rhs, Vector lhs) + public void Approximate(Vector rhs, Vector lhs) { if (rhs == null) { @@ -119,7 +116,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// /// If the size of is different the number of rows of the coefficient matrix. /// - public Vector Approximate(Vector rhs) + public Vector Approximate(Vector rhs) { if (rhs == null) { @@ -131,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners throw new ArgumentException(Resources.ArgumentMatrixDimensions); } - Vector result = new DenseVector(rhs.Count); + Vector result = new DenseVector(rhs.Count); Approximate(rhs, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs index 7cf0ba01..f9ee03f6 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs @@ -32,14 +32,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// /// Monitors an iterative calculation for signs of divergence. /// - public sealed class DivergenceStopCriterium : IIterationStopCriterium + public sealed class DivergenceStopCriterium : IIterationStopCriterium { /// /// Default value for the maximum relative increase that the @@ -207,7 +206,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -218,7 +217,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -301,7 +300,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium } /// - /// Gets required history lenght + /// Gets required history Length /// private int RequiredHistoryLength { @@ -347,7 +346,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -358,7 +357,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -374,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new DivergenceStopCriterium(_maximumRelativeIncrease, _minimumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs index 99f9d100..e8408fcd 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals for NaN's. + /// Defines an that monitors residuals for NaN's. /// - public sealed class FailureStopCriterium : IIterationStopCriterium + public sealed class FailureStopCriterium : IIterationStopCriterium { /// /// Defines the default last iteration number. Set to -1 because iterations normally @@ -65,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -76,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -156,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -166,7 +165,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -182,7 +181,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new FailureStopCriterium(); } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs new file mode 100644 index 00000000..4125546e --- /dev/null +++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs @@ -0,0 +1,80 @@ +// +// 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. +// + +namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium +{ + using System; + using Generic.Solvers.Status; + using Generic.Solvers.StopCriterium; + + /// + /// The base interface for classes that provide stop criteria for iterative calculations. + /// + public interface IIterationStopCriterium +#if !SILVERLIGHT + : ICloneable +#endif + { + /// + /// Determines the status of the iterative calculation based on the stop criteria stored + /// by the current . Status is set to Status field of current object. + /// + /// The number of iterations that have passed so far. + /// The vector containing the current solution values. + /// The right hand side vector. + /// The vector containing the current residual vectors. + /// + /// The individual stop criteria may internally track the progress of the calculation based + /// on the invocation of this method. Therefore this method should only be called if the + /// calculation has moved forwards at least one step. + /// + void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector); + + /// + /// Gets the current calculation status. + /// + /// is not a legal value. Status should be set in implementation. + ICalculationStatus Status { get; } + + /// + /// Resets the to the pre-calculation state. + /// + /// To implementers: Invoking this method should not clear the user defined + /// property values, only the state that is used to track the progress of the + /// calculation. + void ResetToPrecalculationState(); + + /// + /// Gets the which indicates what sort of stop criterium this + /// monitors. + /// + StopLevel StopLevel { get; } + +#if SILVERLIGHT + IIterationStopCriterium Clone(); +#endif + } +} diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs index 3409cae3..e82fb1a0 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; /// - /// Defines an that monitors the numbers of iteration + /// Defines an that monitors the numbers of iteration /// steps as stop criterium. /// - public sealed class IterationCountStopCriterium : IIterationStopCriterium + public sealed class IterationCountStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum number of iterations the process is allowed @@ -131,7 +130,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -208,7 +207,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new IterationCountStopCriterium(_maximumNumberOfIterations); } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs index 25f0790e..78ce43b6 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs @@ -32,15 +32,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium { using System; using System.Diagnostics; - using Generic; using Generic.Solvers.Status; using Generic.Solvers.StopCriterium; using Properties; /// - /// Defines an that monitors residuals as stop criterium. + /// Defines an that monitors residuals as stop criterium. /// - public sealed class ResidualStopCriterium : IIterationStopCriterium + public sealed class ResidualStopCriterium : IIterationStopCriterium { /// /// The default value for the maximum value of the residual. @@ -212,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Determines the status of the iterative calculation based on the stop criteria stored - /// by the current . Result is set into Status field. + /// by the current . Result is set into Status field. /// /// The number of iterations that have passed so far. /// The vector containing the current solution values. @@ -223,7 +222,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// on the invocation of this method. Therefore this method should only be called if the /// calculation has moved forwards at least one step. /// - public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) + public void DetermineStatus(int iterationNumber, Vector solutionVector, Vector sourceVector, Vector residualVector) { if (iterationNumber < 0) { @@ -363,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium } /// - /// Resets the to the pre-calculation state. + /// Resets the to the pre-calculation state. /// public void ResetToPrecalculationState() { @@ -374,7 +373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// /// Gets the which indicates what sort of stop criterium this - /// monitors. + /// monitors. /// /// Returns . public StopLevel StopLevel @@ -390,7 +389,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.StopCriterium /// Clones the current and its settings. /// /// A new instance of the class. - public IIterationStopCriterium Clone() + public IIterationStopCriterium Clone() { return new ResidualStopCriterium(_maximum, _minimumIterationsBelowMaximum); } diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 17b29ad7..58db1062 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -172,6 +172,11 @@ + + + + + @@ -187,6 +192,11 @@ + + + + + @@ -198,6 +208,11 @@ + + + + + @@ -300,6 +315,9 @@ + + + @@ -310,9 +328,11 @@ + + @@ -335,9 +355,6 @@ - - - @@ -350,7 +367,6 @@ Code - @@ -362,7 +378,6 @@ - diff --git a/src/Silverlight/Silverlight.csproj b/src/Silverlight/Silverlight.csproj index 13653ed3..27667cba 100644 --- a/src/Silverlight/Silverlight.csproj +++ b/src/Silverlight/Silverlight.csproj @@ -348,6 +348,15 @@ LinearAlgebra\Complex32\Matrix.cs + + LinearAlgebra\Complex32\Solvers\IIterativeSolver.cs + + + LinearAlgebra\Complex32\Solvers\IIterativeSolverSetup.cs + + + LinearAlgebra\Complex32\Solvers\IIterator.cs + LinearAlgebra\Complex32\Solvers\Iterative\BiCgStab.cs @@ -378,6 +387,9 @@ LinearAlgebra\Complex32\Solvers\Preconditioners\IncompleteLU.cs + + LinearAlgebra\Complex32\Solvers\Preconditioners\IPreConditioner.cs + LinearAlgebra\Complex32\Solvers\Preconditioners\UnitPreconditioner.cs @@ -387,6 +399,9 @@ LinearAlgebra\Complex32\Solvers\StopCriterium\FailureStopCriterium.cs + + LinearAlgebra\Complex32\Solvers\StopCriterium\IIterationStopCriterium.cs + LinearAlgebra\Complex32\Solvers\StopCriterium\IterationCountStopCriterium.cs @@ -468,6 +483,15 @@ LinearAlgebra\Complex\Matrix.cs + + LinearAlgebra\Complex\Solvers\IIterativeSolver.cs + + + LinearAlgebra\Complex\Solvers\IIterativeSolverSetup.cs + + + LinearAlgebra\Complex\Solvers\IIterator.cs + LinearAlgebra\Complex\Solvers\Iterative\BiCgStab.cs @@ -498,6 +522,9 @@ LinearAlgebra\Complex\Solvers\Preconditioners\IncompleteLU.cs + + LinearAlgebra\Complex\Solvers\Preconditioners\IPreConditioner.cs + LinearAlgebra\Complex\Solvers\Preconditioners\UnitPreconditioner.cs @@ -507,6 +534,9 @@ LinearAlgebra\Complex\Solvers\StopCriterium\FailureStopCriterium.cs + + LinearAlgebra\Complex\Solvers\StopCriterium\IIterationStopCriterium.cs + LinearAlgebra\Complex\Solvers\StopCriterium\IterationCountStopCriterium.cs @@ -588,6 +618,15 @@ LinearAlgebra\Double\Matrix.cs + + LinearAlgebra\Double\Solvers\IIterativeSolver.cs + + + LinearAlgebra\Double\Solvers\IIterativeSolverSetup.cs + + + LinearAlgebra\Double\Solvers\IIterator.cs + LinearAlgebra\Double\Solvers\Iterative\BiCgStab.cs @@ -618,6 +657,9 @@ LinearAlgebra\Double\Solvers\Preconditioners\IncompleteLU.cs + + LinearAlgebra\Double\Solvers\Preconditioners\IPreConditioner.cs + LinearAlgebra\Double\Solvers\Preconditioners\UnitPreconditioner.cs @@ -627,6 +669,9 @@ LinearAlgebra\Double\Solvers\StopCriterium\FailureStopCriterium.cs + + LinearAlgebra\Double\Solvers\StopCriterium\IIterationStopCriterium.cs + LinearAlgebra\Double\Solvers\StopCriterium\IterationCountStopCriterium.cs @@ -717,6 +762,15 @@ LinearAlgebra\Single\Matrix.cs + + LinearAlgebra\Single\Solvers\IIterativeSolver.cs + + + LinearAlgebra\Single\Solvers\IIterativeSolverSetup.cs + + + LinearAlgebra\Single\Solvers\IIterator.cs + LinearAlgebra\Single\Solvers\Iterative\BiCgStab.cs @@ -747,6 +801,9 @@ LinearAlgebra\Single\Solvers\Preconditioners\IncompleteLU.cs + + LinearAlgebra\Single\Solvers\Preconditioners\IPreConditioner.cs + LinearAlgebra\Single\Solvers\Preconditioners\UnitPreconditioner.cs @@ -756,6 +813,9 @@ LinearAlgebra\Single\Solvers\StopCriterium\FailureStopCriterium.cs + + LinearAlgebra\Single\Solvers\StopCriterium\IIterationStopCriterium.cs + LinearAlgebra\Single\Solvers\StopCriterium\IterationCountStopCriterium.cs @@ -792,18 +852,6 @@ LinearAlgebra\Generic\Matrix.cs - - LinearAlgebra\Generic\Solvers\IIterativeSolver.cs - - - LinearAlgebra\Generic\Solvers\IIterativeSolverSetup.cs - - - LinearAlgebra\Generic\Solvers\IIterator.cs - - - LinearAlgebra\Generic\Solvers\Preconditioners\IPreConditioner.cs - LinearAlgebra\Generic\Solvers\Status\CalculationCancelled.cs @@ -828,9 +876,6 @@ LinearAlgebra\Generic\Solvers\Status\ICalculationStatus.cs - - LinearAlgebra\Generic\Solvers\StopCriterium\IIterationStopCriterium.cs - LinearAlgebra\Generic\Solvers\StopCriterium\StopLevel.cs diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs index c1a22c6b..c1f978c9 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs @@ -7,7 +7,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ using LinearAlgebra.Complex.Solvers.StopCriterium; using LinearAlgebra.Generic; using LinearAlgebra.Generic.Solvers.Status; - using LinearAlgebra.Generic.Solvers.StopCriterium; using MbUnit.Framework; [TestFixture] @@ -21,7 +20,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -32,7 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -43,13 +42,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex.One); + Vector y = new DenseVector(matrix.RowCount, Complex.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(new Complex(System.Math.PI, System.Math.PI), matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex.One); + Vector y = new DenseVector(matrix.RowCount, Complex.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +164,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex.One); + Vector y = new DenseVector(matrix.RowCount, Complex.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +204,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -236,10 +235,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs index 63926d5a..dbac0dd5 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs @@ -21,7 +21,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -32,7 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -43,13 +43,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +83,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -166,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -207,10 +207,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -238,10 +238,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs index 0a10c267..653da4ee 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs @@ -21,7 +21,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -32,7 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -43,13 +43,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +84,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +165,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -204,10 +204,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -234,10 +234,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs index 7bc5f74a..1ef0ccd8 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs @@ -1,13 +1,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterative { - using System.Numerics; using LinearAlgebra.Complex; using LinearAlgebra.Complex.Solvers; using LinearAlgebra.Complex.Solvers.Iterative; using LinearAlgebra.Complex.Solvers.StopCriterium; - using LinearAlgebra.Generic; using LinearAlgebra.Generic.Solvers.Status; - using LinearAlgebra.Generic.Solvers.StopCriterium; using MbUnit.Framework; [TestFixture] @@ -21,7 +18,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -32,7 +29,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -43,13 +40,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +81,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +162,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +202,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -236,10 +233,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs index 035cab67..21535826 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs @@ -26,7 +26,7 @@ [MultipleAsserts] public void CreateWithEmptyCollection() { - var iterator = new Iterator(new IIterationStopCriterium[] { }); + var iterator = new Iterator(new IIterationStopCriterium[] { }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -35,7 +35,7 @@ [MultipleAsserts] public void CreateWithCollectionWithNulls() { - var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); + var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -44,7 +44,7 @@ [ExpectedArgumentException] public void CreateWithDuplicates() { - new Iterator(new IIterationStopCriterium[] + new Iterator(new IIterationStopCriterium[] { new FailureStopCriterium(), new FailureStopCriterium() @@ -55,7 +55,7 @@ [MultipleAsserts] public void CreateWithCollection() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -98,7 +98,7 @@ [MultipleAsserts] public void Add() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -128,7 +128,7 @@ [ExpectedArgumentNullException] public void RemoveWithNullStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -145,7 +145,7 @@ [MultipleAsserts] public void RemoveWithNonExistingStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -162,7 +162,7 @@ [MultipleAsserts] public void Remove() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -194,7 +194,7 @@ [ExpectedException(typeof(ArgumentOutOfRangeException))] public void DetermineStatusWithNegativeIterationNumber() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -213,7 +213,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSolutionVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -232,7 +232,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSourceVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -251,7 +251,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullResidualVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -270,7 +270,7 @@ [MultipleAsserts] public void DetermineStatus() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -298,7 +298,7 @@ [MultipleAsserts] public void ResetToPrecalculationState() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -325,7 +325,7 @@ [MultipleAsserts] public void Clone() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs index 962b37b3..8724f18b 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs @@ -1,27 +1,24 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners { - using System.Numerics; using LinearAlgebra.Complex; using LinearAlgebra.Complex.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class DiagonalTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new Diagonal(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs index beb3e609..927752fb 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs @@ -1,12 +1,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners { using System; - using System.Numerics; using System.Reflection; using LinearAlgebra.Complex; using LinearAlgebra.Complex.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -74,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi return result; } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { _pivotTolerance = 0; _dropTolerance = 0.0; @@ -82,13 +79,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi return InternalCreatePreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) { @@ -112,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -131,7 +128,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -246,7 +243,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi FillLevel = 10 }; preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs index e2eb406c..fdbb8cce 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs @@ -1,12 +1,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners { using System; - using System.Numerics; using System.Reflection; using LinearAlgebra.Complex; using LinearAlgebra.Complex.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -25,28 +22,28 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi return (T)obj; } - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "UpperTriangle"); + return GetMethod(ilu, "UpperTriangle"); } - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "LowerTriangle"); + return GetMethod(ilu, "LowerTriangle"); } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new IncompleteLU(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs index 7000c743..09dd61ae 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs @@ -2,8 +2,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi { using System.Numerics; using LinearAlgebra.Complex; + using LinearAlgebra.Complex.Solvers.Preconditioners; using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; public abstract class PreconditionerTest @@ -21,9 +21,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi return matrix; } - protected Vector CreateStandardBcVector(int size) + protected Vector CreateStandardBcVector(int size) { - Vector vector = new DenseVector(size); + Vector vector = new DenseVector(size); for (var i = 0; i < size; i++) { vector[i] = i + 1; @@ -32,9 +32,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi return vector; } - internal abstract IPreConditioner CreatePreconditioner(); + internal abstract IPreConditioner CreatePreconditioner(); - protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); + protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); [Test] [MultipleAsserts] @@ -64,7 +64,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); @@ -81,7 +81,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(vector, result); } @@ -96,7 +96,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(null, result); } @@ -111,7 +111,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = null; + Vector result = null; preconditioner.Approximate(vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs index f837a471..e01e3697 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs @@ -1,21 +1,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners { - using System.Numerics; using LinearAlgebra.Complex; using LinearAlgebra.Complex.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class UnitPreconditionerTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new UnitPreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(UnitPreconditioner), preconditioner.GetType(), "#01"); diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs index 5017436c..ba3e4919 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs @@ -22,7 +22,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -33,7 +33,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -44,13 +44,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex32.One); + Vector y = new DenseVector(matrix.RowCount, Complex32.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +84,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(new Complex32((float)Math.PI, (float)Math.PI), matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex32.One); + Vector y = new DenseVector(matrix.RowCount, Complex32.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -166,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, Complex32.One); + Vector y = new DenseVector(matrix.RowCount, Complex32.One); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +205,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -245,10 +245,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs index 93185795..432d235b 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs @@ -22,7 +22,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -33,7 +33,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -44,13 +44,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +84,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -167,10 +167,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -207,10 +207,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -247,10 +247,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs index a73534b5..64f99d12 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs @@ -22,7 +22,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -33,7 +33,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -44,13 +44,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -85,16 +85,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -166,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +205,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -245,10 +245,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs index 39b65ce9..e28f2630 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs @@ -22,7 +22,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -33,7 +33,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -44,13 +44,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -85,16 +85,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -166,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +205,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -245,10 +245,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat { for (var iteration = 5; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/IteratorTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/IteratorTest.cs index d8c41357..871cce11 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/IteratorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/IteratorTest.cs @@ -26,7 +26,7 @@ [MultipleAsserts] public void CreateWithEmptyCollection() { - var iterator = new Iterator(new IIterationStopCriterium[] { }); + var iterator = new Iterator(new IIterationStopCriterium[] { }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -35,7 +35,7 @@ [MultipleAsserts] public void CreateWithCollectionWithNulls() { - var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); + var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -44,7 +44,7 @@ [ExpectedArgumentException] public void CreateWithDuplicates() { - new Iterator(new IIterationStopCriterium[] + new Iterator(new IIterationStopCriterium[] { new FailureStopCriterium(), new FailureStopCriterium() @@ -55,7 +55,7 @@ [MultipleAsserts] public void CreateWithCollection() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -98,7 +98,7 @@ [MultipleAsserts] public void Add() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -128,7 +128,7 @@ [ExpectedArgumentNullException] public void RemoveWithNullStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -145,7 +145,7 @@ [MultipleAsserts] public void RemoveWithNonExistingStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -162,7 +162,7 @@ [MultipleAsserts] public void Remove() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -194,7 +194,7 @@ [ExpectedException(typeof(ArgumentOutOfRangeException))] public void DetermineStatusWithNegativeIterationNumber() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -213,7 +213,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSolutionVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -232,7 +232,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSourceVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -251,7 +251,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullResidualVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -270,7 +270,7 @@ [MultipleAsserts] public void DetermineStatus() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -298,7 +298,7 @@ [MultipleAsserts] public void ResetToPrecalculationState() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -325,7 +325,7 @@ [MultipleAsserts] public void Clone() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs index c7f8e3e0..e1d03e47 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs @@ -1,27 +1,24 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners { - using Numerics; using LinearAlgebra.Complex32; using LinearAlgebra.Complex32.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class DiagonalTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new Diagonal(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs index aa927aec..4e4b36c2 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -142,7 +142,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithIncreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -170,7 +170,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithDecreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 9; values[1] = 8; values[2] = 7; @@ -198,7 +198,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithRandomDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 5; values[1] = 2; values[2] = 8; @@ -258,7 +258,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithDuplicateDoubleEntries() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 1; values[1] = 1; values[2] = 1; @@ -319,7 +319,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithSpecialConstructedDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 0; values[2] = 0; @@ -422,7 +422,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithIncreasingDoubleArrayWithLowerBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -450,7 +450,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithIncreasingDoubleArrayWithUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -478,7 +478,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs index 62bc212e..c8c34f6a 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs @@ -1,12 +1,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners { using System; - using Numerics; using System.Reflection; using LinearAlgebra.Complex32; using LinearAlgebra.Complex32.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -74,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon return result; } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { _pivotTolerance = 0; _dropTolerance = 0.0; @@ -82,13 +79,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon return InternalCreatePreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) { @@ -112,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -131,7 +128,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -246,7 +243,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon FillLevel = 10 }; preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs index f69c8116..71db852d 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs @@ -1,12 +1,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners { using System; - using Numerics; using System.Reflection; using LinearAlgebra.Complex32; using LinearAlgebra.Complex32.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -25,28 +22,28 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon return (T)obj; } - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "UpperTriangle"); + return GetMethod(ilu, "UpperTriangle"); } - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "LowerTriangle"); + return GetMethod(ilu, "LowerTriangle"); } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new IncompleteLU(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs index 32c86338..23740005 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs @@ -1,9 +1,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners { - using Numerics; using LinearAlgebra.Complex32; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; + using LinearAlgebra.Complex32.Solvers.Preconditioners; using MbUnit.Framework; public abstract class PreconditionerTest @@ -21,9 +19,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon return matrix; } - protected Vector CreateStandardBcVector(int size) + protected Vector CreateStandardBcVector(int size) { - Vector vector = new DenseVector(size); + Vector vector = new DenseVector(size); for (var i = 0; i < size; i++) { vector[i] = i + 1; @@ -32,9 +30,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon return vector; } - internal abstract IPreConditioner CreatePreconditioner(); + internal abstract IPreConditioner CreatePreconditioner(); - protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); + protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); [Test] [MultipleAsserts] @@ -64,7 +62,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); @@ -81,7 +79,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(vector, result); } @@ -96,7 +94,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(null, result); } @@ -111,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = null; + Vector result = null; preconditioner.Approximate(vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs index 6b32f546..a2f5b5f2 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs @@ -1,21 +1,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners { - using Numerics; using LinearAlgebra.Complex32; using LinearAlgebra.Complex32.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class UnitPreconditionerTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new UnitPreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(UnitPreconditioner), preconditioner.GetType(), "#01"); diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs index d1cac027..61a46afd 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs @@ -66,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } } - public static Matrix GenerateRandomDenseMatrix(int row, int col) + public static Matrix GenerateRandomDenseMatrix(int row, int col) { // Fill a matrix with standard random numbers. var normal = new Distributions.Normal(); @@ -117,7 +117,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double return v; } - public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) + public static Matrix GenerateRandomUserDefinedMatrix(int row, int col) { // Fill a matrix with standard random numbers. var normal = new Distributions.Normal(); diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs index 96bcd428..8218afc2 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs @@ -20,7 +20,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -31,7 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -42,13 +42,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -82,16 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -164,10 +164,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -203,10 +203,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -235,7 +235,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs index 96f706ce..7eb1436c 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs @@ -20,7 +20,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -31,7 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -42,13 +42,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -82,16 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +165,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -205,10 +205,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -237,7 +237,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs index efc9a5f9..fecf494b 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs @@ -20,7 +20,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -31,7 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -42,13 +42,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +83,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -164,10 +164,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -203,10 +203,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -232,10 +232,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs index 3919f37d..19f25fca 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs @@ -20,7 +20,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -31,7 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -42,13 +42,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +83,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply(System.Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -164,10 +164,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -203,10 +203,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomVector(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10), @@ -232,10 +232,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative [MultipleAsserts] public void CanSolveForRandomMatrix(int order) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(1000), new ResidualStopCriterium(1e-10) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/IteratorTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/IteratorTest.cs index a3faa989..80e3c993 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/IteratorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/IteratorTest.cs @@ -25,7 +25,7 @@ [MultipleAsserts] public void CreateWithEmptyCollection() { - var iterator = new Iterator(new IIterationStopCriterium[] { }); + var iterator = new Iterator(new IIterationStopCriterium[] { }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -34,7 +34,7 @@ [MultipleAsserts] public void CreateWithCollectionWithNulls() { - var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); + var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -43,7 +43,7 @@ [ExpectedArgumentException] public void CreateWithDuplicates() { - new Iterator(new IIterationStopCriterium[] + new Iterator(new IIterationStopCriterium[] { new FailureStopCriterium(), new FailureStopCriterium() @@ -54,7 +54,7 @@ [MultipleAsserts] public void CreateWithCollection() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -97,7 +97,7 @@ [MultipleAsserts] public void Add() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -127,7 +127,7 @@ [ExpectedArgumentNullException] public void RemoveWithNullStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -144,7 +144,7 @@ [MultipleAsserts] public void RemoveWithNonExistingStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -161,7 +161,7 @@ [MultipleAsserts] public void Remove() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -193,7 +193,7 @@ [ExpectedException(typeof(ArgumentOutOfRangeException))] public void DetermineStatusWithNegativeIterationNumber() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -212,7 +212,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSolutionVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -231,7 +231,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSourceVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -250,7 +250,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullResidualVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -269,7 +269,7 @@ [MultipleAsserts] public void DetermineStatus() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -297,7 +297,7 @@ [MultipleAsserts] public void ResetToPrecalculationState() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -324,7 +324,7 @@ [MultipleAsserts] public void Clone() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs index 946f7234..f15492db 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs @@ -2,25 +2,23 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit { using LinearAlgebra.Double; using LinearAlgebra.Double.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class DiagonalTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new Diagonal(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs index 66276968..236492f7 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -141,7 +141,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithIncreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -169,7 +169,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithDecreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 9; values[1] = 8; values[2] = 7; @@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithRandomDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 5; values[1] = 2; values[2] = 8; @@ -257,7 +257,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithDuplicateDoubleEntries() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 1; values[1] = 1; values[2] = 1; @@ -318,7 +318,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithSpecialConstructedDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 0; values[2] = 0; @@ -421,7 +421,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithLowerBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -449,7 +449,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -477,7 +477,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs index 2970ffd9..ce12fe37 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs @@ -4,8 +4,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit using System.Reflection; using LinearAlgebra.Double; using LinearAlgebra.Double.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -73,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit return result; } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { _pivotTolerance = 0; _dropTolerance = 0.0; @@ -81,13 +79,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit return InternalCreatePreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) { @@ -110,7 +108,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -129,7 +127,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -242,7 +240,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit FillLevel = 10 }; preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs index 50aa8976..2737df93 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs @@ -4,8 +4,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit using System.Reflection; using LinearAlgebra.Double; using LinearAlgebra.Double.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -24,28 +22,28 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit return (T)obj; } - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "UpperTriangle"); + return GetMethod(ilu, "UpperTriangle"); } - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "LowerTriangle"); + return GetMethod(ilu, "LowerTriangle"); } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new IncompleteLU(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs index 1ade1ce9..9f279fff 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs @@ -1,8 +1,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners { using LinearAlgebra.Double; + using LinearAlgebra.Double.Solvers.Preconditioners; using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; public abstract class PreconditionerTest @@ -20,9 +20,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit return matrix; } - protected Vector CreateStandardBcVector(int size) + protected Vector CreateStandardBcVector(int size) { - Vector vector = new DenseVector(size); + Vector vector = new DenseVector(size); for (var i = 0; i < size; i++) { vector[i] = i + 1; @@ -31,9 +31,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit return vector; } - internal abstract IPreConditioner CreatePreconditioner(); + internal abstract IPreConditioner CreatePreconditioner(); - protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); + protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); [Test] [MultipleAsserts] @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); @@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(vector, result); } @@ -95,7 +95,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(null, result); } @@ -110,7 +110,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = null; + Vector result = null; preconditioner.Approximate(vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs index e2138bb9..28eec73c 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs @@ -2,19 +2,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit { using LinearAlgebra.Double; using LinearAlgebra.Double.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class UnitPreconditionerTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new UnitPreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(UnitPreconditioner), preconditioner.GetType(), "#01"); diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs index 1f97b779..37d00cdb 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs @@ -5,9 +5,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative using LinearAlgebra.Single.Solvers; using LinearAlgebra.Single.Solvers.Iterative; using LinearAlgebra.Single.Solvers.StopCriterium; - using LinearAlgebra.Generic; using LinearAlgebra.Generic.Solvers.Status; - using LinearAlgebra.Generic.Solvers.StopCriterium; using MbUnit.Framework; [TestFixture] @@ -21,7 +19,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -32,7 +30,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new BiCgStab(); solver.Solve(matrix, input); @@ -43,13 +41,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +81,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +163,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -206,10 +204,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 3 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -247,10 +245,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 3 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs index 77f83524..8088c360 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs @@ -21,7 +21,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -32,7 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new GpBiCg(); solver.Solve(matrix, input); @@ -43,13 +43,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -83,16 +83,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -166,10 +166,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -208,10 +208,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 3 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -249,10 +249,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 3 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs index 98c8c68c..c0ae4b7e 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs @@ -21,7 +21,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -32,7 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new MlkBiCgStab(); solver.Solve(matrix, input); @@ -43,13 +43,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +84,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,14 +165,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Due to datatype "float" it can happen that solution will not converge for specific random starting vectors // That's why we will do 3 tries for (var iteration = 0; iteration <= 3; iteration++) { // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -182,7 +182,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative var solver = new MlkBiCgStab(monitor); // Solve equation Ax = y - Vector x; + Vector x; try { x = solver.Solve(matrix, y); @@ -226,10 +226,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 4 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -267,10 +267,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 4 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs index 0825e408..87b9fed2 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs @@ -5,9 +5,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative using LinearAlgebra.Single.Solvers; using LinearAlgebra.Single.Solvers.Iterative; using LinearAlgebra.Single.Solvers.StopCriterium; - using LinearAlgebra.Generic; using LinearAlgebra.Generic.Solvers.Status; - using LinearAlgebra.Generic.Solvers.StopCriterium; using MbUnit.Framework; [TestFixture] @@ -21,7 +19,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveWideMatrix() { var matrix = new SparseMatrix(2, 3); - Vector input = new DenseVector(2); + Vector input = new DenseVector(2); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -32,7 +30,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveLongMatrix() { var matrix = new SparseMatrix(3, 2); - Vector input = new DenseVector(3); + Vector input = new DenseVector(3); var solver = new TFQMR(); solver.Solve(matrix, input); @@ -43,13 +41,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -84,16 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative public void SolveScaledUnitMatrixAndBackMultiply() { // Create the identity matrix - Matrix matrix = SparseMatrix.Identity(100); + Matrix matrix = SparseMatrix.Identity(100); // Scale it with a funny number matrix.Multiply((float)Math.PI, matrix); // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -165,10 +163,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative } // Create the y vector - Vector y = new DenseVector(matrix.RowCount, 1); + Vector y = new DenseVector(matrix.RowCount, 1); // Create an iteration monitor which will keep track of iterative convergence - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium(ConvergenceBoundary), @@ -206,10 +204,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 3 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var vectorb = MatrixLoader.GenerateRandomDenseVector(order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var vectorb = (Vector)MatrixLoader.GenerateRandomDenseVector(order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)), @@ -247,10 +245,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative // That's why we will do 4 tries and downgrade stop criterium each time for (var iteration = 6; iteration > 3; iteration--) { - var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order); - var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixA = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); + var matrixB = (Matrix)MatrixLoader.GenerateRandomDenseMatrix(order, order); - var monitor = new Iterator(new IIterationStopCriterium[] + var monitor = new Iterator(new IIterationStopCriterium[] { new IterationCountStopCriterium(MaximumIterations), new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration)) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/IteratorTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/IteratorTest.cs index 728fb936..475d875b 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/IteratorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/IteratorTest.cs @@ -25,7 +25,7 @@ [MultipleAsserts] public void CreateWithEmptyCollection() { - var iterator = new Iterator(new IIterationStopCriterium[] { }); + var iterator = new Iterator(new IIterationStopCriterium[] { }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -34,7 +34,7 @@ [MultipleAsserts] public void CreateWithCollectionWithNulls() { - var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); + var iterator = new Iterator(new IIterationStopCriterium[] { null, null }); Assert.IsNotNull(iterator, "Should have an iterator"); Assert.AreEqual(0, iterator.NumberOfCriteria, "There shouldn't be any criteria"); } @@ -43,7 +43,7 @@ [ExpectedArgumentException] public void CreateWithDuplicates() { - new Iterator(new IIterationStopCriterium[] + new Iterator(new IIterationStopCriterium[] { new FailureStopCriterium(), new FailureStopCriterium() @@ -54,7 +54,7 @@ [MultipleAsserts] public void CreateWithCollection() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -97,7 +97,7 @@ [MultipleAsserts] public void Add() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -127,7 +127,7 @@ [ExpectedArgumentNullException] public void RemoveWithNullStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -144,7 +144,7 @@ [MultipleAsserts] public void RemoveWithNonExistingStopCriterium() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -161,7 +161,7 @@ [MultipleAsserts] public void Remove() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -193,7 +193,7 @@ [ExpectedException(typeof(ArgumentOutOfRangeException))] public void DetermineStatusWithNegativeIterationNumber() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -212,7 +212,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSolutionVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -231,7 +231,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullSourceVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -250,7 +250,7 @@ [ExpectedArgumentNullException] public void DetermineStatusWithNullResidualVector() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -269,7 +269,7 @@ [MultipleAsserts] public void DetermineStatus() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -297,7 +297,7 @@ [MultipleAsserts] public void ResetToPrecalculationState() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), @@ -324,7 +324,7 @@ [MultipleAsserts] public void Clone() { - var criteria = new List> + var criteria = new List { new FailureStopCriterium(), new DivergenceStopCriterium(), diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs index d1dc1f4c..3df6f862 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs @@ -2,25 +2,23 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit { using LinearAlgebra.Single; using LinearAlgebra.Single.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class DiagonalTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new Diagonal(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs index 5ed7d006..a331aa7d 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -141,7 +141,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithIncreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -169,7 +169,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithDecreasingDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 9; values[1] = 8; values[2] = 7; @@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithRandomDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 5; values[1] = 2; values[2] = 8; @@ -257,7 +257,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithDuplicateDoubleEntries() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 1; values[1] = 1; values[2] = 1; @@ -318,7 +318,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithSpecialConstructedDoubleArray() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 0; values[2] = 0; @@ -421,7 +421,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithLowerBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -449,7 +449,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; @@ -477,7 +477,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() { var sortedIndices = new int[10]; - Vector values = new DenseVector(10); + Vector values = new DenseVector(10); values[0] = 0; values[1] = 1; values[2] = 2; diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs index 7957a67e..28e865db 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs @@ -4,8 +4,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit using System.Reflection; using LinearAlgebra.Single; using LinearAlgebra.Single.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -73,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit return result; } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { _pivotTolerance = 0; _dropTolerance = 0.0; @@ -81,13 +79,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit return InternalCreatePreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) { @@ -110,7 +108,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -129,7 +127,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit _fillLevel = 100; var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } @@ -242,7 +240,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit FillLevel = 10 }; preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs index adc799aa..eae07dc0 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs @@ -4,8 +4,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit using System.Reflection; using LinearAlgebra.Single; using LinearAlgebra.Single.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] @@ -24,28 +22,28 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit return (T)obj; } - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "UpperTriangle"); + return GetMethod(ilu, "UpperTriangle"); } - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(IncompleteLU ilu) { - return GetMethod>(ilu, "LowerTriangle"); + return GetMethod(ilu, "LowerTriangle"); } - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new IncompleteLU(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal - Vector product = new DenseVector(result.Count); + Vector product = new DenseVector(result.Count); matrix.Multiply(result, product); for (var i = 0; i < product.Count; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs index 3bfebc43..10d49ecf 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs @@ -2,7 +2,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit { using LinearAlgebra.Single; using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; + using LinearAlgebra.Single.Solvers.Preconditioners; using MbUnit.Framework; public abstract class PreconditionerTest @@ -20,9 +20,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit return matrix; } - protected Vector CreateStandardBcVector(int size) + protected Vector CreateStandardBcVector(int size) { - Vector vector = new DenseVector(size); + Vector vector = new DenseVector(size); for (var i = 0; i < size; i++) { vector[i] = i + 1; @@ -31,9 +31,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit return vector; } - internal abstract IPreConditioner CreatePreconditioner(); + internal abstract IPreConditioner CreatePreconditioner(); - protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); + protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result); [Test] [MultipleAsserts] @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count); + Vector result = new DenseVector(vector.Count); preconditioner.Approximate(vector, result); CheckResult(preconditioner, newMatrix, vector, result); @@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(vector, result); } @@ -95,7 +95,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = new DenseVector(vector.Count + 10); + Vector result = new DenseVector(vector.Count + 10); preconditioner.Approximate(null, result); } @@ -110,7 +110,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit var preconditioner = CreatePreconditioner(); preconditioner.Initialize(newMatrix); - Vector result = null; + Vector result = null; preconditioner.Approximate(vector, result); } diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs index 560c5862..e8153148 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs @@ -2,19 +2,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit { using LinearAlgebra.Single; using LinearAlgebra.Single.Solvers.Preconditioners; - using LinearAlgebra.Generic; - using LinearAlgebra.Generic.Solvers.Preconditioners; using MbUnit.Framework; [TestFixture] public sealed class UnitPreconditionerTest : PreconditionerTest { - internal override IPreConditioner CreatePreconditioner() + internal override IPreConditioner CreatePreconditioner() { return new UnitPreconditioner(); } - protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) + protected override void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { Assert.AreEqual(typeof(UnitPreconditioner), preconditioner.GetType(), "#01");