Browse Source

LA: Refactor away the remaining usages of the non-generic base classes

optimization-1
Christoph Ruegg 13 years ago
parent
commit
7ec72961a9
  1. 2
      src/Examples/LinearAlgebra/MatrixRowColumnOperations.cs
  2. 16
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs
  3. 32
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs
  4. 22
      src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs
  5. 16
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs
  6. 32
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs
  7. 22
      src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs
  8. 24
      src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs
  9. 32
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs
  10. 22
      src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs
  11. 20
      src/UnitTests/LinearAlgebraTests/Complex/DenseMatrixTests.cs
  12. 22
      src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs
  13. 12
      src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs
  14. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs
  15. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs
  16. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs
  17. 14
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs
  18. 2
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs
  19. 8
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs
  20. 10
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs
  21. 8
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs
  22. 22
      src/UnitTests/LinearAlgebraTests/Complex/SparseMatrixTests.cs
  23. 11
      src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrixTests.cs
  24. 22
      src/UnitTests/LinearAlgebraTests/Complex32/DenseMatrixTests.cs
  25. 24
      src/UnitTests/LinearAlgebraTests/Complex32/DiagonalMatrixTests.cs
  26. 12
      src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs
  27. 14
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/BiCgStabTest.cs
  28. 14
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/GpBiCgTest.cs
  29. 14
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/MlkBiCgStabTest.cs
  30. 14
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Iterative/TFQMRTest.cs
  31. 2
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs
  32. 16
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs
  33. 8
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs
  34. 10
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs
  35. 10
      src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs
  36. 24
      src/UnitTests/LinearAlgebraTests/Complex32/SparseMatrixTests.cs
  37. 13
      src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrixTests.cs
  38. 21
      src/UnitTests/LinearAlgebraTests/Double/DenseMatrixTests.cs
  39. 14
      src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs
  40. 13
      src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs
  41. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/BiCgStabTest.cs
  42. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/GpBiCgTest.cs
  43. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/MlkBiCgStabTest.cs
  44. 14
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Iterative/TFQMRTest.cs
  45. 2
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs
  46. 16
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs
  47. 8
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs
  48. 10
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs
  49. 10
      src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs
  50. 23
      src/UnitTests/LinearAlgebraTests/Double/SparseMatrixTests.cs
  51. 12
      src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrixTests.cs
  52. 21
      src/UnitTests/LinearAlgebraTests/Single/DenseMatrixTests.cs
  53. 23
      src/UnitTests/LinearAlgebraTests/Single/DiagonalMatrixTests.cs
  54. 12
      src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs
  55. 14
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/BiCgStabTest.cs
  56. 14
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/GpBiCgTest.cs
  57. 14
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/MlkBiCgStabTest.cs
  58. 14
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Iterative/TFQMRTest.cs
  59. 2
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs
  60. 16
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs
  61. 8
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs
  62. 4
      src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs
  63. 23
      src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs
  64. 12
      src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrixTests.cs

2
src/Examples/LinearAlgebra/MatrixRowColumnOperations.cs

@ -101,7 +101,7 @@ namespace Examples.LinearAlgebraExamples
Console.WriteLine(); Console.WriteLine();
// 3. Set column values // 3. Set column values
matrix.SetColumn(2, (Vector)vector); matrix.SetColumn(2, vector);
Console.WriteLine(@"3. Set column values"); Console.WriteLine(@"3. Set column values");
Console.WriteLine(matrix.ToString("#0.00\t", formatProvider)); Console.WriteLine(matrix.ToString("#0.00\t", formatProvider));
Console.WriteLine(); Console.WriteLine();

16
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs

@ -286,7 +286,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// Compute r_0 = b - Ax_0 for some initial guess x_0 // Compute r_0 = b - Ax_0 for some initial guess x_0
// In this case we take x_0 = vector // In this case we take x_0 = vector
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, result, input); CalculateTrueResidual(matrix, residuals, result, input);
// Choose r~ (for example, r~ = r_0) // Choose r~ (for example, r~ = r_0)
@ -295,13 +295,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// create seven temporary vectors needed to hold temporary // create seven temporary vectors needed to hold temporary
// coefficients. All vectors are mangled in each iteration. // coefficients. All vectors are mangled in each iteration.
// These are defined here to prevent stressing the garbage collector // These are defined here to prevent stressing the garbage collector
Vector vecP = new DenseVector(residuals.Count); var vecP = new DenseVector(residuals.Count);
Vector vecPdash = new DenseVector(residuals.Count); var vecPdash = new DenseVector(residuals.Count);
Vector nu = new DenseVector(residuals.Count); var nu = new DenseVector(residuals.Count);
Vector vecS = new DenseVector(residuals.Count); var vecS = new DenseVector(residuals.Count);
Vector vecSdash = new DenseVector(residuals.Count); var vecSdash = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
// create some temporary double variables that are needed // create some temporary double variables that are needed
// to hold values in between iterations // to hold values in between iterations

32
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs

@ -329,11 +329,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// x_0 is initial guess // x_0 is initial guess
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars // Define the temporary scalars
@ -341,26 +341,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// Define the temporary vectors // Define the temporary vectors
// rDash_0 = r_0 // rDash_0 = r_0
Vector rdash = DenseVector.OfVector(residuals); var rdash = DenseVector.OfVector(residuals);
// t_-1 = 0 // t_-1 = 0
Vector t = new DenseVector(residuals.Count); var t = new DenseVector(residuals.Count);
Vector t0 = new DenseVector(residuals.Count); var t0 = new DenseVector(residuals.Count);
// w_-1 = 0 // w_-1 = 0
Vector w = new DenseVector(residuals.Count); var w = new DenseVector(residuals.Count);
// Define the remaining temporary vectors // Define the remaining temporary vectors
Vector c = new DenseVector(residuals.Count); var c = new DenseVector(residuals.Count);
Vector p = new DenseVector(residuals.Count); var p = new DenseVector(residuals.Count);
Vector s = new DenseVector(residuals.Count); var s = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector y = new DenseVector(residuals.Count); var y = new DenseVector(residuals.Count);
Vector z = new DenseVector(residuals.Count); var z = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector temp3 = new DenseVector(residuals.Count); var temp3 = new DenseVector(residuals.Count);
// for (k = 0, 1, .... ) // for (k = 0, 1, .... )
var iterationNumber = 0; var iterationNumber = 0;

22
src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs

@ -349,7 +349,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// Choose an initial guess x_0 // Choose an initial guess x_0
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// Choose k vectors q_1, q_2, ..., q_k // Choose k vectors q_1, q_2, ..., q_k
// Build a new set if: // Build a new set if:
@ -378,24 +378,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary values // Define the temporary values
var c = new Complex[k]; var c = new Complex[k];
// Define the temporary vectors // Define the temporary vectors
Vector gtemp = new DenseVector(residuals.Count); var gtemp = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector utemp = new DenseVector(residuals.Count); var utemp = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp1 = new DenseVector(residuals.Count); var temp1 = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector zd = new DenseVector(residuals.Count); var zd = new DenseVector(residuals.Count);
Vector zg = new DenseVector(residuals.Count); var zg = new DenseVector(residuals.Count);
Vector zw = new DenseVector(residuals.Count); var zw = new DenseVector(residuals.Count);
var d = CreateVectorArray(_startingVectors.Count, residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count);

16
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs

