Browse Source

LA: diagonal matrix mult should choose sensible result storage

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
bd7a3632e8
  1. 10
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  2. 10
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  3. 10
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  4. 10
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  5. 9
      src/UnitTests/LinearAlgebraTests/Double/DiagonalMatrixTests.cs

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

@ -607,13 +607,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
throw DimensionsDontMatch<ArgumentException>(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<ArgumentException>(this, otherDiagonal);
}
var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount);
var result = other.CreateMatrix(RowCount, other.RowCount);
TransposeAndMultiply(other, result);
return result;
}

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

@ -612,13 +612,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
throw DimensionsDontMatch<ArgumentException>(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<ArgumentException>(this, otherDiagonal);
}
var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount);
var result = other.CreateMatrix(RowCount, other.RowCount);
TransposeAndMultiply(other, result);
return result;
}

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

@ -601,13 +601,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
throw DimensionsDontMatch<ArgumentException>(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<ArgumentException>(this, otherDiagonal);
}
var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount);
var result = other.CreateMatrix(RowCount, other.RowCount);
TransposeAndMultiply(other, result);
return result;
}

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

@ -606,13 +606,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
throw DimensionsDontMatch<ArgumentException>(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<ArgumentException>(this, otherDiagonal);
}
var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount);
var result = other.CreateMatrix(RowCount, other.RowCount);
TransposeAndMultiply(other, result);
return result;
}

9
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<double> diagonal = DiagonalMatrix.Identity(3);
Matrix<double> dense = new DenseMatrix(new double[,] { { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } });
var test = diagonal * dense;
var test2 = dense * diagonal;
}
}
}

Loading…
Cancel
Save