|
|
@ -128,44 +128,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
return new SparseVector(SparseVectorStorage<Complex32>.OfInit(length, init)); |
|
|
return new SparseVector(SparseVectorStorage<Complex32>.OfInit(length, init)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Conjugates vector and save result to <paramref name="result"/>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="result">Target vector</param>
|
|
|
|
|
|
protected override void DoConjugate(Vector<Complex32> result) |
|
|
|
|
|
{ |
|
|
|
|
|
if (ReferenceEquals(this, result)) |
|
|
|
|
|
{ |
|
|
|
|
|
var tmp = Build.SameAs(this); |
|
|
|
|
|
DoConjugate(tmp); |
|
|
|
|
|
tmp.CopyTo(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var targetSparse = result as SparseVector; |
|
|
|
|
|
if (targetSparse == null) |
|
|
|
|
|
{ |
|
|
|
|
|
base.DoConjugate(result); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Lets copy only needed data. Portion of needed data is determined by NonZerosCount value
|
|
|
|
|
|
targetSparse._storage.Values = new Complex32[_storage.ValueCount]; |
|
|
|
|
|
targetSparse._storage.Indices = new int[_storage.ValueCount]; |
|
|
|
|
|
targetSparse._storage.ValueCount = _storage.ValueCount; |
|
|
|
|
|
|
|
|
|
|
|
if (_storage.ValueCount != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
CommonParallel.For(0, _storage.ValueCount, (a, b) => |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = a; i < b; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
targetSparse._storage.Values[i] = _storage.Values[i].Conjugate(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
Buffer.BlockCopy(_storage.Indices, 0, targetSparse._storage.Indices, 0, _storage.ValueCount*Constants.SizeOfInt); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Adds a scalar to each element of the vector and stores the result in the result vector.
|
|
|
/// Adds a scalar to each element of the vector and stores the result in the result vector.
|
|
|
/// Warning, the new 'sparse vector' with a non-zero scalar added to it will be a 100% filled
|
|
|
/// Warning, the new 'sparse vector' with a non-zero scalar added to it will be a 100% filled
|
|
|
@ -191,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, result)) |
|
|
if (ReferenceEquals(this, result)) |
|
|
{ |
|
|
{ |
|
|
//populate a new vector with the scalar
|
|
|
//populate a new vector with the scalar
|
|
|
var vnonZeroValues = new Complex32[Count]; |
|
|
var vnonZeroValues = new Complex32[Count]; |
|
|
var vnonZeroIndices = new int[Count]; |
|
|
var vnonZeroIndices = new int[Count]; |
|
|
for (int index = 0; index < Count; index++) |
|
|
for (int index = 0; index < Count; index++) |
|
|
@ -208,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
vnonZeroValues[indices[j]] = values[j] + scalar; |
|
|
vnonZeroValues[indices[j]] = values[j] + scalar; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//assign this vectors arrary to the new arrays.
|
|
|
//assign this vectors arrary to the new arrays.
|
|
|
_storage.Values = vnonZeroValues; |
|
|
_storage.Values = vnonZeroValues; |
|
|
_storage.Indices = vnonZeroIndices; |
|
|
_storage.Indices = vnonZeroIndices; |
|
|
_storage.ValueCount = Count; |
|
|
_storage.ValueCount = Count; |
|
|
@ -422,19 +384,47 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
{ |
|
|
{ |
|
|
result.At(_storage.Indices[index], -_storage.Values[index]); |
|
|
result.At(_storage.Indices[index], -_storage.Values[index]); |
|
|
} |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
if (!ReferenceEquals(this, result)) |
|
|
|
|
|
{ |
|
|
|
|
|
sparseResult._storage.ValueCount = _storage.ValueCount; |
|
|
|
|
|
sparseResult._storage.Indices = new int[_storage.ValueCount]; |
|
|
|
|
|
Buffer.BlockCopy(_storage.Indices, 0, sparseResult._storage.Indices, 0, _storage.ValueCount*Constants.SizeOfInt); |
|
|
|
|
|
sparseResult._storage.Values = new Complex32[_storage.ValueCount]; |
|
|
|
|
|
Array.Copy(_storage.Values, sparseResult._storage.Values, _storage.ValueCount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Control.LinearAlgebraProvider.ScaleArray(-Complex32.One, sparseResult._storage.Values, sparseResult._storage.Values); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Conjugates vector and save result to <paramref name="result"/>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="result">Target vector</param>
|
|
|
|
|
|
protected override void DoConjugate(Vector<Complex32> result) |
|
|
|
|
|
{ |
|
|
|
|
|
var sparseResult = result as SparseVector; |
|
|
|
|
|
if (sparseResult != null) |
|
|
{ |
|
|
{ |
|
|
if (!ReferenceEquals(this, result)) |
|
|
if (!ReferenceEquals(this, result)) |
|
|
{ |
|
|
{ |
|
|
sparseResult._storage.ValueCount = _storage.ValueCount; |
|
|
sparseResult._storage.ValueCount = _storage.ValueCount; |
|
|
sparseResult._storage.Indices = new int[_storage.ValueCount]; |
|
|
sparseResult._storage.Indices = new int[_storage.ValueCount]; |
|
|
Buffer.BlockCopy(_storage.Indices, 0, sparseResult._storage.Indices, 0, _storage.ValueCount * Constants.SizeOfInt); |
|
|
Buffer.BlockCopy(_storage.Indices, 0, sparseResult._storage.Indices, 0, _storage.ValueCount*Constants.SizeOfInt); |
|
|
sparseResult._storage.Values = new Complex32[_storage.ValueCount]; |
|
|
sparseResult._storage.Values = new Complex32[_storage.ValueCount]; |
|
|
Array.Copy(_storage.Values, sparseResult._storage.Values, _storage.ValueCount); |
|
|
Array.Copy(_storage.Values, sparseResult._storage.Values, _storage.ValueCount); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Control.LinearAlgebraProvider.ScaleArray(-Complex32.One, sparseResult._storage.Values, sparseResult._storage.Values); |
|
|
Control.LinearAlgebraProvider.ConjugateArray(sparseResult._storage.Values, sparseResult._storage.Values); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result.Clear(); |
|
|
|
|
|
for (var index = 0; index < _storage.ValueCount; index++) |
|
|
|
|
|
{ |
|
|
|
|
|
result.At(_storage.Indices[index], _storage.Values[index].Conjugate()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -542,7 +532,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
|
|
|
/// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
/// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
|
|
|
/// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
|
|
|
@ -664,7 +654,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Returns the index of the absolute minimum element.
|
|
|
/// Returns the index of the absolute minimum element.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <returns>The index of absolute minimum element.</returns>
|
|
|
/// <returns>The index of absolute minimum element.</returns>
|
|
|
public override int AbsoluteMinimumIndex() |
|
|
public override int AbsoluteMinimumIndex() |
|
|
{ |
|
|
{ |
|
|
if (_storage.ValueCount == 0) |
|
|
if (_storage.ValueCount == 0) |
|
|
@ -805,8 +795,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 |
|
|
/// <param name="u">First vector</param>
|
|
|
/// <param name="u">First vector</param>
|
|
|
/// <param name="v">Second vector</param>
|
|
|
/// <param name="v">Second vector</param>
|
|
|
/// <returns>Matrix M[i,j] = u[i]*v[j] </returns>
|
|
|
/// <returns>Matrix M[i,j] = u[i]*v[j] </returns>
|
|
|
/// <exception cref="ArgumentNullException">If the u vector is <see langword="null" />.</exception>
|
|
|
/// <exception cref="ArgumentNullException">If the u vector is <see langword="null" />.</exception>
|
|
|
/// <exception cref="ArgumentNullException">If the v vector is <see langword="null" />.</exception>
|
|
|
/// <exception cref="ArgumentNullException">If the v vector is <see langword="null" />.</exception>
|
|
|
public static Matrix<Complex32> /*SparseMatrix*/ OuterProduct(SparseVector u, SparseVector v) |
|
|
public static Matrix<Complex32> /*SparseMatrix*/ OuterProduct(SparseVector u, SparseVector v) |
|
|
{ |
|
|
{ |
|
|
if (u == null) |
|
|
if (u == null) |
|
|
|