Browse Source

LA: Generic Vector file cleanup

v2
Christoph Ruegg 14 years ago
parent
commit
8bc8d46b73
  1. 18
      src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs
  2. 480
      src/Numerics/LinearAlgebra/Generic/Vector.cs

18
src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs

@ -73,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// Returns a hash code for this instance. /// Returns a hash code for this instance.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns> /// </returns>
public override sealed int GetHashCode() public override sealed int GetHashCode()
{ {
@ -86,11 +86,25 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns> /// <returns>
/// A <see cref="System.String"/> that represents this instance. /// A <see cref="System.String"/> that represents this instance.
/// </returns> /// </returns>
public override string ToString() public override sealed string ToString()
{ {
return ToString(null, null); return ToString(null, null);
} }
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <param name="formatProvider">
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.
/// </param>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public string ToString(IFormatProvider formatProvider)
{
return ToString(null, formatProvider);
}
#if !PORTABLE #if !PORTABLE
#region ICloneable #region ICloneable

480
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -81,8 +81,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>Gets or sets the value at the given <paramref name="index"/>.</summary> /// <summary>Gets or sets the value at the given <paramref name="index"/>.</summary>
/// <param name="index">The index of the value to get or set.</param> /// <param name="index">The index of the value to get or set.</param>
/// <returns>The value of the vector at the given <paramref name="index"/>.</returns> /// <returns>The value of the vector at the given <paramref name="index"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative or /// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative or
/// greater than the size of the vector.</exception> /// greater than the size of the vector.</exception>
public T this[int index] public T this[int index]
{ {
@ -141,57 +141,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
Storage.Clear(index, count); Storage.Clear(index, count);
} }
/// <summary>
/// Returns a deep-copy clone of the vector.
/// </summary>
/// <returns>A deep-copy clone of the vector.</returns>
public Vector<T> Clone()
{
var result = CreateVector(Count);
Storage.CopyToUnchecked(result.Storage, skipClearing: true);
return result;
}
/// <summary>
/// Copies the values of this vector into the target vector.
/// </summary>
/// <param name="target">The vector to copy elements into.</param>
/// <exception cref="ArgumentNullException">If <paramref name="target"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="target"/> is not the same size as this vector.</exception>
public void CopyTo(Vector<T> target)
{
if (target == null)
{
throw new ArgumentNullException("target");
}
Storage.CopyTo(target.Storage);
}
/// <summary>
/// Copies the requested elements from this vector to another.
/// </summary>
/// <param name="destination">The vector to copy the elements to.</param>
/// <param name="sourceIndex">The element to start copying from.</param>
/// <param name="targetIndex">The element to start copying to.</param>
/// <param name="count">The number of elements to copy.</param>
public void CopySubVectorTo(Vector<T> destination, int sourceIndex, int targetIndex, int count)
{
if (destination == null)
{
throw new ArgumentNullException("destination");
}
// TODO: refactor range checks
Storage.CopySubVectorTo(destination.Storage, sourceIndex, targetIndex, count);
}
[Obsolete("Use CopySubVectorTo instead. Scheduled for removal in v3.0.")]
public void CopyTo(Vector<T> destination, int sourceIndex, int targetIndex, int count)
{
CopySubVectorTo(destination, sourceIndex, targetIndex, count);
}
/// <summary> /// <summary>
/// Creates a matrix with the given dimensions using the same storage type /// Creates a matrix with the given dimensions using the same storage type
/// as this vector. /// as this vector.
@ -209,8 +158,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns>The new <c>Vector</c>.</returns> /// <returns>The new <c>Vector</c>.</returns>
public abstract Vector<T> CreateVector(int size); public abstract Vector<T> CreateVector(int size);
#region Elementary operations
/// <summary> /// <summary>
/// Adds a scalar to each element of the vector. /// Adds a scalar to each element of the vector.
/// </summary> /// </summary>
@ -444,6 +391,42 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="result">The vector to store the result of the subtraction.</param> /// <param name="result">The vector to store the result of the subtraction.</param>
protected abstract void DoSubtract(Vector<T> other, Vector<T> result); protected abstract void DoSubtract(Vector<T> other, Vector<T> result);
/// <summary>
/// Return vector with complex conjugate values of the source vector
/// </summary>
/// <returns>Conjugated vector</returns>
public Vector<T> Conjugate()
{
var retrunVector = CreateVector(Count);
Conjugate(retrunVector);
return retrunVector;
}
/// <summary>
/// Complex conjugates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
public void Conjugate(Vector<T> target)
{
if (target == null)
{
throw new ArgumentNullException("target");
}
if (Count != target.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "target");
}
DoConjugate(target);
}
/// <summary>
/// Complex conjugates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
protected abstract void DoConjugate(Vector<T> target);
/// <summary> /// <summary>
/// Multiplies a scalar to each element of the vector. /// Multiplies a scalar to each element of the vector.
/// </summary> /// </summary>
@ -588,12 +571,51 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="result">The vector to store the result of the division.</param> /// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Vector<T> result); protected abstract void DoDivide(T scalar, Vector<T> result);
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> Modulus(T divisor)
{
var result = CreateVector(Count);
DoModulus(divisor, result);
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>
public void Modulus(T divisor, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulus(divisor, 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 abstract void DoModulus(T divisor, Vector<T> result);
/// <summary> /// <summary>
/// Pointwise multiplies this vector with another vector. /// Pointwise multiplies this vector with another vector.
/// </summary> /// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param> /// <param name="other">The vector to pointwise multiply with this one.</param>
/// <returns>A new vector which is the pointwise multiplication of the two vectors.</returns> /// <returns>A new vector which is the pointwise multiplication of the two vectors.</returns>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
public Vector<T> PointwiseMultiply(Vector<T> other) public Vector<T> PointwiseMultiply(Vector<T> other)
{ {
@ -617,8 +639,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </summary> /// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param> /// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param> /// <param name="result">The vector to store the result of the pointwise multiplication.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseMultiply(Vector<T> other, Vector<T> result) public void PointwiseMultiply(Vector<T> other, Vector<T> result)
@ -658,7 +680,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </summary> /// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param> /// <param name="other">The vector to pointwise divide this one by.</param>
/// <returns>A new vector which is the pointwise division of the two vectors.</returns> /// <returns>A new vector which is the pointwise division of the two vectors.</returns>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
public Vector<T> PointwiseDivide(Vector<T> other) public Vector<T> PointwiseDivide(Vector<T> other)
{ {
@ -682,8 +704,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </summary> /// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param> /// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="result">The vector to store the result of the pointwise division.</param> /// <param name="result">The vector to store the result of the pointwise division.</param>
/// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception>
/// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception>
public void PointwiseDivide(Vector<T> other, Vector<T> result) public void PointwiseDivide(Vector<T> other, Vector<T> result)
@ -724,8 +746,8 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <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<T> OuterProduct(Vector<T> u, Vector<T> v) public static Matrix<T> OuterProduct(Vector<T> u, Vector<T> v)
{ {
if (u == null) if (u == null)
@ -744,7 +766,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
{ {
matrix.SetRow(i, v.Multiply(u[i])); matrix.SetRow(i, v.Multiply(u[i]));
} }
return matrix; return matrix;
} }
@ -762,116 +784,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
} }
/// <summary> /// <summary>
/// Returns the value of the absolute minimum element. /// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
/// </summary>
/// <returns>The value of the absolute minimum element.</returns>
public abstract T AbsoluteMinimum();
/// <summary>
/// Returns the index of the absolute minimum element.
/// </summary>
/// <returns>The index of absolute minimum element.</returns>
public abstract int AbsoluteMinimumIndex();
/// <summary>
/// Returns the value of the absolute maximum element.
/// </summary>
/// <returns>The value of the absolute maximum element.</returns>
public abstract T AbsoluteMaximum();
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public abstract int AbsoluteMaximumIndex();
/// <summary>
/// Returns the value of maximum element.
/// </summary>
/// <returns>The value of maximum element.</returns>
public T Maximum()
{
return this[MaximumIndex()];
}
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public abstract int MaximumIndex();
/// <summary>
/// Returns the value of the minimum element.
/// </summary>
/// <returns>The value of the minimum element.</returns>
public T Minimum()
{
return this[MinimumIndex()];
}
/// <summary>
/// Returns the index of the minimum element.
/// </summary>
/// <returns>The index of minimum element.</returns>
public abstract int MinimumIndex();
/// <summary>
/// Computes the sum of the vector's elements.
/// </summary>
/// <returns>The sum of the vector's elements.</returns>
public abstract T Sum();
/// <summary>
/// Computes the sum of the absolute value of the vector's elements.
/// </summary>
/// <returns>The sum of the absolute value of the vector's elements.</returns>
public abstract T SumMagnitudes();
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <returns>A vector containing the result.</returns>
public Vector<T> Modulus(T divisor)
{
var result = CreateVector(Count);
DoModulus(divisor, result);
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>
public void Modulus(T divisor, Vector<T> result)
{
if (result == null)
{
throw new ArgumentNullException("result");
}
if (Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
}
DoModulus(divisor, 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 abstract void DoModulus(T divisor, Vector<T> result);
#endregion
#region Arithmetic Operator Overloading
/// <summary>
/// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
/// </summary> /// </summary>
/// <remarks>This method is included for completeness.</remarks> /// <remarks>This method is included for completeness.</remarks>
/// <param name="rightSide">The vector to get the values from.</param> /// <param name="rightSide">The vector to get the values from.</param>
@ -916,7 +829,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
} }
/// <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>
@ -1055,10 +968,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return leftSide.Modulus(rightSide); return leftSide.Modulus(rightSide);
} }
#endregion
#region Vector Norms
/// <summary> /// <summary>
/// Computes the p-Norm. /// Computes the p-Norm.
/// </summary> /// </summary>
@ -1081,83 +990,109 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </returns> /// </returns>
public abstract Vector<T> Normalize(double p); public abstract Vector<T> Normalize(double p);
#endregion /// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>
/// <returns>The value of the absolute minimum element.</returns>
public abstract T AbsoluteMinimum();
/// <summary> /// <summary>
/// Return vector with conjugate values of the source vector /// Returns the index of the absolute minimum element.
/// </summary> /// </summary>
/// <returns>Conjugated vector</returns> /// <returns>The index of absolute minimum element.</returns>
public Vector<T> Conjugate() public abstract int AbsoluteMinimumIndex();
{
var retrunVector = CreateVector(Count);
Conjugate(retrunVector);
return retrunVector;
}
/// <summary> /// <summary>
/// Conjugates vector and save result to <paramref name="target"/> /// Returns the value of the absolute maximum element.
/// </summary> /// </summary>
/// <param name="target">Target vector</param> /// <returns>The value of the absolute maximum element.</returns>
public void Conjugate(Vector<T> target) public abstract T AbsoluteMaximum();
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public abstract int AbsoluteMaximumIndex();
/// <summary>
/// Returns the value of maximum element.
/// </summary>
/// <returns>The value of maximum element.</returns>
public T Maximum()
{ {
if (target == null) return this[MaximumIndex()];
{ }
throw new ArgumentNullException("target");
}
if (Count != target.Count) /// <summary>
{ /// Returns the index of the absolute maximum element.
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "target"); /// </summary>
} /// <returns>The index of absolute maximum element.</returns>
public abstract int MaximumIndex();
DoConjugate(target); /// <summary>
/// Returns the value of the minimum element.
/// </summary>
/// <returns>The value of the minimum element.</returns>
public T Minimum()
{
return this[MinimumIndex()];
} }
/// <summary> /// <summary>
/// Conjugates vector and save result to <paramref name="target"/> /// Returns the index of the minimum element.
/// </summary> /// </summary>
/// <param name="target">Target vector</param> /// <returns>The index of minimum element.</returns>
protected abstract void DoConjugate(Vector<T> target); public abstract int MinimumIndex();
/// <summary>
/// Computes the sum of the vector's elements.
/// </summary>
/// <returns>The sum of the vector's elements.</returns>
public abstract T Sum();
#region Copying and Conversion /// <summary>
/// Computes the sum of the absolute value of the vector's elements.
/// </summary>
/// <returns>The sum of the absolute value of the vector's elements.</returns>
public abstract T SumMagnitudes();
/// <summary> /// <summary>
/// Returns the data contained in the vector as an array. /// Returns a deep-copy clone of the vector.
/// </summary> /// </summary>
/// <returns> /// <returns>A deep-copy clone of the vector.</returns>
/// The vector's data as an array. public Vector<T> Clone()
/// </returns>
public T[] ToArray()
{ {
var result = new DenseVectorStorage<T>(Count); var result = CreateVector(Count);
Storage.CopyToUnchecked(result, skipClearing: true); Storage.CopyToUnchecked(result.Storage, skipClearing: true);
return result.Data; return result;
} }
/// <summary> /// <summary>
/// Create a matrix based on this vector in column form (one single column). /// Set the values of this vector to the given values.
/// </summary> /// </summary>
/// <returns> /// <param name="values">The array containing the values to use.</param>
/// This vector as a column matrix. /// <exception cref="ArgumentNullException">If <paramref name="values"/> is <see langword="null" />.</exception>
/// </returns> /// <exception cref="ArgumentException">If <paramref name="values"/> is not the same size as this vector.</exception>
public virtual Matrix<T> ToColumnMatrix() public void SetValues(T[] values)
{ {
var result = CreateMatrix(Count, 1); var source = new DenseVectorStorage<T>(Count, values);
result.Storage.CopyColumnFrom(Storage, 0, skipClearing: true); source.CopyTo(Storage);
return result;
} }
/// <summary> /// <summary>
/// Create a matrix based on this vector in row form (one single row). /// Copies the values of this vector into the target vector.
/// </summary> /// </summary>
/// <returns> /// <param name="target">The vector to copy elements into.</param>
/// This vector as a row matrix. /// <exception cref="ArgumentNullException">If <paramref name="target"/> is <see langword="null"/>.</exception>
/// </returns> /// <exception cref="ArgumentException">If <paramref name="target"/> is not the same size as this vector.</exception>
public virtual Matrix<T> ToRowMatrix() public void CopyTo(Vector<T> target)
{ {
var result = CreateMatrix(1, Count); if (target == null)
result.Storage.CopyRowFrom(Storage, 0, skipClearing: true); {
return result; throw new ArgumentNullException("target");
}
Storage.CopyTo(target.Storage);
} }
/// <summary> /// <summary>
@ -1196,18 +1131,67 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
} }
/// <summary> /// <summary>
/// Set the values of this vector to the given values. /// Copies the requested elements from this vector to another.
/// </summary> /// </summary>
/// <param name="values">The array containing the values to use.</param> /// <param name="destination">The vector to copy the elements to.</param>
/// <exception cref="ArgumentNullException">If <paramref name="values"/> is <see langword="null" />.</exception> /// <param name="sourceIndex">The element to start copying from.</param>
/// <exception cref="ArgumentException">If <paramref name="values"/> is not the same size as this vector.</exception> /// <param name="targetIndex">The element to start copying to.</param>
public void SetValues(T[] values) /// <param name="count">The number of elements to copy.</param>
public void CopySubVectorTo(Vector<T> destination, int sourceIndex, int targetIndex, int count)
{ {
var source = new DenseVectorStorage<T>(Count, values); if (destination == null)
source.CopyTo(Storage); {
throw new ArgumentNullException("destination");
}
// TODO: refactor range checks
Storage.CopySubVectorTo(destination.Storage, sourceIndex, targetIndex, count);
} }
#endregion [Obsolete("Use CopySubVectorTo instead. Scheduled for removal in v3.0.")]
public void CopyTo(Vector<T> destination, int sourceIndex, int targetIndex, int count)
{
CopySubVectorTo(destination, sourceIndex, targetIndex, count);
}
/// <summary>
/// Returns the data contained in the vector as an array.
/// </summary>
/// <returns>
/// The vector's data as an array.
/// </returns>
public T[] ToArray()
{
var result = new DenseVectorStorage<T>(Count);
Storage.CopyToUnchecked(result, skipClearing: true);
return result.Data;
}
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>
/// This vector as a column matrix.
/// </returns>
public virtual Matrix<T> ToColumnMatrix()
{
var result = CreateMatrix(Count, 1);
result.Storage.CopyColumnFrom(Storage, 0, skipClearing: true);
return result;
}
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>
/// This vector as a row matrix.
/// </returns>
public virtual Matrix<T> ToRowMatrix()
{
var result = CreateMatrix(1, Count);
result.Storage.CopyRowFrom(Storage, 0, skipClearing: true);
return result;
}
/// <summary> /// <summary>
/// Returns an enumerator that iterates through the collection. /// Returns an enumerator that iterates through the collection.
@ -1231,9 +1215,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// element. /// element.
/// </returns> /// </returns>
/// <remarks> /// <remarks>
/// The enumerator returns a /// The enumerator returns a
/// <seealso cref="Tuple{T,K}"/> /// <seealso cref="Tuple{T,K}"/>
/// with the first value being the element index and the second value /// with the first value being the element index and the second value
/// being the value of the element at that index. For sparse vectors, the enumerator will exclude all elements /// being the value of the element at that index. For sparse vectors, the enumerator will exclude all elements
/// with a zero value. /// with a zero value.
/// </remarks> /// </remarks>
@ -1245,22 +1229,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
} }
} }
#region IFormattable
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <param name="formatProvider">
/// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.
/// </param>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public string ToString(IFormatProvider formatProvider)
{
return ToString(null, formatProvider);
}
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents this instance. /// Returns a <see cref="System.String"/> that represents this instance.
/// </summary> /// </summary>
@ -1276,17 +1244,17 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
public virtual string ToString(string format, IFormatProvider formatProvider) public virtual string ToString(string format, IFormatProvider formatProvider)
{ {
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
var separator = formatProvider.GetTextInfo().ListSeparator;
for (var index = 0; index < Count; index++) for (var index = 0; index < Count; index++)
{ {
stringBuilder.Append(this[index].ToString(format, formatProvider)); stringBuilder.Append(this[index].ToString(format, formatProvider));
if (index != Count - 1) if (index != Count - 1)
{ {
stringBuilder.Append(formatProvider.GetTextInfo().ListSeparator); stringBuilder.Append(separator);
} }
} }
return stringBuilder.ToString(); return stringBuilder.ToString();
} }
#endregion
} }
} }

Loading…
Cancel
Save