|
| Sparse_Vec () |
| Default constructor.
|
|
| Sparse_Vec (int sz, int data_init=200) |
| Initiate an empty sparse vector. More...
|
|
| Sparse_Vec (const Sparse_Vec< T > &v) |
| Initiate a new sparse vector. More...
|
|
| Sparse_Vec (const Vec< T > &v) |
| Initiate a new sparse vector from a dense vector. More...
|
|
| Sparse_Vec (const Vec< T > &v, T epsilon) |
| Initiate a new sparse vector from a dense vector. Elements of v larger than epsilon are copied into the new sparse vector. More...
|
|
| ~Sparse_Vec () |
| Destructor.
|
|
void | set_size (int sz, int data_init=-1) |
| Set the size sz of the sparse vector. Default value data_init=-1 => allocated size for the data is not changed. More...
|
|
int | size () const |
| Returns the size of the sparse vector.
|
|
int | nnz () |
| Number of non-zero elements in the sparse vector.
|
|
double | density () |
| Returns the density of the sparse vector: (number of non-zero elements)/(size of the vector)
|
|
void | set_small_element (const T &epsilon) |
| Set that all elements smaller than epsilon should be set to zero.
|
|
void | remove_small_elements () |
|
void | resize_data (int new_size) |
| Set the maximum number of non-zero elements to new_size . More...
|
|
void | compact () |
| Set the maximum number of non-zero elements equal to the actual number of non-zero elements.
|
|
void | full (Vec< T > &v) const |
| Returns a full, dense vector in v .
|
|
Vec< T > | full () const |
| Returns a full, dense vector.
|
|
T | operator() (int i) const |
| Returns the element with index i .
|
|
void | set (int i, T v) |
| Set element i equal to v .
|
|
void | set (const ivec &index_vec, const Vec< T > &v) |
| Set the elements of the sparse vector with indices index_vec to the values in v .
|
|
void | set_new (int i, T v) |
| Set a new element with index i equal to v .
|
|
void | set_new (const ivec &index_vec, const Vec< T > &v) |
| Set new elements with indices index_vec equal to the values in v (no check whether the same index is used several times)
|
|
void | add_elem (const int i, const T v) |
| Add element i with v .
|
|
void | add (const ivec &index_vec, const Vec< T > &v) |
| Add v to the elements specified by index_vec with v .
|
|
void | zeros () |
| Set the sparse vector to the all zero vector (removes all non-zero elements)
|
|
void | zero_elem (const int i) |
| Set the i-th element to zero (i.e. clear that element if it contains a non-zero value)
|
|
void | clear () |
| Clear all non-zero elements of the sparse vector.
|
|
void | clear_elem (const int i) |
| Clear the i-th element (if it contains a non-zero value)
|
|
void | get_nz_data (int p, T &data_out) |
| Extract the reference to the p-th non-zero data element.
|
|
T | get_nz_data (int p) |
| Returns the p-th non-zero data element.
|
|
int | get_nz_index (int p) |
| Returns the vector index of the p-th non-zero element.
|
|
void | get_nz (int p, int &idx, T &dat) |
| Returns the p-th non-zero value in dat and the corresponding vector index in idx .
|
|
ivec | get_nz_indices () |
| Return the indices of non-zero values.
|
|
Sparse_Vec< T > | get_subvector (int i1, int i2) const |
| Return sparse subvector from index i1 to index i2 .
|
|
T | sqr () const |
| Returns the sum of all values squared.
|
|
void | operator= (const Sparse_Vec< T > &v) |
| Assign sparse vector the value and length of the sparse vector v .
|
|
void | operator= (const Vec< T > &v) |
| Assign sparse vector the value and length of the dense vector v .
|
|
Sparse_Vec< T > | operator- () const |
| Returns the sign inverse of all elements in the sparse vector.
|
|
bool | operator== (const Sparse_Vec< T > &v) |
| Compare two sparse vectors. False if wrong sizes or different values.
|
|
void | operator+= (const Sparse_Vec< T > &v) |
| Add sparse vector v to all non-zero elements of the sparse vector.
|
|
void | operator+= (const Vec< T > &v) |
| Add vector v to all non-zero elements of the sparse vector.
|
|
void | operator-= (const Sparse_Vec< T > &v) |
| Subtract sparse vector v from all non-zero elements of the sparse vector.
|
|
void | operator-= (const Vec< T > &v) |
| Subtract vector v from all non-zero elements of the sparse vector.
|
|
void | operator*= (const T &v) |
| Multiply the scalar v to all non-zero elements of the sparse vector.
|
|
void | operator/= (const T &v) |
| Divide all non-zero elements of the sparse vector with the scalar v .
|
|
template<class T>
class itpp::Sparse_Vec< T >
Templated sparse vector class.
- Author
- Tony Ottosson and Tobias Ringstrom
A sparse vector is a vector where most elements are zero. The maximum number of none-zero elements is a parameter to the constructor. The elements are stored in random order, i.e. they are not sorted.
Definition at line 43 of file smat.h.