@ -280,7 +280,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// Compute r_0 = b - Ax_0 for some initial guess x_0 // Compute r_0 = b - Ax_0 for some initial guess x_0
// In this case we take x_0 = vector // In this case we take x_0 = vector
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, result, input); CalculateTrueResidual(matrix, residuals, result, input);
// Choose r~ (for example, r~ = r_0) // Choose r~ (for example, r~ = r_0)
@ -289,13 +289,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// create seven temporary vectors needed to hold temporary // create seven temporary vectors needed to hold temporary
// coefficients. All vectors are mangled in each iteration. // coefficients. All vectors are mangled in each iteration.
// These are defined here to prevent stressing the garbage collector // These are defined here to prevent stressing the garbage collector
Vector vecP = new DenseVector(residuals.Count); var vecP = new DenseVector(residuals.Count);
Vector vecPdash = new DenseVector(residuals.Count); var vecPdash = new DenseVector(residuals.Count);
Vector nu = new DenseVector(residuals.Count); var nu = new DenseVector(residuals.Count);
Vector vecS = new DenseVector(residuals.Count); var vecS = new DenseVector(residuals.Count);
Vector vecSdash = new DenseVector(residuals.Count); var vecSdash = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
// create some temporary float variables that are needed // create some temporary float variables that are needed
// to hold values in between iterations // to hold values in between iterations

32
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs

@ -328,11 +328,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// x_0 is initial guess // x_0 is initial guess
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars // Define the temporary scalars
@ -340,26 +340,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// Define the temporary vectors // Define the temporary vectors
// rDash_0 = r_0 // rDash_0 = r_0
Vector rdash = DenseVector.OfVector(residuals); var rdash = DenseVector.OfVector(residuals);
// t_-1 = 0 // t_-1 = 0
Vector t = new DenseVector(residuals.Count); var t = new DenseVector(residuals.Count);
Vector t0 = new DenseVector(residuals.Count); var t0 = new DenseVector(residuals.Count);
// w_-1 = 0 // w_-1 = 0
Vector w = new DenseVector(residuals.Count); var w = new DenseVector(residuals.Count);
// Define the remaining temporary vectors // Define the remaining temporary vectors
Vector c = new DenseVector(residuals.Count); var c = new DenseVector(residuals.Count);
Vector p = new DenseVector(residuals.Count); var p = new DenseVector(residuals.Count);
Vector s = new DenseVector(residuals.Count); var s = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector y = new DenseVector(residuals.Count); var y = new DenseVector(residuals.Count);
Vector z = new DenseVector(residuals.Count); var z = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector temp3 = new DenseVector(residuals.Count); var temp3 = new DenseVector(residuals.Count);
// for (k = 0, 1, .... ) // for (k = 0, 1, .... )
var iterationNumber = 0; var iterationNumber = 0;

22
src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs

@ -348,7 +348,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// Choose an initial guess x_0 // Choose an initial guess x_0
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// Choose k vectors q_1, q_2, ..., q_k // Choose k vectors q_1, q_2, ..., q_k
// Build a new set if: // Build a new set if:
@ -377,24 +377,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary values // Define the temporary values
var c = new Complex32[k]; var c = new Complex32[k];
// Define the temporary vectors // Define the temporary vectors
Vector gtemp = new DenseVector(residuals.Count); var gtemp = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector utemp = new DenseVector(residuals.Count); var utemp = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp1 = new DenseVector(residuals.Count); var temp1 = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector zd = new DenseVector(residuals.Count); var zd = new DenseVector(residuals.Count);
Vector zg = new DenseVector(residuals.Count); var zg = new DenseVector(residuals.Count);
Vector zw = new DenseVector(residuals.Count); var zw = new DenseVector(residuals.Count);
var d = CreateVectorArray(_startingVectors.Count, residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count);

24
src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs

