|
|
|
@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
using System.Linq; |
|
|
|
using Generic; |
|
|
|
using NumberTheory; |
|
|
|
using Properties; |
|
|
|
using Storage; |
|
|
|
using Threading; |
|
|
|
|
|
|
|
@ -67,8 +66,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
_storage = storage; |
|
|
|
} |
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size.
|
|
|
|
/// </summary>
|
|
|
|
@ -143,8 +140,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a matrix with the given dimensions using the same storage type
|
|
|
|
/// as this vector.
|
|
|
|
@ -178,8 +173,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return new SparseVector(size); |
|
|
|
} |
|
|
|
|
|
|
|
#region Operators and supplementary functions
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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
|
|
|
|
@ -320,41 +313,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>This method is included for completeness.</remarks>
|
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
|
/// <returns>A vector containing a the same values as <paramref name="rightSide"/>.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator +(SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (rightSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("rightSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)rightSide.Plus(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds two <strong>Vectors</strong> together and returns the results.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="leftSide">One of the vectors to add.</param>
|
|
|
|
/// <param name="rightSide">The other vector to add.</param>
|
|
|
|
/// <returns>The result of the addition.</returns>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator +(SparseVector leftSide, SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (leftSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("leftSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)leftSide.Add(rightSide); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Subtracts a scalar from each element of the vector and stores the result in the result vector.
|
|
|
|
/// </summary>
|
|
|
|
@ -458,40 +416,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
|
/// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator -(SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (rightSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("rightSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)rightSide.Negate(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Subtracts two <strong>Vectors</strong> and returns the results.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="leftSide">The vector to subtract from.</param>
|
|
|
|
/// <param name="rightSide">The vector to subtract.</param>
|
|
|
|
/// <returns>The result of the subtraction.</returns>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator -(SparseVector leftSide, SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (leftSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("leftSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)leftSide.Subtract(rightSide); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a negated vector.
|
|
|
|
/// </summary>
|
|
|
|
@ -579,6 +503,99 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the modulus for each element of the vector for the given divisor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="divisor">The divisor to use.</param>
|
|
|
|
/// <param name="result">A vector to store the results in.</param>
|
|
|
|
protected override void DoModulus(float divisor, Vector<float> result) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(this, result)) |
|
|
|
{ |
|
|
|
for (var index = 0; index < _storage.ValueCount; index++) |
|
|
|
{ |
|
|
|
_storage.Values[index] %= divisor; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
result.Clear(); |
|
|
|
for (var index = 0; index < _storage.ValueCount; index++) |
|
|
|
{ |
|
|
|
result.At(_storage.Indices[index], _storage.Values[index] % divisor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>This method is included for completeness.</remarks>
|
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
|
/// <returns>A vector containing a the same values as <paramref name="rightSide"/>.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator +(SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (rightSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("rightSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)rightSide.Plus(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds two <strong>Vectors</strong> together and returns the results.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="leftSide">One of the vectors to add.</param>
|
|
|
|
/// <param name="rightSide">The other vector to add.</param>
|
|
|
|
/// <returns>The result of the addition.</returns>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator +(SparseVector leftSide, SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (leftSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("leftSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)leftSide.Add(rightSide); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rightSide">The vector to get the values from.</param>
|
|
|
|
/// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator -(SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (rightSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("rightSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)rightSide.Negate(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Subtracts two <strong>Vectors</strong> and returns the results.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="leftSide">The vector to subtract from.</param>
|
|
|
|
/// <param name="rightSide">The vector to subtract.</param>
|
|
|
|
/// <returns>The result of the subtraction.</returns>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|
|
|
public static SparseVector operator -(SparseVector leftSide, SparseVector rightSide) |
|
|
|
{ |
|
|
|
if (leftSide == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("leftSide"); |
|
|
|
} |
|
|
|
|
|
|
|
return (SparseVector)leftSide.Subtract(rightSide); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies a vector with a scalar.
|
|
|
|
/// </summary>
|
|
|
|
@ -648,30 +665,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return (SparseVector)leftSide.Divide(rightSide); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the modulus for each element of the vector for the given divisor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="divisor">The divisor to use.</param>
|
|
|
|
/// <param name="result">A vector to store the results in.</param>
|
|
|
|
protected override void DoModulus(float divisor, Vector<float> result) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(this, result)) |
|
|
|
{ |
|
|
|
for (var index = 0; index < _storage.ValueCount; index++) |
|
|
|
{ |
|
|
|
_storage.Values[index] %= divisor; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
result.Clear(); |
|
|
|
for (var index = 0; index < _storage.ValueCount; index++) |
|
|
|
{ |
|
|
|
result.At(_storage.Indices[index], _storage.Values[index] % divisor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the modulus of each element of the vector of the given divisor.
|
|
|
|
/// </summary>
|
|
|
|
@ -891,10 +884,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return OuterProduct(this, v); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Vector Norms
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the p-Norm.
|
|
|
|
/// </summary>
|
|
|
|
@ -931,8 +920,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return (float)Math.Pow(sum, 1.0 / p); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Parse Functions
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -1092,8 +1079,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region System.Object override
|
|
|
|
|
|
|
|
public override string ToString(string format, IFormatProvider formatProvider) |
|
|
|
{ |
|
|
|
if (Count > 20) |
|
|
|
@ -1104,8 +1089,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
return base.ToString(format, formatProvider); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns an <see cref="IEnumerator{T}"/> that contains the position and value of the element.
|
|
|
|
/// </summary>
|
|
|
|
|