diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs index 75abe302..cfe8a807 100644 --- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs @@ -607,13 +607,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex throw DimensionsDontMatch(this, other); } - var m = other as DiagonalMatrix; - if (m == null) - { - return base.Multiply(other); - } - - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.ColumnCount); + var result = other.CreateMatrix(RowCount, other.ColumnCount); Multiply(other, result); return result; } @@ -788,7 +782,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex throw DimensionsDontMatch(this, otherDiagonal); } - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); + var result = other.CreateMatrix(RowCount, other.RowCount); TransposeAndMultiply(other, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs index ca5408cc..121c807f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs @@ -612,13 +612,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 throw DimensionsDontMatch(this, other); } - var m = other as DiagonalMatrix; - if (m == null) - { - return base.Multiply(other); - } - - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.ColumnCount); + var result = other.CreateMatrix(RowCount, other.ColumnCount); Multiply(other, result); return result; } @@ -793,7 +787,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 throw DimensionsDontMatch(this, otherDiagonal); } - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); + var result = other.CreateMatrix(RowCount, other.RowCount); TransposeAndMultiply(other, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs index 7fa78a1d..92f938c3 100644 --- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs @@ -601,13 +601,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double throw DimensionsDontMatch(this, other); } - var m = other as DiagonalMatrix; - if (m == null) - { - return base.Multiply(other); - } - - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.ColumnCount); + var result = other.CreateMatrix(RowCount, other.ColumnCount); Multiply(other, result); return result; } @@ -782,7 +776,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double throw DimensionsDontMatch(this, otherDiagonal); } - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); + var result = other.CreateMatrix(RowCount, other.RowCount); TransposeAndMultiply(other, result); return result; } diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs index c1cbd102..9ecd9b52 100644 --- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs @@ -606,13 +606,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single throw DimensionsDontMatch(this, other); } - var m = other as DiagonalMatrix; - if (m == null) - { - return base.Multiply(other); - } - - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.ColumnCount); + var result = other.CreateMatrix(RowCount, other.ColumnCount); Multiply(other, result); return result; } @@ -787,7 +781,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single throw DimensionsDontMatch(this, otherDiagonal); } - var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); + var result = other.CreateMatrix(RowCount, other.RowCount); TransposeAndMultiply(other, result); return result; } diff --git a/src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs index d6024748..8e2b193c 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs @@ -665,5 +665,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double var subM3 = diagMatrix.SubMatrix(0, 3, 1, 2); Assert.IsTrue(subM3.Equals(new DenseMatrix(3, 2, new[] { 0d, 2d, 0d, 0d, 0d, 3d }))); } + + [Test] + public void DiagonalDenseMatrixMultiplication_IssueCP5706() + { + Matrix diagonal = DiagonalMatrix.Identity(3); + Matrix dense = new DenseMatrix(new double[,] { { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } }); + var test = diagonal * dense; + var test2 = dense * diagonal; + } } }