Class Sparse<T>
Sparse vector representation (in LibSVM format).
Inheritance
System.Object
Sparse<T>
Implements
System.ICloneable
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IList
System.Collections.ICollection
System.Collections.IEnumerable
System.IFormattable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Mars.Numerics
Assembly: Mars.Numerics.dll
Syntax
[Serializable]
public sealed class Sparse<T> : ICloneable, IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, IFormattable where T : IEquatable<T>
Type Parameters
Name | Description |
---|---|
T | The type for the non-zero elements in this vector. |
Constructors
| Improve this Doc View SourceSparse()
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
| Improve this Doc View SourceIndices
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
| Improve this Doc View SourceClone()
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<T> 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<T>. 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 System.String that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Overrides
System.Object.ToString()
|
Improve this Doc
View Source
ToString(String, IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The format. |
System.IFormatProvider | formatProvider | The format provider. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Operators
| Improve this Doc View SourceImplicit(Sparse<T> to Array)
Performs an implicit conversion from Sparse<T> to System.Array.
Declaration
public static implicit operator Array(Sparse<T> obj)
Parameters
Type | Name | Description |
---|---|---|
Sparse<T> | obj |
Returns
Type | Description |
---|---|
System.Array |
Explicit Interface Implementations
| Improve this Doc View SourceICollection<T>.Add(T)
Sparse vector representation (in LibSVM format).
Declaration
void ICollection<T>.Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
ICollection<T>.Clear()
Sparse vector representation (in LibSVM format).
Declaration
void ICollection<T>.Clear()
ICollection<T>.Contains(T)
Sparse vector representation (in LibSVM format).
Declaration
bool ICollection<T>.Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<T>.Count
Sparse vector representation (in LibSVM format).
Declaration
int ICollection<T>.Count { get; }
Returns
Type | Description |
---|---|
System.Int32 |
ICollection<T>.IsReadOnly
Sparse vector representation (in LibSVM format).
Declaration
bool ICollection<T>.IsReadOnly { get; }
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<T>.Remove(T)
Sparse vector representation (in LibSVM format).
Declaration
bool ICollection<T>.Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
System.Boolean |
IEnumerable<T>.GetEnumerator()
Sparse vector representation (in LibSVM format).
Declaration
IEnumerator<T> IEnumerable<T>.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
IList<T>.IndexOf(T)
Sparse vector representation (in LibSVM format).
Declaration
int IList<T>.IndexOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Returns
Type | Description |
---|---|
System.Int32 |
IList<T>.Insert(Int32, T)
Sparse vector representation (in LibSVM format).
Declaration
void IList<T>.Insert(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
T | item |
IList<T>.Item[Int32]
Sparse vector representation (in LibSVM format).
Declaration
T IList<T>.this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Returns
Type | Description |
---|---|
T |
IList<T>.RemoveAt(Int32)
Sparse vector representation (in LibSVM format).
Declaration
void IList<T>.RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
ICollection.CopyTo(Array, Int32)
Sparse vector representation (in LibSVM format).
Declaration
void ICollection.CopyTo(Array array, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Array | array | |
System.Int32 | index |
ICollection.Count
Sparse vector representation (in LibSVM format).
Declaration
int ICollection.Count { get; }
Returns
Type | Description |
---|---|
System.Int32 |
ICollection.IsSynchronized
Sparse vector representation (in LibSVM format).
Declaration
bool ICollection.IsSynchronized { get; }
Returns
Type | Description |
---|---|
System.Boolean |
ICollection.SyncRoot
Sparse vector representation (in LibSVM format).
Declaration
object ICollection.SyncRoot { get; }
Returns
Type | Description |
---|---|
System.Object |
IEnumerable.GetEnumerator()
Sparse vector representation (in LibSVM format).
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |
IList.Add(Object)
Sparse vector representation (in LibSVM format).
Declaration
int IList.Add(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value |
Returns
Type | Description |
---|---|
System.Int32 |
IList.Clear()
Sparse vector representation (in LibSVM format).
Declaration
void IList.Clear()
IList.Contains(Object)
Sparse vector representation (in LibSVM format).
Declaration
bool IList.Contains(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value |
Returns
Type | Description |
---|---|
System.Boolean |
IList.IndexOf(Object)
Sparse vector representation (in LibSVM format).
Declaration
int IList.IndexOf(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value |
Returns
Type | Description |
---|---|
System.Int32 |
IList.Insert(Int32, Object)
Sparse vector representation (in LibSVM format).
Declaration
void IList.Insert(int index, object value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
System.Object | value |
IList.IsFixedSize
Sparse vector representation (in LibSVM format).
Declaration
bool IList.IsFixedSize { get; }
Returns
Type | Description |
---|---|
System.Boolean |
IList.IsReadOnly
Sparse vector representation (in LibSVM format).
Declaration
bool IList.IsReadOnly { get; }
Returns
Type | Description |
---|---|
System.Boolean |
IList.Item[Int32]
Sparse vector representation (in LibSVM format).
Declaration
object IList.this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Returns
Type | Description |
---|---|
System.Object |
IList.Remove(Object)
Sparse vector representation (in LibSVM format).
Declaration
void IList.Remove(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value |
IList.RemoveAt(Int32)
Sparse vector representation (in LibSVM format).
Declaration
void IList.RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Implements
System.ICloneable
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IList
System.Collections.ICollection
System.Collections.IEnumerable
System.IFormattable