|
|
@ -197,16 +197,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
protected override void DoAdd(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
protected override void DoAdd(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// diagonal + diagonal = diagonal
|
|
|
var diagOther = other as DiagonalMatrix; |
|
|
var diagOther = other as DiagonalMatrix; |
|
|
var diagResult = result as DiagonalMatrix; |
|
|
var diagResult = result as DiagonalMatrix; |
|
|
|
|
|
if (diagOther != null && diagResult != null) |
|
|
if (diagOther == null || diagResult == null) |
|
|
|
|
|
{ |
|
|
{ |
|
|
base.DoAdd(other, result); |
|
|
Control.LinearAlgebraProvider.AddArrays(_data, diagOther._data, diagResult._data); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
other.CopyTo(result); |
|
|
|
|
|
for (int i = 0; i < _data.Length; i++) |
|
|
{ |
|
|
{ |
|
|
Control.LinearAlgebraProvider.AddArrays(_data, diagOther._data, diagResult._data); |
|
|
result.At(i, i, result.At(i, i) + _data[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -218,16 +221,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
|
|
|
protected override void DoSubtract(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
protected override void DoSubtract(Matrix<Complex32> other, Matrix<Complex32> result) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// diagonal - diagonal = diagonal
|
|
|
var diagOther = other as DiagonalMatrix; |
|
|
var diagOther = other as DiagonalMatrix; |
|
|
var diagResult = result as DiagonalMatrix; |
|
|
var diagResult = result as DiagonalMatrix; |
|
|
|
|
|
if (diagOther != null && diagResult != null) |
|
|
if (diagOther == null || diagResult == null) |
|
|
|
|
|
{ |
|
|
{ |
|
|
base.DoSubtract(other, result); |
|
|
Control.LinearAlgebraProvider.SubtractArrays(_data, diagOther._data, diagResult._data); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
other.Negate(result); |
|
|
|
|
|
for (int i = 0; i < _data.Length; i++) |
|
|
{ |
|
|
{ |
|
|
Control.LinearAlgebraProvider.SubtractArrays(_data, diagOther._data, diagResult._data); |
|
|
result.At(i, i, result.At(i, i) + _data[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|