Browse Source

Linear Algebrea: fix range in non-suqare diagonal sparse mixed products

v4
Christoph Ruegg 6 years ago
parent
commit
64f8e1cd8d
  1. 2
      src/Numerics.Tests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs
  2. 2
      src/Numerics.Tests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs
  3. 2
      src/Numerics.Tests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs
  4. 2
      src/Numerics.Tests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs
  5. 2
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  6. 2
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  7. 2
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  8. 2
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  9. 2
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  10. 2
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  11. 2
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  12. 2
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  13. 2
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  14. 2
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  15. 2
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  16. 2
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

2
src/Numerics.Tests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs

@ -830,7 +830,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
var matrix = TestMatrices[name];
var inverse = matrix.PseudoInverse();
// Testing for Moore–Penrose conditions 1: A*A^+*A = A
AssertHelpers.AlmostEqual(matrix, matrix * inverse * matrix, 12);
AssertHelpers.AlmostEqual(matrix, matrix * (inverse * matrix), 12);
}
/// <summary>

2
src/Numerics.Tests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs

@ -831,7 +831,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
var matrix = TestMatrices[name];
var inverse = matrix.PseudoInverse();
// Testing for Moore–Penrose conditions 1: A*A^+*A = A
AssertHelpers.AlmostEqual(matrix, matrix * inverse * matrix, 5);
AssertHelpers.AlmostEqual(matrix, matrix * (inverse * matrix), 5);
}
/// <summary>

2
src/Numerics.Tests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs

@ -824,7 +824,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
var matrix = TestMatrices[name];
var inverse = matrix.PseudoInverse();
// Testing for Moore–Penrose conditions 1: A*A^+*A = A
AssertHelpers.AlmostEqual(matrix, matrix * inverse * matrix, 12);
AssertHelpers.AlmostEqual(matrix, matrix * (inverse * matrix), 12);
}
/// <summary>

2
src/Numerics.Tests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs

@ -819,7 +819,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
var matrix = TestMatrices[name];
var inverse = matrix.PseudoInverse();
// Testing for Moore–Penrose conditions 1: A*A^+*A = A
AssertHelpers.AlmostEqual(matrix, matrix * inverse * matrix, 5);
AssertHelpers.AlmostEqual(matrix, matrix * (inverse * matrix), 5);
}
/// <summary>

2
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -384,7 +384,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
else
{
result.Clear();
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, other.RowCount, 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, Math.Min(RowCount, other.RowCount), 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
}
}

2
src/Numerics/LinearAlgebra/Complex/Matrix.cs

@ -539,7 +539,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
w.SetDiagonal(s);
return (svd.U * w * svd.VT).ConjugateTranspose();
return (svd.U * (w * svd.VT)).ConjugateTranspose();
}
/// <summary>

2
src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs

@ -901,7 +901,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
else
{
result.Storage.Clear();
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, Math.Min(ColumnCount, other.ColumnCount), Zeros.AllowSkip, ExistingData.AssumeZeros);
}
return;
}

2
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -383,7 +383,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
else
{
result.Clear();
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, other.RowCount, 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, Math.Min(RowCount, other.RowCount), 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
}
}

2
src/Numerics/LinearAlgebra/Complex32/Matrix.cs

@ -539,7 +539,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
w.SetDiagonal(s);
return (svd.U * w * svd.VT).ConjugateTranspose();
return (svd.U * (w * svd.VT)).ConjugateTranspose();
}
/// <summary>

2
src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs

@ -900,7 +900,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
else
{
result.Storage.Clear();
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, Math.Min(ColumnCount, other.ColumnCount), Zeros.AllowSkip, ExistingData.AssumeZeros);
}
return;
}

2
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -362,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
else
{
result.Clear();
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, other.RowCount, 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, Math.Min(RowCount, other.RowCount), 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
}
}

2
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -509,7 +509,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
w.SetDiagonal(s);
return (svd.U * w * svd.VT).Transpose();
return (svd.U * (w * svd.VT)).Transpose();
}
/// <summary>

2
src/Numerics/LinearAlgebra/Double/SparseMatrix.cs

@ -901,7 +901,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
else
{
result.Storage.Clear();
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, Math.Min(ColumnCount, other.ColumnCount), Zeros.AllowSkip, ExistingData.AssumeZeros);
}
return;
}

2
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -362,7 +362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
else
{
result.Clear();
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, other.RowCount, 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
other.Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*_data[i], 0, 0, Math.Min(RowCount, other.RowCount), 0, 0, other.ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
}
}

2
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -510,7 +510,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
w.SetDiagonal(s);
return (svd.U * w * svd.VT).Transpose();
return (svd.U * (w * svd.VT)).Transpose();
}
/// <summary>

2
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -905,7 +905,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
else
{
result.Storage.Clear();
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, ColumnCount, Zeros.AllowSkip, ExistingData.AssumeZeros);
Storage.MapSubMatrixIndexedTo(result.Storage, (i, j, x) => x*diagonal[j], 0, 0, RowCount, 0, 0, Math.Min(ColumnCount, other.ColumnCount), Zeros.AllowSkip, ExistingData.AssumeZeros);
}
return;
}

Loading…
Cancel
Save