Browse Source

LA: Matrix ConjugateTransposeAndMultiply and variants

optimization-3
Christoph Ruegg 13 years ago
parent
commit
67a0923040
  1. 6
      src/Numerics/LinearAlgebra/Builder.cs
  2. 144
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  3. 60
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  4. 136
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  5. 60
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  6. 30
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  7. 162
      src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
  8. 30
      src/Numerics/LinearAlgebra/Single/Matrix.cs

6
src/Numerics/LinearAlgebra/Builder.cs

@ -465,7 +465,7 @@ namespace MathNet.Numerics.LinearAlgebra
public Matrix<T> RandomPositiveDefinite(int order, IContinuousDistribution distribution)
{
var a = Random(order, order, distribution);
return a.TransposeThisAndMultiply(a);
return a.ConjugateTransposeThisAndMultiply(a);
}
/// <summary>
@ -475,7 +475,7 @@ namespace MathNet.Numerics.LinearAlgebra
public Matrix<T> RandomPositiveDefinite(int order)
{
var a = Random(order, order, new Normal(MersenneTwister.Default));
return a.TransposeThisAndMultiply(a);
return a.ConjugateTransposeThisAndMultiply(a);
}
/// <summary>
@ -485,7 +485,7 @@ namespace MathNet.Numerics.LinearAlgebra
public Matrix<T> RandomPositiveDefinite(int order, int seed)
{
var a = Random(order, order, new Normal(new MersenneTwister(seed, true)));
return a.TransposeThisAndMultiply(a);
return a.ConjugateTransposeThisAndMultiply(a);
}
/// <summary>

144
src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs

@ -727,6 +727,62 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
base.DoTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeAndMultiply(Matrix<Complex> other, Matrix<Complex> result)
{
var denseOther = other as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
1.0,
_values,
_rowCount,
_columnCount,
denseOther._values,
denseOther._rowCount,
denseOther._columnCount,
0.0,
denseResult._values);
return;
}
var diagonalOther = other.Storage as DiagonalMatrixStorage<Complex>;
if (diagonalOther != null)
{
var diagonal = diagonalOther.Data;
var conjugateDiagonal = new Complex[diagonal.Length];
for (int i = 0; i < diagonal.Length; i++)
{
conjugateDiagonal[i] = diagonal[i].Conjugate();
}
var d = Math.Min(ColumnCount, other.RowCount);
if (d < other.RowCount)
{
result.ClearSubMatrix(0, RowCount, ColumnCount, other.RowCount - ColumnCount);
}
int index = 0;
for (int j = 0; j < d; j++)
{
for (int i = 0; i < RowCount; i++)
{
result.At(i, j, _values[index]*conjugateDiagonal[j]);
index++;
}
}
return;
}
base.DoConjugateTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -736,15 +792,39 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
var denseRight = rightSide as DenseVector;
var denseResult = result as DenseVector;
if (denseRight == null || denseResult == null)
if (denseRight != null && denseResult != null)
{
base.DoTransposeThisAndMultiply(rightSide, result);
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
Providers.LinearAlgebra.Transpose.DontTranspose,
1.0,
_values,
_rowCount,
_columnCount,
denseRight.Values,
denseRight.Count,
1,
0.0,
denseResult.Values);
return;
}
else
base.DoTransposeThisAndMultiply(rightSide, result);
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex> rightSide, Vector<Complex> result)
{
var denseRight = rightSide as DenseVector;
var denseResult = result as DenseVector;
if (denseRight != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.Transpose,
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
Providers.LinearAlgebra.Transpose.DontTranspose,
1.0,
_values,
@ -755,7 +835,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
1,
0.0,
denseResult.Values);
return;
}
base.DoConjugateTransposeThisAndMultiply(rightSide, result);
}
/// <summary>
@ -809,6 +892,57 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
base.DoTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Matrix<Complex> other, Matrix<Complex> result)
{
var denseOther = other as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
Providers.LinearAlgebra.Transpose.DontTranspose,
1.0,
_values,
_rowCount,
_columnCount,
denseOther._values,
denseOther._rowCount,
denseOther._columnCount,
0.0,
denseResult._values);
return;
}
var diagonalOther = other.Storage as DiagonalMatrixStorage<Complex>;
if (diagonalOther != null)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
if (d < other.ColumnCount)
{
result.ClearSubMatrix(0, ColumnCount, RowCount, other.ColumnCount - RowCount);
}
int index = 0;
for (int i = 0; i < ColumnCount; i++)
{
for (int j = 0; j < d; j++)
{
result.At(i, j, _values[index].Conjugate()*diagonal[j]);
index++;
}
index += (RowCount - d);
}
return;
}
base.DoConjugateTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>

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

