Class PiecewiseVector
A one-dimensional vector of double values, optimised for the case where many contiguous ranges of elements have the same value.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Math
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public class PiecewiseVector : Vector, IReadOnlyList<double>, IReadOnlyCollection<double>, SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>, SettableToWeightedSum<Vector>, IList<double>, ICollection<double>, IEnumerable<double>, IEnumerable, ICloneable, CanSetAllElementsTo<double>, SettableTo<Vector>
Constructors
PiecewiseVector()
Constructs a zero vector with the given number of elements.
Declaration
protected PiecewiseVector()
PiecewiseVector(PiecewiseVector)
Copy constructor.
Declaration
protected PiecewiseVector(PiecewiseVector that)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | that | the vector to copy into this new vector |
PiecewiseVector(IList<Double>)
Creates a piecewise vector from a list of doubles.
Declaration
protected PiecewiseVector(IList<double> dlist)
Parameters
Type | Name | Description |
---|---|---|
IList<Double> | dlist | the list of doubles |
PiecewiseVector(Int32)
Constructs a zero vector with the given number of elements.
Declaration
protected PiecewiseVector(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements to allocate (>= 0). |
PiecewiseVector(Int32, Double)
Constructs a vector of a given length and assigns all elements the given value.
Declaration
protected PiecewiseVector(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. |
PiecewiseVector(Int32, Double, List<ConstantVector>)
Constructs a vector of a given length and assigns all elements the given value, except for the specified list of vectors. This list is stored internally as is so MUST be sorted by index and must not be modified externally.
Declaration
protected PiecewiseVector(int count, double commonValue, List<ConstantVector> sortedVectors)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements to allocate (>= 0). |
Double | commonValue | The value to assign to all elements. |
List<ConstantVector> | sortedVectors | The list of vectors, which must be disjoint and sorted by index. |
Properties
CommonValue
The value of all elements which are not in any of the vector pieces.
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
Item[Int32]
Gets and sets an element.
Declaration
public override double this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Property Value
Type | Description |
---|---|
Double |
Overrides
Pieces
A list of the pieces of this vector.
Declaration
public List<ConstantVector> Pieces { get; }
Property Value
Type | Description |
---|---|
List<ConstantVector> |
Methods
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 | The condition for the elements to satisfy. |
Returns
Type | Description |
---|---|
Boolean | True if all elements satisfy the condition, false otherwise. |
Overrides
Any(PiecewiseVector, Func<Double, Double, Boolean>)
Declaration
public bool Any(PiecewiseVector that, Func<double, double, bool> fun)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | that | |
Func<Double, Double, Boolean> | fun |
Returns
Type | Description |
---|---|
Boolean |
Any(Vector, Func<Double, Double, Boolean>)
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 | The condition for the elements to satisfy. |
Returns
Type | Description |
---|---|
Boolean | True if any elements satisfy the condition, false otherwise. |
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 then the result becomes dense
Append(Double)
Appends an item to a vector - returns a new piecewise vector
Declaration
public override Vector Append(double item)
Parameters
Type | Name | Description |
---|---|---|
Double | item |
Returns
Type | Description |
---|---|
Vector |
Overrides
ApplyRangeFunction(PiecewiseVector, PiecewiseVector.RangeFunc)
Applies a function to ranges in common between this vector and another and returns the number of elements with common values in both vectors.
Declaration
protected int ApplyRangeFunction(PiecewiseVector b, PiecewiseVector.RangeFunc func)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | b | |
PiecewiseVector.RangeFunc | func |
Returns
Type | Description |
---|---|
Int32 |
Clone()
Clones this vector - return as a vector
Declaration
public override Vector Clone()
Returns
Type | Description |
---|---|
Vector |
Overrides
Constant(Int32, Double)
Create a piecewise vector of given length with elements all equal to a specified value
Declaration
public static PiecewiseVector 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 |
---|---|
PiecewiseVector |
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 piecewise vector as a copy of another vector (of any type)
Declaration
public static PiecewiseVector Copy(Vector that)
Parameters
Type | Name | Description |
---|---|---|
Vector | that | The source vector - can be dense or sparse |
Returns
Type | Description |
---|---|
PiecewiseVector |
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 and values of all the 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 piecewise vector from a dense array.
Declaration
public static PiecewiseVector FromArray(params double[] data)
Parameters
Type | Name | Description |
---|---|---|
Double[] | data | 1D array of elements. |
Returns
Type | Description |
---|---|
PiecewiseVector |
Remarks
The array data is copied into new storage. The size of the vector is taken from the array.
FromSubvectors(Int32, Double, List<ConstantVector>)
Constructs a piecewise vector from a sorted list of subvectors, which will be used directly and not copied.
Declaration
[Construction(new string[]{"Count", "CommonValue", "Pieces"})]
public static PiecewiseVector FromSubvectors(int count, double commonValue, List<ConstantVector> sortedDisjointVectors)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Count for result |
Double | commonValue | Common value |
List<ConstantVector> | sortedDisjointVectors | Sorted list of disjoint subvectors |
Returns
Type | Description |
---|---|
PiecewiseVector |
GetCommonValueCount()
Gets the number of elements that don't belong to any subvector and so take the common value.
Declaration
protected int GetCommonValueCount()
Returns
Type | Description |
---|---|
Int32 |
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
GetSubvector(Int32)
Gets the subvector that contains the specified index, or null if none.
Declaration
protected ConstantVector? GetSubvector(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
Nullable<ConstantVector> |
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
HasCommonElements()
Gets whether there are any elements that don't belong to a subvector and so take the common value.
Declaration
public bool HasCommonElements()
Returns
Type | Description |
---|---|
Boolean |
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(PiecewiseVector)
Returns the inner product of this piecewise vector with another piecewise vector.
Declaration
public double Inner(PiecewiseVector that)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | that | Second vector, which must have the same size as |
Returns
Type | Description |
---|---|
Double | Their inner product. |
Inner(PiecewiseVector, Converter<Double, Double>)
Returns the inner product of this piecewise vector with a function of a second piecewise vector.
Declaration
public double Inner(PiecewiseVector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | 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>, PiecewiseVector, Converter<Double, Double>)
Returns the inner product of a function of this piecewise vector with a function of a second piecewise vector.
Declaration
public double Inner(Converter<double, double> thisFun, PiecewiseVector that, Converter<double, double> thatFun)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | thisFun | Function to convert the elements of this vector |
PiecewiseVector | 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.
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
Reduce(Double, PiecewiseVector, Func<Double, Double, Double, Double>)
Reduce method. Operates on this vector and that vector
Declaration
public double Reduce(double initial, PiecewiseVector that, Func<double, double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
Double | initial | Initial value |
PiecewiseVector | 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, Int32, TRes>)
Reduce method which can take advantage of piecewise structure. Operates on this list
Declaration
public TRes Reduce<TRes>(TRes initial, Func<TRes, double, int, TRes> repeatedFun)
Parameters
Type | Name | Description |
---|---|---|
TRes | initial | Initial value |
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.
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
SetTo(PiecewiseVector)
Copies values from a piecewise vector to this piecewise vector.
Declaration
public virtual void SetTo(PiecewiseVector that)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | 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
SetToConstantInRange(Int32, Int32, Double)
Sets the vector to a constant value between the specified start and end indices inclusive (and zero elsewhere).
Declaration
public void SetToConstantInRange(int start, int end, double value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | start | The start index |
Int32 | end | The end index |
Double | value | The constant value |
SetToConstantInRanges(IEnumerable<Int32>, Double)
Sets the vector to a constant value in multiple ranges (and zero elsewhere). The start and end points of the ranges are specified as consecutive pairs in a single enumerable which must therefore have even length.
Declaration
public void SetToConstantInRanges(IEnumerable<int> startEndPairs, double value)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Int32> | startEndPairs | Enumerable containing pairs of start and end values |
Double | value |
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(PiecewiseVector, PiecewiseVector, Func<Double, Double, Double>)
Sets the elements of this piecewise vector to a function of the elements of two other piecewise vectors
Declaration
public virtual PiecewiseVector SetToFunction(PiecewiseVector a, PiecewiseVector b, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | a | The first vector |
PiecewiseVector | b | The second vector |
Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
Type | Description |
---|---|
PiecewiseVector |
Remarks
Assumes the vectors are compatible
SetToFunction(PiecewiseVector, Converter<Double, Double>)
Sets the elements of this piecewise vector to a function of the elements of another piecewise vector
Declaration
public virtual PiecewiseVector SetToFunction(PiecewiseVector that, Converter<double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | that | The other vector |
Converter<Double, Double> | fun | The function which maps doubles to doubles |
Returns
Type | Description |
---|---|
PiecewiseVector |
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(PiecewiseVector, Func<Double, Double, Double>)
Sets the elements of this piecewise vector to a function of the elements of this piecewise vector and another piecewise vectors x = fun(x,b)
Declaration
public virtual PiecewiseVector SetToFunctionInPlace(PiecewiseVector b, Func<double, double, double> fun)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | b | The second vector |
Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
Type | Description |
---|---|
PiecewiseVector |
Remarks
Assumes the vectors are compatible
SetToSubvector(PiecewiseVector, Int32)
Copies values from a piecewise vector. The common value is set to the common value from the source vector.
Declaration
public virtual void SetToSubvector(PiecewiseVector that, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
PiecewiseVector | 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 piecewise, 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 piecewise 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>, PiecewiseVector, Converter<Double, Boolean>)
Returns the sum of a function of this piecewise vector filtered by a function of a second piecewise vector.
Declaration
public double Sum(Converter<double, double> fun, PiecewiseVector that, Converter<double, bool> cond)
Parameters
Type | Name | Description |
---|---|---|
Converter<Double, Double> | fun | Function to convert the elements of this vector |
PiecewiseVector | 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 piecewise vector to an array of doubles
Declaration
public override double[] ToArray()
Returns
Type | Description |
---|---|
Double[] |
Overrides
ToString(String)
String representation of vector with a specified format for each element
Declaration
public override string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format |
Returns
Type | Description |
---|---|
String |
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 | |
String | delimiter |
Returns
Type | Description |
---|---|
String |
Overrides
ToString(String, String, Func<Int32, String>)
String representation of vector with a specified format and delimiter and a function for converting integers to display strings.
Declaration
public override string ToString(string format, string delimiter, Func<int, string> intToString)
Parameters
Type | Name | Description |
---|---|---|
String | format | |
String | delimiter | |
Func<Int32, String> | intToString |
Returns
Type | Description |
---|---|
String |
Overrides
ToVector()
Converts this piecewise vector to an ordinary dense vector
Declaration
public DenseVector ToVector()
Returns
Type | Description |
---|---|
DenseVector |
Zero(Int32)
Create a piecewise vector of given length with elements all 0.0
Declaration
public static PiecewiseVector Zero(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | Number of elements in vector |
Returns
Type | Description |
---|---|
PiecewiseVector |
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 |