tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
tensor::Sparse< elt > Class Template Reference

A sparse matrix. More...

Public Member Functions

index columns () const
 Number of columns.
 
index dimension (int which) const
 Length of a given Sparse matrix index. More...
 
const Indicesdimensions () const
 Return Sparse matrix dimensions. More...
 
bool is_empty () const
 Empty matrix?
 
index length () const
 Number of nonzero elements. More...
 
elt_t operator() (index row, index col) const
 Return an element of the sparse matrix. More...
 
Sparseoperator= (const Sparse< elt_t > &s)
 Assignment operator. More...
 
index rows () const
 Number of rows. More...
 
 Sparse ()
 Build an empty matrix. More...
 
 Sparse (index rows, index cols, index nonzero=0)
 Create a matrix with all elements set to zero. More...
 
 Sparse (const Indices &row_indices, const Indices &column_indices, const Vector< elt_t > &data, index rows=0, index columns=0)
 Create a sparse matrix from the coordinates and values. More...
 
 Sparse (const Tensor< elt_t > &tensor)
 Convert a tensor to sparse form. More...
 
 Sparse (const Sparse< elt_t > &s)
 Copy constructor. More...
 

Static Public Member Functions

static Sparse< elt_t > eye (index rows, index cols)
 Identity matrix in sparse form. More...
 
static Sparse< elt_t > eye (index rows)
 Identity matrix in sparse form. More...
 
static Sparse< elt_t > random (index rows, index columns, double density=0.2)
 Return a random sparse matrix. More...
 

Data Fields

Indices column_
 Gives for each data_ entry the column in the matrix. More...
 
Vector< elt_t > data_
 The single data entries. More...
 
Indices dims_
 The dimensions (rows and columns) of the sparse matrix. More...
 
Indices row_start_
 Gives for each row of the matrix at which index the column_/data_ entries start. More...
 

Detailed Description

template<typename elt>
class tensor::Sparse< elt >

A sparse matrix.

A sparse matrix is a compact representation of two-dimensional tensors that have a lot of zero elements. Our implementation behaves much like Matlab's sparse matrices, in the sense that one can build them up from 2D tensors, preallocate them, perform matrix multiplication with mmult(), etc, etc.

Definition at line 37 of file sparse.h.

Constructor & Destructor Documentation

template<typename elt>
tensor::Sparse< elt >::Sparse ( )

Build an empty matrix.

template<typename elt>
tensor::Sparse< elt >::Sparse ( index  rows,
index  cols,
index  nonzero = 0 
)

Create a matrix with all elements set to zero.

template<typename elt>
tensor::Sparse< elt >::Sparse ( const Indices row_indices,
const Indices column_indices,
const Vector< elt_t > &  data,
index  rows = 0,
index  columns = 0 
)

Create a sparse matrix from the coordinates and values.

template<typename elt>
tensor::Sparse< elt >::Sparse ( const Tensor< elt_t > &  tensor)
explicit

Convert a tensor to sparse form.

template<typename elt>
tensor::Sparse< elt >::Sparse ( const Sparse< elt_t > &  s)

Copy constructor.

Member Function Documentation

template<typename elt>
index tensor::Sparse< elt >::dimension ( int  which) const

Length of a given Sparse matrix index.

template<typename elt>
const Indices& tensor::Sparse< elt >::dimensions ( ) const
inline

Return Sparse matrix dimensions.

Definition at line 63 of file sparse.h.

template<typename elt>
static Sparse<elt_t> tensor::Sparse< elt >::eye ( index  rows,
index  cols 
)
static

Identity matrix in sparse form.

template<typename elt>
static Sparse<elt_t> tensor::Sparse< elt >::eye ( index  rows)
inlinestatic

Identity matrix in sparse form.

Definition at line 79 of file sparse.h.

template<typename elt>
index tensor::Sparse< elt >::length ( ) const
inline

Number of nonzero elements.

Definition at line 71 of file sparse.h.

template<typename elt>
elt_t tensor::Sparse< elt >::operator() ( index  row,
index  col 
) const

Return an element of the sparse matrix.

template<typename elt>
Sparse& tensor::Sparse< elt >::operator= ( const Sparse< elt_t > &  s)

Assignment operator.

template<typename elt>
static Sparse<elt_t> tensor::Sparse< elt >::random ( index  rows,
index  columns,
double  density = 0.2 
)
static

Return a random sparse matrix.

template<typename elt>
index tensor::Sparse< elt >::rows ( ) const
inline

Number of rows.

Definition at line 67 of file sparse.h.

Field Documentation

template<typename elt>
Indices tensor::Sparse< elt >::column_

Gives for each data_ entry the column in the matrix.

Definition at line 96 of file sparse.h.

template<typename elt>
Vector<elt_t> tensor::Sparse< elt >::data_

The single data entries.

Definition at line 98 of file sparse.h.

template<typename elt>
Indices tensor::Sparse< elt >::dims_

The dimensions (rows and columns) of the sparse matrix.

Definition at line 92 of file sparse.h.

template<typename elt>
Indices tensor::Sparse< elt >::row_start_

Gives for each row of the matrix at which index the column_/data_ entries start.

Definition at line 94 of file sparse.h.