Class Sparse<T>
Sparse vector representation (in LibSVM format).
Inheritance
ICloneable
Sparse<T>
Implements
IList<T>
IList
IFormattable
Namespace: Mars.Numerics
Assembly: Mars.Numerics.dll
Syntax
public sealed class Sparse<T> : ICloneable, IList<T>, IList, IFormattable where T : IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type for the non-zero elements in this vector. |
Constructors
Sparse()
Creates a sparse vector with zero elements.
Declaration
public Sparse()
Sparse(Int32)
Creates a sparse vector with the maximum number of elements.
Declaration
public Sparse(int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length | The maximum number of non-zero elements that this vector can accomodate. |
Sparse(Int32[], T[])
Creates a sparse vector from a vector of indices
and a vector of values occuring at those indices.
Declaration
public Sparse(int[] indices, T[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | indices | The indices for non-zero entries. |
T[] | values | The non-zero values happening at each index. |
Properties
Indices
Gets or sets the vector of indices indicating the location
of the non-zero elements contained in this sparse vector.
Declaration
public int[] Indices { get; set; }
Property Value
Type | Description |
---|---|
System.Int32[] |
Item[Int32]
Gets the the value stored at position
i
.
Declaration
public T this[int i] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i |
Property Value
Type | Description |
---|---|
T |
Length
Gets the maximum non-zero element index in the sparse vector.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Values
Gets or sets the vector of values indicating which non-zero
value happens at each position indicated in Indices.
Declaration
public T[] Values { get; set; }
Property Value
Type | Description |
---|---|
T[] |
Methods
Clone()
Creates a new object that is a copy of the current instance.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new object that is a copy of this instance. |
CopyTo(T[], Int32)
Copies the elements of the System.Collections.Generic.ICollection`1 to an
System.Array, starting at a particular System.Array index.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The one-dimensional System.Array that is the destination of the elements copied from System.Collections.Generic.ICollection`1. The System.Array must have zero-based indexing. |
System.Int32 | arrayIndex | The zero-based index in array at which copying begins. |
IsFull()
Determines whether this Sparse vector has elements on all indices.
Declaration
public bool IsFull()
Returns
Type | Description |
---|---|
System.Boolean | true if this instance is full; otherwise, false . |
ToDense()
Converts this sparse vector to a dense vector of the given length.
Declaration
public T[] ToDense()
Returns
Type | Description |
---|---|
T[] |
ToDense(Int32)
Converts this sparse vector to a dense vector of the given length.
Declaration
public T[] ToDense(int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | length |
Returns
Type | Description |
---|---|
T[] |
ToSparse()
Converts this sparse vector to a sparse representation where
the indices are intertwined with their corresponding values.
Declaration
public T[] ToSparse()
Returns
Type | Description |
---|---|
T[] |
ToString()
Returns a that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
A |
ToString(String, IFormatProvider)
Returns a that represents this instance.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The format. |
IFormatProvider | formatProvider | The format provider. |
Returns
Type | Description |
---|---|
System.String |
A |
Operators
Implicit(Sparse<T> to Array)
Performs an implicit conversion from Sparse<T> to .
Declaration
public static implicit operator Array(Sparse<T> obj)
Parameters
Type | Name | Description |
---|---|---|
Sparse<T> | obj |
Returns
Type | Description |
---|---|
Array |
Implements
IList<>
IList
IFormattable