﻿Vector Class
 Vector Class
Microsoft Research
Base class for vectors. DenseVector, SparseVector, and ApproximateSparseVector all inherit from this base class.
Inheritance Hierarchy

Namespace: MicrosoftResearch.Infer.Maths
Assembly: Infer.Runtime (in Infer.Runtime.dll) Version: 2.6.41128.1 (2.6.41128.1)
Syntax
```[SerializableAttribute]
public abstract class Vector : IList<double>,
ICollection<double>, IEnumerable<double>, IEnumerable,
SettableTo<Vector>, ICloneable, IXmlSerializable, CanSetAllElementsTo<double>,
SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>,
SettableToWeightedSum<Vector>```

The Vector type exposes the following members.

Methods
NameDescription
All
Tests if all elements in the vector satisfy the specified condition.
Any(ConverterDouble, Boolean)
Tests if any elements in the vector satisfy the specified condition.
Any(Vector, FuncDouble, Double, Boolean)
Test if any corresponding elements in this and that vector satisfy a condition
Append(Double)
Appends an item to a vector - returns a new vector
Append(Vector)
Return a new vector which is the concatenation of this vector and a second vector.
Clone
Clones this vector - return as a vector
Concat
Create a vector by concatenating two vectors.
Constant(Int32, Double)
Create a dense vector of given length with elements all equal to a specified value
Constant(Int32, Double, Sparsity)
Create a vector of given length with elements all equal to a specified value
Contains
Returns true if the Vector contains the specified item value
Copy(Vector)
Create a vector as a copy of another vector.
Copy(Vector, Sparsity)
Create a vector as a copy of another vector with a given target sparsity
CopyTo
Copies this vector to the given array starting at the specified index in the target array
CountAll
Returns the number of elements in the vector which satisfy a given condition.
EqualsAll
Tests if all elements are equal to a given value.
FindAll
Returns an enumeration over the indices and values of all elements which satisfy the specified condition. Indices are returned in sorted order.
FromArray(Double)
Constructs a dense vector from an array.
FromArray(Double, Sparsity)
Constructs a vector from an array.
FromArray(Int32, Double, Int32)
Constructs a vector from part of an array.
FromArray(Int32, Double, Int32, Sparsity)
Constructs a vector from part of an array.
FromList
Constructs a vector from a list. Maintains sparsity.
GetEnumerator
Gets a typed enumerator which yields the vector elements
GreaterThan(Double)
Tests if all elements are strictly greater than a given value.
GreaterThan(Vector)
Tests if this vector is strictly greater than a second vector.
GreaterThanOrEqual(Double)
Tests if all elements are greater than or equal to a given value.
GreaterThanOrEqual(Vector)
Tests if this vector is than or equal to a second vector.
IndexAtCumulativeSum
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.
IndexOf
Returns the index of the first occurence of the given value in the array. Returns -1 if the value is not in the array
IndexOfAll
Returns an enumeration over the indices of all elements which satisfy the specified condition. Indices are returned in sorted order.
IndexOfMaximum
Returns the index of the maximum element.
IndexOfMinimum
Returns the index of the minimum element.
Inner(Vector)
Returns the inner product of this vector with another vector.
Inner(Vector, ConverterDouble, Double)
Returns the inner product of a function of this vector with a second vector.
Inner(ConverterDouble, Double, Vector, ConverterDouble, Double)
Returns the inner product of a function of this vector with a function of a second vector.
InnerProduct
Returns the inner product of two vectors.
LessThan(Double)
Tests if all elements are strictly less than a given value.
LessThan(Vector)
Tests if this vector is strictly less than a second vector.
LessThanOrEqual(Double)
Tests if all elements are less than or equal to a given value.
LessThanOrEqual(Vector)
Tests if this vector is less than or equal to a second vector.
LogSumExp
Returns the log of the sum of exponentials of the elements of the vector computed to high accuracy
Max
Returns the maximum of the elements in the vector
Max(ConverterDouble, Double)
Returns the maximum of a function of the elements in the vector
MaxDiff(Vector)
Returns the maximum absolute difference between this vector and another vector.
MaxDiff(Vector, Double)
Returns the maximum relative difference between this vector and another.
Median
Returns the minimum of the elements in the vector
Min
Returns the minimum of the elements in the vector
Min(ConverterDouble, Double)
Returns the minimum of a function of the elements in the vector
Outer
Returns the outer product of this vector with another vector.
PredivideBy(LowerTriangularMatrix)
Gets the solution to Ax=b, where A is a lower triangular matrix, and b is this vector. Equivalent to the left-division x = A\b.
PredivideBy(PositiveDefiniteMatrix)
Premultiply this vector by the inverse of a positive definite matrix
PredivideBy(UpperTriangularMatrix)
Gets the solution to Ax=b, where A is an upper triangular matrix, and b is this vector. Equivalent to the left-division x = A\b.
PredivideByTranspose
Gets the solution to A'x=b, where A is a lower triangular matrix, and b is this vector. Equivalent to the left-division x = A'\b.
Reduce(Double, FuncDouble, Double, Double)
Reduce method. Operates on this vector
Reduce(Double, Vector, FuncDouble, Double, Double, Double)
Reduce method. Operates on this vector and that vector
Reduce(Double, Vector, Vector, FuncDouble, Double, Double, Double, Double)
Reduce method. Operates on this vector and two other vectors
Scale
Multiplies this vector by a scalar.
SetAllElementsTo
Sets all elements to a given value.
SetSubvector
Set a subvector of this to another vector.
SetTo(IEnumerableDouble)
Copies values from an Enumerable to this vector
SetTo(Double)
Copies values from an array.
SetTo(Vector)
Copies values from a Vector to this vector
SetToDiagonal
Sets this vector to the diagonal of a matrix.
SetToDifference(Double, Vector)
Set this vector to a constant minus another vector
SetToDifference(Vector, Vector)
Sets this vector to the difference of two vectors
SetToDifference(Vector, Double)
Set this vector to another vector minus a constant
SetToFunction(Vector, ConverterDouble, Double)
Sets the elements of this vector to a function of the elements of a given vector
SetToFunction(Vector, Vector, FuncDouble, Double, Double)
Sets the elements of this vector to a function of the elements of two vectors
SetToPower
Sets this vector to the elementwise power of another vector.
SetToProduct(Matrix, Vector)
Set this vector to the product of a matrix by a vector (i.e. A*x).
SetToProduct(Vector, Matrix)
Sets this vector to the product of a vector by a matrix (i.e. x*A).
SetToProduct(Vector, Vector)
Sets this vector to the elementwise product of two other vectors.
SetToProduct(Vector, Double)
Sets this vector to a vector times a scalar.
SetToRatio
Sets this vector to the elementwise ratio of two other vectors.
SetToSubarray
Copies values from an array.
SetToSubvector
Copies value from a vector.
SetToSum(Vector, Vector)
Sets this vector to the elementwise sum of two other vectors.
SetToSum(Vector, Double)
Sets this vector to another vector plus a scalar.
SetToSum(Double, Vector, Double, Vector)
Set this vector to a linear combination of two other vectors
Subvector(Int32, Int32)
Create a subvector of this vector
Subvector(Vector, Int32, Int32)
Copy a subvector.
Sum
Returns the sum of all elements.
Sum(ConverterDouble, Double)
Returns the sum of a function of all elements.
Sum(ConverterDouble, Double, Vector, ConverterDouble, Boolean)
Returns the sum of a function of this vector filtered by a function of a second vector.
SumI
Returns the sum of over zero-based index * element.
SumISq
Returns the sum of over square of index^2 times element.
ToArray
Converts this vector to an array of doubles
ToString
Converts this sparse vector into a human readable string
(Overrides ObjectToString.)
ToString(String)
String representation of vector with a specified format for each element
ToString(String, String)
String representation of vector with a specified format and delimiter
ToString(String, String, FuncInt32, String)
String representation of vector with a specified format and delimiter and a function for converting integers to display strings.
Zero(Int32)
Creates a dense vector of given length with elements all 0.0
Zero(Int32, Sparsity)
Creates a vector of given length with elements all 0.0
Top
Operators
NameDescription
Returns the sum of two vectors.
Add a scalar to every element of a vector.
Division
Returns the ratio of two vectors
Equality
Equality operator.
ExclusiveOr
Returns a vector to some power.
GreaterThan(Vector, Vector)
Greater than operator.
GreaterThan(Vector, Double)
Greater than operator.
GreaterThanOrEqual(Vector, Vector)
Greater than or equal to operator.
GreaterThanOrEqual(Vector, Double)
Greater than or equal to operator.
Inequality
Inequality operator.
LessThan(Vector, Vector)
Less than operator.
LessThan(Vector, Double)
Less than operator.
LessThanOrEqual(Vector, Vector)
Less than or equal to operator.
LessThanOrEqual(Vector, Double)
Less than or equal to operator.
Multiply(Double, Vector)
Multiply every element of this vector by a scalar.
Multiply(Vector, Vector)
Returns the elementwise product of two vectors.
Multiply(Vector, Double)
Multiplies every element of a vector by a scalar.
Subtraction(Double, Vector)
Subtracts a scalar from each element of a vector.
Subtraction(Vector, Vector)
Returns the difference of two vectors
Subtraction(Vector, Double)
Subtracts a scalar from each element of a vector.
UnaryNegation
Returns a vector which is the unary negation of a vector.
Top
Extension Methods
Properties
NameDescription
Count
Number of elements in vector
IsApproximate
True if this vector is approximate (sparse only)
IsDense
True if this vector is dense
IsExact
True if this vector is exact (dense or sparse)