From d18a0b24b36f55b162894a358c624132e55ecfd6 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 21 Sep 2013 12:58:54 +0200 Subject: [PATCH] LA: preconditioner more consistent naming --- MathNet.Numerics.sln.DotSettings | 3 + ...{Diagonal.cs => DiagonalPreconditioner.cs} | 3 +- ...{IncompleteLU.cs => ILU0Preconditioner.cs} | 3 +- .../{Ilutp.cs => ILUTPPreconditioner.cs} | 204 +++++++++++++++- .../Preconditioners/IlutpElementSorter.cs | 230 ------------------ ...{Diagonal.cs => DiagonalPreconditioner.cs} | 2 +- ...{IncompleteLU.cs => ILU0Preconditioner.cs} | 2 +- .../{Ilutp.cs => ILUTPPreconditioner.cs} | 203 +++++++++++++++- .../Preconditioners/IlutpElementSorter.cs | 225 ----------------- ...{Diagonal.cs => DiagonalPreconditioner.cs} | 2 +- ...{IncompleteLU.cs => ILU0Preconditioner.cs} | 2 +- .../{Ilutp.cs => ILUTPPreconditioner.cs} | 203 +++++++++++++++- .../Preconditioners/IlutpElementSorter.cs | 223 ----------------- .../{Milu0.cs => MILU0Preconditioner.cs} | 2 +- ...{Diagonal.cs => DiagonalPreconditioner.cs} | 2 +- ...{IncompleteLU.cs => ILU0Preconditioner.cs} | 2 +- .../{Ilutp.cs => ILUTPPreconditioner.cs} | 203 +++++++++++++++- .../Preconditioners/IlutpElementSorter.cs | 223 ----------------- src/Numerics/Numerics.csproj | 30 +-- .../Solvers/Preconditioners/DiagonalTest.cs | 4 +- .../Preconditioners/IluptElementSorterTest.cs | 38 +-- .../Solvers/Preconditioners/IlutpTest.cs | 20 +- .../Preconditioners/IncompleteLUTest.cs | 12 +- .../Solvers/Preconditioners/DiagonalTest.cs | 4 +- .../Preconditioners/IluptElementSorterTest.cs | 38 +-- .../Solvers/Preconditioners/IlutpTest.cs | 20 +- .../Preconditioners/IncompleteLUTest.cs | 12 +- .../Solvers/Preconditioners/DiagonalTest.cs | 4 +- .../Preconditioners/IluptElementSorterTest.cs | 38 +-- .../Solvers/Preconditioners/IlutpTest.cs | 20 +- .../Preconditioners/IncompleteLUTest.cs | 12 +- .../Solvers/Preconditioners/DiagonalTest.cs | 4 +- .../Preconditioners/IluptElementSorterTest.cs | 38 +-- .../Solvers/Preconditioners/IlutpTest.cs | 20 +- .../Preconditioners/IncompleteLUTest.cs | 12 +- 35 files changed, 961 insertions(+), 1102 deletions(-) rename src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/{Diagonal.cs => DiagonalPreconditioner.cs} (98%) rename src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/{IncompleteLU.cs => ILU0Preconditioner.cs} (99%) rename src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/{Ilutp.cs => ILUTPPreconditioner.cs} (76%) delete mode 100644 src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs rename src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/{Diagonal.cs => DiagonalPreconditioner.cs} (98%) rename src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/{IncompleteLU.cs => ILU0Preconditioner.cs} (99%) rename src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/{Ilutp.cs => ILUTPPreconditioner.cs} (76%) delete mode 100644 src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs rename src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/{Diagonal.cs => DiagonalPreconditioner.cs} (98%) rename src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/{IncompleteLU.cs => ILU0Preconditioner.cs} (99%) rename src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/{Ilutp.cs => ILUTPPreconditioner.cs} (76%) delete mode 100644 src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs rename src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/{Milu0.cs => MILU0Preconditioner.cs} (99%) rename src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/{Diagonal.cs => DiagonalPreconditioner.cs} (98%) rename src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/{IncompleteLU.cs => ILU0Preconditioner.cs} (99%) rename src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/{Ilutp.cs => ILUTPPreconditioner.cs} (76%) delete mode 100644 src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings index e3609001..db547745 100644 --- a/MathNet.Numerics.sln.DotSettings +++ b/MathNet.Numerics.sln.DotSettings @@ -49,10 +49,13 @@ OTHER DEALINGS IN THE SOFTWARE. CDF DFT FFT + ILU + ILUTP LU MAE MC MCMC + MILU MSE PDF QR diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/DiagonalPreconditioner.cs similarity index 98% rename from src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/DiagonalPreconditioner.cs index a7807974..de29381d 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/DiagonalPreconditioner.cs @@ -39,14 +39,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners using Complex = Numerics.Complex; #else using Complex = System.Numerics.Complex; - #endif /// /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreconditioner + public sealed class DiagonalPreconditioner : IPreconditioner { /// /// The inverse of the matrix diagonal. diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILU0Preconditioner.cs similarity index 99% rename from src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILU0Preconditioner.cs index 692f0d61..c855e51f 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILU0Preconditioner.cs @@ -39,7 +39,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners using Complex = Numerics.Complex; #else using Complex = System.Numerics.Complex; - #endif /// @@ -51,7 +50,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreconditioner + public sealed class ILU0Preconditioner : IPreconditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILUTPPreconditioner.cs similarity index 76% rename from src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs rename to src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILUTPPreconditioner.cs index 7c4b9161..de4132f1 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/ILUTPPreconditioner.cs @@ -40,7 +40,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners using Complex = Numerics.Complex; #else using Complex = System.Numerics.Complex; - #endif /// @@ -60,7 +59,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreconditioner + public sealed class ILUTPPreconditioner : IPreconditioner { /// /// The default fill level. @@ -103,14 +102,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners double _pivotTolerance; /// - /// Initializes a new instance of the class with the default settings. + /// Initializes a new instance of the class with the default settings. /// - public Ilutp() + public ILUTPPreconditioner() { } /// - /// Initializes a new instance of the class with the specified settings. + /// Initializes a new instance of the class with the specified settings. /// /// /// The amount of fill that is allowed in the matrix. The value is a fraction of @@ -125,7 +124,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners /// The pivot tolerance which indicates at what level pivoting will take place. A /// value of 0.0 means that no pivoting will take place. /// - public Ilutp(double fillLevel, double dropTolerance, double pivotTolerance) + public ILUTPPreconditioner(double fillLevel, double dropTolerance, double pivotTolerance) { if (fillLevel < 0) { @@ -613,7 +612,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners // Sorting starts at index 0 because the index array // starts at zero // and ends at index upperBound - lowerBound - IlutpElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); } /// @@ -684,4 +683,195 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners } } } + + /// + /// An element sort algorithm for the class. + /// + /// + /// This sort algorithm is used to sort the columns in a sparse matrix based on + /// the value of the element on the diagonal of the matrix. + /// + internal static class ILUTPElementSorter + { + /// + /// Sorts the elements of the vector in decreasing + /// fashion. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + // Move all the indices that we're interested in to the beginning of the + // array. Ignore the rest of the indices. + if (lowerBound > 0) + { + for (var i = 0; i < (upperBound - lowerBound + 1); i++) + { + Exchange(sortedIndices, i, i + lowerBound); + } + + upperBound -= lowerBound; + lowerBound = 0; + } + + HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); + } + + /// + /// Sorts the elements of the vector in decreasing + /// fashion using heap sort algorithm. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; + var end = (upperBound - lowerBound + 1) - 1 + lowerBound; + + BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); + + while (end >= lowerBound) + { + Exchange(sortedIndices, end, lowerBound); + SiftDoubleIndices(sortedIndices, values, lowerBound, end); + end -= 1; + } + } + + /// + /// Build heap for double indicies + /// + /// Root position + /// Length of + /// Indicies of + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + { + while (start >= 0) + { + SiftDoubleIndices(sortedIndices, values, start, count); + start -= 1; + } + } + + /// + /// Sift double indicies + /// + /// Indicies of + /// Target + /// Root position + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + { + var root = begin; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) + { + child += 1; + } + + if (values[sortedIndices[root]].Magnitude <= values[sortedIndices[child]].Magnitude) + { + return; + } + + Exchange(sortedIndices, root, child); + root = child; + } + } + + /// + /// Sorts the given integers in a decreasing fashion. + /// + /// The values. + public static void SortIntegersDecreasing(int[] values) + { + HeapSortIntegers(values, values.Length); + } + + /// + /// Sort the given integers in a decreasing fashion using heapsort algorithm + /// + /// Array of values to sort + /// Length of + private static void HeapSortIntegers(int[] values, int count) + { + var start = (count / 2) - 1; + var end = count - 1; + + BuildHeap(values, start, count); + + while (end >= 0) + { + Exchange(values, end, 0); + Sift(values, 0, end); + end -= 1; + } + } + + /// + /// Build heap + /// + /// Target values array + /// Root position + /// Length of + private static void BuildHeap(int[] values, int start, int count) + { + while (start >= 0) + { + Sift(values, start, count); + start -= 1; + } + } + + /// + /// Sift values + /// + /// Target value array + /// Root position + /// Length of + private static void Sift(int[] values, int start, int count) + { + var root = start; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[child] > values[child + 1])) + { + child += 1; + } + + if (values[root] > values[child]) + { + Exchange(values, root, child); + root = child; + } + else + { + return; + } + } + } + + /// + /// Exchange values in array + /// + /// Target values array + /// First value to exchange + /// Second value to exchange + private static void Exchange(int[] values, int first, int second) + { + var t = values[first]; + values[first] = values[second]; + values[second] = t; + } + } } diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs deleted file mode 100644 index d0f8f48c..00000000 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Preconditioners/IlutpElementSorter.cs +++ /dev/null @@ -1,230 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Preconditioners -{ - -#if NOSYSNUMERICS - using Numerics; -#else - using System.Numerics; -#endif - - /// - /// An element sort algorithm for the class. - /// - /// - /// This sort algorithm is used to sort the columns in a sparse matrix based on - /// the value of the element on the diagonal of the matrix. - /// - internal static class IlutpElementSorter - { - /// - /// Sorts the elements of the vector in decreasing - /// fashion. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - // Move all the indices that we're interested in to the beginning of the - // array. Ignore the rest of the indices. - if (lowerBound > 0) - { - for (var i = 0; i < (upperBound - lowerBound + 1); i++) - { - Exchange(sortedIndices, i, i + lowerBound); - } - - upperBound -= lowerBound; - lowerBound = 0; - } - - HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); - } - - /// - /// Sorts the elements of the vector in decreasing - /// fashion using heap sort algorithm. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; - var end = (upperBound - lowerBound + 1) - 1 + lowerBound; - - BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); - - while (end >= lowerBound) - { - Exchange(sortedIndices, end, lowerBound); - SiftDoubleIndices(sortedIndices, values, lowerBound, end); - end -= 1; - } - } - - /// - /// Build heap for double indicies - /// - /// Root position - /// Length of - /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) - { - while (start >= 0) - { - SiftDoubleIndices(sortedIndices, values, start, count); - start -= 1; - } - } - - /// - /// Sift double indicies - /// - /// Indicies of - /// Target - /// Root position - /// Length of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) - { - var root = begin; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) - { - child += 1; - } - - if (values[sortedIndices[root]].Magnitude <= values[sortedIndices[child]].Magnitude) - { - return; - } - - Exchange(sortedIndices, root, child); - root = child; - } - } - - /// - /// Sorts the given integers in a decreasing fashion. - /// - /// The values. - public static void SortIntegersDecreasing(int[] values) - { - HeapSortIntegers(values, values.Length); - } - - /// - /// Sort the given integers in a decreasing fashion using heapsort algorithm - /// - /// Array of values to sort - /// Length of - private static void HeapSortIntegers(int[] values, int count) - { - var start = (count / 2) - 1; - var end = count - 1; - - BuildHeap(values, start, count); - - while (end >= 0) - { - Exchange(values, end, 0); - Sift(values, 0, end); - end -= 1; - } - } - - /// - /// Build heap - /// - /// Target values array - /// Root position - /// Length of - private static void BuildHeap(int[] values, int start, int count) - { - while (start >= 0) - { - Sift(values, start, count); - start -= 1; - } - } - - /// - /// Sift values - /// - /// Target value array - /// Root position - /// Length of - private static void Sift(int[] values, int start, int count) - { - var root = start; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[child] > values[child + 1])) - { - child += 1; - } - - if (values[root] > values[child]) - { - Exchange(values, root, child); - root = child; - } - else - { - return; - } - } - } - - /// - /// Exchange values in array - /// - /// Target values array - /// First value to exchange - /// Second value to exchange - private static void Exchange(int[] values, int first, int second) - { - var t = values[first]; - values[first] = values[second]; - values[second] = t; - } - } -} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/DiagonalPreconditioner.cs similarity index 98% rename from src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs rename to src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/DiagonalPreconditioner.cs index adb9461e..04c830a6 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/DiagonalPreconditioner.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreconditioner + public sealed class DiagonalPreconditioner : IPreconditioner { /// /// The inverse of the matrix diagonal. diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILU0Preconditioner.cs similarity index 99% rename from src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs rename to src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILU0Preconditioner.cs index b8d5b715..2d5dfa84 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILU0Preconditioner.cs @@ -45,7 +45,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreconditioner + public sealed class ILU0Preconditioner : IPreconditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILUTPPreconditioner.cs similarity index 76% rename from src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs rename to src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILUTPPreconditioner.cs index 1fedf956..1ad9768c 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/ILUTPPreconditioner.cs @@ -54,7 +54,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreconditioner + public sealed class ILUTPPreconditioner : IPreconditioner { /// /// The default fill level. @@ -97,14 +97,14 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners double _pivotTolerance; /// - /// Initializes a new instance of the class with the default settings. + /// Initializes a new instance of the class with the default settings. /// - public Ilutp() + public ILUTPPreconditioner() { } /// - /// Initializes a new instance of the class with the specified settings. + /// Initializes a new instance of the class with the specified settings. /// /// /// The amount of fill that is allowed in the matrix. The value is a fraction of @@ -119,7 +119,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners /// The pivot tolerance which indicates at what level pivoting will take place. A /// value of 0.0 means that no pivoting will take place. /// - public Ilutp(double fillLevel, double dropTolerance, double pivotTolerance) + public ILUTPPreconditioner(double fillLevel, double dropTolerance, double pivotTolerance) { if (fillLevel < 0) { @@ -607,7 +607,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners // Sorting starts at index 0 because the index array // starts at zero // and ends at index upperBound - lowerBound - IlutpElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); } /// @@ -678,4 +678,195 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners } } } + + /// + /// An element sort algorithm for the class. + /// + /// + /// This sort algorithm is used to sort the columns in a sparse matrix based on + /// the value of the element on the diagonal of the matrix. + /// + internal static class ILUTPElementSorter + { + /// + /// Sorts the elements of the vector in decreasing + /// fashion. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + // Move all the indices that we're interested in to the beginning of the + // array. Ignore the rest of the indices. + if (lowerBound > 0) + { + for (var i = 0; i < (upperBound - lowerBound + 1); i++) + { + Exchange(sortedIndices, i, i + lowerBound); + } + + upperBound -= lowerBound; + lowerBound = 0; + } + + HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); + } + + /// + /// Sorts the elements of the vector in decreasing + /// fashion using heap sort algorithm. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; + var end = (upperBound - lowerBound + 1) - 1 + lowerBound; + + BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); + + while (end >= lowerBound) + { + Exchange(sortedIndices, end, lowerBound); + SiftDoubleIndices(sortedIndices, values, lowerBound, end); + end -= 1; + } + } + + /// + /// Build heap for double indicies + /// + /// Root position + /// Length of + /// Indicies of + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + { + while (start >= 0) + { + SiftDoubleIndices(sortedIndices, values, start, count); + start -= 1; + } + } + + /// + /// Sift double indicies + /// + /// Indicies of + /// Target + /// Root position + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + { + var root = begin; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) + { + child += 1; + } + + if (values[sortedIndices[root]].Magnitude <= values[sortedIndices[child]].Magnitude) + { + return; + } + + Exchange(sortedIndices, root, child); + root = child; + } + } + + /// + /// Sorts the given integers in a decreasing fashion. + /// + /// The values. + public static void SortIntegersDecreasing(int[] values) + { + HeapSortIntegers(values, values.Length); + } + + /// + /// Sort the given integers in a decreasing fashion using heapsort algorithm + /// + /// Array of values to sort + /// Length of + private static void HeapSortIntegers(int[] values, int count) + { + var start = (count / 2) - 1; + var end = count - 1; + + BuildHeap(values, start, count); + + while (end >= 0) + { + Exchange(values, end, 0); + Sift(values, 0, end); + end -= 1; + } + } + + /// + /// Build heap + /// + /// Target values array + /// Root position + /// Length of + private static void BuildHeap(int[] values, int start, int count) + { + while (start >= 0) + { + Sift(values, start, count); + start -= 1; + } + } + + /// + /// Sift values + /// + /// Target value array + /// Root position + /// Length of + private static void Sift(int[] values, int start, int count) + { + var root = start; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[child] > values[child + 1])) + { + child += 1; + } + + if (values[root] > values[child]) + { + Exchange(values, root, child); + root = child; + } + else + { + return; + } + } + } + + /// + /// Exchange values in array + /// + /// Target values array + /// First value to exchange + /// Second value to exchange + private static void Exchange(int[] values, int first, int second) + { + var t = values[first]; + values[first] = values[second]; + values[second] = t; + } + } } diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs deleted file mode 100644 index 92351f97..00000000 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Preconditioners/IlutpElementSorter.cs +++ /dev/null @@ -1,225 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Preconditioners -{ - using Numerics; - - /// - /// An element sort algorithm for the class. - /// - /// - /// This sort algorithm is used to sort the columns in a sparse matrix based on - /// the value of the element on the diagonal of the matrix. - /// - internal static class IlutpElementSorter - { - /// - /// Sorts the elements of the vector in decreasing - /// fashion. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - // Move all the indices that we're interested in to the beginning of the - // array. Ignore the rest of the indices. - if (lowerBound > 0) - { - for (var i = 0; i < (upperBound - lowerBound + 1); i++) - { - Exchange(sortedIndices, i, i + lowerBound); - } - - upperBound -= lowerBound; - lowerBound = 0; - } - - HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); - } - - /// - /// Sorts the elements of the vector in decreasing - /// fashion using heap sort algorithm. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; - var end = (upperBound - lowerBound + 1) - 1 + lowerBound; - - BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); - - while (end >= lowerBound) - { - Exchange(sortedIndices, end, lowerBound); - SiftDoubleIndices(sortedIndices, values, lowerBound, end); - end -= 1; - } - } - - /// - /// Build heap for double indicies - /// - /// Root position - /// Length of - /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) - { - while (start >= 0) - { - SiftDoubleIndices(sortedIndices, values, start, count); - start -= 1; - } - } - - /// - /// Sift double indicies - /// - /// Indicies of - /// Target - /// Root position - /// Length of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) - { - var root = begin; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[sortedIndices[child]].Magnitude > values[sortedIndices[child + 1]].Magnitude)) - { - child += 1; - } - - if (values[sortedIndices[root]].Magnitude <= values[sortedIndices[child]].Magnitude) - { - return; - } - - Exchange(sortedIndices, root, child); - root = child; - } - } - - /// - /// Sorts the given integers in a decreasing fashion. - /// - /// The values. - public static void SortIntegersDecreasing(int[] values) - { - HeapSortIntegers(values, values.Length); - } - - /// - /// Sort the given integers in a decreasing fashion using heapsort algorithm - /// - /// Array of values to sort - /// Length of - private static void HeapSortIntegers(int[] values, int count) - { - var start = (count / 2) - 1; - var end = count - 1; - - BuildHeap(values, start, count); - - while (end >= 0) - { - Exchange(values, end, 0); - Sift(values, 0, end); - end -= 1; - } - } - - /// - /// Build heap - /// - /// Target values array - /// Root position - /// Length of - private static void BuildHeap(int[] values, int start, int count) - { - while (start >= 0) - { - Sift(values, start, count); - start -= 1; - } - } - - /// - /// Sift values - /// - /// Target value array - /// Root position - /// Length of - private static void Sift(int[] values, int start, int count) - { - var root = start; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[child] > values[child + 1])) - { - child += 1; - } - - if (values[root] > values[child]) - { - Exchange(values, root, child); - root = child; - } - else - { - return; - } - } - } - - /// - /// Exchange values in array - /// - /// Target values array - /// First value to exchange - /// Second value to exchange - private static void Exchange(int[] values, int first, int second) - { - var t = values[first]; - values[first] = values[second]; - values[second] = t; - } - } -} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/DiagonalPreconditioner.cs similarity index 98% rename from src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs rename to src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/DiagonalPreconditioner.cs index a065e22e..75c2a1e7 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/DiagonalPreconditioner.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreconditioner + public sealed class DiagonalPreconditioner : IPreconditioner { /// /// The inverse of the matrix diagonal. diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILU0Preconditioner.cs similarity index 99% rename from src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs rename to src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILU0Preconditioner.cs index e86750b0..9ed18d9b 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILU0Preconditioner.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreconditioner + public sealed class ILU0Preconditioner : IPreconditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILUTPPreconditioner.cs similarity index 76% rename from src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs rename to src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILUTPPreconditioner.cs index 098c314b..651a57f6 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/ILUTPPreconditioner.cs @@ -52,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreconditioner + public sealed class ILUTPPreconditioner : IPreconditioner { /// /// The default fill level. @@ -95,14 +95,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners double _pivotTolerance; /// - /// Initializes a new instance of the class with the default settings. + /// Initializes a new instance of the class with the default settings. /// - public Ilutp() + public ILUTPPreconditioner() { } /// - /// Initializes a new instance of the class with the specified settings. + /// Initializes a new instance of the class with the specified settings. /// /// /// The amount of fill that is allowed in the matrix. The value is a fraction of @@ -117,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// The pivot tolerance which indicates at what level pivoting will take place. A /// value of 0.0 means that no pivoting will take place. /// - public Ilutp(double fillLevel, double dropTolerance, double pivotTolerance) + public ILUTPPreconditioner(double fillLevel, double dropTolerance, double pivotTolerance) { if (fillLevel < 0) { @@ -605,7 +605,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners // Sorting starts at index 0 because the index array // starts at zero // and ends at index upperBound - lowerBound - IlutpElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); } /// @@ -676,4 +676,195 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners } } } + + /// + /// An element sort algorithm for the class. + /// + /// + /// This sort algorithm is used to sort the columns in a sparse matrix based on + /// the value of the element on the diagonal of the matrix. + /// + internal static class ILUTPElementSorter + { + /// + /// Sorts the elements of the vector in decreasing + /// fashion. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + // Move all the indices that we're interested in to the beginning of the + // array. Ignore the rest of the indices. + if (lowerBound > 0) + { + for (var i = 0; i < (upperBound - lowerBound + 1); i++) + { + Exchange(sortedIndices, i, i + lowerBound); + } + + upperBound -= lowerBound; + lowerBound = 0; + } + + HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); + } + + /// + /// Sorts the elements of the vector in decreasing + /// fashion using heap sort algorithm. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; + var end = (upperBound - lowerBound + 1) - 1 + lowerBound; + + BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); + + while (end >= lowerBound) + { + Exchange(sortedIndices, end, lowerBound); + SiftDoubleIndices(sortedIndices, values, lowerBound, end); + end -= 1; + } + } + + /// + /// Build heap for double indicies + /// + /// Root position + /// Length of + /// Indicies of + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + { + while (start >= 0) + { + SiftDoubleIndices(sortedIndices, values, start, count); + start -= 1; + } + } + + /// + /// Sift double indicies + /// + /// Indicies of + /// Target + /// Root position + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + { + var root = begin; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) + { + child += 1; + } + + if (values[sortedIndices[root]] <= values[sortedIndices[child]]) + { + return; + } + + Exchange(sortedIndices, root, child); + root = child; + } + } + + /// + /// Sorts the given integers in a decreasing fashion. + /// + /// The values. + public static void SortIntegersDecreasing(int[] values) + { + HeapSortIntegers(values, values.Length); + } + + /// + /// Sort the given integers in a decreasing fashion using heapsort algorithm + /// + /// Array of values to sort + /// Length of + private static void HeapSortIntegers(int[] values, int count) + { + var start = (count / 2) - 1; + var end = count - 1; + + BuildHeap(values, start, count); + + while (end >= 0) + { + Exchange(values, end, 0); + Sift(values, 0, end); + end -= 1; + } + } + + /// + /// Build heap + /// + /// Target values array + /// Root position + /// Length of + private static void BuildHeap(int[] values, int start, int count) + { + while (start >= 0) + { + Sift(values, start, count); + start -= 1; + } + } + + /// + /// Sift values + /// + /// Target value array + /// Root position + /// Length of + private static void Sift(int[] values, int start, int count) + { + var root = start; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[child] > values[child + 1])) + { + child += 1; + } + + if (values[root] > values[child]) + { + Exchange(values, root, child); + root = child; + } + else + { + return; + } + } + } + + /// + /// Exchange values in array + /// + /// Target values array + /// First value to exchange + /// Second value to exchange + private static void Exchange(int[] values, int first, int second) + { + var t = values[first]; + values[first] = values[second]; + values[second] = t; + } + } } diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs deleted file mode 100644 index 1cd744c1..00000000 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/IlutpElementSorter.cs +++ /dev/null @@ -1,223 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners -{ - /// - /// An element sort algorithm for the class. - /// - /// - /// This sort algorithm is used to sort the columns in a sparse matrix based on - /// the value of the element on the diagonal of the matrix. - /// - internal static class IlutpElementSorter - { - /// - /// Sorts the elements of the vector in decreasing - /// fashion. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - // Move all the indices that we're interested in to the beginning of the - // array. Ignore the rest of the indices. - if (lowerBound > 0) - { - for (var i = 0; i < (upperBound - lowerBound + 1); i++) - { - Exchange(sortedIndices, i, i + lowerBound); - } - - upperBound -= lowerBound; - lowerBound = 0; - } - - HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); - } - - /// - /// Sorts the elements of the vector in decreasing - /// fashion using heap sort algorithm. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; - var end = (upperBound - lowerBound + 1) - 1 + lowerBound; - - BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); - - while (end >= lowerBound) - { - Exchange(sortedIndices, end, lowerBound); - SiftDoubleIndices(sortedIndices, values, lowerBound, end); - end -= 1; - } - } - - /// - /// Build heap for double indicies - /// - /// Root position - /// Length of - /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) - { - while (start >= 0) - { - SiftDoubleIndices(sortedIndices, values, start, count); - start -= 1; - } - } - - /// - /// Sift double indicies - /// - /// Indicies of - /// Target - /// Root position - /// Length of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) - { - var root = begin; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) - { - child += 1; - } - - if (values[sortedIndices[root]] <= values[sortedIndices[child]]) - { - return; - } - - Exchange(sortedIndices, root, child); - root = child; - } - } - - /// - /// Sorts the given integers in a decreasing fashion. - /// - /// The values. - public static void SortIntegersDecreasing(int[] values) - { - HeapSortIntegers(values, values.Length); - } - - /// - /// Sort the given integers in a decreasing fashion using heapsort algorithm - /// - /// Array of values to sort - /// Length of - private static void HeapSortIntegers(int[] values, int count) - { - var start = (count / 2) - 1; - var end = count - 1; - - BuildHeap(values, start, count); - - while (end >= 0) - { - Exchange(values, end, 0); - Sift(values, 0, end); - end -= 1; - } - } - - /// - /// Build heap - /// - /// Target values array - /// Root position - /// Length of - private static void BuildHeap(int[] values, int start, int count) - { - while (start >= 0) - { - Sift(values, start, count); - start -= 1; - } - } - - /// - /// Sift values - /// - /// Target value array - /// Root position - /// Length of - private static void Sift(int[] values, int start, int count) - { - var root = start; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[child] > values[child + 1])) - { - child += 1; - } - - if (values[root] > values[child]) - { - Exchange(values, root, child); - root = child; - } - else - { - return; - } - } - } - - /// - /// Exchange values in array - /// - /// Target values array - /// First value to exchange - /// Second value to exchange - private static void Exchange(int[] values, int first, int second) - { - var t = values[first]; - values[first] = values[second]; - values[second] = t; - } - } -} \ No newline at end of file diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Milu0.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/MILU0Preconditioner.cs similarity index 99% rename from src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Milu0.cs rename to src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/MILU0Preconditioner.cs index 8453505a..70e6e478 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/Milu0.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Preconditioners/MILU0Preconditioner.cs @@ -48,7 +48,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners /// /// Original Fortran code by Youcef Saad (07 January 2004) /// - public sealed class Milu0 : IPreconditioner + public sealed class MILU0Preconditioner : IPreconditioner { // Matrix stored in Modified Sparse Row (MSR) format containing the L and U // factors together. diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/DiagonalPreconditioner.cs similarity index 98% rename from src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs rename to src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/DiagonalPreconditioner.cs index 16317f81..4318b66a 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Diagonal.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/DiagonalPreconditioner.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// A diagonal preconditioner. The preconditioner uses the inverse /// of the matrix diagonal as preconditioning values. /// - public sealed class Diagonal : IPreconditioner + public sealed class DiagonalPreconditioner : IPreconditioner { /// /// The inverse of the matrix diagonal. diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILU0Preconditioner.cs similarity index 99% rename from src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs rename to src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILU0Preconditioner.cs index 01f6b854..89e31167 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IncompleteLU.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILU0Preconditioner.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// Yousef Saad
/// Algorithm is described in Chapter 10, section 10.3.2, page 275
/// - public sealed class IncompleteLU : IPreconditioner + public sealed class ILU0Preconditioner : IPreconditioner { /// /// The matrix holding the lower (L) and upper (U) matrices. The diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILUTPPreconditioner.cs similarity index 76% rename from src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs rename to src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILUTPPreconditioner.cs index a13d41cd..046d8dbf 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/Ilutp.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/ILUTPPreconditioner.cs @@ -52,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// pp. 20 - 28
/// Algorithm is described in Section 2, page 22 /// - public sealed class Ilutp : IPreconditioner + public sealed class ILUTPPreconditioner : IPreconditioner { /// /// The default fill level. @@ -95,14 +95,14 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners double _pivotTolerance; /// - /// Initializes a new instance of the class with the default settings. + /// Initializes a new instance of the class with the default settings. /// - public Ilutp() + public ILUTPPreconditioner() { } /// - /// Initializes a new instance of the class with the specified settings. + /// Initializes a new instance of the class with the specified settings. /// /// /// The amount of fill that is allowed in the matrix. The value is a fraction of @@ -117,7 +117,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners /// The pivot tolerance which indicates at what level pivoting will take place. A /// value of 0.0 means that no pivoting will take place. /// - public Ilutp(double fillLevel, double dropTolerance, double pivotTolerance) + public ILUTPPreconditioner(double fillLevel, double dropTolerance, double pivotTolerance) { if (fillLevel < 0) { @@ -605,7 +605,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners // Sorting starts at index 0 because the index array // starts at zero // and ends at index upperBound - lowerBound - IlutpElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, upperBound - lowerBound, sortedIndices, values); } /// @@ -676,4 +676,195 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners } } } + + /// + /// An element sort algorithm for the class. + /// + /// + /// This sort algorithm is used to sort the columns in a sparse matrix based on + /// the value of the element on the diagonal of the matrix. + /// + internal static class ILUTPElementSorter + { + /// + /// Sorts the elements of the vector in decreasing + /// fashion. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + // Move all the indices that we're interested in to the beginning of the + // array. Ignore the rest of the indices. + if (lowerBound > 0) + { + for (var i = 0; i < (upperBound - lowerBound + 1); i++) + { + Exchange(sortedIndices, i, i + lowerBound); + } + + upperBound -= lowerBound; + lowerBound = 0; + } + + HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); + } + + /// + /// Sorts the elements of the vector in decreasing + /// fashion using heap sort algorithm. The vector itself is not affected. + /// + /// The starting index. + /// The stopping index. + /// An array that will contain the sorted indices once the algorithm finishes. + /// The that contains the values that need to be sorted. + private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) + { + var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; + var end = (upperBound - lowerBound + 1) - 1 + lowerBound; + + BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); + + while (end >= lowerBound) + { + Exchange(sortedIndices, end, lowerBound); + SiftDoubleIndices(sortedIndices, values, lowerBound, end); + end -= 1; + } + } + + /// + /// Build heap for double indicies + /// + /// Root position + /// Length of + /// Indicies of + /// Target + private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) + { + while (start >= 0) + { + SiftDoubleIndices(sortedIndices, values, start, count); + start -= 1; + } + } + + /// + /// Sift double indicies + /// + /// Indicies of + /// Target + /// Root position + /// Length of + private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) + { + var root = begin; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) + { + child += 1; + } + + if (values[sortedIndices[root]] <= values[sortedIndices[child]]) + { + return; + } + + Exchange(sortedIndices, root, child); + root = child; + } + } + + /// + /// Sorts the given integers in a decreasing fashion. + /// + /// The values. + public static void SortIntegersDecreasing(int[] values) + { + HeapSortIntegers(values, values.Length); + } + + /// + /// Sort the given integers in a decreasing fashion using heapsort algorithm + /// + /// Array of values to sort + /// Length of + private static void HeapSortIntegers(int[] values, int count) + { + var start = (count / 2) - 1; + var end = count - 1; + + BuildHeap(values, start, count); + + while (end >= 0) + { + Exchange(values, end, 0); + Sift(values, 0, end); + end -= 1; + } + } + + /// + /// Build heap + /// + /// Target values array + /// Root position + /// Length of + private static void BuildHeap(int[] values, int start, int count) + { + while (start >= 0) + { + Sift(values, start, count); + start -= 1; + } + } + + /// + /// Sift values + /// + /// Target value array + /// Root position + /// Length of + private static void Sift(int[] values, int start, int count) + { + var root = start; + + while (root * 2 < count) + { + var child = root * 2; + if ((child < count - 1) && (values[child] > values[child + 1])) + { + child += 1; + } + + if (values[root] > values[child]) + { + Exchange(values, root, child); + root = child; + } + else + { + return; + } + } + } + + /// + /// Exchange values in array + /// + /// Target values array + /// First value to exchange + /// Second value to exchange + private static void Exchange(int[] values, int first, int second) + { + var t = values[first]; + values[first] = values[second]; + values[second] = t; + } + } } diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs deleted file mode 100644 index 88257716..00000000 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Preconditioners/IlutpElementSorter.cs +++ /dev/null @@ -1,223 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 Math.NET -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Preconditioners -{ - /// - /// An element sort algorithm for the class. - /// - /// - /// This sort algorithm is used to sort the columns in a sparse matrix based on - /// the value of the element on the diagonal of the matrix. - /// - internal static class IlutpElementSorter - { - /// - /// Sorts the elements of the vector in decreasing - /// fashion. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - public static void SortDoubleIndicesDecreasing(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - // Move all the indices that we're interested in to the beginning of the - // array. Ignore the rest of the indices. - if (lowerBound > 0) - { - for (var i = 0; i < (upperBound - lowerBound + 1); i++) - { - Exchange(sortedIndices, i, i + lowerBound); - } - - upperBound -= lowerBound; - lowerBound = 0; - } - - HeapSortDoublesIndices(lowerBound, upperBound, sortedIndices, values); - } - - /// - /// Sorts the elements of the vector in decreasing - /// fashion using heap sort algorithm. The vector itself is not affected. - /// - /// The starting index. - /// The stopping index. - /// An array that will contain the sorted indices once the algorithm finishes. - /// The that contains the values that need to be sorted. - private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector values) - { - var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound; - var end = (upperBound - lowerBound + 1) - 1 + lowerBound; - - BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values); - - while (end >= lowerBound) - { - Exchange(sortedIndices, end, lowerBound); - SiftDoubleIndices(sortedIndices, values, lowerBound, end); - end -= 1; - } - } - - /// - /// Build heap for double indicies - /// - /// Root position - /// Length of - /// Indicies of - /// Target - private static void BuildDoubleIndexHeap(int start, int count, int[] sortedIndices, Vector values) - { - while (start >= 0) - { - SiftDoubleIndices(sortedIndices, values, start, count); - start -= 1; - } - } - - /// - /// Sift double indicies - /// - /// Indicies of - /// Target - /// Root position - /// Length of - private static void SiftDoubleIndices(int[] sortedIndices, Vector values, int begin, int count) - { - var root = begin; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[sortedIndices[child]] > values[sortedIndices[child + 1]])) - { - child += 1; - } - - if (values[sortedIndices[root]] <= values[sortedIndices[child]]) - { - return; - } - - Exchange(sortedIndices, root, child); - root = child; - } - } - - /// - /// Sorts the given integers in a decreasing fashion. - /// - /// The values. - public static void SortIntegersDecreasing(int[] values) - { - HeapSortIntegers(values, values.Length); - } - - /// - /// Sort the given integers in a decreasing fashion using heapsort algorithm - /// - /// Array of values to sort - /// Length of - private static void HeapSortIntegers(int[] values, int count) - { - var start = (count / 2) - 1; - var end = count - 1; - - BuildHeap(values, start, count); - - while (end >= 0) - { - Exchange(values, end, 0); - Sift(values, 0, end); - end -= 1; - } - } - - /// - /// Build heap - /// - /// Target values array - /// Root position - /// Length of - private static void BuildHeap(int[] values, int start, int count) - { - while (start >= 0) - { - Sift(values, start, count); - start -= 1; - } - } - - /// - /// Sift values - /// - /// Target value array - /// Root position - /// Length of - private static void Sift(int[] values, int start, int count) - { - var root = start; - - while (root * 2 < count) - { - var child = root * 2; - if ((child < count - 1) && (values[child] > values[child + 1])) - { - child += 1; - } - - if (values[root] > values[child]) - { - Exchange(values, root, child); - root = child; - } - else - { - return; - } - } - } - - /// - /// Exchange values in array - /// - /// Target values array - /// First value to exchange - /// Second value to exchange - private static void Exchange(int[] values, int first, int second) - { - var t = values[first]; - values[first] = values[second]; - values[second] = t; - } - } -} \ No newline at end of file diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 7e7e2b8b..b092ccd8 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -122,7 +122,7 @@ - + @@ -244,10 +244,9 @@ - - - - + + + @@ -269,10 +268,9 @@ - - - - + + + @@ -310,10 +308,9 @@ - - - - + + + @@ -338,10 +335,9 @@ - - - - + + + Code diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs index 18d67f62..39d24c01 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs @@ -51,7 +51,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new Diagonal(); + return new DiagonalPreconditioner(); } /// @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(DiagonalPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IluptElementSorterTest.cs index 6ee93e79..afb407bb 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -46,7 +46,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi public void HeapSortWithIncreasingIntegerArray() { var sortedIndices = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi public void HeapSortWithDecreasingIntegerArray() { var sortedIndices = new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi public void HeapSortWithRandomIntegerArray() { var sortedIndices = new[] { 5, 2, 8, 6, 0, 4, 1, 7, 3, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -88,7 +88,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi public void HeapSortWithDuplicateEntries() { var sortedIndices = new[] { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -129,7 +129,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi public void HeapSortWithSpecialConstructedIntegerArray() { var sortedIndices = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -140,7 +140,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi } sortedIndices = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -151,7 +151,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi } sortedIndices = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -162,7 +162,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi } sortedIndices = new[] { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -196,7 +196,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -226,7 +226,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(i, sortedIndices[i], "#01-" + i); @@ -256,7 +256,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { switch (i) @@ -319,7 +319,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -382,7 +382,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -407,7 +407,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -432,7 +432,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -457,7 +457,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -491,7 +491,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -521,7 +521,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 5; i++) { Assert.AreEqual(sortedIndices.Length - 5 - i, sortedIndices[i], "#01-" + i); @@ -551,7 +551,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 3 - i, sortedIndices[i], "#01-" + i); diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs index c9192d92..8e27d0ff 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs @@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// Ilutp instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(Ilutp ilutp, string methodName) + private static T GetMethod(ILUTPPreconditioner ilutp, string methodName) { var type = ilutp.GetType(); var methodInfo = type.GetMethod( @@ -99,7 +99,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// /// Ilutp instance. /// Upper triangle. - private static SparseMatrix GetUpperTriangle(Ilutp ilutp) + private static SparseMatrix GetUpperTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "UpperTriangle"); } @@ -109,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// /// Ilutp instance. /// Lower triangle. - private static SparseMatrix GetLowerTriangle(Ilutp ilutp) + private static SparseMatrix GetLowerTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "LowerTriangle"); } @@ -119,7 +119,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// /// Ilutp instance. /// Pivots array. - private static int[] GetPivots(Ilutp ilutp) + private static int[] GetPivots(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "Pivots"); } @@ -144,9 +144,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// Create preconditioner (internal) ///
/// Ilutp instance. - private Ilutp InternalCreatePreconditioner() + private ILUTPPreconditioner InternalCreatePreconditioner() { - var result = new Ilutp + var result = new ILUTPPreconditioner { DropTolerance = _dropTolerance, FillLevel = _fillLevel, @@ -176,7 +176,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILUTPPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -248,7 +248,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 0.0, DropTolerance = 0, @@ -304,7 +304,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, @@ -341,7 +341,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi const int Size = 10; var newMatrix = CreateReverseUnitMatrix(Size); var vector = CreateStandardBcVector(Size); - var preconditioner = new Ilutp + var preconditioner = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, diff --git a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs index d9658766..b2b8055f 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs @@ -54,7 +54,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// IncompleteLU instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(IncompleteLU ilu, string methodName) + private static T GetMethod(ILU0Preconditioner ilu, string methodName) { var type = ilu.GetType(); var methodInfo = type.GetMethod( @@ -73,7 +73,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi ///
/// IncompleteLU instance. /// Upper triangle. - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "UpperTriangle"); } @@ -83,7 +83,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi ///
/// IncompleteLU instance. /// Lower triangle. - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "LowerTriangle"); } @@ -94,7 +94,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new IncompleteLU(); + return new ILU0Preconditioner(); } /// @@ -106,7 +106,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILU0Preconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -136,7 +136,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new IncompleteLU(); + var ilu = new ILU0Preconditioner(); ilu.Initialize(sparseMatrix); var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu)); diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs index 88117494..88ac3f40 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs @@ -46,7 +46,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new Diagonal(); + return new DiagonalPreconditioner(); } /// @@ -58,7 +58,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(DiagonalPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs index 7ebf2e0c..2564fdd1 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithIncreasingIntegerArray() { var sortedIndices = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -57,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithDecreasingIntegerArray() { var sortedIndices = new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithRandomIntegerArray() { var sortedIndices = new[] { 5, 2, 8, 6, 0, 4, 1, 7, 3, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -85,7 +85,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithDuplicateEntries() { var sortedIndices = new[] { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -126,7 +126,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon public void HeapSortWithSpecialConstructedIntegerArray() { var sortedIndices = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -137,7 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon } sortedIndices = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon } sortedIndices = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -159,7 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon } sortedIndices = new[] { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -193,7 +193,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -223,7 +223,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(i, sortedIndices[i], "#01-" + i); @@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { switch (i) @@ -316,7 +316,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -379,7 +379,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -404,7 +404,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -429,7 +429,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -454,7 +454,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -488,7 +488,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -518,7 +518,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 5; i++) { Assert.AreEqual(sortedIndices.Length - 5 - i, sortedIndices[i], "#01-" + i); @@ -548,7 +548,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 3 - i, sortedIndices[i], "#01-" + i); diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs index e795793e..b9aa53fd 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs @@ -75,7 +75,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// Ilutp instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(Ilutp ilutp, string methodName) + private static T GetMethod(ILUTPPreconditioner ilutp, string methodName) { var type = ilutp.GetType(); var methodInfo = type.GetMethod( @@ -94,7 +94,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// /// Ilutp instance. /// Upper triangle. - private static SparseMatrix GetUpperTriangle(Ilutp ilutp) + private static SparseMatrix GetUpperTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "UpperTriangle"); } @@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// /// Ilutp instance. /// Lower triangle. - private static SparseMatrix GetLowerTriangle(Ilutp ilutp) + private static SparseMatrix GetLowerTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "LowerTriangle"); } @@ -114,7 +114,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon ///
/// Ilutp instance. /// Pivots array. - private static int[] GetPivots(Ilutp ilutp) + private static int[] GetPivots(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "Pivots"); } @@ -139,9 +139,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// Create preconditioner (internal) ///
/// Ilutp instance. - private Ilutp InternalCreatePreconditioner() + private ILUTPPreconditioner InternalCreatePreconditioner() { - var result = new Ilutp + var result = new ILUTPPreconditioner { DropTolerance = _dropTolerance, FillLevel = _fillLevel, @@ -171,7 +171,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILUTPPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -243,7 +243,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 0.0, DropTolerance = 0, @@ -299,7 +299,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, @@ -336,7 +336,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon const int Size = 10; var newMatrix = CreateReverseUnitMatrix(Size); var vector = CreateStandardBcVector(Size); - var preconditioner = new Ilutp + var preconditioner = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs index 77704125..d6b9705b 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs @@ -49,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// IncompleteLU instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(IncompleteLU ilu, string methodName) + private static T GetMethod(ILU0Preconditioner ilu, string methodName) { var type = ilu.GetType(); var methodInfo = type.GetMethod( @@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon ///
/// IncompleteLU instance. /// Upper triangle. - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "UpperTriangle"); } @@ -78,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon ///
/// IncompleteLU instance. /// Lower triangle. - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "LowerTriangle"); } @@ -89,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new IncompleteLU(); + return new ILU0Preconditioner(); } /// @@ -101,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILU0Preconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -131,7 +131,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new IncompleteLU(); + var ilu = new ILU0Preconditioner(); ilu.Initialize(sparseMatrix); var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu)); for (var i = 0; i < sparseMatrix.RowCount; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs index ba972334..0e96356a 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs @@ -44,7 +44,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new Diagonal(); + return new DiagonalPreconditioner(); } /// @@ -56,7 +56,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(DiagonalPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs index ff91ed38..212473ae 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithIncreasingIntegerArray() { var sortedIndices = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -57,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithDecreasingIntegerArray() { var sortedIndices = new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithRandomIntegerArray() { var sortedIndices = new[] { 5, 2, 8, 6, 0, 4, 1, 7, 3, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -85,7 +85,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithDuplicateEntries() { var sortedIndices = new[] { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -126,7 +126,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit public void HeapSortWithSpecialConstructedIntegerArray() { var sortedIndices = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -137,7 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit } sortedIndices = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit } sortedIndices = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -159,7 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit } sortedIndices = new[] { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -193,7 +193,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -223,7 +223,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(i, sortedIndices[i], "#01-" + i); @@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { switch (i) @@ -316,7 +316,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -379,7 +379,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -404,7 +404,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -429,7 +429,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -454,7 +454,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -488,7 +488,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -518,7 +518,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 5; i++) { Assert.AreEqual(sortedIndices.Length - 5 - i, sortedIndices[i], "#01-" + i); @@ -548,7 +548,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 3 - i, sortedIndices[i], "#01-" + i); diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs index 0285aff6..f9ba3c90 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs @@ -73,7 +73,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// Ilutp instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(Ilutp ilutp, string methodName) + private static T GetMethod(ILUTPPreconditioner ilutp, string methodName) { var type = ilutp.GetType(); var methodInfo = type.GetMethod( @@ -92,7 +92,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// /// Ilutp instance. /// Upper triangle. - private static SparseMatrix GetUpperTriangle(Ilutp ilutp) + private static SparseMatrix GetUpperTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "UpperTriangle"); } @@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// /// Ilutp instance. /// Lower triangle. - private static SparseMatrix GetLowerTriangle(Ilutp ilutp) + private static SparseMatrix GetLowerTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "LowerTriangle"); } @@ -112,7 +112,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit ///
/// Ilutp instance. /// Pivots array. - private static int[] GetPivots(Ilutp ilutp) + private static int[] GetPivots(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "Pivots"); } @@ -137,9 +137,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// Create preconditioner (internal) ///
/// Ilutp instance. - private Ilutp InternalCreatePreconditioner() + private ILUTPPreconditioner InternalCreatePreconditioner() { - var result = new Ilutp + var result = new ILUTPPreconditioner { DropTolerance = _dropTolerance, FillLevel = _fillLevel, @@ -169,7 +169,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILUTPPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -240,7 +240,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 0.0, DropTolerance = 0, @@ -295,7 +295,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, @@ -331,7 +331,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit const int Size = 10; var newMatrix = CreateReverseUnitMatrix(Size); var vector = CreateStandardBcVector(Size); - var preconditioner = new Ilutp + var preconditioner = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, diff --git a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs index d32e2b9a..46608b66 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs @@ -47,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// IncompleteLU instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(IncompleteLU ilu, string methodName) + private static T GetMethod(ILU0Preconditioner ilu, string methodName) { var type = ilu.GetType(); var methodInfo = type.GetMethod( @@ -66,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit ///
/// IncompleteLU instance. /// Upper triangle. - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "UpperTriangle"); } @@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit ///
/// IncompleteLU instance. /// Lower triangle. - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "LowerTriangle"); } @@ -87,7 +87,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new IncompleteLU(); + return new ILU0Preconditioner(); } /// @@ -99,7 +99,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILU0Preconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -128,7 +128,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new IncompleteLU(); + var ilu = new ILU0Preconditioner(); ilu.Initialize(sparseMatrix); var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu)); for (var i = 0; i < sparseMatrix.RowCount; i++) diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs index f1f80a5f..e2e555ac 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs @@ -44,7 +44,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new Diagonal(); + return new DiagonalPreconditioner(); } /// @@ -56,7 +56,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(DiagonalPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs index c2088457..47d9dbbe 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs @@ -43,7 +43,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithIncreasingIntegerArray() { var sortedIndices = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -57,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithDecreasingIntegerArray() { var sortedIndices = new[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithRandomIntegerArray() { var sortedIndices = new[] { 5, 2, 8, 6, 0, 4, 1, 7, 3, 9 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -85,7 +85,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithDuplicateEntries() { var sortedIndices = new[] { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -126,7 +126,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit public void HeapSortWithSpecialConstructedIntegerArray() { var sortedIndices = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -137,7 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit } sortedIndices = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -148,7 +148,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit } sortedIndices = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -159,7 +159,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit } sortedIndices = new[] { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }; - IlutpElementSorter.SortIntegersDecreasing(sortedIndices); + ILUTPElementSorter.SortIntegersDecreasing(sortedIndices); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -193,7 +193,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -223,7 +223,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { Assert.AreEqual(i, sortedIndices[i], "#01-" + i); @@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { switch (i) @@ -316,7 +316,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -379,7 +379,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -404,7 +404,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -429,7 +429,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 0) @@ -454,7 +454,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length; i++) { if (i == 9) @@ -488,7 +488,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(4, sortedIndices.Length - 1, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 1 - i, sortedIndices[i], "#01-" + i); @@ -518,7 +518,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 5, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 5; i++) { Assert.AreEqual(sortedIndices.Length - 5 - i, sortedIndices[i], "#01-" + i); @@ -548,7 +548,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sortedIndices[i] = i; } - IlutpElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); + ILUTPElementSorter.SortDoubleIndicesDecreasing(2, sortedIndices.Length - 3, sortedIndices, values); for (var i = 0; i < sortedIndices.Length - 4; i++) { Assert.AreEqual(sortedIndices.Length - 3 - i, sortedIndices[i], "#01-" + i); diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs index 1978db52..4c33d82d 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IlutpTest.cs @@ -73,7 +73,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// Ilutp instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(Ilutp ilutp, string methodName) + private static T GetMethod(ILUTPPreconditioner ilutp, string methodName) { var type = ilutp.GetType(); var methodInfo = type.GetMethod( @@ -92,7 +92,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// /// Ilutp instance. /// Upper triangle. - private static SparseMatrix GetUpperTriangle(Ilutp ilutp) + private static SparseMatrix GetUpperTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "UpperTriangle"); } @@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// /// Ilutp instance. /// Lower triangle. - private static SparseMatrix GetLowerTriangle(Ilutp ilutp) + private static SparseMatrix GetLowerTriangle(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "LowerTriangle"); } @@ -112,7 +112,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit ///
/// Ilutp instance. /// Pivots array. - private static int[] GetPivots(Ilutp ilutp) + private static int[] GetPivots(ILUTPPreconditioner ilutp) { return GetMethod(ilutp, "Pivots"); } @@ -137,9 +137,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// Create preconditioner (internal) ///
/// Ilutp instance. - private Ilutp InternalCreatePreconditioner() + private ILUTPPreconditioner InternalCreatePreconditioner() { - var result = new Ilutp + var result = new ILUTPPreconditioner { DropTolerance = _dropTolerance, FillLevel = _fillLevel, @@ -169,7 +169,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(Ilutp), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILUTPPreconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -240,7 +240,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 0.0, DropTolerance = 0, @@ -295,7 +295,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new Ilutp + var ilu = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, @@ -331,7 +331,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit const int Size = 10; var newMatrix = CreateReverseUnitMatrix(Size); var vector = CreateStandardBcVector(Size); - var preconditioner = new Ilutp + var preconditioner = new ILUTPPreconditioner { PivotTolerance = 1.0, DropTolerance = 0, diff --git a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs index 26118b05..9d6462ab 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs @@ -47,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// IncompleteLU instance. /// Method name. /// Result of the method invocation. - private static T GetMethod(IncompleteLU ilu, string methodName) + private static T GetMethod(ILU0Preconditioner ilu, string methodName) { var type = ilu.GetType(); var methodInfo = type.GetMethod( @@ -66,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// /// IncompleteLU instance. /// Upper triangle. - private static Matrix GetUpperTriangle(IncompleteLU ilu) + private static Matrix GetUpperTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "UpperTriangle"); } @@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// /// IncompleteLU instance. /// Lower triangle. - private static Matrix GetLowerTriangle(IncompleteLU ilu) + private static Matrix GetLowerTriangle(ILU0Preconditioner ilu) { return GetMethod>(ilu, "LowerTriangle"); } @@ -87,7 +87,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// New preconditioner instance. internal override IPreconditioner CreatePreconditioner() { - return new IncompleteLU(); + return new ILU0Preconditioner(); } /// @@ -99,7 +99,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit /// Result vector. protected override void CheckResult(IPreconditioner preconditioner, SparseMatrix matrix, Vector vector, Vector result) { - Assert.AreEqual(typeof(IncompleteLU), preconditioner.GetType(), "#01"); + Assert.AreEqual(typeof(ILU0Preconditioner), preconditioner.GetType(), "#01"); // Compute M * result = product // compare vector and product. Should be equal @@ -128,7 +128,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit sparseMatrix[2, 0] = 6; sparseMatrix[2, 1] = 8; sparseMatrix[2, 2] = 9; - var ilu = new IncompleteLU(); + var ilu = new ILU0Preconditioner(); ilu.Initialize(sparseMatrix); var original = GetLowerTriangle(ilu).Multiply(GetUpperTriangle(ilu));