@ -352,7 +352,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// Choose an initial guess x_0 // Choose an initial guess x_0
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// Choose k vectors q_1, q_2, ..., q_k // Choose k vectors q_1, q_2, ..., q_k
// Build a new set if: // Build a new set if:
@ -381,24 +381,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars // Define the temporary scalars
var c = new double[k]; var c = new double[k];
// Define the temporary vectors // Define the temporary vectors
Vector gtemp = new DenseVector(residuals.Count); var gtemp = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector utemp = new DenseVector(residuals.Count); var utemp = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp1 = new DenseVector(residuals.Count); var temp1 = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector zd = new DenseVector(residuals.Count); var zd = new DenseVector(residuals.Count);
Vector zg = new DenseVector(residuals.Count); var zg = new DenseVector(residuals.Count);
Vector zw = new DenseVector(residuals.Count); var zw = new DenseVector(residuals.Count);
var d = CreateVectorArray(_startingVectors.Count, residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count);
@ -793,7 +793,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++) for (var column = 0; column < input.ColumnCount; column++)
{ {
var solution = Solve(matrix, (Vector)input.Column(column)); var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed()) foreach (var element in solution.EnumerateNonZeroIndexed())
{ {
result.At(element.Item1, column, element.Item2); result.At(element.Item1, column, element.Item2);

32
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs

@ -326,11 +326,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// x_0 is initial guess // x_0 is initial guess
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars // Define the temporary scalars
@ -338,26 +338,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// Define the temporary vectors // Define the temporary vectors
// rDash_0 = r_0 // rDash_0 = r_0
Vector rdash = DenseVector.OfVector(residuals); var rdash = DenseVector.OfVector(residuals);
// t_-1 = 0 // t_-1 = 0
Vector t = new DenseVector(residuals.Count); var t = new DenseVector(residuals.Count);
Vector t0 = new DenseVector(residuals.Count); var t0 = new DenseVector(residuals.Count);
// w_-1 = 0 // w_-1 = 0
Vector w = new DenseVector(residuals.Count); var w = new DenseVector(residuals.Count);
// Define the remaining temporary vectors // Define the remaining temporary vectors
Vector c = new DenseVector(residuals.Count); var c = new DenseVector(residuals.Count);
Vector p = new DenseVector(residuals.Count); var p = new DenseVector(residuals.Count);
Vector s = new DenseVector(residuals.Count); var s = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector y = new DenseVector(residuals.Count); var y = new DenseVector(residuals.Count);
Vector z = new DenseVector(residuals.Count); var z = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector temp3 = new DenseVector(residuals.Count); var temp3 = new DenseVector(residuals.Count);
// for (k = 0, 1, .... ) // for (k = 0, 1, .... )
var iterationNumber = 0; var iterationNumber = 0;
@ -628,7 +628,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
for (var column = 0; column < input.ColumnCount; column++) for (var column = 0; column < input.ColumnCount; column++)
{ {
var solution = Solve(matrix, (Vector) input.Column(column)); var solution = Solve(matrix, input.Column(column));
foreach (var element in solution.EnumerateNonZeroIndexed()) foreach (var element in solution.EnumerateNonZeroIndexed())
{ {
result.At(element.Item1, column, element.Item2); result.At(element.Item1, column, element.Item2);

22
src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs

@ -351,7 +351,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// Choose an initial guess x_0 // Choose an initial guess x_0
// Take x_0 = 0 // Take x_0 = 0
Vector xtemp = new DenseVector(input.Count); var xtemp = new DenseVector(input.Count);
// Choose k vectors q_1, q_2, ..., q_k // Choose k vectors q_1, q_2, ..., q_k
// Build a new set if: // Build a new set if:
@ -380,24 +380,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative
// r_0 = b - Ax_0 // r_0 = b - Ax_0
// This is basically a SAXPY so it could be made a lot faster // This is basically a SAXPY so it could be made a lot faster
Vector residuals = new DenseVector(matrix.RowCount); var residuals = new DenseVector(matrix.RowCount);
CalculateTrueResidual(matrix, residuals, xtemp, input); CalculateTrueResidual(matrix, residuals, xtemp, input);
// Define the temporary scalars // Define the temporary scalars
var c = new float[k]; var c = new float[k];
// Define the temporary vectors // Define the temporary vectors
Vector gtemp = new DenseVector(residuals.Count); var gtemp = new DenseVector(residuals.Count);
Vector u = new DenseVector(residuals.Count); var u = new DenseVector(residuals.Count);
Vector utemp = new DenseVector(residuals.Count); var utemp = new DenseVector(residuals.Count);
Vector temp = new DenseVector(residuals.Count); var temp = new DenseVector(residuals.Count);
Vector temp1 = new DenseVector(residuals.Count); var temp1 = new DenseVector(residuals.Count);
Vector temp2 = new DenseVector(residuals.Count); var temp2 = new DenseVector(residuals.Count);
Vector zd = new DenseVector(residuals.Count); var zd = new DenseVector(residuals.Count);
Vector zg = new DenseVector(residuals.Count); var zg = new DenseVector(residuals.Count);
Vector zw = new DenseVector(residuals.Count); var zw = new DenseVector(residuals.Count);
var d = CreateVectorArray(_startingVectors.Count, residuals.Count); var d = CreateVectorArray(_startingVectors.Count, residuals.Count);

20
src/UnitTests/LinearAlgebraTests/Complex/DenseMatrixTests.cs

@ -28,13 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using System;
using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using LinearAlgebra.Complex;
using NUnit.Framework;
/// <summary> /// <summary>
/// Dense matrix tests. /// Dense matrix tests.
@ -47,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex> CreateMatrix(int rows, int columns)
{ {
return new DenseMatrix(rows, columns); return new DenseMatrix(rows, columns);
} }
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex[,] data) protected override Matrix<Complex> CreateMatrix(Complex[,] data)
{ {
return DenseMatrix.OfArray(data); return DenseMatrix.OfArray(data);
} }
@ -68,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -78,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex[] data) protected override Vector<Complex> CreateVector(Complex[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }
@ -89,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex>>
{ {
{"Singular3x3", new DenseMatrix(3, 3, new[] {new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1)})}, {"Singular3x3", new DenseMatrix(3, 3, new[] {new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1)})},
{"Square3x3", new DenseMatrix(3, 3, new[] {new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1)})}, {"Square3x3", new DenseMatrix(3, 3, new[] {new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1)})},

22
src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs

@ -28,13 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using System;
using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using LinearAlgebra.Complex;
using NUnit.Framework;
/// <summary> /// <summary>
/// Diagonal matrix tests. /// Diagonal matrix tests.
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{"Wide2x3", new[,] {{new Complex(-1.1, 1), Complex.Zero, Complex.Zero}, {Complex.Zero, new Complex(1.1, 1), Complex.Zero}}} {"Wide2x3", new[,] {{new Complex(-1.1, 1), Complex.Zero, Complex.Zero}, {Complex.Zero, new Complex(1.1, 1), Complex.Zero}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<Complex>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));
@ -70,7 +72,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex> CreateMatrix(int rows, int columns)
{ {
return new DiagonalMatrix(rows, columns); return new DiagonalMatrix(rows, columns);
} }
@ -80,7 +82,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex[,] data) protected override Matrix<Complex> CreateMatrix(Complex[,] data)
{ {
return DiagonalMatrix.OfArray(data); return DiagonalMatrix.OfArray(data);
} }
@ -91,7 +93,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -101,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex[] data) protected override Vector<Complex> CreateVector(Complex[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -112,7 +114,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[Test] [Test]
public void CanCreateMatrixFromDiagonalArray() public void CanCreateMatrixFromDiagonalArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex>>
{ {
{"Singular3x3", new DiagonalMatrix(3, 3, new[] {new Complex(1.0, 1), Complex.Zero, new Complex(3.0, 1)})}, {"Singular3x3", new DiagonalMatrix(3, 3, new[] {new Complex(1.0, 1), Complex.Zero, new Complex(3.0, 1)})},
{"Square3x3", new DiagonalMatrix(3, 3, new[] {new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.6, 1)})}, {"Square3x3", new DiagonalMatrix(3, 3, new[] {new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.6, 1)})},

12
src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs

@ -52,7 +52,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <summary> /// <summary>
/// Gets or sets test matrices instances to use. /// Gets or sets test matrices instances to use.
/// </summary> /// </summary>
protected Dictionary<string, Matrix> TestMatrices { get; set; } protected Dictionary<string, Matrix<Complex>> TestMatrices { get; set; }
/// <summary> /// <summary>
/// Creates a matrix for the given number of rows and columns. /// Creates a matrix for the given number of rows and columns.
@ -60,14 +60,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected abstract Matrix CreateMatrix(int rows, int columns); protected abstract Matrix<Complex> CreateMatrix(int rows, int columns);
/// <summary> /// <summary>
/// Creates a matrix from a 2D array. /// Creates a matrix from a 2D array.
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected abstract Matrix CreateMatrix(Complex[,] data); protected abstract Matrix<Complex> CreateMatrix(Complex[,] data);
/// <summary> /// <summary>
/// Creates a vector of the given size. /// Creates a vector of the given size.
@ -75,14 +75,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(int size); protected abstract Vector<Complex> CreateVector(int size);
/// <summary> /// <summary>
/// Creates a vector from an array. /// Creates a vector from an array.
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(Complex[] data); protected abstract Vector<Complex> CreateVector(Complex[] data);
/// <summary> /// <summary>
/// Setup test matrices. /// Setup test matrices.
@ -101,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{"Symmetric3x3", new[,] {{Complex.One, 2.0, 3.0}, {2.0, 2.0, 0.0}, {3.0, 0.0, 3.0}}} {"Symmetric3x3", new[,] {{Complex.One, 2.0, 3.0}, {2.0, 2.0, 0.0}, {3.0, 0.0, 3.0}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<Complex>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));

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

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -89,10 +89,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex.One); var y = DenseVector.Create(matrix.RowCount, i => Complex.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -131,13 +131,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(new Complex(Math.PI, Math.PI), matrix); matrix.Multiply(new Complex(Math.PI, Math.PI), matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex.One); var y = DenseVector.Create(matrix.RowCount, i => Complex.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -215,7 +215,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex.One); var y = DenseVector.Create(matrix.RowCount, i => Complex.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

2
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/DiagonalTest.cs

@ -66,7 +66,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)

8
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs

@ -179,7 +179,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)
{ {
@ -205,7 +205,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -226,7 +226,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -347,7 +347,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
FillLevel = 10 FillLevel = 10
}; };
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }

10
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs

@ -72,9 +72,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Upper triangle.</returns> /// <returns>Upper triangle.</returns>
private static Matrix GetUpperTriangle(IncompleteLU ilu) private static Matrix<Complex> GetUpperTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "UpperTriangle"); return GetMethod<Matrix<Complex>>(ilu, "UpperTriangle");
} }
/// <summary> /// <summary>
@ -82,9 +82,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Lower triangle.</returns> /// <returns>Lower triangle.</returns>
private static Matrix GetLowerTriangle(IncompleteLU ilu) private static Matrix<Complex> GetLowerTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "LowerTriangle"); return GetMethod<Matrix<Complex>>(ilu, "LowerTriangle");
} }
/// <summary> /// <summary>
@ -109,7 +109,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)

8
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/PreConditionerTest.cs

@ -70,9 +70,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
/// </summary> /// </summary>
/// <param name="size">Size of the vector.</param> /// <param name="size">Size of the vector.</param>
/// <returns>New vector.</returns> /// <returns>New vector.</returns>
protected Vector CreateStandardBcVector(int size) protected DenseVector CreateStandardBcVector(int size)
{ {
Vector vector = new DenseVector(size); var vector = new DenseVector(size);
for (var i = 0; i < size; i++) for (var i = 0; i < size; i++)
{ {
vector[i] = i + 1; vector[i] = i + 1;
@ -164,7 +164,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count + 10); var result = new DenseVector(vector.Count + 10);
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result));
} }
@ -181,7 +181,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = null; Vector<Complex> result = null;
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result));
} }

22
src/UnitTests/LinearAlgebraTests/Complex/SparseMatrixTests.cs

