SDPSL
Semidefinite Programming Specification Library
|
Implements a matrix bit-mask. More...
#include <matrixmask.h>
Classes | |
struct | Position |
A position in the mask. More... | |
Public Types | |
typedef std::list< Position > ::const_iterator | const_iterator |
Constant iterator. | |
Public Member Functions | |
MatrixMask (int nn) | |
Constructs an nn by nn mask with all entries off. | |
MatrixMask (int mm, int nn) | |
Constructs an mm by nn mask with all entries off. | |
MatrixMask (const MatrixMask &other) | |
Copy constructor. | |
MatrixMask & | operator= (const MatrixMask &)=delete |
Assignment is not implemented. | |
int | on_count () const |
Returns number of on positions. | |
int | num_rows () const |
Returns number of rows. | |
int | num_cols () const |
Returns number of columns. | |
bool | is_on (int i, int j) const |
Returns true if entry (i, j) of the mask is on. | |
void | turn_on (int i, int j) |
Turns on entry (i, j) of the mask. | |
void | turn_off (int i, int j) |
Turns off entry (i, j) of the mask. | |
void | clear () |
Clears the whole mask, turning off all entries. | |
const_iterator | begin () const |
Returns iterator to the beginning of the list of on positions. | |
const_iterator | end () const |
Returns past-the-end iterator to the list of on positions. | |
Friends | |
class | shared_ref< MatrixMask > |
class | const_shared_ref< MatrixMask > |
Implements a matrix bit-mask.
A MatrixMask
contains an m by n matrix of bits. It can be used, for instance, to store the nonzero positions of a matrix. Some functions use a MatrixMask
in order to efficiently deal with sparse matrices.
A MatrixMask
also contains a list of the entries that are on. So it is efficient to iterate over all the entries turned on.
Each entry of the mask occupies only one bit, so that even large masks do not use up too much space. So it is efficient to use masks of large size. Notice however that, if too many positions are on, then the list of positions that are turned on might come to occupy a large amount of memory. So masks are better kept sparse.
MatrixMask
implements the shared reference mechanism. To understand how it works, see the documentation of shared_ref
, const_shared_ref
, and Matrix
for an example.
MatrixMask
supports both C++ and C++11 style iteration. One iterates over a list of positions, i.e., instances of struct
MatrixMask::Position
, containing the nonzero entries of the mask.
on_pos
to a vector. This might save memory.