compressed Programmers Guide Contents | Index |  Search

Category:containers,selectors Component type:type
Description

TwoD Storage Type Selectors

This storage type is the traditional compressed row or compressed column format. The storage consists of three arrays, one array for all of the elements, one array consisting of the row or column index (row for column-major and column for row-major matrices), and one array consisting of pointers to the start of each row/column. The following is an example sparse matrix in compressed for format, with the stored indices specified as index_from_one. Note that the MTL interface is still indexed from zero whether or not the underlying stored indices are from one.
``` [  1      2   3      ]
[     4           5  ]
[  6      7   8      ]
[  9         10      ]
[        11      12  ]

row pointer array
[  1  4  6  9  11 13 ]

element value array
[  1  2  3  4  5  6  7  8  9 10 11 12 ]

element column index array
[  1  3  4  2  5  1  3  4  1  4  3  5 ]
```
Of course, the user of the MTL sparse matrix does not need to concern his or herself with the implementation details of this matrix storage format. The interface to an MTL compressed row matrix is the same as that of any MTL matrix, as described in Matrix.

OneD Storage Type Selectors

This is a OneD type used to construct array matrices. The compressed OneD format uses two arrays, one to hold the elements of the vector, and the other to hold the indices that coorespond to each element (either their row or column number).
Example
In sparse_matrix.cc:
```  //  [1,0,2]
//  [0,3,0]
//  [0,4,5]
const int m = 3, n = 3, nnz = 5;
double values[] = { 1, 2, 3, 4, 5 };
int indices[]   = { 1, 3, 2, 2, 3 };
int row_ptr[]   = { 1, 3, 4, 6 };

// Create from pre-existing arrays
typedef matrix<double,
rectangle<>,
compressed<int, external,
index_from_one>,
row_major>::type MatA;

MatA A(m, n, nnz, values, row_ptr, indices);
// Create from scratch
typedef matrix<double,
rectangle<>,
compressed<>,
row_major >::type MatB;
MatB B(m, n);
B(0,0) = 1;  B(0,2) = 2;
B(1,1) = 3;
B(2,1) = 4;  B(2,2) = 5;

```
Definition
matrix.h
Template Parameters

ParameterDescriptionDefault
SizeTypeThe type used in the index and pointer array int
MemLocSpecify whether the memory used is "owned" by the matrix or if it was provided to the matrix from some external source (with a pointer to some data) internal
IndexStyleSpecify whether the underlying index array stores indices starting from one (fortan style) or from zero (c-style) - index_from_zero
Model of
Members
Member Where defined Description
size_type
enum { id = COMPRESSED, oned_id, ext=MemLoc, issparse=1, index=IndexStyle }
New members
Notes