@ -28,12 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using LinearAlgebra.Complex;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Numerics; using System.Numerics;
/// <summary> /// <summary>
@ -47,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex> CreateMatrix(int rows, int columns)
{ {
return new SparseMatrix(rows, columns); return new SparseMatrix(rows, columns);
} }
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex[,] data) protected override Matrix<Complex> CreateMatrix(Complex[,] data)
{ {
return SparseMatrix.OfArray(data); return SparseMatrix.OfArray(data);
} }
@ -68,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -78,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex[] data) protected override Vector<Complex> CreateVector(Complex[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -89,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex>>
{ {
{"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1)})}, {"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1)})},
{"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1)})}, {"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1)})},
@ -185,7 +187,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
var matrix = new SparseMatrix(500, 1000); var matrix = new SparseMatrix(500, 1000);
var nonzero = 0; var nonzero = 0;
var rnd = new Random(); var rnd = new System.Random();
for (var i = 0; i < matrix.RowCount; i++) for (var i = 0; i < matrix.RowCount; i++)
{ {

11
src/UnitTests/LinearAlgebraTests/Complex/UserDefinedMatrixTests.cs

@ -24,10 +24,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.LinearAlgebra;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using System.Numerics; using System.Numerics;
using LinearAlgebra.Complex;
/// <summary> /// <summary>
/// Test class for user-defined matrix. /// Test class for user-defined matrix.
@ -40,7 +41,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex> CreateMatrix(int rows, int columns)
{ {
return new UserDefinedMatrix(rows, columns); return new UserDefinedMatrix(rows, columns);
} }
@ -50,7 +51,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex[,] data) protected override Matrix<Complex> CreateMatrix(Complex[,] data)
{ {
return new UserDefinedMatrix(data); return new UserDefinedMatrix(data);
} }
@ -61,7 +62,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex> CreateVector(int size)
{ {
return new UserDefinedVector(size); return new UserDefinedVector(size);
} }
@ -71,7 +72,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex[] data) protected override Vector<Complex> CreateVector(Complex[] data)
{ {
return new UserDefinedVector(data); return new UserDefinedVector(data);
} }

22
src/UnitTests/LinearAlgebraTests/Complex32/DenseMatrixTests.cs

@ -28,13 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using LinearAlgebra.Complex32; using Numerics;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Complex32 = Numerics.Complex32;
/// <summary> /// <summary>
/// Dense matrix tests. /// Dense matrix tests.
@ -47,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex32> CreateMatrix(int rows, int columns)
{ {
return new DenseMatrix(rows, columns); return new DenseMatrix(rows, columns);
} }
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex32[,] data) protected override Matrix<Complex32> CreateMatrix(Complex32[,] data)
{ {
return DenseMatrix.OfArray(data); return DenseMatrix.OfArray(data);
} }
@ -68,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex32> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -78,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex32[] data) protected override Vector<Complex32> CreateVector(Complex32[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }
@ -89,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex32>>
{ {
{"Singular3x3", new DenseMatrix(3, 3, new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1)})}, {"Singular3x3", new DenseMatrix(3, 3, new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1)})},
{"Square3x3", new DenseMatrix(3, 3, new[] {new Complex32(-1.1f, 1), Complex32.Zero, new Complex32(-4.4f, 1), new Complex32(-2.2f, 1), new Complex32(1.1f, 1), new Complex32(5.5f, 1), new Complex32(-3.3f, 1), new Complex32(2.2f, 1), new Complex32(6.6f, 1)})}, {"Square3x3", new DenseMatrix(3, 3, new[] {new Complex32(-1.1f, 1), Complex32.Zero, new Complex32(-4.4f, 1), new Complex32(-2.2f, 1), new Complex32(1.1f, 1), new Complex32(5.5f, 1), new Complex32(-3.3f, 1), new Complex32(2.2f, 1), new Complex32(6.6f, 1)})},

24
src/UnitTests/LinearAlgebraTests/Complex32/DiagonalMatrixTests.cs

@ -28,13 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using LinearAlgebra.Complex32; using Numerics;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Complex32 = Numerics.Complex32;
/// <summary> /// <summary>
/// Diagonal matrix tests. /// Diagonal matrix tests.
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{"Wide2x3", new[,] {{new Complex32(-1.1f, 1), Complex32.Zero, Complex32.Zero}, {Complex32.Zero, new Complex32(1.1f, 1), Complex32.Zero}}} {"Wide2x3", new[,] {{new Complex32(-1.1f, 1), Complex32.Zero, Complex32.Zero}, {Complex32.Zero, new Complex32(1.1f, 1), Complex32.Zero}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<Complex32>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));
@ -70,7 +72,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex32> CreateMatrix(int rows, int columns)
{ {
return new DiagonalMatrix(rows, columns); return new DiagonalMatrix(rows, columns);
} }
@ -80,7 +82,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex32[,] data) protected override Matrix<Complex32> CreateMatrix(Complex32[,] data)
{ {
return DiagonalMatrix.OfArray(data); return DiagonalMatrix.OfArray(data);
} }
@ -91,7 +93,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex32> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -101,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex32[] data) protected override Vector<Complex32> CreateVector(Complex32[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -112,7 +114,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[Test] [Test]
public void CanCreateMatrixFromDiagonalArray() public void CanCreateMatrixFromDiagonalArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex32>>
{ {
{"Singular3x3", new DiagonalMatrix(3, 3, new[] {new Complex32(1.0f, 1), Complex32.Zero, new Complex32(3.0f, 1)})}, {"Singular3x3", new DiagonalMatrix(3, 3, new[] {new Complex32(1.0f, 1), Complex32.Zero, new Complex32(3.0f, 1)})},
{"Square3x3", new DiagonalMatrix(3, 3, new[] {new Complex32(-1.1f, 1), new Complex32(1.1f, 1), new Complex32(6.6f, 1)})}, {"Square3x3", new DiagonalMatrix(3, 3, new[] {new Complex32(-1.1f, 1), new Complex32(1.1f, 1), new Complex32(6.6f, 1)})},

12
src/UnitTests/LinearAlgebraTests/Complex32/MatrixLoader.cs

@ -52,7 +52,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <summary> /// <summary>
/// Gets or sets test matrices instances to use. /// Gets or sets test matrices instances to use.
/// </summary> /// </summary>
protected Dictionary<string, Matrix> TestMatrices { get; set; } protected Dictionary<string, Matrix<Complex32>> TestMatrices { get; set; }
/// <summary> /// <summary>
/// Creates a matrix for the given number of rows and columns. /// Creates a matrix for the given number of rows and columns.
@ -60,14 +60,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected abstract Matrix CreateMatrix(int rows, int columns); protected abstract Matrix<Complex32> CreateMatrix(int rows, int columns);
/// <summary> /// <summary>
/// Creates a matrix from a 2D array. /// Creates a matrix from a 2D array.
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected abstract Matrix CreateMatrix(Complex32[,] data); protected abstract Matrix<Complex32> CreateMatrix(Complex32[,] data);
/// <summary> /// <summary>
/// Creates a vector of the given size. /// Creates a vector of the given size.
@ -75,14 +75,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(int size); protected abstract Vector<Complex32> CreateVector(int size);
/// <summary> /// <summary>
/// Creates a vector from an array. /// Creates a vector from an array.
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(Complex32[] data); protected abstract Vector<Complex32> CreateVector(Complex32[] data);
/// <summary> /// <summary>
/// Setup test matrices. /// Setup test matrices.
@ -101,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{"Symmetric3x3", new[,] {{Complex32.One, 2.0f, 3.0f}, {2.0f, 2.0f, 0.0f}, {3.0f, 0.0f, 3.0f}}} {"Symmetric3x3", new[,] {{Complex32.One, 2.0f, 3.0f}, {2.0f, 2.0f, 0.0f}, {3.0f, 0.0f, 3.0f}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<Complex32>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));

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

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -76,7 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -89,10 +89,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex32.One); var y = DenseVector.Create(matrix.RowCount, i => Complex32.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -131,13 +131,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(new Complex32((float) Math.PI, (float) Math.PI), matrix); matrix.Multiply(new Complex32((float) Math.PI, (float) Math.PI), matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex32.One); var y = DenseVector.Create(matrix.RowCount, i => Complex32.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -215,7 +215,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => Complex32.One); var y = DenseVector.Create(matrix.RowCount, i => Complex32.One);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Iterat
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

2
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/DiagonalTest.cs

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)
{ {

16
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IluptElementSorterTest.cs

@ -177,7 +177,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithIncreasingDoubleArray() public void HeapSortWithIncreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -207,7 +207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithDecreasingDoubleArray() public void HeapSortWithDecreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 9; values[0] = 9;
values[1] = 8; values[1] = 8;
values[2] = 7; values[2] = 7;
@ -237,7 +237,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithRandomDoubleArray() public void HeapSortWithRandomDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 5; values[0] = 5;
values[1] = 2; values[1] = 2;
values[2] = 8; values[2] = 8;
@ -299,7 +299,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithDuplicateDoubleEntries() public void HeapSortWithDuplicateDoubleEntries()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 1; values[0] = 1;
values[1] = 1; values[1] = 1;
values[2] = 1; values[2] = 1;
@ -363,7 +363,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithSpecialConstructedDoubleArray() public void HeapSortWithSpecialConstructedDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 0; values[1] = 0;
values[2] = 0; values[2] = 0;
@ -472,7 +472,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithIncreasingDoubleArrayWithLowerBound() public void HeapSortWithIncreasingDoubleArrayWithLowerBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -502,7 +502,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithIncreasingDoubleArrayWithUpperBound() public void HeapSortWithIncreasingDoubleArrayWithUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -532,7 +532,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;

8
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IlutpTest.cs

@ -174,7 +174,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)
{ {
@ -200,7 +200,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -221,7 +221,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -342,7 +342,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
FillLevel = 10 FillLevel = 10
}; };
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }

10
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/IncompleteLUTest.cs

@ -67,9 +67,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Upper triangle.</returns> /// <returns>Upper triangle.</returns>
private static Matrix GetUpperTriangle(IncompleteLU ilu) private static Matrix<Complex32> GetUpperTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "UpperTriangle"); return GetMethod<Matrix<Complex32>>(ilu, "UpperTriangle");
} }
/// <summary> /// <summary>
@ -77,9 +77,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Lower triangle.</returns> /// <returns>Lower triangle.</returns>
private static Matrix GetLowerTriangle(IncompleteLU ilu) private static Matrix<Complex32> GetLowerTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "LowerTriangle"); return GetMethod<Matrix<Complex32>>(ilu, "LowerTriangle");
} }
/// <summary> /// <summary>
@ -104,7 +104,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)

