|
|
|
@ -189,39 +189,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
i => new Complex32((float) distribution.Sample(), (float) distribution.Sample()))); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds another matrix to this matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The matrix to add to this matrix.</param>
|
|
|
|
/// <returns>The result of the addition.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
|
|
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
|
public override Matrix<Complex32> Add(Matrix<Complex32> other) |
|
|
|
{ |
|
|
|
if (other == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("other"); |
|
|
|
} |
|
|
|
|
|
|
|
if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other"); |
|
|
|
} |
|
|
|
|
|
|
|
Matrix<Complex32> result; |
|
|
|
if (other is DiagonalMatrix) |
|
|
|
{ |
|
|
|
result = new DiagonalMatrix(RowCount, ColumnCount); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
result = new DenseMatrix(RowCount, ColumnCount); |
|
|
|
} |
|
|
|
|
|
|
|
Add(other, result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds another matrix to this matrix.
|
|
|
|
/// </summary>
|
|
|
|
@ -244,39 +211,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Subtracts another matrix from this matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The matrix to subtract.</param>
|
|
|
|
/// <returns>The result of the subtraction.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
|
|
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
|
public override Matrix<Complex32> Subtract(Matrix<Complex32> other) |
|
|
|
{ |
|
|
|
if (other == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("other"); |
|
|
|
} |
|
|
|
|
|
|
|
if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other"); |
|
|
|
} |
|
|
|
|
|
|
|
Matrix<Complex32> result; |
|
|
|
if (other is DiagonalMatrix) |
|
|
|
{ |
|
|
|
result = new DiagonalMatrix(RowCount, ColumnCount); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
result = new DenseMatrix(RowCount, ColumnCount); |
|
|
|
} |
|
|
|
|
|
|
|
Subtract(other, result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Subtracts another matrix from this matrix.
|
|
|
|
/// </summary>
|
|
|
|
@ -356,8 +290,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
/// </summary>
|
|
|
|
/// <param name="scalar">The scalar to multiply the matrix with.</param>
|
|
|
|
/// <param name="result">The matrix to store the result of the multiplication.</param>
|
|
|
|
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the same as this matrix.</exception>
|
|
|
|
protected override void DoMultiply(Complex32 scalar, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
if (scalar.IsZero()) |
|
|
|
@ -393,72 +325,44 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The matrix to multiply with.</param>
|
|
|
|
/// <param name="result">The result of the multiplication.</param>
|
|
|
|
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If <strong>this.Columns != other.Rows</strong>.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the this.Rows x other.Columns.</exception>
|
|
|
|
public override void Multiply(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
if (other == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("other"); |
|
|
|
} |
|
|
|
|
|
|
|
if (result == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("result"); |
|
|
|
} |
|
|
|
|
|
|
|
if (ColumnCount != other.RowCount) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentException>(this, other); |
|
|
|
} |
|
|
|
|
|
|
|
if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentException>(this, other); |
|
|
|
} |
|
|
|
|
|
|
|
var m = other as DiagonalMatrix; |
|
|
|
var r = result as DiagonalMatrix; |
|
|
|
|
|
|
|
if (m == null || r == null) |
|
|
|
{ |
|
|
|
base.Multiply(other, result); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var thisDataCopy = new Complex32[r._data.Length]; |
|
|
|
var otherDataCopy = new Complex32[r._data.Length]; |
|
|
|
Array.Copy(_data, thisDataCopy, (r._data.Length > _data.Length) ? _data.Length : r._data.Length); |
|
|
|
Array.Copy(m._data, otherDataCopy, (r._data.Length > m._data.Length) ? m._data.Length : r._data.Length); |
|
|
|
|
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, r._data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies 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.Columns != other.Rows</strong>.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
|
|
|
|
/// <returns>The result of multiplication.</returns>
|
|
|
|
public override Matrix<Complex32> Multiply(Matrix<Complex32> other) |
|
|
|
protected override void DoMultiply(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
if (other == null) |
|
|
|
var diagonalOther = other as DiagonalMatrix; |
|
|
|
var diagonalResult = result as DiagonalMatrix; |
|
|
|
if (diagonalOther != null && diagonalResult != null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("other"); |
|
|
|
var thisDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
var otherDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
Array.Copy(_data, thisDataCopy, (diagonalResult._data.Length > _data.Length) ? _data.Length : diagonalResult._data.Length); |
|
|
|
Array.Copy(diagonalOther._data, otherDataCopy, (diagonalResult._data.Length > diagonalOther._data.Length) ? diagonalOther._data.Length : diagonalResult._data.Length); |
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, diagonalResult._data); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (ColumnCount != other.RowCount) |
|
|
|
var denseOther = other.Storage as DenseColumnMajorMatrixStorage<Complex32>; |
|
|
|
if (denseOther != null) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentException>(this, other); |
|
|
|
var dense = denseOther.Data; |
|
|
|
var diagonal = _data; |
|
|
|
var d = Math.Min(denseOther.RowCount, RowCount); |
|
|
|
if (d < RowCount) |
|
|
|
{ |
|
|
|
result.ClearSubMatrix(denseOther.RowCount, RowCount - denseOther.RowCount, 0, denseOther.ColumnCount); |
|
|
|
} |
|
|
|
int index = 0; |
|
|
|
for (int i = 0; i < denseOther.ColumnCount; i++) |
|
|
|
{ |
|
|
|
for (int j = 0; j < d; j++) |
|
|
|
{ |
|
|
|
result.At(j, i, dense[index]*diagonal[j]); |
|
|
|
index++; |
|
|
|
} |
|
|
|
index += (denseOther.RowCount - d); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var result = other.CreateMatrix(RowCount, other.ColumnCount); |
|
|
|
Multiply(other, result); |
|
|
|
return result; |
|
|
|
base.DoMultiply(other, result); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -591,22 +495,88 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">The matrix to multiply with.</param>
|
|
|
|
/// <param name="result">The result of the multiplication.</param>
|
|
|
|
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null" />.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If the result matrix is <see langword="null" />.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If <strong>this.Columns != other.Rows</strong>.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If the result matrix's dimensions are not the this.Rows x other.Columns.</exception>
|
|
|
|
public override void TransposeAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
|
protected override void DoTransposeAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
var otherDiagonal = other as DiagonalMatrix; |
|
|
|
var resultDiagonal = result as DiagonalMatrix; |
|
|
|
var diagonalOther = other as DiagonalMatrix; |
|
|
|
var diagonalResult = result as DiagonalMatrix; |
|
|
|
if (diagonalOther != null && diagonalResult != null) |
|
|
|
{ |
|
|
|
var thisDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
var otherDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
Array.Copy(_data, thisDataCopy, (diagonalResult._data.Length > _data.Length) ? _data.Length : diagonalResult._data.Length); |
|
|
|
Array.Copy(diagonalOther._data, otherDataCopy, (diagonalResult._data.Length > diagonalOther._data.Length) ? diagonalOther._data.Length : diagonalResult._data.Length); |
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, diagonalResult._data); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (otherDiagonal == null || resultDiagonal == null) |
|
|
|
var denseOther = other.Storage as DenseColumnMajorMatrixStorage<Complex32>; |
|
|
|
if (denseOther != null) |
|
|
|
{ |
|
|
|
base.TransposeAndMultiply(other, result); |
|
|
|
var dense = denseOther.Data; |
|
|
|
var diagonal = _data; |
|
|
|
var d = Math.Min(denseOther.ColumnCount, RowCount); |
|
|
|
if (d < RowCount) |
|
|
|
{ |
|
|
|
result.ClearSubMatrix(denseOther.ColumnCount, RowCount - denseOther.ColumnCount, 0, denseOther.RowCount); |
|
|
|
} |
|
|
|
int index = 0; |
|
|
|
for (int j = 0; j < d; j++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < denseOther.RowCount; i++) |
|
|
|
{ |
|
|
|
result.At(j, i, dense[index]*diagonal[j]); |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
base.DoTransposeAndMultiply(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 DoTransposeThisAndMultiply(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
var diagonalOther = other as DiagonalMatrix; |
|
|
|
var diagonalResult = result as DiagonalMatrix; |
|
|
|
if (diagonalOther != null && diagonalResult != null) |
|
|
|
{ |
|
|
|
var thisDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
var otherDataCopy = new Complex32[diagonalResult._data.Length]; |
|
|
|
Array.Copy(_data, thisDataCopy, (diagonalResult._data.Length > _data.Length) ? _data.Length : diagonalResult._data.Length); |
|
|
|
Array.Copy(diagonalOther._data, otherDataCopy, (diagonalResult._data.Length > diagonalOther._data.Length) ? diagonalOther._data.Length : diagonalResult._data.Length); |
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, diagonalResult._data); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var denseOther = other.Storage as DenseColumnMajorMatrixStorage<Complex32>; |
|
|
|
if (denseOther != null) |
|
|
|
{ |
|
|
|
var dense = denseOther.Data; |
|
|
|
var diagonal = _data; |
|
|
|
var d = Math.Min(denseOther.RowCount, ColumnCount); |
|
|
|
if (d < ColumnCount) |
|
|
|
{ |
|
|
|
result.ClearSubMatrix(denseOther.RowCount, ColumnCount - denseOther.RowCount, 0, denseOther.ColumnCount); |
|
|
|
} |
|
|
|
int index = 0; |
|
|
|
for (int i = 0; i < denseOther.ColumnCount; i++) |
|
|
|
{ |
|
|
|
for (int j = 0; j < d; j++) |
|
|
|
{ |
|
|
|
result.At(j, i, dense[index]*diagonal[j]); |
|
|
|
index++; |
|
|
|
} |
|
|
|
index += (denseOther.RowCount - d); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Multiply(otherDiagonal.Transpose(), result); |
|
|
|
base.DoTransposeThisAndMultiply(other, result); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|