@ -293,6 +293,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeAndMultiply(Matrix<Complex> other, Matrix<Complex> result)
{
for (var j = 0; j < other.RowCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
var s = Complex.Zero;
for (var l = 0; l < ColumnCount; l++)
{
s += At(i, l)*other.At(j, l).Conjugate();
}
result.At(i, j, s);
}
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -314,6 +335,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Matrix<Complex> other, Matrix<Complex> result)
{
for (var j = 0; j < other.ColumnCount; j++)
{
for (var i = 0; i < ColumnCount; i++)
{
var s = Complex.Zero;
for (var l = 0; l < RowCount; l++)
{
s += At(l, i).Conjugate()*other.At(l, j);
}
result.At(i, j, s);
}
}
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -332,6 +374,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex> rightSide, Vector<Complex> result)
{
for (var i = 0; i < ColumnCount; i++)
{
var s = Complex.Zero;
for (var j = 0; j < RowCount; j++)
{
s += At(j, i).Conjugate()*rightSide[j];
}
result[i] = s;
}
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>

136
src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs

@ -722,6 +722,62 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
base.DoTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result)
{
var denseOther = other as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.DontTranspose,
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
1.0f,
_values,
_rowCount,
_columnCount,
denseOther._values,
denseOther._rowCount,
denseOther._columnCount,
0.0f,
denseResult._values);
return;
}
var diagonalOther = other.Storage as DiagonalMatrixStorage<Complex32>;
if (diagonalOther != null)
{
var diagonal = diagonalOther.Data;
var conjugateDiagonal = new Complex32[diagonal.Length];
for (int i = 0; i < diagonal.Length; i++)
{
conjugateDiagonal[i] = diagonal[i].Conjugate();
}
var d = Math.Min(ColumnCount, other.RowCount);
if (d < other.RowCount)
{
result.ClearSubMatrix(0, RowCount, ColumnCount, other.RowCount - ColumnCount);
}
int index = 0;
for (int j = 0; j < d; j++)
{
for (int i = 0; i < RowCount; i++)
{
result.At(i, j, _values[index]*conjugateDiagonal[j]);
index++;
}
}
return;
}
base.DoConjugateTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -753,6 +809,35 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex32> rightSide, Vector<Complex32> result)
{
var denseRight = rightSide as DenseVector;
var denseResult = result as DenseVector;
if (denseRight != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
Providers.LinearAlgebra.Transpose.DontTranspose,
1.0f,
_values,
_rowCount,
_columnCount,
denseRight.Values,
denseRight.Count,
1,
0.0f,
denseResult.Values);
return;
}
base.DoConjugateTransposeThisAndMultiply(rightSide, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -804,6 +889,57 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
base.DoTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result)
{
var denseOther = other as DenseMatrix;
var denseResult = result as DenseMatrix;
if (denseOther != null && denseResult != null)
{
Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(
Providers.LinearAlgebra.Transpose.ConjugateTranspose,
Providers.LinearAlgebra.Transpose.DontTranspose,
1.0f,
_values,
_rowCount,
_columnCount,
denseOther._values,
denseOther._rowCount,
denseOther._columnCount,
0.0f,
denseResult._values);
return;
}
var diagonalOther = other.Storage as DiagonalMatrixStorage<Complex32>;
if (diagonalOther != null)
{
var diagonal = diagonalOther.Data;
var d = Math.Min(RowCount, other.ColumnCount);
if (d < other.ColumnCount)
{
result.ClearSubMatrix(0, ColumnCount, RowCount, other.ColumnCount - RowCount);
}
int index = 0;
for (int i = 0; i < ColumnCount; i++)
{
for (int j = 0; j < d; j++)
{
result.At(i, j, _values[index].Conjugate()*diagonal[j]);
index++;
}
index += (RowCount - d);
}
return;
}
base.DoConjugateTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>

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

@ -287,6 +287,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result)
{
for (var j = 0; j < other.RowCount; j++)
{
for (var i = 0; i < RowCount; i++)
{
var s = Complex32.Zero;
for (var l = 0; l < ColumnCount; l++)
{
s += At(i, l)*other.At(j, l).Conjugate();
}
result.At(i, j, s);
}
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -308,6 +329,27 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result)
{
for (var j = 0; j < other.ColumnCount; j++)
{
for (var i = 0; i < ColumnCount; i++)
{
var s = Complex32.Zero;
for (var l = 0; l < RowCount; l++)
{
s += At(l, i).Conjugate()*other.At(l, j);
}
result.At(i, j, s);
}
}
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -326,6 +368,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<Complex32> rightSide, Vector<Complex32> result)
{
for (var i = 0; i < ColumnCount; i++)
{
var s = Complex32.Zero;
for (var j = 0; j < RowCount; j++)
{
s += At(j, i).Conjugate()*rightSide[j];
}
result[i] = s;
}
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>

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

@ -277,6 +277,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override sealed void DoConjugateTransposeAndMultiply(Matrix<double> other, Matrix<double> result)
{
DoTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -298,6 +308,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override sealed void DoConjugateTransposeThisAndMultiply(Matrix<double> other, Matrix<double> result)
{
DoTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -316,6 +336,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<double> rightSide, Vector<double> result)
{
DoTransposeThisAndMultiply(rightSide, result);
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>

162
src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs

@ -122,12 +122,19 @@ namespace MathNet.Numerics.LinearAlgebra
protected abstract void DoMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
/// Multiplies this matrix with the transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoConjugateTransposeAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -135,6 +142,13 @@ namespace MathNet.Numerics.LinearAlgebra
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoConjugateTransposeThisAndMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -142,6 +156,13 @@ namespace MathNet.Numerics.LinearAlgebra
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoConjugateTransposeThisAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
@ -807,6 +828,145 @@ namespace MathNet.Numerics.LinearAlgebra
return result;
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentException">If <strong>this.Columns != other.ColumnCount</strong>.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the this.RowCount x other.RowCount.</exception>
public virtual void ConjugateTransposeAndMultiply(Matrix<T> other, Matrix<T> result)
{
if (ColumnCount != other.ColumnCount || result.RowCount != RowCount || result.ColumnCount != other.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other, result);
}
if (ReferenceEquals(this, result) || ReferenceEquals(other, result))
{
var tmp = Build.SameAs(result);
DoConjugateTransposeAndMultiply(other, tmp);
tmp.CopyTo(result);
}
else
{
DoConjugateTransposeAndMultiply(other, result);
}
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and returns the result.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <exception cref="ArgumentException">If <strong>this.Columns != other.ColumnCount</strong>.</exception>
/// <returns>The result of the multiplication.</returns>
public Matrix<T> ConjugateTransposeAndMultiply(Matrix<T> other)
{
if (ColumnCount != other.ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other);
}
var result = Build.SameAs(this, other, RowCount, other.RowCount);
DoConjugateTransposeAndMultiply(other, result);
return result;
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix by a vector and returns the result.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <returns>The result of the multiplication.</returns>
/// <exception cref="ArgumentException">If <c>this.RowCount != rightSide.Count</c>.</exception>
public Vector<T> ConjugateTransposeThisAndMultiply(Vector<T> rightSide)
{
if (RowCount != rightSide.Count)
{
throw DimensionsDontMatch<ArgumentException>(this, rightSide, "rightSide");
}
var result = Vector<T>.Build.SameAs(this, rightSide, ColumnCount);
DoConjugateTransposeThisAndMultiply(rightSide, result);
return result;
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentException">If <strong>result.Count != this.ColumnCount</strong>.</exception>
/// <exception cref="ArgumentException">If <strong>this.RowCount != <paramref name="rightSide"/>.Count</strong>.</exception>
public void ConjugateTransposeThisAndMultiply(Vector<T> rightSide, Vector<T> result)
{
if (RowCount != rightSide.Count)
{
throw DimensionsDontMatch<ArgumentException>(this, rightSide, "rightSide");
}
if (ColumnCount != result.Count)
{
throw DimensionsDontMatch<ArgumentException>(this, result, "result");
}
if (ReferenceEquals(rightSide, result))
{
var tmp = Vector<T>.Build.SameAs(result);
DoConjugateTransposeThisAndMultiply(rightSide, tmp);
tmp.CopyTo(result);
}
else
{
DoConjugateTransposeThisAndMultiply(rightSide, result);
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
/// <exception cref="ArgumentException">If <strong>this.Rows != other.RowCount</strong>.</exception>
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the this.ColumnCount x other.ColumnCount.</exception>
public void ConjugateTransposeThisAndMultiply(Matrix<T> other, Matrix<T> result)
{
if (RowCount != other.RowCount || result.RowCount != ColumnCount || result.ColumnCount != other.ColumnCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other, result);
}
if (ReferenceEquals(this, result) || ReferenceEquals(other, result))
{
var tmp = Build.SameAs(result);
DoConjugateTransposeThisAndMultiply(other, tmp);
tmp.CopyTo(result);
}
else
{
DoConjugateTransposeThisAndMultiply(other, result);
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with another matrix and returns the result.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <exception cref="ArgumentException">If <strong>this.Rows != other.RowCount</strong>.</exception>
/// <returns>The result of the multiplication.</returns>
public Matrix<T> ConjugateTransposeThisAndMultiply(Matrix<T> other)
{
if (RowCount != other.RowCount)
{
throw DimensionsDontMatch<ArgumentException>(this, other);
}
var result = Build.SameAs(this, other, ColumnCount, other.ColumnCount);
DoConjugateTransposeThisAndMultiply(other, result);
return result;
}
/// <summary>
/// Negate each element of this matrix.
/// </summary>

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

@ -277,6 +277,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Multiplies this matrix with the conjugate transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override sealed void DoConjugateTransposeAndMultiply(Matrix<float> other, Matrix<float> result)
{
DoTransposeAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -298,6 +308,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override sealed void DoConjugateTransposeThisAndMultiply(Matrix<float> other, Matrix<float> result)
{
DoTransposeThisAndMultiply(other, result);
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
@ -316,6 +336,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <summary>
/// Multiplies the conjugate transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected override void DoConjugateTransposeThisAndMultiply(Vector<float> rightSide, Vector<float> result)
{
DoTransposeThisAndMultiply(rightSide, result);
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>

Loading…
Cancel
Save