10
src/UnitTests/LinearAlgebraTests/Complex32/Solvers/Preconditioners/PreConditionerTest.cs

@ -56,7 +56,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
{ {
matrix[i, i] = 2; matrix[i, i] = 2;
} }
return matrix; return matrix;
} }
@ -65,14 +64,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
/// </summary> /// </summary>
/// <param name="size">Size of the vector.</param> /// <param name="size">Size of the vector.</param>
/// <returns>New vector.</returns> /// <returns>New vector.</returns>
protected Vector CreateStandardBcVector(int size) protected DenseVector CreateStandardBcVector(int size)
{ {
Vector vector = new DenseVector(size); var vector = new DenseVector(size);
for (var i = 0; i < size; i++) for (var i = 0; i < size; i++)
{ {
vector[i] = i + 1; vector[i] = i + 1;
} }
return vector; return vector;
} }
@ -159,7 +157,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count + 10); var result = new DenseVector(vector.Count + 10);
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result));
} }
@ -176,7 +174,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.Solvers.Precon
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = null; Vector<Complex32> result = null;
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result));
} }

24
src/UnitTests/LinearAlgebraTests/Complex32/SparseMatrixTests.cs

@ -28,13 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex32;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using LinearAlgebra.Complex32; using Numerics;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Complex32 = Numerics.Complex32;
/// <summary> /// <summary>
/// Sparse matrix tests. /// Sparse matrix tests.
@ -47,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex32> CreateMatrix(int rows, int columns)
{ {
return new SparseMatrix(rows, columns); return new SparseMatrix(rows, columns);
} }
@ -57,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex32[,] data) protected override Matrix<Complex32> CreateMatrix(Complex32[,] data)
{ {
return SparseMatrix.OfArray(data); return SparseMatrix.OfArray(data);
} }
@ -68,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex32> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -78,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex32[] data) protected override Vector<Complex32> CreateVector(Complex32[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -89,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<Complex32>>
{ {
{"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1)})}, {"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(1.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1), new Complex32(2.0f, 1)})},
{"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex32(-1.1f, 1), Complex32.Zero, new Complex32(-4.4f, 1), new Complex32(-2.2f, 1), new Complex32(1.1f, 1), new Complex32(5.5f, 1), new Complex32(-3.3f, 1), new Complex32(2.2f, 1), new Complex32(6.6f, 1)})}, {"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {new Complex32(-1.1f, 1), Complex32.Zero, new Complex32(-4.4f, 1), new Complex32(-2.2f, 1), new Complex32(1.1f, 1), new Complex32(5.5f, 1), new Complex32(-3.3f, 1), new Complex32(2.2f, 1), new Complex32(6.6f, 1)})},
@ -185,7 +187,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
var matrix = new SparseMatrix(500, 1000); var matrix = new SparseMatrix(500, 1000);
var nonzero = 0; var nonzero = 0;
var rnd = new Random(); var rnd = new System.Random();
for (var i = 0; i < matrix.RowCount; i++) for (var i = 0; i < matrix.RowCount; i++)
{ {

13
src/UnitTests/LinearAlgebraTests/Complex32/UserDefinedMatrixTests.cs

@ -24,10 +24,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.LinearAlgebra;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using LinearAlgebra.Complex32; using Numerics;
using Complex32 = Numerics.Complex32;
/// <summary> /// <summary>
/// Test class for user-defined matrix. /// Test class for user-defined matrix.
@ -40,7 +41,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<Complex32> CreateMatrix(int rows, int columns)
{ {
return new UserDefinedMatrix(rows, columns); return new UserDefinedMatrix(rows, columns);
} }
@ -50,7 +51,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(Complex32[,] data) protected override Matrix<Complex32> CreateMatrix(Complex32[,] data)
{ {
return new UserDefinedMatrix(data); return new UserDefinedMatrix(data);
} }
@ -61,7 +62,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<Complex32> CreateVector(int size)
{ {
return new UserDefinedVector(size); return new UserDefinedVector(size);
} }
@ -71,7 +72,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(Complex32[] data) protected override Vector<Complex32> CreateVector(Complex32[] data)
{ {
return new UserDefinedVector(data); return new UserDefinedVector(data);
} }

21
src/UnitTests/LinearAlgebraTests/Double/DenseMatrixTests.cs

@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using LinearAlgebra.Double;
using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Dense matrix tests. /// Dense matrix tests.
/// </summary> /// </summary>
@ -46,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<double> CreateMatrix(int rows, int columns)
{ {
return new DenseMatrix(rows, columns); return new DenseMatrix(rows, columns);
} }
@ -56,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(double[,] data) protected override Matrix<double> CreateMatrix(double[,] data)
{ {
return DenseMatrix.OfArray(data); return DenseMatrix.OfArray(data);
} }
@ -67,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<double> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -77,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(double[] data) protected override Vector<double> CreateVector(double[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }
@ -88,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<double>>
{ {
{"Singular3x3", new DenseMatrix(3, 3, new[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0})}, {"Singular3x3", new DenseMatrix(3, 3, new[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0})},
{"Square3x3", new DenseMatrix(3, 3, new[] {-1.1, 0.0, -4.4, -2.2, 1.1, 5.5, -3.3, 2.2, 6.6})}, {"Square3x3", new DenseMatrix(3, 3, new[] {-1.1, 0.0, -4.4, -2.2, 1.1, 5.5, -3.3, 2.2, 6.6})},

14
src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
@ -57,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{"Wide2x3", new[,] {{-1.1, 0.0, 0.0}, {0.0, 1.1, 0.0}}} {"Wide2x3", new[,] {{-1.1, 0.0, 0.0}, {0.0, 1.1, 0.0}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<double>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));
@ -70,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<double> CreateMatrix(int rows, int columns)
{ {
return new DiagonalMatrix(rows, columns); return new DiagonalMatrix(rows, columns);
} }
@ -80,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(double[,] data) protected override Matrix<double> CreateMatrix(double[,] data)
{ {
return DiagonalMatrix.OfArray(data); return DiagonalMatrix.OfArray(data);
} }
@ -91,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<double> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -101,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(double[] data) protected override Vector<double> CreateVector(double[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }

13
src/UnitTests/LinearAlgebraTests/Double/MatrixLoader.cs

@ -29,7 +29,6 @@
// </copyright> // </copyright>
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using MathNet.Numerics.Distributions; using MathNet.Numerics.Distributions;
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra.Double;
@ -51,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <summary> /// <summary>
/// Gets or sets test matrices instances to use. /// Gets or sets test matrices instances to use.
/// </summary> /// </summary>
protected Dictionary<string, Matrix> TestMatrices { get; set; } protected Dictionary<string, Matrix<double>> TestMatrices { get; set; }
/// <summary> /// <summary>
/// Creates a matrix for the given number of rows and columns. /// Creates a matrix for the given number of rows and columns.
@ -59,14 +58,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected abstract Matrix CreateMatrix(int rows, int columns); protected abstract Matrix<double> CreateMatrix(int rows, int columns);
/// <summary> /// <summary>
/// Creates a matrix from a 2D array. /// Creates a matrix from a 2D array.
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected abstract Matrix CreateMatrix(double[,] data); protected abstract Matrix<double> CreateMatrix(double[,] data);
/// <summary> /// <summary>
/// Creates a vector of the given size. /// Creates a vector of the given size.
@ -74,14 +73,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(int size); protected abstract Vector<double> CreateVector(int size);
/// <summary> /// <summary>
/// Creates a vector from an array. /// Creates a vector from an array.
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(double[] data); protected abstract Vector<double> CreateVector(double[] data);
/// <summary> /// <summary>
/// Setup test matrices. /// Setup test matrices.
@ -100,7 +99,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{"Symmetric3x3", new[,] {{1.0, 2.0, 3.0}, {2.0, 2.0, 0.0}, {3.0, 0.0, 3.0}}} {"Symmetric3x3", new[,] {{1.0, 2.0, 3.0}, {2.0, 2.0, 0.0}, {3.0, 0.0, 3.0}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<double>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -213,7 +213,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply(Math.PI, matrix); matrix.Multiply(Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

2
src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/DiagonalTest.cs

@ -59,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)
{ {

16
src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IluptElementSorterTest.cs

@ -177,7 +177,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArray() public void HeapSortWithIncreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -207,7 +207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithDecreasingDoubleArray() public void HeapSortWithDecreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 9; values[0] = 9;
values[1] = 8; values[1] = 8;
values[2] = 7; values[2] = 7;
@ -237,7 +237,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithRandomDoubleArray() public void HeapSortWithRandomDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 5; values[0] = 5;
values[1] = 2; values[1] = 2;
values[2] = 8; values[2] = 8;
@ -299,7 +299,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithDuplicateDoubleEntries() public void HeapSortWithDuplicateDoubleEntries()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 1; values[0] = 1;
values[1] = 1; values[1] = 1;
values[2] = 1; values[2] = 1;
@ -363,7 +363,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithSpecialConstructedDoubleArray() public void HeapSortWithSpecialConstructedDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 0; values[1] = 0;
values[2] = 0; values[2] = 0;
@ -472,7 +472,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithLowerBound() public void HeapSortWithIncreasingDoubleArrayWithLowerBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -502,7 +502,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithUpperBound() public void HeapSortWithIncreasingDoubleArrayWithUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -532,7 +532,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;

8
src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IlutpTest.cs

@ -172,7 +172,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)
{ {
@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -218,7 +218,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
_fillLevel = 100; _fillLevel = 100;
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }
@ -337,7 +337,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
FillLevel = 10 FillLevel = 10
}; };
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count); var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result); preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result); CheckResult(preconditioner, newMatrix, vector, result);
} }

10
src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/IncompleteLUTest.cs

@ -65,9 +65,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Upper triangle.</returns> /// <returns>Upper triangle.</returns>
private static Matrix GetUpperTriangle(IncompleteLU ilu) private static Matrix<double> GetUpperTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "UpperTriangle"); return GetMethod<Matrix<double>>(ilu, "UpperTriangle");
} }
/// <summary> /// <summary>
@ -75,9 +75,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Lower triangle.</returns> /// <returns>Lower triangle.</returns>
private static Matrix GetLowerTriangle(IncompleteLU ilu) private static Matrix<double> GetLowerTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "LowerTriangle"); return GetMethod<Matrix<double>>(ilu, "LowerTriangle");
} }
/// <summary> /// <summary>
@ -102,7 +102,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)

