diff --git a/src/Numerics/LinearAlgebra/Builder.cs b/src/Numerics/LinearAlgebra/Builder.cs
new file mode 100644
index 00000000..732f3031
--- /dev/null
+++ b/src/Numerics/LinearAlgebra/Builder.cs
@@ -0,0 +1,268 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
+// http://mathnetnumerics.codeplex.com
+//
+// Copyright (c) 2009-2013 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+#if NOSYSNUMERICS
+ using Complex64 = Numerics.Complex;
+#else
+ using Complex64 = System.Numerics.Complex;
+#endif
+
+namespace MathNet.Numerics.LinearAlgebra.Double
+{
+ internal class GenericBuilder : IGenericBuilder
+ {
+ public double Zero
+ {
+ get { return 0d; }
+ }
+
+ public double One
+ {
+ get { return 1d; }
+ }
+
+ public Matrix DenseMatrix(int rows, int columns)
+ {
+ return new DenseMatrix(rows, columns);
+ }
+
+ public Matrix SparseMatrix(int rows, int columns)
+ {
+ return new SparseMatrix(rows, columns);
+ }
+
+ public Vector DenseVector(int size)
+ {
+ return new DenseVector(size);
+ }
+
+ public Vector SparseVector(int size)
+ {
+ return new SparseVector(size);
+ }
+ }
+}
+
+namespace MathNet.Numerics.LinearAlgebra.Single
+{
+ internal class GenericBuilder : IGenericBuilder
+ {
+ public float Zero
+ {
+ get { return 0f; }
+ }
+
+ public float One
+ {
+ get { return 1f; }
+ }
+
+ public Matrix DenseMatrix(int rows, int columns)
+ {
+ return new DenseMatrix(rows, columns);
+ }
+
+ public Matrix SparseMatrix(int rows, int columns)
+ {
+ return new SparseMatrix(rows, columns);
+ }
+
+ public Vector DenseVector(int size)
+ {
+ return new DenseVector(size);
+ }
+
+ public Vector SparseVector(int size)
+ {
+ return new SparseVector(size);
+ }
+ }
+}
+
+namespace MathNet.Numerics.LinearAlgebra.Complex
+{
+ internal class GenericBuilder : IGenericBuilder
+ {
+ public Complex64 Zero
+ {
+ get { return Complex64.Zero; }
+ }
+
+ public Complex64 One
+ {
+ get { return Complex64.One; }
+ }
+
+ public Matrix DenseMatrix(int rows, int columns)
+ {
+ return new DenseMatrix(rows, columns);
+ }
+
+ public Matrix SparseMatrix(int rows, int columns)
+ {
+ return new SparseMatrix(rows, columns);
+ }
+
+ public Vector DenseVector(int size)
+ {
+ return new DenseVector(size);
+ }
+
+ public Vector SparseVector(int size)
+ {
+ return new SparseVector(size);
+ }
+ }
+}
+
+namespace MathNet.Numerics.LinearAlgebra.Complex32
+{
+ internal class GenericBuilder : IGenericBuilder
+ {
+ public Numerics.Complex32 Zero
+ {
+ get { return Numerics.Complex32.Zero; }
+ }
+
+ public Numerics.Complex32 One
+ {
+ get { return Numerics.Complex32.One; }
+ }
+
+ public Matrix DenseMatrix(int rows, int columns)
+ {
+ return new DenseMatrix(rows, columns);
+ }
+
+ public Matrix SparseMatrix(int rows, int columns)
+ {
+ return new SparseMatrix(rows, columns);
+ }
+
+ public Vector DenseVector(int size)
+ {
+ return new DenseVector(size);
+ }
+
+ public Vector SparseVector(int size)
+ {
+ return new SparseVector(size);
+ }
+ }
+}
+
+namespace MathNet.Numerics.LinearAlgebra
+{
+ ///
+ /// Generic linear algebra type builder, for situations where a matrix or vector
+ /// must be created in a generic way. Usage of generic builders should not be
+ /// required in normal user code.
+ ///
+ public interface IGenericBuilder where T : struct, IEquatable, IFormattable
+ {
+ ///
+ /// Gets the value of 0.0 for type T.
+ ///
+ T Zero { get; }
+
+ ///
+ /// Gets the value of 1.0 for type T.
+ ///
+ T One { get; }
+
+ ///
+ /// Create a dense matrix of T with the given number of rows and columns.
+ ///
+ /// The number of rows.
+ /// The number of columns.
+ Matrix DenseMatrix(int rows, int columns);
+
+ ///
+ /// Create a sparse matrix of T with the given number of rows and columns.
+ ///
+ /// The number of rows.
+ /// The number of columns.
+ Matrix SparseMatrix(int rows, int columns);
+
+ ///
+ /// Create a dense vector of T with the given size.
+ ///
+ /// The size of the vector.
+ Vector DenseVector(int size);
+
+ ///
+ /// Create a sparse vector of T with the given size.
+ ///
+ /// The size of the vector.
+ Vector SparseVector(int size);
+ }
+
+ public static class Builder where T : struct, IEquatable, IFormattable
+ {
+ static Lazy> _singleton = new Lazy>(Create);
+
+ static IGenericBuilder Create()
+ {
+ if (typeof(T) == typeof(Complex64))
+ {
+ return (IGenericBuilder)(object)new Complex.GenericBuilder();
+ }
+
+ if (typeof(T) == typeof(Numerics.Complex32))
+ {
+ return (IGenericBuilder)(object)new Complex32.GenericBuilder();
+ }
+
+ if (typeof(T) == typeof(double))
+ {
+ return (IGenericBuilder)(object)new Double.GenericBuilder();
+ }
+
+ if (typeof(T) == typeof(float))
+ {
+ return (IGenericBuilder)(object)new Single.GenericBuilder();
+ }
+
+ throw new NotSupportedException();
+ }
+
+ public static void Register(IGenericBuilder builder)
+ {
+ _singleton = new Lazy>(() => builder);
+ }
+
+ public static IGenericBuilder Instance
+ {
+ get { return _singleton.Value; }
+ }
+ }
+}
diff --git a/src/Numerics/LinearAlgebra/Common.cs b/src/Numerics/LinearAlgebra/Common.cs
index f766c708..d6616f65 100644
--- a/src/Numerics/LinearAlgebra/Common.cs
+++ b/src/Numerics/LinearAlgebra/Common.cs
@@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra
using Complex64 = Numerics.Complex;
#else
using Complex64 = System.Numerics.Complex;
-
#endif
///
diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
index 1cd31c5a..a138e3a9 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
@@ -357,33 +357,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
get { return _values; }
}
- ///
- /// Creates a DenseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DenseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new DenseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new DenseVector(size);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
index 2214c347..b5fcd701 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
@@ -197,39 +197,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseVector(array);
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new DenseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new DenseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index 70f501ed..5058c00e 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -186,35 +186,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
i => new Complex(distribution.Sample(), distribution.Sample())));
}
- ///
- /// Creates a DiagonalMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DiagonalMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return fullyMutable
- ? (Matrix) new SparseMatrix(numberOfRows, numberOfColumns)
- : new DiagonalMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
#region Elementary operations
///
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs
index 53478ac0..0aac6a61 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterativeSolver.cs
@@ -32,6 +32,13 @@ using MathNet.Numerics.LinearAlgebra.Solvers.Status;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Defines the interface for classes that solve the matrix equation Ax = b in
/// an iterative manner.
@@ -64,7 +71,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.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
@@ -73,7 +80,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.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
@@ -82,7 +89,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.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
@@ -91,6 +98,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.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/Complex/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
index a8cd1935..85c64a8c 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/IIterator.cs
@@ -34,6 +34,13 @@ using System;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Defines the base interface for iterators that help control an iterative calculation.
///
@@ -80,7 +87,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs
index a44f2b66..4b8425df 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs
@@ -212,14 +212,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -231,7 +231,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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
@@ -439,7 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -459,7 +459,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -483,7 +483,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X.
- public Matrix Solve(Matrix matrix, Matrix input)
+ public Matrix Solve(Matrix matrix, Matrix input)
{
if (matrix == null)
{
@@ -495,7 +495,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -507,7 +507,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X
- public void Solve(Matrix matrix, Matrix input, Matrix result)
+ public void Solve(Matrix matrix, Matrix input, Matrix result)
{
if (matrix == null)
{
@@ -531,7 +531,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
index 83ae2595..77208b91 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs
@@ -38,6 +38,13 @@ using System.Reflection;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// A composite matrix solver. The actual solver is made by a sequence of
/// matrix solvers.
@@ -413,14 +420,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -432,7 +439,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
@@ -482,8 +489,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 = (Vector)input.Clone();
- var internalResult = (Vector)result.Clone();
+ var internalInput = input.Clone();
+ var internalResult = result.Clone();
foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped))
{
@@ -574,7 +581,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)
{
@@ -586,7 +593,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -598,7 +605,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)
{
@@ -622,7 +629,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs
index 23c8fe88..f13b546d 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs
@@ -261,14 +261,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -280,7 +280,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
@@ -524,7 +524,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -542,7 +542,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -583,7 +583,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)
{
@@ -595,7 +595,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -607,7 +607,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)
{
@@ -631,7 +631,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs
index 8c9e83c3..7a4637ef 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs
@@ -97,7 +97,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
///
/// The collection of starting vectors which are used as the basis for the Krylov sub-space.
///
- IList _startingVectors;
+ IList> _startingVectors;
///
/// The number of starting vectors used by the algorithm
@@ -235,7 +235,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 { return _startingVectors; }
@@ -281,14 +281,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -300,7 +300,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
@@ -639,7 +639,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// the is smaller than
/// the .
///
- static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables)
+ 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
@@ -650,7 +650,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// mean = 0 and sd = 1
var distribution = new Normal();
- Matrix matrix = new DenseMatrix(numberOfVariables, count);
+ var matrix = new DenseMatrix(numberOfVariables, count);
for (var i = 0; i < matrix.ColumnCount; i++)
{
var samples = new Complex[matrix.RowCount];
@@ -670,10 +670,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((Vector) orthogonalMatrix.Column(i));
+ result.Add(orthogonalMatrix.Column(i));
// Normalize the result vector
result[i].Multiply(1/result[i].L2Norm(), result[i]);
@@ -688,9 +688,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Number of vectors
/// Size of each vector
/// Array of random vectors
- static Vector[] CreateVectorArray(int arraySize, int vectorSize)
+ 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);
@@ -706,7 +706,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Residual data.
/// x data.
/// b data.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -724,7 +724,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -748,7 +748,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)
{
@@ -760,7 +760,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -772,7 +772,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)
{
@@ -796,7 +796,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs
index fdead38e..9451e49f 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs
@@ -200,14 +200,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -219,7 +219,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
@@ -430,7 +430,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -448,7 +448,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -482,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)
{
@@ -494,7 +494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -506,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)
{
@@ -530,7 +530,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
index 48e8f8c7..a84d46b2 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterator.cs
@@ -37,6 +37,13 @@ using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// An iterator that is used to check if an iterative calculation should continue or stop.
///
@@ -212,7 +219,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs
index c6c18c69..4ecad2c5 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs
@@ -72,7 +72,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
/// 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)
{
@@ -96,7 +96,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)
{
@@ -113,7 +113,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -123,7 +123,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/Complex/Solvers/Preconditioners/IPreConditioner.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs
index b542ceac..6c514f69 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IPreConditioner.cs
@@ -30,6 +30,13 @@
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// The base interface for preconditioner classes.
///
@@ -54,20 +61,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
/// 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 dbc49216..7a6c6f61 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs
@@ -261,9 +261,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 (Matrix)_upper.Clone();
+ return _upper.Clone();
}
///
@@ -273,9 +273,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 (Matrix)_lower.Clone();
+ return _lower.Clone();
}
///
@@ -307,7 +307,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)
{
@@ -379,8 +379,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
_pivots[i] = i;
}
- Vector workVector = new DenseVector(sparseMatrix.RowCount);
- Vector rowVector = new DenseVector(sparseMatrix.ColumnCount);
+ var workVector = new DenseVector(sparseMatrix.RowCount);
+ var rowVector = new DenseVector(sparseMatrix.ColumnCount);
var indexSorting = new int[sparseMatrix.RowCount];
// spaceLeft = lfilNnz * nnz(A)
@@ -536,7 +536,7 @@ 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)
+ private void PivotRow(Vector row)
{
var knownPivots = new Dictionary();
@@ -588,7 +588,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
/// 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++)
{
@@ -605,7 +605,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
/// Sort till upper bound
/// Array with sorted vector indicies
/// Source
- private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
+ 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++)
@@ -630,7 +630,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)
{
@@ -647,7 +647,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -657,7 +657,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)
{
@@ -682,7 +682,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);
+ var rowValues = new DenseVector(_lower.RowCount);
for (var i = 0; i < _lower.RowCount; i++)
{
_lower.Row(i, rowValues);
@@ -712,7 +712,7 @@ 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 = (Vector)lhs.Clone();
+ var temp = lhs.Clone();
Pivot(temp, lhs);
}
@@ -722,7 +722,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
///
/// Source .
/// Result after pivoting.
- private void Pivot(Vector vector, Vector result)
+ private void Pivot(Vector vector, Vector result)
{
for (var i = 0; i < _pivots.Length; i++)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs
index bc9b8e0f..50b4233f 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs
@@ -60,7 +60,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++)
@@ -78,7 +78,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++)
@@ -105,7 +105,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)
{
@@ -167,7 +167,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)
{
@@ -184,7 +184,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -194,7 +194,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)
{
@@ -224,7 +224,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
// z_i = l_ii^-1 * (y_i - SUM_(j
/// A unit preconditioner. This preconditioner does not actually do anything
/// it is only used when running an without
@@ -54,7 +60,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)
{
@@ -87,7 +93,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)
{
@@ -116,7 +122,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)
{
@@ -128,7 +134,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
- Vector result = new DenseVector(rhs.Count);
+ var 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 312060ee..56a58e7e 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -35,6 +35,13 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Monitors an iterative calculation for signs of divergence.
///
@@ -217,7 +224,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
index ebe6b045..1aa6e50b 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -36,6 +36,13 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Defines an that monitors residuals for NaN's.
///
@@ -75,7 +82,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
index 9f80bc7a..1d6c41c0 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -29,6 +29,13 @@ using MathNet.Numerics.LinearAlgebra.Solvers.StopCriterium;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// The base interface for classes that provide stop criteria for iterative calculations.
///
@@ -47,7 +54,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
index d88ed2ae..0c241524 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -35,6 +35,13 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Defines an that monitors the numbers of iteration
/// steps as stop criterium.
@@ -130,7 +137,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
index 261bb3ea..84e3ee13 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -36,6 +36,13 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.StopCriterium
{
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
+
///
/// Defines an that monitors residuals as stop criterium.
///
@@ -222,7 +229,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
index c19ceff1..fc366b6a 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
@@ -328,33 +328,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage.OfDiagonalInit(rows, columns, init));
}
- ///
- /// Creates a SparseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A SparseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new SparseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
///
/// Returns a new matrix containing the lower triangle of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
index e1251a79..2fa68581 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
@@ -133,39 +133,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseVector(SparseVectorStorage.OfInit(length, init));
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new SparseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new SparseVector(size);
- }
-
///
/// Conjugates vector and save result to
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
index 357c789c..f68780b8 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
@@ -352,33 +352,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
get { return _values; }
}
- ///
- /// Creates a DenseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DenseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new DenseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new DenseVector(size);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
index 6fab3dfa..2aeb2f25 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
@@ -192,39 +192,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseVector(array);
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new DenseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new DenseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index 2f16cd5d..f8954ef8 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -181,35 +181,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
i => new Complex32((float) distribution.Sample(), (float) distribution.Sample())));
}
- ///
- /// Creates a DiagonalMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DiagonalMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return fullyMutable
- ? (Matrix) new SparseMatrix(numberOfRows, numberOfColumns)
- : new DiagonalMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
#region Elementary operations
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs
index b87f5b91..ea4ca6de 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterativeSolver.cs
@@ -32,6 +32,8 @@ using MathNet.Numerics.LinearAlgebra.Solvers.Status;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
+ using Numerics;
+
///
/// Defines the interface for classes that solve the matrix equation Ax = b in
/// an iterative manner.
@@ -64,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.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
@@ -73,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.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
@@ -82,7 +84,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.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
@@ -91,6 +93,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.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/Complex32/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
index c865439b..605f1630 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/IIterator.cs
@@ -34,6 +34,8 @@ using System;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
+ using Numerics;
+
///
/// Defines the base interface for iterators that help control an iterative calculation.
///
@@ -80,7 +82,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs
index a0e81e5d..a39339b6 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs
@@ -206,14 +206,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -225,7 +225,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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
@@ -433,7 +433,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -453,7 +453,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -477,7 +477,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X.
- public Matrix Solve(Matrix matrix, Matrix input)
+ public Matrix Solve(Matrix matrix, Matrix input)
{
if (matrix == null)
{
@@ -489,7 +489,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -501,7 +501,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X
- public void Solve(Matrix matrix, Matrix input, Matrix result)
+ public void Solve(Matrix matrix, Matrix input, Matrix result)
{
if (matrix == null)
{
@@ -525,7 +525,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
index eea9a4f6..80c03a18 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs
@@ -38,6 +38,8 @@ using System.Reflection;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
{
+ using Numerics;
+
///
/// A composite matrix solver. The actual solver is made by a sequence of
/// matrix solvers.
@@ -413,14 +415,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -432,7 +434,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
@@ -482,8 +484,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 = (Vector)input.Clone();
- var internalResult = (Vector)result.Clone();
+ var internalInput = input.Clone();
+ var internalResult = result.Clone();
foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped))
{
@@ -574,7 +576,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)
{
@@ -586,7 +588,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -598,7 +600,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)
{
@@ -622,7 +624,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs
index adab5a69..c8683e21 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs
@@ -255,14 +255,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -274,7 +274,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
@@ -523,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -541,7 +541,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -582,7 +582,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)
{
@@ -594,7 +594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -606,7 +606,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)
{
@@ -630,7 +630,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs
index d0bd74f3..d0c3705d 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs
@@ -91,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
///
/// The collection of starting vectors which are used as the basis for the Krylov sub-space.
///
- IList _startingVectors;
+ IList> _startingVectors;
///
/// The number of starting vectors used by the algorithm
@@ -229,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 { return _startingVectors; }
@@ -275,14 +275,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -294,7 +294,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
@@ -638,7 +638,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// the is smaller than
/// the .
///
- static IList CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables)
+ 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
@@ -649,7 +649,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// mean = 0 and sd = 1
var distribution = new Normal();
- Matrix matrix = new DenseMatrix(numberOfVariables, count);
+ var matrix = new DenseMatrix(numberOfVariables, count);
for (var i = 0; i < matrix.ColumnCount; i++)
{
var samples = new Complex32[matrix.RowCount];
@@ -669,10 +669,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((Vector) orthogonalMatrix.Column(i));
+ result.Add(orthogonalMatrix.Column(i));
// Normalize the result vector
result[i].Multiply(1/result[i].L2Norm().Real, result[i]);
@@ -687,9 +687,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Number of vectors
/// Size of each vector
/// Array of random vectors
- static Vector[] CreateVectorArray(int arraySize, int vectorSize)
+ 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);
@@ -705,7 +705,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Residual data.
/// x data.
/// b data.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -723,7 +723,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -747,7 +747,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)
{
@@ -759,7 +759,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -771,7 +771,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)
{
@@ -795,7 +795,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs
index 07f07df1..216bea34 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs
@@ -194,14 +194,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -213,7 +213,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
@@ -429,7 +429,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -447,7 +447,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -481,7 +481,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)
{
@@ -493,7 +493,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -505,7 +505,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)
{
@@ -529,7 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
index e5dc4ad4..9eac256f 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterator.cs
@@ -37,6 +37,8 @@ using System.Linq;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
+ using Numerics;
+
///
/// An iterator that is used to check if an iterative calculation should continue or stop.
///
@@ -212,7 +214,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs
index c9c87171..4a56535a 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs
@@ -67,7 +67,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// 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)
{
@@ -91,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)
{
@@ -108,7 +108,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -118,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
index 0c34892e..f1e80c06 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IPreConditioner.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IPreConditioner.cs
@@ -30,6 +30,8 @@
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
{
+ using Numerics;
+
///
/// The base interface for preconditioner classes.
///
@@ -54,20 +56,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// 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/Complex32/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs
index fe82cc9c..52ab9c81 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs
@@ -256,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 (Matrix)_upper.Clone();
+ return _upper.Clone();
}
///
@@ -268,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 (Matrix)_lower.Clone();
+ return _lower.Clone();
}
///
@@ -302,7 +302,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)
{
@@ -374,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);
+ var workVector = new DenseVector(sparseMatrix.RowCount);
+ var rowVector = new DenseVector(sparseMatrix.ColumnCount);
var indexSorting = new int[sparseMatrix.RowCount];
// spaceLeft = lfilNnz * nnz(A)
@@ -531,7 +531,7 @@ 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)
+ private void PivotRow(Vector row)
{
var knownPivots = new Dictionary();
@@ -583,7 +583,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// 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,7 +600,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// Sort till upper bound
/// Array with sorted vector indicies
/// Source
- private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
+ 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++)
@@ -625,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)
{
@@ -642,7 +642,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -652,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)
{
@@ -677,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);
+ var rowValues = new DenseVector(_lower.RowCount);
for (var i = 0; i < _lower.RowCount; i++)
{
_lower.Row(i, rowValues);
@@ -707,7 +707,7 @@ 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 = (Vector)lhs.Clone();
+ var temp = lhs.Clone();
Pivot(temp, lhs);
}
@@ -717,7 +717,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
///
/// Source .
/// Result after pivoting.
- private void Pivot(Vector vector, Vector result)
+ 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 76ba3a20..92351f97 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs
@@ -30,6 +30,8 @@
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
{
+ using Numerics;
+
///
/// An element sort algorithm for the class.
///
@@ -47,7 +49,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// 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)
+ 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.
@@ -73,7 +75,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// 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)
+ 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,7 +97,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// Length of
/// Indicies of
/// Target
- private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
+ private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
{
while (start >= 0)
{
@@ -111,7 +113,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
/// Target
/// Root position
/// Length of
- private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
+ private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
{
var root = begin;
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs
index 0a919276..3a25e7b2 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs
@@ -55,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++)
@@ -73,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++)
@@ -100,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)
{
@@ -162,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)
{
@@ -179,7 +179,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -189,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)
{
@@ -219,7 +219,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
// z_i = l_ii^-1 * (y_i - SUM_(j
/// A unit preconditioner. This preconditioner does not actually do anything
@@ -54,7 +55,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)
{
@@ -87,7 +88,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)
{
@@ -116,7 +117,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)
{
@@ -128,7 +129,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
- Vector result = new DenseVector(rhs.Count);
+ var 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 5f908fd9..f9a3c5e3 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -35,6 +35,8 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
{
+ using Numerics;
+
///
/// Monitors an iterative calculation for signs of divergence.
///
@@ -217,7 +219,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
index a76ac310..5a5c909e 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -36,6 +36,8 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
{
+ using Numerics;
+
///
/// Defines an that monitors residuals for NaN's.
///
@@ -75,7 +77,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
index 1ae098f7..1bc6ed87 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -29,6 +29,8 @@ using MathNet.Numerics.LinearAlgebra.Solvers.StopCriterium;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
{
+ using Numerics;
+
///
/// The base interface for classes that provide stop criteria for iterative calculations.
///
@@ -47,7 +49,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
index a01c4071..630439c5 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -35,6 +35,8 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
{
+ using Numerics;
+
///
/// Defines an that monitors the numbers of iteration
/// steps as stop criterium.
@@ -130,7 +132,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
index 04a0ae0a..812da360 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -36,6 +36,8 @@ using System.Diagnostics;
namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.StopCriterium
{
+ using Numerics;
+
///
/// Defines an that monitors residuals as stop criterium.
///
@@ -222,7 +224,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)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
index 87d27ce5..db7951ac 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
@@ -323,33 +323,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage.OfDiagonalInit(rows, columns, init));
}
- ///
- /// Creates a SparseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A SparseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new SparseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
///
/// Returns a new matrix containing the lower triangle of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
index 54a40d35..bc6ecfc6 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
@@ -128,39 +128,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseVector(SparseVectorStorage.OfInit(length, init));
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new SparseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new SparseVector(size);
- }
-
///
/// Conjugates vector and save result to
///
diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
index 4aa404a1..3e2d8573 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
@@ -349,33 +349,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
get { return _values; }
}
- ///
- /// Creates a DenseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DenseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new DenseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new DenseVector(size);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
index b7da46cd..da9665f0 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
@@ -192,39 +192,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseVector(array);
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new DenseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new DenseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index 7a08146d..f25d16b5 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -180,35 +180,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
i => distribution.Sample()));
}
- ///
- /// Creates a DiagonalMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DiagonalMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return fullyMutable
- ? (Matrix) new SparseMatrix(numberOfRows, numberOfColumns)
- : new DiagonalMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
#region Elementary operations
///
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs
index a6b45d25..a717f56a 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterativeSolver.cs
@@ -64,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.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
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.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
@@ -82,7 +82,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.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
@@ -91,6 +91,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.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/Double/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
index c7fccaee..b5d29fd8 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/IIterator.cs
@@ -80,7 +80,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs
index e40ec1ce..3332750e 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs
@@ -204,7 +204,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , x.
- public Vector Solve(Matrix matrix, Vector vector)
+ public Vector Solve(Matrix matrix, Vector vector)
{
if (vector == null)
{
@@ -223,7 +223,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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
@@ -278,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);
+ var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, result, input);
// Choose r~ (for example, r~ = r_0)
@@ -287,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);
+ var vecP = new DenseVector(residuals.Count);
+ var vecPdash = new DenseVector(residuals.Count);
+ var nu = new DenseVector(residuals.Count);
+ var vecS = new DenseVector(residuals.Count);
+ var vecSdash = new DenseVector(residuals.Count);
+ var temp = new DenseVector(residuals.Count);
+ var temp2 = new DenseVector(residuals.Count);
// create some temporary double variables that are needed
// to hold values in between iterations
@@ -431,7 +431,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -451,7 +451,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// 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,7 +475,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X.
- public Matrix Solve(Matrix matrix, Matrix input)
+ public Matrix Solve(Matrix matrix, Matrix input)
{
if (matrix == null)
{
@@ -487,7 +487,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -499,7 +499,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X
- public void Solve(Matrix matrix, Matrix input, Matrix result)
+ public void Solve(Matrix matrix, Matrix input, Matrix result)
{
if (matrix == null)
{
@@ -523,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
index 2345cc9f..60e27db0 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs
@@ -410,14 +410,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -429,7 +429,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
@@ -479,8 +479,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 = (Vector)input.Clone();
- var internalResult = (Vector)result.Clone();
+ var internalInput = input.Clone();
+ var internalResult = result.Clone();
foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped))
{
@@ -571,7 +571,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)
{
@@ -583,7 +583,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -595,7 +595,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)
{
@@ -619,7 +619,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs
index 04b75688..6ade9c87 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs
@@ -259,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -278,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
@@ -332,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);
+ var 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);
+ var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars
@@ -344,26 +344,26 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// Define the temporary vectors
// rDash_0 = r_0
- Vector rdash = DenseVector.OfVector(residuals);
+ var rdash = DenseVector.OfVector(residuals);
// t_-1 = 0
- Vector t = new DenseVector(residuals.Count);
- Vector t0 = new DenseVector(residuals.Count);
+ var t = new DenseVector(residuals.Count);
+ var t0 = new DenseVector(residuals.Count);
// w_-1 = 0
- Vector w = new DenseVector(residuals.Count);
+ var 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);
+ var c = new DenseVector(residuals.Count);
+ var p = new DenseVector(residuals.Count);
+ var s = new DenseVector(residuals.Count);
+ var u = new DenseVector(residuals.Count);
+ var y = new DenseVector(residuals.Count);
+ var z = new DenseVector(residuals.Count);
- Vector temp = new DenseVector(residuals.Count);
- Vector temp2 = new DenseVector(residuals.Count);
- Vector temp3 = new DenseVector(residuals.Count);
+ var temp = new DenseVector(residuals.Count);
+ var temp2 = new DenseVector(residuals.Count);
+ var temp3 = new DenseVector(residuals.Count);
// for (k = 0, 1, .... )
var iterationNumber = 0;
@@ -527,7 +527,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -545,7 +545,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// 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)
{
@@ -586,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)
{
@@ -598,7 +598,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -610,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)
{
@@ -634,7 +634,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs
index 9546f0f4..bd7ec696 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs
@@ -89,7 +89,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
///
/// 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
@@ -227,7 +227,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
@@ -279,14 +279,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -298,7 +298,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
@@ -642,7 +642,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
@@ -653,7 +653,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// mean = 0 and sd = 1
var distribution = new Normal();
- Matrix matrix = new DenseMatrix(numberOfVariables, count);
+ var matrix = new DenseMatrix(numberOfVariables, count);
for (var i = 0; i < matrix.ColumnCount; i++)
{
var samples = distribution.Samples().Take(matrix.RowCount).ToArray();
@@ -667,10 +667,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((Vector)orthogonalMatrix.Column(i));
+ result.Add(orthogonalMatrix.Column(i));
// Normalize the result vector
result[i].Multiply(1 / result[i].L2Norm(), result[i]);
@@ -685,9 +685,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,7 +703,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// Residual data.
/// x data.
/// b data.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -721,7 +721,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// 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)
{
@@ -745,7 +745,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)
{
@@ -757,7 +757,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -769,7 +769,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs
index 8de943c7..77e1a85f 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs
@@ -192,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -211,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
@@ -427,7 +427,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -445,7 +445,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
/// 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)
{
@@ -479,7 +479,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)
{
@@ -491,7 +491,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -503,7 +503,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)
{
@@ -527,7 +527,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
index 5467ab30..f3e7f3af 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterator.cs
@@ -212,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs
index 9dccb70a..e0b84658 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs
@@ -66,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// 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)
{
@@ -90,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)
{
@@ -107,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -117,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
index e6534041..993e16ea 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IPreConditioner.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IPreConditioner.cs
@@ -54,20 +54,20 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// 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/Double/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs
index 9be4b79a..16c8336c 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs
@@ -255,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 (Matrix)_upper.Clone();
+ return _upper.Clone();
}
///
@@ -267,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 (Matrix)_lower.Clone();
+ return _lower.Clone();
}
///
@@ -301,7 +301,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)
{
@@ -373,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);
+ var workVector = new DenseVector(sparseMatrix.RowCount);
+ var rowVector = new DenseVector(sparseMatrix.ColumnCount);
var indexSorting = new int[sparseMatrix.RowCount];
// spaceLeft = lfilNnz * nnz(A)
@@ -530,7 +530,7 @@ 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)
+ private void PivotRow(Vector row)
{
var knownPivots = new Dictionary();
@@ -582,7 +582,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// 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++)
{
@@ -599,7 +599,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// Sort till upper bound
/// Array with sorted vector indicies
/// Source
- private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
+ 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++)
@@ -624,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)
{
@@ -641,7 +641,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -651,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)
{
@@ -676,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);
+ var rowValues = new DenseVector(_lower.RowCount);
for (var i = 0; i < _lower.RowCount; i++)
{
_lower.Row(i, rowValues);
@@ -706,7 +706,7 @@ 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 = (Vector)lhs.Clone();
+ var temp = lhs.Clone();
Pivot(temp, lhs);
}
@@ -716,7 +716,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
///
/// Source .
/// Result after pivoting.
- private void Pivot(Vector vector, Vector result)
+ 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 3b5db00a..1cd744c1 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs
@@ -47,7 +47,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// 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)
+ 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.
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// 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)
+ 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,7 +95,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// Length of
/// Indicies of
/// Target
- private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
+ private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
{
while (start >= 0)
{
@@ -111,7 +111,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
/// Target
/// Root position
/// Length of
- private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
+ private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
{
var root = begin;
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs
index 3b97f71c..8767f10f 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs
@@ -54,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++)
@@ -72,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++)
@@ -99,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)
{
@@ -161,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)
{
@@ -178,7 +178,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -188,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)
{
@@ -218,7 +218,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
// z_i = l_ii^-1 * (y_i - SUM_(j
/// If is .
/// If is not a square matrix.
- public void Initialize(Matrix matrix)
+ public void Initialize(Matrix matrix)
{
if (matrix == null)
{
@@ -87,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)
{
@@ -116,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)
{
@@ -128,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
- Vector result = new DenseVector(rhs.Count);
+ var 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 bfaab1d6..9cc562c2 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -217,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
index 91197f1b..d4353a75 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -75,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
index 3f5fe6bc..23f87ece 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -47,7 +47,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
index a78dd9d2..dfee9ebb 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -130,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
index 578812e7..17ea01e9 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -222,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)
{
diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
index 56ca254a..736a9cb5 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
@@ -321,33 +321,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage.OfDiagonalInit(rows, columns, init));
}
- ///
- /// Creates a SparseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A SparseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new SparseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
///
/// Returns a new matrix containing the lower triangle of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
index 0435aad2..b287b7a6 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
@@ -128,39 +128,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseVector(SparseVectorStorage.OfInit(length, init));
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new SparseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new SparseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// Warning, the new 'sparse vector' with a non-zero scalar added to it will be a 100% filled
diff --git a/src/Numerics/LinearAlgebra/IBuilder.cs b/src/Numerics/LinearAlgebra/IBuilder.cs
new file mode 100644
index 00000000..349fcc9d
--- /dev/null
+++ b/src/Numerics/LinearAlgebra/IBuilder.cs
@@ -0,0 +1,64 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
+// http://mathnetnumerics.codeplex.com
+//
+// Copyright (c) 2009-2013 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace MathNet.Numerics.LinearAlgebra
+{
+ public interface IBuilder where T : struct, IEquatable, IFormattable
+ {
+ ///
+ /// Creates a Matrix for the given number of rows and columns.
+ ///
+ /// The number of rows.
+ /// The number of columns.
+ /// True if all fields must be mutable (e.g. not a diagonal matrix).
+ ///
+ /// A Matrix with the given dimensions.
+ ///
+ ///
+ /// Creates a matrix of the same matrix type as the current matrix.
+ ///
+ Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false);
+
+ ///
+ /// Creates a Vector with a the given dimension.
+ ///
+ /// The size of the vector.
+ /// True if all fields must be mutable.
+ ///
+ /// A Vector with the given dimension.
+ ///
+ ///
+ /// Creates a vector of the same type as the current matrix.
+ ///
+ Vector CreateVector(int size, bool fullyMutable = false);
+ }
+}
diff --git a/src/Numerics/LinearAlgebra/Matrix.cs b/src/Numerics/LinearAlgebra/Matrix.cs
index 3e8b2abf..bdfcf69b 100644
--- a/src/Numerics/LinearAlgebra/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Matrix.cs
@@ -59,6 +59,8 @@ namespace MathNet.Numerics.LinearAlgebra
ColumnCount = storage.ColumnCount;
}
+ static readonly IGenericBuilder Builder = Builder.Instance;
+
///
/// Gets the raw matrix data storage.
///
@@ -235,31 +237,29 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// Creates a Matrix for the given number of rows and columns.
+ /// Create a matrix of the same kind for the given number of rows and columns.
///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A Matrix with the given dimensions.
- ///
- ///
- /// Creates a matrix of the same matrix type as the current matrix.
- ///
- public abstract Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false);
+ /// The number of rows.
+ /// The number of columns.
+ /// Creates a matrix of the same matrix type as the current matrix.
+ public Matrix CreateMatrix(int rows, int columns)
+ {
+ return Storage.IsDense
+ ? Builder.DenseMatrix(rows, columns)
+ : Builder.SparseMatrix(rows, columns);
+ }
///
- /// Creates a Vector with a the given dimension.
+ /// Create a vector of the same kind with the given size.
///
/// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A Vector with the given dimension.
- ///
- ///
- /// Creates a vector of the same type as the current matrix.
- ///
- public abstract Vector CreateVector(int size, bool fullyMutable = false);
+ /// Creates a vector of the same type as the current matrix.
+ public Vector CreateVector(int size)
+ {
+ return Storage.IsDense
+ ? Builder.DenseVector(size)
+ : Builder.SparseVector(size);
+ }
///
/// Copies a row into an Vector.
@@ -1060,7 +1060,7 @@ namespace MathNet.Numerics.LinearAlgebra
throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension);
}
- var result = CreateMatrix(RowCount, ColumnCount + right.ColumnCount, fullyMutable: true);
+ var result = CreateMatrix(RowCount, ColumnCount + right.ColumnCount);
Storage.CopySubMatrixToUnchecked(result.Storage, 0, 0, RowCount, 0, 0, ColumnCount, skipClearing: true);
right.Storage.CopySubMatrixToUnchecked(result.Storage, 0, 0, right.RowCount, 0, ColumnCount, right.ColumnCount, skipClearing: true);
return result;
@@ -1116,7 +1116,7 @@ namespace MathNet.Numerics.LinearAlgebra
throw new ArgumentException(Resources.ArgumentMatrixSameColumnDimension, "lower");
}
- var result = CreateMatrix(RowCount + lower.RowCount, ColumnCount, fullyMutable: true);
+ var result = CreateMatrix(RowCount + lower.RowCount, ColumnCount);
Storage.CopySubMatrixToUnchecked(result.Storage, 0, 0, RowCount, 0, 0, ColumnCount, skipClearing: true);
lower.Storage.CopySubMatrixToUnchecked(result.Storage, 0, RowCount, lower.RowCount, 0, 0, lower.ColumnCount, skipClearing: true);
return result;
@@ -1170,7 +1170,7 @@ namespace MathNet.Numerics.LinearAlgebra
throw new ArgumentNullException("lower");
}
- var result = CreateMatrix(RowCount + lower.RowCount, ColumnCount + lower.ColumnCount, fullyMutable: true);
+ var result = CreateMatrix(RowCount + lower.RowCount, ColumnCount + lower.ColumnCount);
Storage.CopySubMatrixToUnchecked(result.Storage, 0, 0, RowCount, 0, 0, ColumnCount);
lower.Storage.CopySubMatrixToUnchecked(result.Storage, 0, RowCount, lower.RowCount, 0, ColumnCount, lower.ColumnCount);
return result;
diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
index 091dce4b..e2a8b8ff 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
@@ -349,33 +349,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
get { return _values; }
}
- ///
- /// Creates a DenseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DenseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new DenseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new DenseVector(size);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
index a665dc1b..a74868fb 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
@@ -191,39 +191,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseVector(array);
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new DenseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new DenseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
///
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index 30e30f97..3b84e6d7 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -180,35 +180,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
i => (float) distribution.Sample()));
}
- ///
- /// Creates a DiagonalMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A DiagonalMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return fullyMutable
- ? (Matrix) new SparseMatrix(numberOfRows, numberOfColumns)
- : new DiagonalMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
#region Elementary operations
///
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs
index ce385e16..d77e1a8a 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterativeSolver.cs
@@ -64,7 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.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
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.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
@@ -82,7 +82,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.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
@@ -91,6 +91,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single.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/Single/Solvers/IIterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
index c802bb8d..dad55a83 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/IIterator.cs
@@ -80,7 +80,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs
index 0acef0a0..73626e54 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs
@@ -204,14 +204,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -223,7 +223,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// The coefficient , A.
/// The solution , b.
/// The result , 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
@@ -278,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);
+ var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, result, input);
// Choose r~ (for example, r~ = r_0)
@@ -287,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);
+ var vecP = new DenseVector(residuals.Count);
+ var vecPdash = new DenseVector(residuals.Count);
+ var nu = new DenseVector(residuals.Count);
+ var vecS = new DenseVector(residuals.Count);
+ var vecSdash = new DenseVector(residuals.Count);
+ var temp = new DenseVector(residuals.Count);
+ var temp2 = new DenseVector(residuals.Count);
// create some temporary float variables that are needed
// to hold values in between iterations
@@ -431,7 +431,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -451,7 +451,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// 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,7 +475,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X.
- public Matrix Solve(Matrix matrix, Matrix input)
+ public Matrix Solve(Matrix matrix, Matrix input)
{
if (matrix == null)
{
@@ -487,7 +487,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -499,7 +499,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// The coefficient , A.
/// The solution , B.
/// The result , X
- public void Solve(Matrix matrix, Matrix input, Matrix result)
+ public void Solve(Matrix matrix, Matrix input, Matrix result)
{
if (matrix == null)
{
@@ -523,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
index 016a80b8..642b7559 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs
@@ -413,14 +413,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -432,7 +432,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
@@ -482,8 +482,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 = (Vector)input.Clone();
- var internalResult = (Vector)result.Clone();
+ var internalInput = input.Clone();
+ var internalResult = result.Clone();
foreach (var solver in _solvers.TakeWhile(solver => !_hasBeenStopped))
{
@@ -574,7 +574,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)
{
@@ -586,7 +586,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -598,7 +598,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)
{
@@ -622,7 +622,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs
index 6bbbd0ea..9000861d 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs
@@ -253,14 +253,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -272,7 +272,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
@@ -521,7 +521,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -539,7 +539,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -580,7 +580,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)
{
@@ -592,7 +592,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -604,7 +604,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs
index 251b265b..ae9d99a3 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs
@@ -88,7 +88,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
///
/// 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
@@ -226,7 +226,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
@@ -278,14 +278,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -297,7 +297,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
@@ -641,7 +641,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
@@ -652,7 +652,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// mean = 0 and sd = 1
var distribution = new Normal();
- Matrix matrix = new DenseMatrix(numberOfVariables, count);
+ var matrix = new DenseMatrix(numberOfVariables, count);
for (var i = 0; i < matrix.ColumnCount; i++)
{
var samples = new float[matrix.RowCount];
@@ -670,10 +670,10 @@ 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((Vector)orthogonalMatrix.Column(i));
+ result.Add(orthogonalMatrix.Column(i));
// Normalize the result vector
result[i].Multiply(1 / result[i].L2Norm(), result[i]);
@@ -688,9 +688,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single.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);
@@ -706,7 +706,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Residual data.
/// x data.
/// b data.
- private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ private static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -724,7 +724,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// 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)
{
@@ -748,7 +748,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)
{
@@ -760,7 +760,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix)matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -772,7 +772,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)
{
@@ -796,7 +796,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector)input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs
index 8ac4116f..0ffe4c0a 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs
@@ -192,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);
+ var result = new DenseVector(matrix.RowCount);
Solve(matrix, vector, result);
return result;
}
@@ -211,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
@@ -427,7 +427,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Residual values in .
/// Instance of the x.
/// Instance of the b.
- static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
+ static void CalculateTrueResidual(Matrix matrix, Vector residual, Vector x, Vector b)
{
// -Ax = residual
matrix.Multiply(x, residual);
@@ -445,7 +445,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
/// Source .
/// Residual .
/// true if continue, otherwise false
- bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
+ bool ShouldContinue(int iterationNumber, Vector result, Vector source, Vector residuals)
{
if (_hasBeenStopped)
{
@@ -479,7 +479,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)
{
@@ -491,7 +491,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
throw new ArgumentNullException("input");
}
- var result = (Matrix) matrix.CreateMatrix(input.RowCount, input.ColumnCount);
+ var result = matrix.CreateMatrix(input.RowCount, input.ColumnCount);
Solve(matrix, input, result);
return result;
}
@@ -503,7 +503,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)
{
@@ -527,7 +527,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++)
{
- var solution = Solve(matrix, (Vector) input.Column(column));
+ var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed())
{
result.At(element.Item1, column, element.Item2);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
index a04f890c..81918ba5 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterator.cs
@@ -212,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs
index f9006655..1c6441c8 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs
@@ -66,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// 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)
{
@@ -90,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)
{
@@ -107,7 +107,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -117,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
index 1680f989..090316ad 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IPreConditioner.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IPreConditioner.cs
@@ -54,20 +54,20 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// 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/Single/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs
index 040ebe67..42551083 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs
@@ -255,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 (Matrix)_upper.Clone();
+ return _upper.Clone();
}
///
@@ -267,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 (Matrix)_lower.Clone();
+ return _lower.Clone();
}
///
@@ -301,7 +301,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)
{
@@ -373,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);
+ var workVector = new DenseVector(sparseMatrix.RowCount);
+ var rowVector = new DenseVector(sparseMatrix.ColumnCount);
var indexSorting = new int[sparseMatrix.RowCount];
// spaceLeft = lfilNnz * nnz(A)
@@ -530,7 +530,7 @@ 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)
+ private void PivotRow(Vector row)
{
var knownPivots = new Dictionary();
@@ -582,7 +582,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// 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++)
{
@@ -599,7 +599,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// Sort till upper bound
/// Array with sorted vector indicies
/// Source
- private static void FindLargestItems(int lowerBound, int upperBound, int[] sortedIndices, Vector values)
+ 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++)
@@ -624,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)
{
@@ -641,7 +641,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -651,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)
{
@@ -676,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);
+ var rowValues = new DenseVector(_lower.RowCount);
for (var i = 0; i < _lower.RowCount; i++)
{
_lower.Row(i, rowValues);
@@ -706,7 +706,7 @@ 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 = (Vector)lhs.Clone();
+ var temp = lhs.Clone();
Pivot(temp, lhs);
}
@@ -716,7 +716,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
///
/// Source .
/// Result after pivoting.
- private void Pivot(Vector vector, Vector result)
+ 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 e9b5e846..88257716 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs
@@ -47,7 +47,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// 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)
+ 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.
@@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// 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)
+ 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,7 +95,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// Length of
/// Indicies of
/// Target
- private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
+ private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values)
{
while (start >= 0)
{
@@ -111,7 +111,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
/// Target
/// Root position
/// Length of
- private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
+ private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count)
{
var root = begin;
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs
index 8c720692..2d806b38 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs
@@ -54,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++)
@@ -72,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++)
@@ -99,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)
{
@@ -161,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)
{
@@ -178,7 +178,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
}
- Vector result = new DenseVector(rhs.Count);
+ var result = new DenseVector(rhs.Count);
Approximate(rhs, result);
return result;
}
@@ -188,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)
{
@@ -218,7 +218,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
// z_i = l_ii^-1 * (y_i - SUM_(j
/// If is .
/// If is not a square matrix.
- public void Initialize(Matrix matrix)
+ public void Initialize(Matrix matrix)
{
if (matrix == null)
{
@@ -87,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)
{
@@ -116,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)
{
@@ -128,7 +128,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
- Vector result = new DenseVector(rhs.Count);
+ var 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 bf5e7fc3..9ac0be1f 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/DivergenceStopCriterium.cs
@@ -217,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
index 8e339b8d..41ec51ca 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/FailureStopCriterium.cs
@@ -75,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
index 94286cb5..5e0b32ea 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IIterationStopCriterium.cs
@@ -47,7 +47,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.
///
- 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.
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
index da7e7b84..c83805c2 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/IterationCountStopCriterium.cs
@@ -130,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
index 49d0a2cc..1d2fa386 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/StopCriterium/ResidualStopCriterium.cs
@@ -222,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)
{
diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
index 30602258..595b8b09 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
@@ -321,33 +321,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage.OfDiagonalInit(rows, columns, init));
}
- ///
- /// Creates a SparseMatrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// True if all fields must be mutable (e.g. not a diagonal matrix).
- ///
- /// A SparseMatrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new SparseMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a with a the given dimension.
- ///
- /// The size of the vector.
- /// True if all fields must be mutable.
- ///
- /// A with the given dimension.
- ///
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new SparseVector(size);
- }
-
///
/// Returns a new matrix containing the lower triangle of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
index 0c6416db..8701efbd 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
@@ -128,39 +128,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseVector(SparseVectorStorage.OfInit(length, init));
}
- ///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
- ///
- ///
- /// The number of rows.
- ///
- ///
- /// The number of columns.
- ///
- ///
- /// A matrix with the given dimensions.
- ///
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new SparseMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
- ///
- ///
- /// The size of the Vector to create.
- ///
- ///
- /// The new Vector.
- ///
- public override Vector CreateVector(int size)
- {
- return new SparseVector(size);
- }
-
///
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// Warning, the new 'sparse vector' with a non-zero scalar added to it will be a 100% filled
diff --git a/src/Numerics/LinearAlgebra/Vector.cs b/src/Numerics/LinearAlgebra/Vector.cs
index 50f0662a..ab0c69b2 100644
--- a/src/Numerics/LinearAlgebra/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Vector.cs
@@ -58,6 +58,8 @@ namespace MathNet.Numerics.LinearAlgebra
Count = storage.Length;
}
+ static readonly IGenericBuilder Builder = Builder.Instance;
+
///
/// Gets the raw vector data storage.
///
@@ -131,21 +133,29 @@ namespace MathNet.Numerics.LinearAlgebra
}
///
- /// Creates a matrix with the given dimensions using the same storage type
- /// as this vector.
+ /// Create a matrix of the same kind with the provided number of rows and columns.
///
/// The number of rows.
/// The number of columns.
- /// A matrix with the given dimensions.
- public abstract Matrix CreateMatrix(int rows, int columns);
+ /// Creates a matrix of the same matrix type as the current matrix.
+ public Matrix CreateMatrix(int rows, int columns)
+ {
+ return Storage.IsDense
+ ? Builder.DenseMatrix(rows, columns)
+ : Builder.SparseMatrix(rows, columns);
+ }
///
- /// Creates a Vector of the given size using the same storage type
- /// as this vector.
+ /// Create a vector of the same kind with the provided dimension.
///
- /// The size of the Vector to create.
- /// The new Vector.
- public abstract Vector CreateVector(int size);
+ /// The size of the vector.
+ /// Creates a vector of the same type as the current matrix.
+ public Vector CreateVector(int size)
+ {
+ return Storage.IsDense
+ ? Builder.DenseVector(size)
+ : Builder.SparseVector(size);
+ }
///
/// Returns a deep-copy clone of the vector.
diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj
index 8d56ad46..19dbcccd 100644
--- a/src/Numerics/Numerics.csproj
+++ b/src/Numerics/Numerics.csproj
@@ -121,6 +121,7 @@
+
diff --git a/src/Numerics/Precision.cs b/src/Numerics/Precision.cs
index 52f894e2..9a26bc54 100644
--- a/src/Numerics/Precision.cs
+++ b/src/Numerics/Precision.cs
@@ -1308,7 +1308,7 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- private static bool AlmostEqualWithRelativeDecimalPlaces(this double a, double b, int decimalPlaces)
+ public static bool AlmostEqualWithRelativeDecimalPlaces(this double a, double b, int decimalPlaces)
{
// If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal
int magnitudeOfFirst = Magnitude(a);
@@ -1346,7 +1346,7 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// if both floats are equal to each other within the specified number of decimal places; otherwise .
- private static bool AlmostEqualWithRelativeDecimalPlaces(this float a, float b, int decimalPlaces)
+ public static bool AlmostEqualWithRelativeDecimalPlaces(this float a, float b, int decimalPlaces)
{
// If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal
int magnitudeOfFirst = Magnitude(a);
@@ -1385,7 +1385,7 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- private static bool AlmostEqualWithAbsoluteDecimalPlaces(this double a, double b, int decimalPlaces)
+ public static bool AlmostEqualWithAbsoluteDecimalPlaces(this double a, double b, int decimalPlaces)
{
double decimalPlaceMagnitude = Math.Pow(10, -(decimalPlaces - 1));
@@ -1411,7 +1411,7 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// if both floats are equal to each other within the specified number of decimal places; otherwise .
- private static bool AlmostEqualWithAbsoluteDecimalPlaces(this float a, float b, int decimalPlaces)
+ public static bool AlmostEqualWithAbsoluteDecimalPlaces(this float a, float b, int decimalPlaces)
{
var decimalPlaceMagnitude = (float)Math.Pow(10, -(decimalPlaces - 1));
diff --git a/src/UnitTests/AssertHelpers.cs b/src/UnitTests/AssertHelpers.cs
index 55915b79..cfe88ce7 100644
--- a/src/UnitTests/AssertHelpers.cs
+++ b/src/UnitTests/AssertHelpers.cs
@@ -38,28 +38,19 @@ namespace MathNet.Numerics.UnitTests
///
/// Asserts that the expected value and the actual value are equal.
///
- /// The expected value.
- /// The actual value.
public static void AreEqual(Complex expected, Complex actual)
{
- if (expected.IsNaN() && actual.IsNaN())
- {
- return;
- }
-
- if (expected.IsInfinity() && expected.IsInfinity())
+ if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity())
{
return;
}
- var pass = expected.Real.AlmostEqual(actual.Real);
- if (!pass)
+ if (!expected.Real.AlmostEqual(actual.Real))
{
Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real);
}
- pass = expected.Imaginary.AlmostEqual(actual.Imaginary);
- if (!pass)
+ if (!expected.Imaginary.AlmostEqual(actual.Imaginary))
{
Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary);
}
@@ -68,28 +59,19 @@ namespace MathNet.Numerics.UnitTests
///
/// Asserts that the expected value and the actual value are equal.
///
- /// The expected value.
- /// The actual value.
public static void AreEqual(Complex32 expected, Complex32 actual)
{
- if (expected.IsNaN() && actual.IsNaN())
- {
- return;
- }
-
- if (expected.IsInfinity() && expected.IsInfinity())
+ if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity())
{
return;
}
- var pass = expected.Real.AlmostEqual(actual.Real);
- if (!pass)
+ if (!expected.Real.AlmostEqual(actual.Real))
{
Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real);
}
- pass = expected.Imaginary.AlmostEqual(actual.Imaginary);
- if (!pass)
+ if (!expected.Imaginary.AlmostEqual(actual.Imaginary))
{
Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary);
}
@@ -99,9 +81,6 @@ namespace MathNet.Numerics.UnitTests
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
/// and are NaN then no assert is thrown.
///
- /// The expected value.
- /// The actual value.
- /// The number of decimal places to agree on.
public static void AlmostEqual(double expected, double actual, int decimalPlaces)
{
if (double.IsNaN(expected) && double.IsNaN(actual))
@@ -109,10 +88,8 @@ namespace MathNet.Numerics.UnitTests
return;
}
- var pass = expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces);
- if (!pass)
+ if (!expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces))
{
- // signals Gallio that the test failed.
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
@@ -121,9 +98,6 @@ namespace MathNet.Numerics.UnitTests
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
/// and are NaN then no assert is thrown.
///
- /// The expected value.
- /// The actual value.
- /// The number of decimal places to agree on.
public static void AlmostEqual(float expected, float actual, int decimalPlaces)
{
if (float.IsNaN(expected) && float.IsNaN(actual))
@@ -131,10 +105,8 @@ namespace MathNet.Numerics.UnitTests
return;
}
- var pass = expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces);
- if (!pass)
+ if (!expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces))
{
- // signals Gallio that the test failed.
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
@@ -142,19 +114,14 @@ namespace MathNet.Numerics.UnitTests
///
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
///
- /// The expected value.
- /// The actual value.
- /// The number of decimal places to agree on.
public static void AlmostEqual(Complex expected, Complex actual, int decimalPlaces)
{
- var pass = expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces);
- if (!pass)
+ if (!expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- pass = expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces);
- if (!pass)
+ if (!expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
@@ -163,19 +130,80 @@ namespace MathNet.Numerics.UnitTests
///
/// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
///
- /// The expected value.
- /// The actual value.
- /// The number of decimal places to agree on.
public static void AlmostEqual(Complex32 expected, Complex32 actual, int decimalPlaces)
{
- var pass = expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces);
- if (!pass)
+ if (!expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces))
+ {
+ Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
+ }
+
+ if (!expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces))
+ {
+ Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
+ }
+ }
+
+ ///
+ /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
+ /// and are NaN then no assert is thrown.
+ ///
+ public static void AlmostEqualAbsolute(double expected, double actual, int decimalPlaces)
+ {
+ if (double.IsNaN(expected) && double.IsNaN(actual))
+ {
+ return;
+ }
+
+ if (!expected.AlmostEqualWithAbsoluteDecimalPlaces(actual, decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
+ }
+ }
+
+ ///
+ /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
+ /// and are NaN then no assert is thrown.
+ ///
+ public static void AlmostEqualAbsolute(float expected, float actual, int decimalPlaces)
+ {
+ if (float.IsNaN(expected) && float.IsNaN(actual))
+ {
+ return;
+ }
+
+ if (!expected.AlmostEqualWithAbsoluteDecimalPlaces(actual, decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
+ }
+ }
+
+ ///
+ /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
+ ///
+ public static void AlmostEqualAbsolute(Complex expected, Complex actual, int decimalPlaces)
+ {
+ if (!expected.Real.AlmostEqualWithAbsoluteDecimalPlaces(actual.Real, decimalPlaces))
+ {
+ Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
+ }
+
+ if (!expected.Imaginary.AlmostEqualWithAbsoluteDecimalPlaces(actual.Imaginary, decimalPlaces))
+ {
+ Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
+ }
+ }
+
+ ///
+ /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
+ ///
+ public static void AlmostEqualAbsolute(Complex32 expected, Complex32 actual, int decimalPlaces)
+ {
+ if (!expected.Real.AlmostEqualWithAbsoluteDecimalPlaces(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- pass = expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces);
- if (!pass)
+ if (!expected.Imaginary.AlmostEqualWithAbsoluteDecimalPlaces(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
@@ -203,9 +231,6 @@ namespace MathNet.Numerics.UnitTests
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
///
- /// The expected value list.
- /// The actual value list.
- /// The accuracy required for being almost equal.
public static void AlmostEqualList(IList expected, IList actual, double maximumError)
{
for (var i = 0; i < expected.Count; i++)
@@ -221,9 +246,6 @@ namespace MathNet.Numerics.UnitTests
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
///
- /// The expected value list.
- /// The actual value list.
- /// The accuracy required for being almost equal.
public static void AlmostEqualList(IList expected, IList actual, double maximumError)
{
for (var i = 0; i < expected.Count; i++)
@@ -241,9 +263,6 @@ namespace MathNet.Numerics.UnitTests
///
/// The type of the structures. Must implement
/// .
- /// The expected value list.
- /// The actual value list.
- /// The accuracy required for being almost equal.
public static void AlmostEqualList(IList expected, IList actual, double maximumError)
where T : IPrecisionSupport
{
@@ -260,9 +279,6 @@ namespace MathNet.Numerics.UnitTests
/// Asserts that the expected value and the actual value are equal up to a certain
/// maximum error.
///
- /// The expected value list.
- /// The actual value list.
- /// The accuracy required for being almost equal.
public static void AlmostEqualList(IList expected, IList actual, double maximumError)
{
for (var i = 0; i < expected.Count; i++)
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs
index 42cee967..72fe982e 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs
@@ -398,7 +398,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 12);
}
}
@@ -432,7 +432,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
for (var i = 0; i < vectorX.Count; i++)
{
- AssertHelpers.AlmostEqual(test[i], vectorX[i], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 12);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs
index 9caabb72..390fe5fd 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs
@@ -676,7 +676,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 12);
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs
index df319b06..324a3620 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs
@@ -108,129 +108,35 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
}
}
- ///
- /// Creates a DenseMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A DenseMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
- }
- }
-
- return matrixA;
+ return DenseMatrix.CreateRandom(row, col, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a positive definite DenseMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite DenseMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
- }
- }
-
- // Generate a Hermitian matrix which is positive definite.
- return matrixA.ConjugateTranspose()*matrixA;
+ var a = DenseMatrix.CreateRandom(order, order, new Normal(new MersenneTwister(1)));
+ return a.ConjugateTranspose()*a;
}
- ///
- /// Creates a DenseVector with random values.
- ///
- /// The size of the vector.
- /// A DenseVector with the given dimension and random values.
- public static Vector GenerateRandomDenseVector(int order)
+ public static Vector GenerateRandomDenseVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new DenseVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = new Complex(normal.Sample(), normal.Sample());
- }
-
- return v;
+ return DenseVector.CreateRandom(order, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a UserDefinedMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A UserDefinedMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
- }
- }
-
- return matrixA;
+ return new UserDefinedMatrix(GenerateRandomDenseMatrix(row, col).ToArray());
}
- ///
- /// Creates a positive definite UserDefinedMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite UserDefinedMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
- }
- }
-
- // Generate a Hermitian matrix which is positive definite.
- return matrixA.ConjugateTranspose()*matrixA;
+ return new UserDefinedMatrix(GenerateRandomPositiveDefiniteHermitianDenseMatrix(order).ToArray());
}
- ///
- /// Creates a UserDefinedVector with random values.
- ///
- /// The size of the vector.
- /// A UserDefinedVector with the given dimension and random values.
- public static Vector GenerateRandomUserDefinedVector(int order)
+ public static Vector GenerateRandomUserDefinedVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new UserDefinedVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = new Complex(normal.Sample(), normal.Sample());
- }
-
- // Generate a matrix which is positive definite.
- return v;
+ return new UserDefinedVector(GenerateRandomDenseVector(order).ToArray());
}
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs
index 1d7d8a6f..878b67e7 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs
@@ -23,11 +23,20 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners
{
- using LinearAlgebra.Complex;
- using LinearAlgebra.Complex.Solvers.Preconditioners;
- using NUnit.Framework;
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
///
/// Diagonal preconditioner test.
@@ -51,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs
index 71b15204..604d86f5 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs
@@ -23,13 +23,22 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Complex;
- using LinearAlgebra.Complex.Solvers.Preconditioners;
- using NUnit.Framework;
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
///
/// Incomplete LU with tpPreconditioner test with drop tolerance and partial pivoting.
@@ -164,7 +173,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs
index d3546f14..9bfcbc84 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs
@@ -23,13 +23,22 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Complex;
- using LinearAlgebra.Complex.Solvers.Preconditioners;
- using NUnit.Framework;
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
///
/// Incomplete LU preconditioner test.
@@ -94,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs
index b0977140..7e059467 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs
@@ -23,12 +23,21 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners
{
- using System;
- using LinearAlgebra.Complex;
- using LinearAlgebra.Complex.Solvers.Preconditioners;
- using NUnit.Framework;
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
///
/// Abstract class for preconditioners tests.
@@ -85,7 +94,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// Source matrix.
/// Initial vector.
/// Result vector.
- protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
+ protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
///
/// Approximate with a unit matrix returning new vector.
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs
index 10799322..01d9c8cb 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/UnitPreconditionerTest.cs
@@ -23,11 +23,20 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Preconditioners
{
- using LinearAlgebra.Complex;
- using LinearAlgebra.Complex.Solvers.Preconditioners;
- using NUnit.Framework;
+
+#if NOSYSNUMERICS
+ using Complex = Numerics.Complex;
+#else
+ using Complex = System.Numerics.Complex;
+#endif
///
/// Unit precondition tests
@@ -51,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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/Complex/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
index 9343b103..674f0d5d 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrix.cs
@@ -107,27 +107,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
}
- ///
- /// Creates a matrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new UserDefinedMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a vector with a the given dimension.
- ///
- /// The size of the vector.
- /// A vector with the given dimension.
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new UserDefinedVector(size);
- }
-
///
/// Initializes a square matrix with all zero's except for ones on the diagonal.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedVector.cs b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedVector.cs
index 392b6cf9..6c24e9e6 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedVector.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/UserDefinedVector.cs
@@ -86,26 +86,5 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
: base(new UserDefinedVectorStorage(data.Length, (Complex[])data.Clone()))
{
}
-
- ///
- /// Creates a matrix with the given dimensions using the same storage type as this vector.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new UserDefinedMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type as this vector.
- ///
- /// The size of the Vector to create.
- /// The new Vector.
- public override Vector CreateVector(int size)
- {
- return new UserDefinedVector(size);
- }
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
index d115830c..89993f60 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
@@ -159,7 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
var expected = CreateVector(5);
var actual = expected.CreateVector(5);
- Assert.AreEqual(expected.GetType(), actual.GetType(), "vectors are same type.");
+ Assert.AreEqual(expected.Storage.IsDense, actual.Storage.IsDense, "vectors are same kind.");
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs
index 13686f65..fe5028cb 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/GramSchmidtTests.cs
@@ -405,7 +405,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 6);
}
}
@@ -439,7 +439,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization
for (var i = 0; i < vectorX.Count; i++)
{
- AssertHelpers.AlmostEqual(test[i], vectorX[i], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 6);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs
index 17646698..95c4ddd3 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Factorization/QRTests.cs
@@ -657,6 +657,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization
}
}
}
+
///
/// Can solve when using a tall matrix.
///
@@ -684,7 +685,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 6);
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs
index 075f617f..30751d6f 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs
@@ -108,129 +108,35 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
}
- ///
- /// Creates a DenseMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A DenseMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
- }
-
- return matrixA;
+ return DenseMatrix.CreateRandom(row, col, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a positive definite DenseMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite DenseMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
- }
-
- // Generate a Hermitian matrix which is positive definite.
- return matrixA.ConjugateTranspose()*matrixA;
+ var a = DenseMatrix.CreateRandom(order, order, new Normal(new MersenneTwister(1)));
+ return a.ConjugateTranspose()*a;
}
- ///
- /// Creates a DenseVector with random values.
- ///
- /// The size of the vector.
- /// A DenseVector with the given dimension and random values.
- public static Vector GenerateRandomDenseVector(int order)
+ public static Vector GenerateRandomDenseVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new DenseVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
-
- return v;
+ return DenseVector.CreateRandom(order, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a UserDefinedMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A UserDefinedMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
- }
-
- return matrixA;
+ return new UserDefinedMatrix(GenerateRandomDenseMatrix(row, col).ToArray());
}
- ///
- /// Creates a positive definite UserDefinedMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite UserDefinedMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
- }
-
- // Generate a Hermitian matrix which is positive definite.
- return matrixA.ConjugateTranspose()*matrixA;
+ return new UserDefinedMatrix(GenerateRandomPositiveDefiniteHermitianDenseMatrix(order).ToArray());
}
- ///
- /// Creates a UserDefinedVector with random values.
- ///
- /// The size of the vector.
- /// A UserDefinedVector with the given dimension and random values.
- public static Vector GenerateRandomUserDefinedVector(int order)
+ public static Vector GenerateRandomUserDefinedVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new UserDefinedVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = new Complex32((float) normal.Sample(), (float) normal.Sample());
- }
-
- // Generate a matrix which is positive definite.
- return v;
+ return new UserDefinedVector(GenerateRandomDenseVector(order).ToArray());
}
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs
index 8980a9d3..3bf6308b 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs
@@ -24,11 +24,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex32;
+using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners
{
- using LinearAlgebra.Complex32;
- using LinearAlgebra.Complex32.Solvers.Preconditioners;
- using NUnit.Framework;
+ using Numerics;
///
/// Diagonal preconditioner test.
@@ -52,7 +55,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs
index cd41396f..46a652a7 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs
@@ -24,13 +24,16 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex32;
+using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Complex32;
- using LinearAlgebra.Complex32.Solvers.Preconditioners;
- using NUnit.Framework;
+ using Numerics;
///
/// Incomplete LU with tpPreconditioner test with drop tolerance and partial pivoting.
@@ -165,7 +168,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs
index 39a283cd..0a1e04a1 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs
@@ -24,13 +24,16 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex32;
+using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Complex32;
- using LinearAlgebra.Complex32.Solvers.Preconditioners;
- using NUnit.Framework;
+ using Numerics;
///
/// Incomplete LU preconditioner test.
@@ -95,7 +98,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs
index eef97932..4bfbae20 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs
@@ -23,12 +23,16 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex32;
+using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners
{
- using System;
- using LinearAlgebra.Complex32;
- using LinearAlgebra.Complex32.Solvers.Preconditioners;
- using NUnit.Framework;
+ using Numerics;
///
/// Abstract class for preconditioners tests.
@@ -85,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// Source matrix.
/// Initial vector.
/// Result vector.
- protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
+ protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
///
/// Approximate with a unit matrix returning new vector.
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs
index cee941b9..d9faf512 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/UnitPreconditionerTest.cs
@@ -23,11 +23,15 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex32;
+using MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Preconditioners
{
- using LinearAlgebra.Complex32;
- using LinearAlgebra.Complex32.Solvers.Preconditioners;
- using NUnit.Framework;
+ using Numerics;
///
/// Unit precondition tests
@@ -51,7 +55,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
index 0810af7d..a017b24a 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrix.cs
@@ -107,27 +107,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
}
- ///
- /// Creates a matrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new UserDefinedMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a vector with a the given dimension.
- ///
- /// The size of the vector.
- /// A vector with the given dimension.
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new UserDefinedVector(size);
- }
-
///
/// Initializes a square matrix with all zero's except for ones on the diagonal.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedVector.cs b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedVector.cs
index 83cd5ebb..be3d1355 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedVector.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedVector.cs
@@ -86,26 +86,5 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
: base(new UserDefinedVectorStorage(data.Length, (Complex32[])data.Clone()))
{
}
-
- ///
- /// Creates a matrix with the given dimensions using the same storage type as this vector.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new UserDefinedMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type as this vector.
- ///
- /// The size of the Vector to create.
- /// The new Vector.
- public override Vector CreateVector(int size)
- {
- return new UserDefinedVector(size);
- }
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
index 622e835c..e40daf5d 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
@@ -159,7 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
var expected = CreateVector(5);
var actual = expected.CreateVector(5);
- Assert.AreEqual(expected.GetType(), actual.GetType(), "vectors are same type.");
+ Assert.AreEqual(expected.Storage.IsDense, actual.Storage.IsDense, "vectors are same kind.");
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs
index 7a19609b..881371fc 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/GramSchmidtTests.cs
@@ -379,7 +379,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 12);
}
}
@@ -413,7 +413,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization
for (var i = 0; i < vectorX.Count; i++)
{
- AssertHelpers.AlmostEqual(test[i], vectorX[i], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 12);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs
index 2a9c3523..c26a0cc6 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Factorization/QRTests.cs
@@ -670,7 +670,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 9);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 12);
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs
index 955d2af6..fbbdf3b4 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs
@@ -29,6 +29,7 @@
//
using System.Collections.Generic;
+using System.Runtime.Remoting.Messaging;
using MathNet.Numerics.Distributions;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
@@ -106,129 +107,35 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
}
- ///
- /// Creates a DenseMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A DenseMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = normal.Sample();
- }
- }
-
- return matrixA;
+ return DenseMatrix.CreateRandom(row, col, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a positive definite DenseMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite DenseMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteDenseMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = normal.Sample();
- }
- }
-
- // Generate a matrix which is positive definite.
- return matrixA.Transpose()*matrixA;
+ var a = DenseMatrix.CreateRandom(order, order, new Normal(new MersenneTwister(1)));
+ return a.TransposeThisAndMultiply(a);
}
- ///
- /// Creates a DenseVector with random values.
- ///
- /// The size of the vector.
- /// A DenseVector with the given dimension and random values.
- public static Vector GenerateRandomDenseVector(int order)
+ public static Vector GenerateRandomDenseVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new DenseVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = normal.Sample();
- }
-
- return v;
+ return DenseVector.CreateRandom(order, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a UserDefinedMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A UserDefinedMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = normal.Sample();
- }
- }
-
- return matrixA;
+ return new UserDefinedMatrix(GenerateRandomDenseMatrix(row, col).ToArray());
}
- ///
- /// Creates a positive definite UserDefinedMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite UserDefinedMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteUserDefinedMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = normal.Sample();
- }
- }
-
- // Generate a matrix which is positive definite.
- return matrixA.Transpose()*matrixA;
+ return new UserDefinedMatrix(GenerateRandomPositiveDefiniteDenseMatrix(order).ToArray());
}
- ///
- /// Creates a UserDefinedVector with random values.
- ///
- /// The size of the vector.
- /// A UserDefinedVector with the given dimension and random values.
- public static Vector GenerateRandomUserDefinedVector(int order)
+ public static Vector GenerateRandomUserDefinedVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new UserDefinedVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = normal.Sample();
- }
-
- // Generate a matrix which is positive definite.
- return v;
+ return new UserDefinedVector(GenerateRandomDenseVector(order).ToArray());
}
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs
index 8a64e01b..63b6bd3b 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs
@@ -24,12 +24,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Double;
+using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners
{
- using LinearAlgebra.Double;
- using LinearAlgebra.Double.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Diagonal preconditioner test.
///
@@ -52,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs
index 02ab3136..f7aa8209 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs
@@ -24,14 +24,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Double;
+using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Double;
- using LinearAlgebra.Double.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Incomplete LU with tpPreconditioner test with drop tolerance and partial pivoting.
///
@@ -165,7 +166,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs
index 9c063ffa..31b855fb 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs
@@ -24,14 +24,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Double;
+using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Double;
- using LinearAlgebra.Double.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Incomplete LU preconditioner test.
///
@@ -95,7 +96,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs
index 07ce76d9..149250f7 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs
@@ -24,13 +24,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Double;
+using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners
{
- using System;
- using LinearAlgebra.Double;
- using LinearAlgebra.Double.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Abstract class for preconditioners tests.
///
@@ -86,7 +87,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
+ protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
///
/// Approximate with a unit matrix returning new vector.
diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs
index 101485c6..f757dd59 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/UnitPreconditionerTest.cs
@@ -24,12 +24,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Double;
+using MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Preconditioners
{
- using LinearAlgebra.Double;
- using LinearAlgebra.Double.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Unit precondition tests
///
@@ -52,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
index 9d2b9c8b..b597c003 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrix.cs
@@ -105,27 +105,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
}
- ///
- /// Creates a matrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new UserDefinedMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a vector with a the given dimension.
- ///
- /// The size of the vector.
- /// A vector with the given dimension.
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new UserDefinedVector(size);
- }
-
///
/// Initializes a square matrix with all zero's except for ones on the diagonal.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVector.cs b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVector.cs
index 438af13c..85bd12a4 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVector.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVector.cs
@@ -84,26 +84,5 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
: base(new UserDefinedVectorStorage(data.Length, (double[])data.Clone()))
{
}
-
- ///
- /// Creates a matrix with the given dimensions using the same storage type as this vector.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new UserDefinedMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type as this vector.
- ///
- /// The size of the Vector to create.
- /// The new Vector.
- public override Vector CreateVector(int size)
- {
- return new UserDefinedVector(size);
- }
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
index d5e1a1a9..90b25062 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
@@ -156,7 +156,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{
var expected = CreateVector(5);
var actual = expected.CreateVector(5);
- Assert.AreEqual(expected.GetType(), actual.GetType(), "vectors are same type.");
+ Assert.AreEqual(expected.Storage.IsDense, actual.Storage.IsDense, "vectors are same kind.");
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
index 5592ef8d..604ebe7c 100644
--- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
+++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
@@ -216,11 +216,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
}
[Theory]
- public void CanCreateSameType(Matrix matrix)
+ public void CanCreateSameKind(Matrix matrix)
{
var empty = matrix.CreateMatrix(5, 6);
Assert.That(empty, Is.EqualTo(CreateDenseZero(5, 6)));
- Assert.That(empty.GetType(), Is.EqualTo(matrix.GetType()));
+ Assert.That(empty.Storage.IsDense, Is.EqualTo(matrix.Storage.IsDense));
Assert.That(() => matrix.CreateMatrix(0, 2), Throws.InstanceOf());
Assert.That(() => matrix.CreateMatrix(2, 0), Throws.InstanceOf());
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs
index dc1cb771..f987eaed 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/GramSchmidtTests.cs
@@ -379,7 +379,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 6);
}
}
@@ -413,7 +413,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
for (var i = 0; i < vectorX.Count; i++)
{
- AssertHelpers.AlmostEqual(test[i], vectorX[i], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 6);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs
index 4e359900..020b849a 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/QRTests.cs
@@ -671,7 +671,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
{
for (var j = 0; j < matrixX.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(test[i, j], matrixX[i, j], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i, j], matrixX[i, j], 6);
}
}
@@ -707,7 +707,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
for (var i = 0; i < vectorX.Count; i++)
{
- AssertHelpers.AlmostEqual(test[i], vectorX[i], 4);
+ AssertHelpers.AlmostEqualAbsolute(test[i], vectorX[i], 6);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserEvdTests.cs b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserEvdTests.cs
index 3be73123..38b4647f 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserEvdTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Factorization/UserEvdTests.cs
@@ -220,7 +220,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
- Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-3);
+ Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-2);
}
// Make sure A didn't change.
@@ -304,7 +304,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Factorization
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
- Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-3);
+ Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-2);
}
// Make sure A didn't change.
diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs
index 35f7e820..78c0e6d6 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs
@@ -106,129 +106,35 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
}
}
- ///
- /// Creates a DenseMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A DenseMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = (float) normal.Sample();
- }
- }
-
- return matrixA;
+ return DenseMatrix.CreateRandom(row, col, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a positive definite DenseMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite DenseMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteDenseMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new DenseMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = (float) normal.Sample();
- }
- }
-
- // Generate a matrix which is positive definite.
- return matrixA.Transpose()*matrixA;
+ var a = DenseMatrix.CreateRandom(order, order, new Normal(new MersenneTwister(1)));
+ return a.TransposeThisAndMultiply(a);
}
- ///
- /// Creates a DenseVector with random values.
- ///
- /// The size of the vector.
- /// A DenseVector with the given dimension and random values.
- public static Vector GenerateRandomDenseVector(int order)
+ public static Vector GenerateRandomDenseVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new DenseVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = (float) normal.Sample();
- }
-
- return v;
+ return DenseVector.CreateRandom(order, new Normal(new MersenneTwister(1)));
}
- ///
- /// Creates a UserDefinedMatrix with random values.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A UserDefinedMatrix with the given dimensions and random values.
- 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 Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(row, col);
- for (var i = 0; i < row; i++)
- {
- for (var j = 0; j < col; j++)
- {
- matrixA[i, j] = (float) normal.Sample();
- }
- }
-
- return matrixA;
+ return new UserDefinedMatrix(GenerateRandomDenseMatrix(row, col).ToArray());
}
- ///
- /// Creates a positive definite UserDefinedMatrix with random values.
- ///
- /// The order of the matrix.
- /// A positive definite UserDefinedMatrix with the given order and random values.
public static Matrix GenerateRandomPositiveDefiniteUserDefinedMatrix(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var matrixA = new UserDefinedMatrix(order);
- for (var i = 0; i < order; i++)
- {
- for (var j = 0; j < order; j++)
- {
- matrixA[i, j] = (float) normal.Sample();
- }
- }
-
- // Generate a matrix which is positive definite.
- return matrixA.Transpose()*matrixA;
+ return new UserDefinedMatrix(GenerateRandomPositiveDefiniteDenseMatrix(order).ToArray());
}
- ///
- /// Creates a UserDefinedVector with random values.
- ///
- /// The size of the vector.
- /// A UserDefinedVector with the given dimension and random values.
- public static Vector GenerateRandomUserDefinedVector(int order)
+ public static Vector GenerateRandomUserDefinedVector(int order)
{
- // Fill a matrix with standard random numbers.
- var normal = new Normal(new MersenneTwister(1));
- var v = new UserDefinedVector(order);
- for (var i = 0; i < order; i++)
- {
- v[i] = (float) normal.Sample();
- }
-
- // Generate a matrix which is positive definite.
- return v;
+ return new UserDefinedVector(GenerateRandomDenseVector(order).ToArray());
}
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs
index 4e9d8f3b..10f29326 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs
@@ -28,6 +28,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Single;
using MathNet.Numerics.LinearAlgebra.Single.Solvers;
using MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative;
@@ -231,7 +232,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);
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs
index 21966727..ece742a0 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs
@@ -23,12 +23,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Single;
+using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Preconditioners
{
- using LinearAlgebra.Single;
- using LinearAlgebra.Single.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Diagonal preconditioner test.
///
@@ -51,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs
index fb052490..4c7b0ed3 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs
@@ -23,14 +23,16 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Single;
+using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Single;
- using LinearAlgebra.Single.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Incomplete LU with IlutpPreconditioner test with drop tolerance and partial pivoting.
///
@@ -164,7 +166,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs
index 2fa72e6f..3f159024 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs
@@ -23,14 +23,16 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using System.Reflection;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Single;
+using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Preconditioners
{
- using System;
- using System.Reflection;
- using LinearAlgebra.Single;
- using LinearAlgebra.Single.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Incomplete LU preconditioner test.
///
@@ -94,7 +96,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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");
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs
index c0834e26..8be45a2a 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs
@@ -23,13 +23,15 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using System;
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Single;
+using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Preconditioners
{
- using System;
- using LinearAlgebra.Single;
- using LinearAlgebra.Single.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Abstract class for preconditioners tests.
///
@@ -85,7 +87,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
+ protected abstract void CheckResult(IPreConditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result);
///
/// Approximate with a unit matrix returning new vector.
diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs
index 9687ae52..d401f0fc 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/UnitPreconditionerTest.cs
@@ -23,12 +23,14 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
+
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Single;
+using MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners;
+using NUnit.Framework;
+
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Preconditioners
{
- using LinearAlgebra.Single;
- using LinearAlgebra.Single.Solvers.Preconditioners;
- using NUnit.Framework;
-
///
/// Unit precondition tests
///
@@ -51,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// Source matrix.
/// Initial vector.
/// Result vector.
- 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/UserDefinedMatrix.cs b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
index 2c11d72c..6cce674b 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrix.cs
@@ -105,27 +105,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
}
- ///
- /// Creates a matrix for the given number of rows and columns.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int numberOfRows, int numberOfColumns, bool fullyMutable = false)
- {
- return new UserDefinedMatrix(numberOfRows, numberOfColumns);
- }
-
- ///
- /// Creates a vector with a the given dimension.
- ///
- /// The size of the vector.
- /// A vector with the given dimension.
- public override Vector CreateVector(int size, bool fullyMutable = false)
- {
- return new UserDefinedVector(size);
- }
-
///
/// Initializes a square matrix with all zero's except for ones on the diagonal.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Single/UserDefinedVector.cs b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedVector.cs
index 142ea26c..1c276c42 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/UserDefinedVector.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/UserDefinedVector.cs
@@ -84,26 +84,5 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
: base(new UserDefinedVectorStorage(data.Length, (float[])data.Clone()))
{
}
-
- ///
- /// Creates a matrix with the given dimensions using the same storage type as this vector.
- ///
- /// The number of rows.
- /// The number of columns.
- /// A matrix with the given dimensions.
- public override Matrix CreateMatrix(int rows, int columns)
- {
- return new UserDefinedMatrix(rows, columns);
- }
-
- ///
- /// Creates a Vector of the given size using the same storage type as this vector.
- ///
- /// The size of the Vector to create.
- /// The new Vector.
- public override Vector CreateVector(int size)
- {
- return new UserDefinedVector(size);
- }
}
}
diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
index cd48594a..0d4e64dd 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
@@ -156,7 +156,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{
var expected = CreateVector(5);
var actual = expected.CreateVector(5);
- Assert.AreEqual(expected.GetType(), actual.GetType(), "vectors are same type.");
+ Assert.AreEqual(expected.Storage.IsDense, actual.Storage.IsDense, "vectors are same kind.");
}
///