Class SparseVector
A one-dimensional vector of double values, optimised for the case where many of the elements share a common value (which need not be zero).
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Math
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public class SparseVector : Vector, IReadOnlyList<double>, IReadOnlyCollection<double>, SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>, SettableToWeightedSum<Vector>, ISparseList<double>, IList<double>, ICollection<double>, ISparseEnumerable<double>, IEnumerable<double>, IEnumerable, ICloneable, CanSetAllElementsTo<double>, SettableTo<Vector>
Constructors
SparseVector()
Constructs a zero vector with the given number of elements.
Declaration
protected SparseVector()
SparseVector(SparseVector)
Copy constructor.
Declaration
protected SparseVector(SparseVector that)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | the vector to copy into this new vector |
SparseVector(IList<Double>)
Creates a sparse vector from a list of doubles.
Declaration
protected SparseVector(IList<double> dlist)
Parameters
Type | Name | Description |
---|---|---|
IList<Double> | dlist | the list of doubles |
SparseVector(Int32)
Constructs a zero vector with the given number of elements.
Declaration
protected SparseVector(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements to allocate (>= 0). |
SparseVector(Int32, Double)
Constructs a vector of a given length and assigns all elements the given value.
Declaration
protected SparseVector(int count, double commonValue)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements to allocate (>= 0). |
Double | commonValue | The value to assign to all elements. |
SparseVector(Int32, Double, List<ValueAtIndex<Double>>)
Constructs a vector of a given length and assigns all elements the given value, except for the specified list of sparse values. This list is stored internally as is so MUST be sorted by index and must not be modified externally.
Declaration
protected SparseVector(int count, double commonValue, List<ValueAtIndex<double>> sortedSparseValues)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements to allocate (>= 0). |
Double | commonValue | The value to assign to all elements. |
List<ValueAtIndex<Double>> | sortedSparseValues | The list of sparse values, which must be sorted by index. |
Properties
CommonValue
The value of all elements not mentioned explicitly as sparse values.
Declaration
[DataMember]
public double CommonValue { get; protected set; }
Property Value
Type | Description |
---|---|
Double |
Count
The number of elements in this vector
Declaration
public override int Count { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
HasCommonElements
Returns true if there is at least one element which has the common value.
Declaration
public bool HasCommonElements { get; }
Property Value
Type | Description |
---|---|
Boolean |
Item[Int32]
Gets or sets an element at a given index.
Declaration
public override double this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of an element. |
Property Value
Type | Description |
---|---|
Double | The element at a given index. |
Overrides
SparseCount
The number of elements not equal to the common value
Declaration
public int SparseCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
SparseValues
A list of the value and indices of elements which may not have the common value (although they are not precluded from doing so). This list is kept sorted by index to allow efficient operations on the sparse vector.
Declaration
[DataMember]
public List<ValueAtIndex<double>> SparseValues { get; protected set; }
Property Value
Type | Description |
---|---|
List<ValueAtIndex<Double>> |
Methods
Add(Double)
Declaration
public void Add(double item)
Parameters
Type | Name | Description |
---|---|---|
Double | item |
All(Converter<Double, Boolean>)
Tests if all elements in the vector satisfy the specified condition.
Declaration
public override bool All(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun |
Returns
Type | Description |
---|---|
Boolean |
Overrides
Any(SparseVector, Func<Double, Double, Boolean>)
Test if any corresponding elements in this and that vector satisfy a condition
Declaration
public bool Any(SparseVector that, Func<double, double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | |
Func<Double, Double, Boolean> | fun |
Returns
Type | Description |
---|---|
Boolean |
Any(Vector, Func<Double, Double, Boolean>)
Test if any corresponding elements in this and that vector satisfy a condition
Declaration
public override bool Any(Vector that, Func<double, double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | |
Func<Double, Double, Boolean> | fun |
Returns
Type | Description |
---|---|
Boolean |
Overrides
Any(Converter<Double, Boolean>)
Tests if any elements in the vector satisfy the specified condition.
Declaration
public override bool Any(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun |
Returns
Type | Description |
---|---|
Boolean |
Overrides
Append(Vector)
Returns a new vector which appends a second vector to this vector
Declaration
public override Vector Append(Vector second)
Parameters
Type | Name | Description |
---|---|---|
Vector | second | Second vector |
Returns
Type | Description |
---|---|
Vector |
Overrides
Remarks
If the second vector is dense, or if the common values for the two vectors are different, then the result becomes dense
Append(Double)
Appends an item to a vector - returns a new sparse vector
Declaration
public override Vector Append(double item)
Parameters
Type | Name | Description |
---|---|---|
Double | item |
Returns
Type | Description |
---|---|
Vector |
Overrides
AsSparseVector(IList<Double>)
Converts the supplied list of doubles to a sparse vector, or does nothing if it is already a sparse vector.
Declaration
public static SparseVector AsSparseVector(IList<double> iList)
Parameters
Type | Name | Description |
---|---|---|
IList<Double> | iList |
Returns
Type | Description |
---|---|
SparseVector | A sparse vector containing the list of doubles |
Clear()
Declaration
public void Clear()
Clone()
Clones this vector - return as a vector
Declaration
public override Vector Clone()
Returns
Type | Description |
---|---|
Vector |
Overrides
Constant(Int32, Double)
Create a sparse vector of given length with elements all equal to a specified value
Declaration
public static SparseVector Constant(int count, double value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements in vector |
Double | value | value for each element |
Returns
Type | Description |
---|---|
SparseVector |
Contains(Double)
Returns true if the Vector contains the specified value
Declaration
public override bool Contains(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value to test for |
Returns
Type | Description |
---|---|
Boolean |
Overrides
Copy(Vector)
Creator a sparse vector as a copy of another vector (which may not be sparse)
Declaration
public static SparseVector Copy(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The source vector - can be dense or sparse |
Returns
Type | Description |
---|---|
SparseVector |
CopyTo(Double[], Int32)
Copies this vector to the given array starting at the specified index in the target array
Declaration
public override void CopyTo(double[] array, int index)
Parameters
Type | Name | Description |
---|---|---|
Double[] | array | The target array |
Int32 | index | The start index in the target array |
Overrides
CountAll(Converter<Double, Boolean>)
Returns the number of elements in the vector which satisfy a given condition.
Declaration
public override int CountAll(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun | The condition for the elements to satisfy. |
Returns
Type | Description |
---|---|
Int32 | The number of elements in the vector which satisfy the condition. |
Overrides
Equals(Object)
Determines object equality.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | Another (vector) object. |
Returns
Type | Description |
---|---|
Boolean | True if equal. |
Overrides
FindAll(Converter<Double, Boolean>)
Returns an enumeration over the indices of all elements which satisfy the specified condition. Indices are returned in sorted order.
Declaration
public override IEnumerable<ValueAtIndex<double>> FindAll(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun | A function to check if the condition is satisfied. |
Returns
Type | Description |
---|---|
IEnumerable<ValueAtIndex<Double>> | An enumeration over the indices and values of all the elements which satisfy the specified condition. |
Overrides
FindFirstIndex(Converter<Double, Boolean>)
Returns the index of the first element that satisfies a given condition.
Declaration
public override int FindFirstIndex(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun | The condition for the element to satisfy. |
Returns
Type | Description |
---|---|
Int32 | The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1. |
Overrides
FindLastIndex(Converter<Double, Boolean>)
Returns the index of the last element that satisfies a given condition.
Declaration
public override int FindLastIndex(Converter<double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Boolean> | fun | The condition for the element to satisfy. |
Returns
Type | Description |
---|---|
Int32 | The last index. |
Overrides
FromArray(Double[])
Constructs a sparse vector from a dense array.
Declaration
public static SparseVector FromArray(params double[] data)
Parameters
Type | Name | Description |
---|---|---|
Double[] | data | 1D array of elements. |
Returns
Type | Description |
---|---|
SparseVector |
Remarks
The array data is copied into new storage. The size of the vector is taken from the array.
FromArray(Int32, Double[], Int32)
Constructs a vector from part of an array.
Declaration
public static SparseVector FromArray(int count, double[] data, int start)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The number of elements in the vector. |
Double[] | data | Storage for the vector elements. |
Int32 | start | The starting index in the array for the vector elements. |
Returns
Type | Description |
---|---|
SparseVector |
Remarks
Throws an exception if Data is null, start < 0, or count < 0.
FromSparseValues(Int32, Double, List<ValueAtIndex<Double>>)
Constructs a sparse vector from a sorted list of sparse elements.
Declaration
[Construction(new string[]{"Count", "CommonValue", "SparseValues"})]
public static SparseVector FromSparseValues(int count, double commonValue, List<ValueAtIndex<double>> sortedSparseValues)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Count for result |
Double | commonValue | Common value |
List<ValueAtIndex<Double>> | sortedSparseValues | Sorted list of sparse elements |
Returns
Type | Description |
---|---|
SparseVector |
GetEnumerator()
Gets a typed enumerator which yields the vector elements
Declaration
public override IEnumerator<double> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Double> |
Overrides
GetFirstCommonIndex()
Gets the dense index of the first common element.
Declaration
public int GetFirstCommonIndex()
Returns
Type | Description |
---|---|
Int32 | Returns the dense index of the first common element or -1 if there are no common elements |
GetHashCode()
Gets a hash code for the instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The code. |
Overrides
GetSparseEnumerator()
Returns a sparse enumerator
Declaration
public ISparseEnumerator<double> GetSparseEnumerator()
Returns
Type | Description |
---|---|
ISparseEnumerator<Double> |
GetSparseIndex(Int32)
Gets the index into the sparse values array corresponding to an element index. If there is no sparse value at that index, returns the binary complement of the index in the sparse array where such an element should be inserted to retain the sort order of the sparse array.
Declaration
protected int GetSparseIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
Int32 |
GreaterThan(Vector)
Tests if this vector is strictly greater than a second vector.
Declaration
public override bool GreaterThan(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The value to test against. |
Returns
Type | Description |
---|---|
Boolean | True if each element is strictly greater than the corresponding element of |
Overrides
GreaterThanOrEqual(Vector)
Tests if this vector is than or equal to a second vector.
Declaration
public override bool GreaterThanOrEqual(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The value to test against. |
Returns
Type | Description |
---|---|
Boolean | True if each element is greater than or equal to the corresponding element of |
Overrides
IndexAtCumulativeSum(Double)
Returns the index of the first element at which the sum of all elements so far is greater than a particular value. Useful for finding the median of a Discrete distribution.
Declaration
public override int IndexAtCumulativeSum(double targetSum)
Parameters
Type | Name | Description |
---|---|---|
Double | targetSum | The sum of interest |
Returns
Type | Description |
---|---|
Int32 | The index of the element where |
Overrides
IndexOf(Double)
Returns the index of the first occurence of the given value in the array. Returns -1 if the value is not in the array
Declaration
public override int IndexOf(double item)
Parameters
Type | Name | Description |
---|---|---|
Double | item | The item to check for |
Returns
Type | Description |
---|---|
Int32 | Its index in the array |
Overrides
IndexOfMaximum()
Returns the index of the maximum element.
Declaration
public override int IndexOfMaximum()
Returns
Type | Description |
---|---|
Int32 | The index of the maximum element. |
Overrides
IndexOfMinimum()
Returns the index of the minimum element.
Declaration
public override int IndexOfMinimum()
Returns
Type | Description |
---|---|
Int32 | The index of the minimum element. |
Overrides
Inner(SparseVector)
Returns the inner product of this sparse vector with another sparse vector.
Declaration
public double Inner(SparseVector that)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | Second vector, which must have the same size as |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Inner(SparseVector, Converter<Double, Double>)
Returns the inner product of this sparse vector with a function of a second sparse vector.
Declaration
public double Inner(SparseVector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | Second vector, which must have the same size as |
Converter<Double, Double> | fun | Function to convert the elements of the second vector |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Inner(Vector)
Returns the inner product of this vector with another vector.
Declaration
public override double Inner(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | Second vector, which must have the same size as |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Overrides
Inner(Vector, Converter<Double, Double>)
Returns the inner product of this vector with a function of a second vector.
Declaration
public override double Inner(Vector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | Second vector, which must have the same size as |
Converter<Double, Double> | fun | Function to convert the elements of the second vector |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Overrides
Inner(Converter<Double, Double>, SparseVector, Converter<Double, Double>)
Returns the inner product of a function of this sparse vector with a function of a second sparse vector.
Declaration
public double Inner(Converter<double, double> thisFun, SparseVector that, Converter<double, double> thatFun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | thisFun | Function to convert the elements of this vector |
SparseVector | that | Second vector, which must have the same size as |
Converter<Double, Double> | thatFun | Function to convert the elements of that vector |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Inner(Converter<Double, Double>, Vector, Converter<Double, Double>)
Returns the inner product of a function of this vector with a function of a second vector.
Declaration
public override double Inner(Converter<double, double> thisFun, Vector that, Converter<double, double> thatFun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | thisFun | Function to convert the elements of this vector |
Vector | that | Second vector, which must have the same size as |
Converter<Double, Double> | thatFun | Function to convert the elements of that vector |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Overrides
LessThan(Vector)
Tests if this vector is strictly less than a second vector.
Declaration
public override bool LessThan(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The value to test against. |
Returns
Type | Description |
---|---|
Boolean | True if each element is strictly less than the corresponding element of |
Overrides
LessThanOrEqual(Vector)
Tests if this vector is less than or equal to a second vector.
Declaration
public override bool LessThanOrEqual(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The value to test against. |
Returns
Type | Description |
---|---|
Boolean | True if each element is strictly less than or equal to the corresponding element of |
Overrides
LogSumExp()
Returns the log of the sum of exponentials of the elements of the vector computed to high accuracy
Declaration
public override double LogSumExp()
Returns
Type | Description |
---|---|
Double |
Overrides
Max()
Returns the maximum of the elements in the vector
Declaration
public override double Max()
Returns
Type | Description |
---|---|
Double |
Overrides
Max(Converter<Double, Double>)
Returns the maximum of a function of the elements in the vector
Declaration
public override double Max(Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Conversion function |
Returns
Type | Description |
---|---|
Double |
Overrides
MaxDiff(Vector)
Returns the maximum absolute difference between this vector and another vector.
Declaration
public override double MaxDiff(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The second vector. |
Returns
Type | Description |
---|---|
Double |
|
Overrides
Remarks
This routine is typically used instead of Equals
, since Equals
is susceptible to roundoff errors.
MaxDiff(Vector, Double)
Returns the maximum relative difference between this vector and another.
Declaration
public override double MaxDiff(Vector that, double rel)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The second vector. |
Double | rel | An offset to avoid division by zero. |
Returns
Type | Description |
---|---|
Double |
|
Overrides
Remarks
This routine is typically used instead of Equals
, since Equals
is susceptible to roundoff errors.
Median()
Returns the median of all elements.
Declaration
public override double Median()
Returns
Type | Description |
---|---|
Double |
Overrides
Min()
Returns the minimum of the elements in the vector
Declaration
public override double Min()
Returns
Type | Description |
---|---|
Double |
Overrides
Min(Converter<Double, Double>)
Returns the minimum of the elements in the vector
Declaration
public override double Min(Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Conversion function |
Returns
Type | Description |
---|---|
Double |
Overrides
Outer(SparseVector)
Returns the outer product of this sparse vector with another sparse vector.
Declaration
public Matrix Outer(SparseVector that)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | Second vector. |
Returns
Type | Description |
---|---|
Matrix | Their outer product. |
Outer(Vector)
Returns the outer product of this vector with another vector.
Declaration
public override Matrix Outer(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | Second vector. |
Returns
Type | Description |
---|---|
Matrix | Their outer product. |
Overrides
Reduce(Double, SparseVector, SparseVector, Func<Double, Double, Double, Double, Double>)
Reduce method. Operates on this vector and two other vectors
Declaration
public double Reduce(double initial, SparseVector a, SparseVector b, Func<double, double, double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Double | initial | Initial value |
SparseVector | a | A second vector |
SparseVector | b | A third vector |
Func<Double, Double, Double, Double, Double> | fun | Reduction function |
Returns
Type | Description |
---|---|
Double |
Reduce(Double, SparseVector, Func<Double, Double, Double, Double>)
Reduce method. Operates on this vector and that vector
Declaration
public double Reduce(double initial, SparseVector that, Func<double, double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Double | initial | Initial value |
SparseVector | that | A second vector |
Func<Double, Double, Double, Double> | fun | Reduction function taking partial result, current element, and current element of |
Returns
Type | Description |
---|---|
Double |
Reduce(Double, Vector, Func<Double, Double, Double, Double>)
Reduce method. Operates on this vector and that vector
Declaration
public override double Reduce(double initial, Vector that, Func<double, double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Double | initial | Initial value |
Vector | that | A second vector |
Func<Double, Double, Double, Double> | fun | Reduction function taking partial result, current element, and current element of |
Returns
Type | Description |
---|---|
Double |
Overrides
Reduce(Double, Func<Double, Double, Double>)
Reduce method. Operates on this vector
Declaration
public override double Reduce(double initial, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Double | initial | Initial value |
Func<Double, Double, Double> | fun | Reduction function taking partial result and current element |
Returns
Type | Description |
---|---|
Double |
Overrides
Reduce<TRes>(TRes, Func<TRes, Double, TRes>, Func<TRes, Double, Int32, TRes>)
Reduce method which can take advantage of sparse structure. Operates on this list
Declaration
public TRes Reduce<TRes>(TRes initial, Func<TRes, double, TRes> fun, Func<TRes, double, int, TRes> repeatedFun)
Parameters
Type | Name | Description |
---|---|---|
TRes | initial | Initial value |
Func<TRes, Double, TRes> | fun | Reduction function taking partial result and current element |
Func<TRes, Double, Int32, TRes> | repeatedFun | Function which computes the reduction function applied multiple times |
Returns
Type | Description |
---|---|
TRes |
Type Parameters
Name | Description |
---|---|
TRes |
Remarks
This method does not take advantage of this list's sparseness.
Reduce<TRes, T1>(TRes, ISparseEnumerable<T1>, Func<TRes, Double, T1, TRes>, Func<TRes, Double, T1, Int32, TRes>)
Reduce method which can take advantage of sparse structure. Operates on this list and another sparse collection
Declaration
public TRes Reduce<TRes, T1>(TRes initial, ISparseEnumerable<T1> that, Func<TRes, double, T1, TRes> fun, Func<TRes, double, T1, int, TRes> repeatedFun)
Parameters
Type | Name | Description |
---|---|---|
TRes | initial | Initial value |
ISparseEnumerable<T1> | that | The other sparse collection |
Func<TRes, Double, T1, TRes> | fun | Reduction function taking partial result and current element |
Func<TRes, Double, T1, Int32, TRes> | repeatedFun | Function which computes the reduction function applied multiple times |
Returns
Type | Description |
---|---|
TRes |
Type Parameters
Name | Description |
---|---|
TRes | |
T1 |
Reduce<TRes, T1, T2>(TRes, ISparseEnumerable<T1>, ISparseEnumerable<T2>, Func<TRes, Double, T1, T2, TRes>, Func<TRes, Double, T1, T2, Int32, TRes>)
Reduce method which can take advantage of sparse structure. Operates on this list and two other sparse collections
Declaration
public TRes Reduce<TRes, T1, T2>(TRes initial, ISparseEnumerable<T1> b, ISparseEnumerable<T2> c, Func<TRes, double, T1, T2, TRes> fun, Func<TRes, double, T1, T2, int, TRes> repeatedFun)
Parameters
Type | Name | Description |
---|---|---|
TRes | initial | Initial value |
ISparseEnumerable<T1> | b | A second sparse collection |
ISparseEnumerable<T2> | c | A third sparse collection |
Func<TRes, Double, T1, T2, TRes> | fun | Reduction function taking partial result and current element |
Func<TRes, Double, T1, T2, Int32, TRes> | repeatedFun | Function which computes the reduction function applied multiple times |
Returns
Type | Description |
---|---|
TRes |
Type Parameters
Name | Description |
---|---|
TRes | |
T1 | |
T2 |
Remove(Double)
Declaration
public bool Remove(double item)
Parameters
Type | Name | Description |
---|---|---|
Double | item |
Returns
Type | Description |
---|---|
Boolean |
Scale(Double)
Multiplies this vector by a scalar.
Declaration
public override void Scale(double scale)
Parameters
Type | Name | Description |
---|---|---|
Double | scale | The scalar. |
Overrides
Remarks
this receives the product. This method is a synonym for SetToProduct(this, scale)
SetAllElementsTo(Double)
Sets all elements to a given value.
Declaration
public override void SetAllElementsTo(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The new value. |
Overrides
SetSubvector(Int32, Vector)
Set a subvector of this sparse vector to another vector. The common value is not changed
Declaration
public override void SetSubvector(int startIndex, Vector that)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startIndex | The index of the first element of this to copy to. |
Vector | that | A vector whose length is at most |
Overrides
SetTo(SparseVector)
Copies values from a sparse vector to this sparse vector.
Declaration
public virtual void SetTo(SparseVector that)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that |
SetTo(Vector)
Copies values from a Vector to this vector.
Declaration
public override void SetTo(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that |
Overrides
Remarks
The source vector can be dense, in which case the minimum value is used as the common value.
SetTo(IEnumerable<Double>)
Copies values from an Enumerable to this vector
Declaration
public override void SetTo(IEnumerable<double> that)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Double> | that |
Overrides
SetTo(IList<Double>)
Copies values from a list of doubles which must have the same size as this vector. The 'common value' is set to the minimum value of the list.
Declaration
public virtual void SetTo(IList<double> dlist)
Parameters
Type | Name | Description |
---|---|---|
IList<Double> | dlist |
SetTo(IList<Double>, Double)
Copies values from a list of doubles which must have the same size as this vector, using the specified common value.
Declaration
public virtual void SetTo(IList<double> dlist, double commonValue)
Parameters
Type | Name | Description |
---|---|---|
IList<Double> | dlist | List of doubles |
Double | commonValue | Common value |
SetTo(Double[])
Copies values from an array. The minimum value is used as the common value
Declaration
public override void SetTo(double[] values)
Parameters
Type | Name | Description |
---|---|---|
Double[] | values | An array whose length matches |
Overrides
SetToDiagonal(Matrix)
Sets this vector to the diagonal of a matrix.
Declaration
public override void SetToDiagonal(Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | A matrix with Rows==Cols==this.Count. |
Overrides
SetToFunction(SparseVector, SparseVector, Func<Double, Double, Double>)
Sets the elements of this sparse vector to a function of the elements of two other sparse vectors
Declaration
public virtual SparseVector SetToFunction(SparseVector a, SparseVector b, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | a | The first vector |
SparseVector | b | The second vector |
Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
Type | Description |
---|---|
SparseVector |
Remarks
Assumes the vectors are compatible
SetToFunction(SparseVector, Converter<Double, Double>)
Sets the elements of this sparse vector to a function of the elements of another sparse vector
Declaration
public virtual SparseVector SetToFunction(SparseVector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | The other vector |
Converter<Double, Double> | fun | The function which maps doubles to doubles |
Returns
Type | Description |
---|---|
SparseVector |
Remarks
Assumes the vectors are compatible
SetToFunction(Vector, Vector, Func<Double, Double, Double>)
Sets the elements of this vector to a function of the elements of two vectors
Declaration
public override Vector SetToFunction(Vector a, Vector b, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Vector | a | The first vector |
Vector | b | The second vector |
Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
Type | Description |
---|---|
Vector |
Overrides
Remarks
Assumes the vectors are compatible
SetToFunction(Vector, Converter<Double, Double>)
Sets the elements of this vector to a function of the elements of a given vector
Declaration
public override Vector SetToFunction(Vector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The given vector |
Converter<Double, Double> | fun | The function which maps doubles to doubles |
Returns
Type | Description |
---|---|
Vector |
Overrides
Remarks
Assumes the vectors are compatible
SetToFunctionInPlace(SparseVector, Func<Double, Double, Double>)
Sets the elements of this sparse vector to a function of the elements of this sparse vector and another sparse vectors x = fun(x,b)
Declaration
public virtual SparseVector SetToFunctionInPlace(SparseVector b, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | b | The second vector |
Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
Type | Description |
---|---|
SparseVector |
Remarks
Assumes the vectors are compatible
SetToSubarray(Double[], Int32)
Copies values from an array. The minimum is used as the common value
Declaration
public override void SetToSubarray(double[] values, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Double[] | values | An array whose length is at least |
Int32 | startIndex | The index of the first value in |
Overrides
SetToSubvector(SparseVector, Int32)
Copies values from a sparse vector. The common value is set to the common value from the source vector.
Declaration
public virtual void SetToSubvector(SparseVector that, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
SparseVector | that | A vector whose length is at least |
Int32 | startIndex | The index of the first value in |
SetToSubvector(Vector, Int32)
Copies values from a vector. If the source vector is sparse, then the common value is set to the common value from the source vector. If the source vector is dense, then the common value is set to the minimum of the data in the source vector
Declaration
public override void SetToSubvector(Vector that, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | A vector whose length is at least |
Int32 | startIndex | The index of the first value in |
Overrides
Subvector(Int32, Int32)
Create a subvector of this sparse vector.
Declaration
public override Vector Subvector(int startIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | startIndex | |
Int32 | count |
Returns
Type | Description |
---|---|
Vector |
Overrides
Sum()
Returns the sum of all elements.
Declaration
public override double Sum()
Returns
Type | Description |
---|---|
Double |
Overrides
Sum(Converter<Double, Double>)
Returns the sum of a function of all elements.
Declaration
public override double Sum(Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Conversion function |
Returns
Type | Description |
---|---|
Double |
Overrides
Sum(Converter<Double, Double>, SparseVector, Converter<Double, Boolean>)
Returns the sum of a function of this sparse vector filtered by a function of a second sparse vector.
Declaration
public double Sum(Converter<double, double> fun, SparseVector that, Converter<double, bool> cond)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Function to convert the elements of this vector |
SparseVector | that | Second vector, which must have the same size as |
Converter<Double, Boolean> | cond | Function to convert the elements of that vector to give the filter condition |
Returns
Type | Description |
---|---|
Double | The filtered and mapped sum |
Sum(Converter<Double, Double>, Vector, Converter<Double, Boolean>)
Returns the sum of a function of this vector filtered by a function of a second vector.
Declaration
public override double Sum(Converter<double, double> fun, Vector that, Converter<double, bool> cond)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Function to convert the elements of this vector |
Vector | that | Second vector, which must have the same size as |
Converter<Double, Boolean> | cond | Function to convert the elements of that vector to give the filter condition |
Returns
Type | Description |
---|---|
Double | The filtered and mapped sum |
Overrides
SumI()
Returns the sum of over zero-based index times element.
Declaration
public override double SumI()
Returns
Type | Description |
---|---|
Double |
Overrides
SumISq()
Returns the sum of over square of index^2 times element.
Declaration
public override double SumISq()
Returns
Type | Description |
---|---|
Double |
Overrides
ToArray()
Converts this sparse vector to an array of doubles
Declaration
public override double[] ToArray()
Returns
Type | Description |
---|---|
Double[] |
Overrides
ToString(String, String)
String representation of vector with a specified format and delimiter
Declaration
public override string ToString(string format, string delimiter)
Parameters
Type | Name | Description |
---|---|---|
String | format | Format of each element value |
String | delimiter | Delimiter between sparse elements |
Returns
Type | Description |
---|---|
String | A string |
Overrides
ToVector()
Converts this sparse vector to an ordinary non-sparse vector
Declaration
public Vector ToVector()
Returns
Type | Description |
---|---|
Vector |
Zero(Int32)
Create a sparse vector of given length with elements all 0.0
Declaration
public static SparseVector Zero(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements in vector |
Returns
Type | Description |
---|---|
SparseVector |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Gets an enumerator which yields the vector elements
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |
ICloneable.Clone()
Clones this vector - return as an object
Declaration
object ICloneable.Clone()
Returns
Type | Description |
---|---|
Object |