10
src/UnitTests/LinearAlgebraTests/Double/Solvers/Preconditioners/PreConditionerTest.cs

@ -54,7 +54,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
{ {
matrix[i, i] = 2; matrix[i, i] = 2;
} }
return matrix; return matrix;
} }
@ -63,14 +62,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="size">Size of the vector.</param> /// <param name="size">Size of the vector.</param>
/// <returns>New vector.</returns> /// <returns>New vector.</returns>
protected Vector CreateStandardBcVector(int size) protected DenseVector CreateStandardBcVector(int size)
{ {
Vector vector = new DenseVector(size); var vector = new DenseVector(size);
for (var i = 0; i < size; i++) for (var i = 0; i < size; i++)
{ {
vector[i] = i + 1; vector[i] = i + 1;
} }
return vector; return vector;
} }
@ -157,7 +155,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = new DenseVector(vector.Count + 10); var result = new DenseVector(vector.Count + 10);
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(null, result));
} }
@ -174,7 +172,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.Solvers.Precondit
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = null; Vector<double> result = null;
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result));
} }

23
src/UnitTests/LinearAlgebraTests/Double/SparseMatrixTests.cs

@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using LinearAlgebra.Double;
using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Sparse matrix tests. /// Sparse matrix tests.
/// </summary> /// </summary>
@ -46,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<double> CreateMatrix(int rows, int columns)
{ {
return new SparseMatrix(rows, columns); return new SparseMatrix(rows, columns);
} }
@ -56,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(double[,] data) protected override Matrix<double> CreateMatrix(double[,] data)
{ {
return SparseMatrix.OfArray(data); return SparseMatrix.OfArray(data);
} }
@ -67,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<double> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -77,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(double[] data) protected override Vector<double> CreateVector(double[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -88,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<double>>
{ {
{"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new double[] {1, 1, 1, 1, 1, 1, 2, 2, 2})}, {"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new double[] {1, 1, 1, 1, 1, 1, 2, 2, 2})},
{"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {-1.1, 0.0, -4.4, -2.2, 1.1, 5.5, -3.3, 2.2, 6.6})}, {"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {-1.1, 0.0, -4.4, -2.2, 1.1, 5.5, -3.3, 2.2, 6.6})},
@ -184,7 +185,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
var matrix = new SparseMatrix(500, 1000); var matrix = new SparseMatrix(500, 1000);
var nonzero = 0; var nonzero = 0;
var rnd = new Random(); var rnd = new System.Random();
for (var i = 0; i < matrix.RowCount; i++) for (var i = 0; i < matrix.RowCount; i++)
{ {

12
src/UnitTests/LinearAlgebraTests/Double/UserDefinedMatrixTests.cs

@ -24,10 +24,10 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.LinearAlgebra;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using LinearAlgebra.Double;
/// <summary> /// <summary>
/// Test class for user-defined matrix. /// Test class for user-defined matrix.
/// </summary> /// </summary>
@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<double> CreateMatrix(int rows, int columns)
{ {
return new UserDefinedMatrix(rows, columns); return new UserDefinedMatrix(rows, columns);
} }
@ -49,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(double[,] data) protected override Matrix<double> CreateMatrix(double[,] data)
{ {
return new UserDefinedMatrix(data); return new UserDefinedMatrix(data);
} }
@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<double> CreateVector(int size)
{ {
return new UserDefinedVector(size); return new UserDefinedVector(size);
} }
@ -70,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(double[] data) protected override Vector<double> CreateVector(double[] data)
{ {
return new UserDefinedVector(data); return new UserDefinedVector(data);
} }

21
src/UnitTests/LinearAlgebraTests/Single/DenseMatrixTests.cs

@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Single;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using LinearAlgebra.Single;
using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Dense matrix tests. /// Dense matrix tests.
/// </summary> /// </summary>
@ -46,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<float> CreateMatrix(int rows, int columns)
{ {
return new DenseMatrix(rows, columns); return new DenseMatrix(rows, columns);
} }
@ -56,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(float[,] data) protected override Matrix<float> CreateMatrix(float[,] data)
{ {
return DenseMatrix.OfArray(data); return DenseMatrix.OfArray(data);
} }
@ -67,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<float> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -77,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(float[] data) protected override Vector<float> CreateVector(float[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }
@ -88,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<float>>
{ {
{"Singular3x3", new DenseMatrix(3, 3, new[] {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f})}, {"Singular3x3", new DenseMatrix(3, 3, new[] {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f})},
{"Square3x3", new DenseMatrix(3, 3, new[] {-1.1f, 0.0f, -4.4f, -2.2f, 1.1f, 5.5f, -3.3f, 2.2f, 6.6f})}, {"Square3x3", new DenseMatrix(3, 3, new[] {-1.1f, 0.0f, -4.4f, -2.2f, 1.1f, 5.5f, -3.3f, 2.2f, 6.6f})},

23
src/UnitTests/LinearAlgebraTests/Single/DiagonalMatrixTests.cs

@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Single;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using LinearAlgebra.Single;
using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Diagonal matrix tests. /// Diagonal matrix tests.
/// </summary> /// </summary>
@ -56,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{"Wide2x3", new[,] {{-1.1f, 0.0f, 0.0f}, {0.0f, 1.1f, 0.0f}}} {"Wide2x3", new[,] {{-1.1f, 0.0f, 0.0f}, {0.0f, 1.1f, 0.0f}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<float>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));
@ -69,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<float> CreateMatrix(int rows, int columns)
{ {
return new DiagonalMatrix(rows, columns); return new DiagonalMatrix(rows, columns);
} }
@ -79,7 +80,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(float[,] data) protected override Matrix<float> CreateMatrix(float[,] data)
{ {
return DiagonalMatrix.OfArray(data); return DiagonalMatrix.OfArray(data);
} }
@ -90,7 +91,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<float> CreateVector(int size)
{ {
return new DenseVector(size); return new DenseVector(size);
} }
@ -100,7 +101,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(float[] data) protected override Vector<float> CreateVector(float[] data)
{ {
return new DenseVector(data); return new DenseVector(data);
} }
@ -111,7 +112,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[Test] [Test]
public void CanCreateMatrixFromDiagonalArray() public void CanCreateMatrixFromDiagonalArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<float>>
{ {
{"Singular3x3", new DiagonalMatrix(3, 3, new[] {1.0f, 0.0f, 3.0f})}, {"Singular3x3", new DiagonalMatrix(3, 3, new[] {1.0f, 0.0f, 3.0f})},
{"Square3x3", new DiagonalMatrix(3, 3, new[] {-1.1f, 1.1f, 6.6f})}, {"Square3x3", new DiagonalMatrix(3, 3, new[] {-1.1f, 1.1f, 6.6f})},

12
src/UnitTests/LinearAlgebraTests/Single/MatrixLoader.cs

@ -50,7 +50,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <summary> /// <summary>
/// Gets or sets test matrices instances to use. /// Gets or sets test matrices instances to use.
/// </summary> /// </summary>
protected Dictionary<string, Matrix> TestMatrices { get; set; } protected Dictionary<string, Matrix<float>> TestMatrices { get; set; }
/// <summary> /// <summary>
/// Creates a matrix for the given number of rows and columns. /// Creates a matrix for the given number of rows and columns.
@ -58,14 +58,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected abstract Matrix CreateMatrix(int rows, int columns); protected abstract Matrix<float> CreateMatrix(int rows, int columns);
/// <summary> /// <summary>
/// Creates a matrix from a 2D array. /// Creates a matrix from a 2D array.
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected abstract Matrix CreateMatrix(float[,] data); protected abstract Matrix<float> CreateMatrix(float[,] data);
/// <summary> /// <summary>
/// Creates a vector of the given size. /// Creates a vector of the given size.
@ -73,14 +73,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(int size); protected abstract Vector<float> CreateVector(int size);
/// <summary> /// <summary>
/// Creates a vector from an array. /// Creates a vector from an array.
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected abstract Vector CreateVector(float[] data); protected abstract Vector<float> CreateVector(float[] data);
/// <summary> /// <summary>
/// Setup test matrices. /// Setup test matrices.
@ -99,7 +99,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{"Symmetric3x3", new[,] {{1.0f, 2.0f, 3.0f}, {2.0f, 2.0f, 0.0f}, {3.0f, 0.0f, 3.0f}}} {"Symmetric3x3", new[,] {{1.0f, 2.0f, 3.0f}, {2.0f, 2.0f, 0.0f}, {3.0f, 0.0f, 3.0f}}}
}; };
TestMatrices = new Dictionary<string, Matrix>(); TestMatrices = new Dictionary<string, Matrix<float>>();
foreach (var name in TestData2D.Keys) foreach (var name in TestData2D.Keys)
{ {
TestMatrices.Add(name, CreateMatrix(TestData2D[name])); TestMatrices.Add(name, CreateMatrix(TestData2D[name]));

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new BiCgStab(); var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -213,7 +213,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new GpBiCg(); var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -129,13 +129,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

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

@ -62,7 +62,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -75,7 +75,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new MlkBiCgStab(); var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -88,10 +88,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -131,13 +131,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -215,7 +215,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Due to datatype "float" it can happen that solution will not converge for specific random starting vectors // Due to datatype "float" it can happen that solution will not converge for specific random starting vectors
// That's why we will do 3 tries // That's why we will do 3 tries

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

@ -61,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveWideMatrixThrowsArgumentException() public void SolveWideMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(2, 3); var matrix = new SparseMatrix(2, 3);
Vector input = new DenseVector(2); var input = new DenseVector(2);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveLongMatrixThrowsArgumentException() public void SolveLongMatrixThrowsArgumentException()
{ {
var matrix = new SparseMatrix(3, 2); var matrix = new SparseMatrix(3, 2);
Vector input = new DenseVector(3); var input = new DenseVector(3);
var solver = new TFQMR(); var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input)); Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveUnitMatrixAndBackMultiply() public void SolveUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -130,13 +130,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
public void SolveScaledUnitMatrixAndBackMultiply() public void SolveScaledUnitMatrixAndBackMultiply()
{ {
// Create the identity matrix // Create the identity matrix
Matrix matrix = SparseMatrix.Identity(100); var matrix = SparseMatrix.Identity(100);
// Scale it with a funny number // Scale it with a funny number
matrix.Multiply((float) Math.PI, matrix); matrix.Multiply((float) Math.PI, matrix);
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]
@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Iterative
} }
// Create the y vector // Create the y vector
Vector y = DenseVector.Create(matrix.RowCount, i => 1); var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence // Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[] var monitor = new Iterator(new IIterationStopCriterium[]

2
src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/DiagonalTest.cs

@ -59,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
// Compute M * result = product // Compute M * result = product
// compare vector and product. Should be equal // compare vector and product. Should be equal
Vector product = new DenseVector(result.Count); var product = new DenseVector(result.Count);
matrix.Multiply(result, product); matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++) for (var i = 0; i < product.Count; i++)

16
src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IluptElementSorterTest.cs

@ -177,7 +177,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArray() public void HeapSortWithIncreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -207,7 +207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithDecreasingDoubleArray() public void HeapSortWithDecreasingDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 9; values[0] = 9;
values[1] = 8; values[1] = 8;
values[2] = 7; values[2] = 7;
@ -237,7 +237,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithRandomDoubleArray() public void HeapSortWithRandomDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 5; values[0] = 5;
values[1] = 2; values[1] = 2;
values[2] = 8; values[2] = 8;
@ -299,7 +299,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithDuplicateDoubleEntries() public void HeapSortWithDuplicateDoubleEntries()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 1; values[0] = 1;
values[1] = 1; values[1] = 1;
values[2] = 1; values[2] = 1;
@ -363,7 +363,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithSpecialConstructedDoubleArray() public void HeapSortWithSpecialConstructedDoubleArray()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 0; values[1] = 0;
values[2] = 0; values[2] = 0;
@ -472,7 +472,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithLowerBound() public void HeapSortWithIncreasingDoubleArrayWithLowerBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -502,7 +502,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithUpperBound() public void HeapSortWithIncreasingDoubleArrayWithUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;
@ -532,7 +532,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound() public void HeapSortWithIncreasingDoubleArrayWithLowerAndUpperBound()
{ {
var sortedIndices = new int[10]; var sortedIndices = new int[10];
Vector values = new DenseVector(10); var values = new DenseVector(10);
values[0] = 0; values[0] = 0;
values[1] = 1; values[1] = 1;
values[2] = 2; values[2] = 2;

8
src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/IncompleteLUTest.cs

@ -65,9 +65,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Upper triangle.</returns> /// <returns>Upper triangle.</returns>
private static Matrix GetUpperTriangle(IncompleteLU ilu) private static Matrix<float> GetUpperTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "UpperTriangle"); return GetMethod<Matrix<float>>(ilu, "UpperTriangle");
} }
/// <summary> /// <summary>
@ -75,9 +75,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="ilu"><c>IncompleteLU</c> instance.</param> /// <param name="ilu"><c>IncompleteLU</c> instance.</param>
/// <returns>Lower triangle.</returns> /// <returns>Lower triangle.</returns>
private static Matrix GetLowerTriangle(IncompleteLU ilu) private static Matrix<float> GetLowerTriangle(IncompleteLU ilu)
{ {
return GetMethod<Matrix>(ilu, "LowerTriangle"); return GetMethod<Matrix<float>>(ilu, "LowerTriangle");
} }
/// <summary> /// <summary>

4
src/UnitTests/LinearAlgebraTests/Single/Solvers/Preconditioners/PreConditionerTest.cs

@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
/// </summary> /// </summary>
/// <param name="size">Size of the vector.</param> /// <param name="size">Size of the vector.</param>
/// <returns>New vector.</returns> /// <returns>New vector.</returns>
protected Vector CreateStandardBcVector(int size) protected DenseVector CreateStandardBcVector(int size)
{ {
var vector = new DenseVector(size); var vector = new DenseVector(size);
for (var i = 0; i < size; i++) for (var i = 0; i < size; i++)
@ -174,7 +174,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single.Solvers.Precondit
var preconditioner = CreatePreconditioner(); var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix); preconditioner.Initialize(newMatrix);
Vector result = null; Vector<float> result = null;
Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result)); Assert.Throws<ArgumentNullException>(() => preconditioner.Approximate(vector, result));
} }

23
src/UnitTests/LinearAlgebraTests/Single/SparseMatrixTests.cs

@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using System;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Single;
using NUnit.Framework;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using LinearAlgebra.Single;
using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Sparse matrix tests. /// Sparse matrix tests.
/// </summary> /// </summary>
@ -46,7 +47,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<float> CreateMatrix(int rows, int columns)
{ {
return new SparseMatrix(rows, columns); return new SparseMatrix(rows, columns);
} }
@ -56,7 +57,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(float[,] data) protected override Matrix<float> CreateMatrix(float[,] data)
{ {
return SparseMatrix.OfArray(data); return SparseMatrix.OfArray(data);
} }
@ -67,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<float> CreateVector(int size)
{ {
return new SparseVector(size); return new SparseVector(size);
} }
@ -77,7 +78,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(float[] data) protected override Vector<float> CreateVector(float[] data)
{ {
return SparseVector.OfEnumerable(data); return SparseVector.OfEnumerable(data);
} }
@ -88,7 +89,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[Test] [Test]
public void CanCreateMatrixFrom1DArray() public void CanCreateMatrixFrom1DArray()
{ {
var testData = new Dictionary<string, Matrix> var testData = new Dictionary<string, Matrix<float>>
{ {
{"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new float[] {1, 1, 1, 1, 1, 1, 2, 2, 2})}, {"Singular3x3", SparseMatrix.OfColumnMajor(3, 3, new float[] {1, 1, 1, 1, 1, 1, 2, 2, 2})},
{"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {-1.1f, 0.0f, -4.4f, -2.2f, 1.1f, 5.5f, -3.3f, 2.2f, 6.6f})}, {"Square3x3", SparseMatrix.OfColumnMajor(3, 3, new[] {-1.1f, 0.0f, -4.4f, -2.2f, 1.1f, 5.5f, -3.3f, 2.2f, 6.6f})},
@ -184,7 +185,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
var matrix = new SparseMatrix(500, 1000); var matrix = new SparseMatrix(500, 1000);
var nonzero = 0; var nonzero = 0;
var rnd = new Random(); var rnd = new System.Random();
for (var i = 0; i < matrix.RowCount; i++) for (var i = 0; i < matrix.RowCount; i++)
{ {

12
src/UnitTests/LinearAlgebraTests/Single/UserDefinedMatrixTests.cs

@ -24,10 +24,10 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.LinearAlgebra;
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using LinearAlgebra.Single;
/// <summary> /// <summary>
/// Test class for user-defined matrix. /// Test class for user-defined matrix.
/// </summary> /// </summary>
@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="rows">The number of rows.</param> /// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param> /// <param name="columns">The number of columns.</param>
/// <returns>A matrix with the given dimensions.</returns> /// <returns>A matrix with the given dimensions.</returns>
protected override Matrix CreateMatrix(int rows, int columns) protected override Matrix<float> CreateMatrix(int rows, int columns)
{ {
return new UserDefinedMatrix(rows, columns); return new UserDefinedMatrix(rows, columns);
} }
@ -49,7 +49,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The 2D array to create this matrix from.</param> /// <param name="data">The 2D array to create this matrix from.</param>
/// <returns>A matrix with the given values.</returns> /// <returns>A matrix with the given values.</returns>
protected override Matrix CreateMatrix(float[,] data) protected override Matrix<float> CreateMatrix(float[,] data)
{ {
return new UserDefinedMatrix(data); return new UserDefinedMatrix(data);
} }
@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="size">The size of the vector to create. /// <param name="size">The size of the vector to create.
/// </param> /// </param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(int size) protected override Vector<float> CreateVector(int size)
{ {
return new UserDefinedVector(size); return new UserDefinedVector(size);
} }
@ -70,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="data">The array to create this vector from.</param> /// <param name="data">The array to create this vector from.</param>
/// <returns>The new vector. </returns> /// <returns>The new vector. </returns>
protected override Vector CreateVector(float[] data) protected override Vector<float> CreateVector(float[] data)
{ {
return new UserDefinedVector(data); return new UserDefinedVector(data);
} }

Loading…
Cancel
Save