compressed1D<T, SizeType = int, int IND_OFFSET = index_from_zero> [MTL Home] Programmers Guide
  Contents | Index |  Search 


Category:containers Component type:type
Description
The compressed1D Vector is a sparse vector implemented with a pair of parallel arrays. One array is for the element values, and the other array is for the indices of those elements. The elements are ordered by their index as they are inserted into the compressed1D. compressed1D's can be used to build matrices with the array storage format, and they can also be used on their own.
 [ (1.2, 3), (4.6, 5), (1.0, 10), (3.7, 32) ] A Sparse Vector

 [ 1.2, 4.6, 1.0, 3.7 ]  Value Array
 [  3,   5,  10,  32 ]   Index Array
 

The compressed1D::iterator dereferences (*i) to return the element value. One can access the index of that element with the i.index() function. One can also access the array of indices through the nz_struct() method.

One particularly useful fact is that one can perform scatters and gathers of sparse elements by using the mtl::copy(x,y) function with a sparse and a dense vector. This method does not change the size() of the vector.

Example
In gather_scatter.cc:
void do_gather_scatter(DenseVec& d, SparseVec& c) {
  using namespace mtl;

  c[2] = 0;
  c[5] = 0;
  c[7] = 0;

  gather(d,c);
  scale(c,2.0);
  scatter(c,d);
  typedef dense1D<double> denseVec;
  typedef compressed1D<double> compVec;
  denseVec d(9,2);
  compVec c;
  do_gather_scatter(d, c);

More examples can be found in array2D.cc, sparse_copy.cc

Definition
compressed1D.h
Template Parameters

ParameterDescriptionDefault
Tthe element type 
SizeTypethe type for the stored indices int
IND_OFFSETTo handle indexing from 0 or 1 index_from_zero
Model of
Vector
Members
Member Where defined Description
enum { N = 0 }    
sparsity   This is a sparse vector
dimension   This is a 1D container
scaled_type   Scaled type of this vector
value_type   Element type
pointer   A pointer to the element type
size_type   Unsigned integral type for dimensions and indices
difference_type   Integral type for differences in iterators
reference   Reference to the value type
const_reference   Const reference to the value type
iterator   Iterator type
const_iterator   Const iterator type
reverse_iterator   Reverse iterator type
const_reverse_iterator   The const reverse iterator type
IndexArrayRef   Reference to the index array
IndexArray   The type for the index array
subrange_type   The type for the subrange vector
compressed1D ()   Default Constructor
compressed1D (size_type n)   Length N Constructor
compressed1D (const self& x)   Copy Constructor
template <class IndexIter>
compressed1D (IndexIter first, IndexIter last, size_type n)
  Index Array Constructor
self& operator= (const self& x)   Assignment Operator
iterator begin () Container Return an iterator pointing to the beginning of the vector
iterator end () Container Return an iterator pointing past the end of the vector
const_iterator begin () const Container Return a const iterator pointing to the begining of the vector
const_iterator end () const Container Return a const iterator pointing past the end of the vector
reverse_iterator rbegin () Reversible Container Return a reverse iterator pointing to the last element of the vector
reverse_iterator rend () Reversible Container Return a reverse iterator pointing past the end of the vector
const_reverse_iterator rbegin () const Reversible Container Return a const reverse iterator pointing to the last element of the vector
const_reverse_iterator rend () const Reversible Container Return a const reverse iterator pointing past the end of the vector
reference operator[] (size_type i)   Access the element with index i
const_reference operator[] (size_type i) const   Access the element with index i
iterator insert (size_type i, const T& val)   Insert val into the vector at index i
void push_back (size_type i, const T& val)   Push back, warning: must insert elements ordered by index.
void clear ()   Erase the vector
size_type size () const   The size of the vector (including non-zeroes)
size_type nnz () const   The number of non-zero elements (the number stored)
void resize (size_type n)   Resize the vector to size n
void reserve (size_type n)   Reserve storage for n non-zero elements
IndexArrayRef nz_struct () const   Returns the array of indices
IndexArrayRef nz_struct ()   Returns the array of indices
New members
Notes
See also

[MTL Home] Copyright © 1998,1999 University of Notre Dame. All Rights Reserved.