diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index b833b8ad..ffc1c4b0 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -444,6 +444,68 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Multiplies the transpose of this matrix with a vector and places the results into the result vector. + /// + /// The vector to multiply with. + /// The result of the multiplication. + protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) + { + var denseRight = rightSide as DenseVector; + var denseResult = result as DenseVector; + + if (denseRight == null || denseResult == null) + { + base.DoTransposeThisAndMultiply(rightSide, result); + } + else + { + Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( + Algorithms.LinearAlgebra.Transpose.Transpose, + Algorithms.LinearAlgebra.Transpose.DontTranspose, + 1.0f, + Data, + RowCount, + ColumnCount, + denseRight.Data, + denseRight.Count, + 1, + 0.0f, + denseResult.Data); + } + } + + /// + /// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix. + /// + /// The matrix to multiply with. + /// The result of the multiplication. + protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result) + { + var denseOther = other as DenseMatrix; + var denseResult = result as DenseMatrix; + + if (denseOther == null || denseResult == null) + { + base.DoTransposeThisAndMultiply(other, result); + } + else + { + Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate( + Algorithms.LinearAlgebra.Transpose.Transpose, + Algorithms.LinearAlgebra.Transpose.DontTranspose, + 1.0f, + Data, + RowCount, + ColumnCount, + denseOther.Data, + denseOther.RowCount, + denseOther.ColumnCount, + 0.0f, + denseResult.Data); + } + } + /// /// Negate each element of this matrix and place the results into the result matrix. /// diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index b25b39e0..b4ff2426 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -269,6 +269,47 @@ namespace MathNet.Numerics.LinearAlgebra.Single } } + /// + /// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix. + /// + /// The matrix to multiply with. + /// The result of the multiplication. + protected override void DoTransposeThisAndMultiply(Matrix other, Matrix result) + { + for (var j = 0; j < other.ColumnCount; j++) + { + for (var i = 0; i < ColumnCount; i++) + { + var s = 0.0f; + for (var l = 0; l < RowCount; l++) + { + s += At(l, i) * other.At(l, j); + } + + result.At(i, j, s); + } + } + } + + /// + /// Multiplies the transpose of this matrix with a vector and places the results into the result vector. + /// + /// The vector to multiply with. + /// The result of the multiplication. + protected override void DoTransposeThisAndMultiply(Vector rightSide, Vector result) + { + for (var i = 0; i < ColumnCount; i++) + { + var s = 0.0f; + for (var j = 0; j != RowCount; j++) + { + s += At(j, i) * rightSide[j]; + } + result[i] = s; + } + } + + /// /// Computes the modulus for each element of the matrix. ///