All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
NetworKit::DynamicMatrix Class Reference

The DynamicMatrix class represents a matrix that is optimized for sparse matrices and internally uses a graph data structure. More...

#include <DynamicMatrix.h>

Public Member Functions

 DynamicMatrix ()
 Default constructor. More...
 
 DynamicMatrix (const count dimension, const double zero=0.0)
 Constructs the Matrix with size dimension x dimension. More...
 
 DynamicMatrix (const count nRows, const count nCols, const double zero=0.0)
 Constructs the Matrix with size nRows x nCols. More...
 
 DynamicMatrix (const count dimension, const std::vector< Triplet > &triplets, const double zero=0.0)
 Constructs the dimension x dimension Matrix from the elements at position positions with values . More...
 
 DynamicMatrix (const count nRows, const count nCols, const std::vector< Triplet > &triplets, const double zero=0.0)
 Constructs the nRows x nCols Matrix from the elements at position positions with values . More...
 
 DynamicMatrix (const DynamicMatrix &other)=default
 Default copy constructor. More...
 
 DynamicMatrix (DynamicMatrix &&other)=default
 Default move constructor. More...
 
virtual ~DynamicMatrix ()=default
 Default destructor. More...
 
DynamicMatrixoperator= (DynamicMatrix &&other)=default
 Default move assignment operator. More...
 
DynamicMatrixoperator= (const DynamicMatrix &other)=default
 Default copy assignment operator. More...
 
bool operator== (const DynamicMatrix &other) const
 Compares this matrix to other and returns true if the shape and zero element are the same as well as all entries, otherwise returns false. More...
 
bool operator!= (const DynamicMatrix &other) const
 Compares this matrix to other and returns false if the shape and zero element are the same as well as all entries, otherwise returns true. More...
 
count numberOfRows () const
 
count numberOfColumns () const
 
double getZero () const
 Returns the zero element of the matrix. More...
 
count nnzInRow (const index i) const
 
count nnz () const
 
double operator() (const index i, const index j) const
 
void setValue (const index i, const index j, const double value)
 Set the matrix at position (i, j) to value. More...
 
Vector row (const index i) const
 
Vector column (const index j) const
 
Vector diagonal () const
 
DynamicMatrix operator+ (const DynamicMatrix &other) const
 Adds this matrix to other and returns the result. More...
 
DynamicMatrixoperator+= (const DynamicMatrix &other)
 Adds other to this matrix. More...
 
DynamicMatrix operator- (const DynamicMatrix &other) const
 Subtracts other from this matrix and returns the result. More...
 
DynamicMatrixoperator-= (const DynamicMatrix &other)
 Subtracts other from this matrix. More...
 
DynamicMatrix operator* (const double scalar) const
 Multiplies this matrix with a scalar specified in scalar and returns the result. More...
 
DynamicMatrixoperator*= (const double scalar)
 Multiplies this matrix with a scalar specified in scalar. More...
 
Vector operator* (const Vector &vector) const
 Multiplies this matrix with vector and returns the result. More...
 
DynamicMatrix operator* (const DynamicMatrix &other) const
 Multiplies this matrix with other and returns the result in a new matrix. More...
 
DynamicMatrix operator/ (const double divisor) const
 Divides this matrix by a divisor specified in divisor and returns the result in a new matrix. More...
 
DynamicMatrixoperator/= (const double divisor)
 Divides this matrix by a divisor specified in divisor. More...
 
DynamicMatrix transpose () const
 Transposes this matrix and returns it. More...
 
DynamicMatrix extract (const std::vector< index > &rowIndices, const std::vector< index > &columnIndices) const
 Extracts a matrix with rows and columns specified by rowIndices and columnIndices from this matrix. More...
 
void assign (const std::vector< index > &rowIndices, const std::vector< index > &columnIndices, const DynamicMatrix &source)
 Assign the contents of the matrix source to this matrix at rows and columns specified by rowIndices and columnIndices. More...
 
template<typename F >
void apply (const F unaryElementFunction)
 Applies the unary function unaryElementFunction to each value in the matrix. More...
 
template<typename L >
void forNonZeroElementsInRow (index row, L handle) const
 Iterate over all non-zero elements of row row in the matrix and call handle(index row, index column, double value) More...
 
template<typename L >
void forElementsInRow (index i, L handle) const
 Iterate over all elements in row i in the matrix and call handle(index column, double value) More...
 
template<typename L >
void forNonZeroElementsInRowOrder (L handle) const
 Iterate over all non-zero elements of the matrix in row order and call handle(index row, index column, double value). More...
 
template<typename L >
void parallelForNonZeroElementsInRowOrder (L handle) const
 Iterate in parallel over all rows and call handle(index row, index column, double value) on non-zero elements of the matrix. More...
 

Static Public Member Functions

static DynamicMatrix mTmMultiply (const DynamicMatrix &A, const DynamicMatrix &B)
 Computes A^T * B. More...
 
static DynamicMatrix mmTMultiply (const DynamicMatrix &A, const DynamicMatrix &B)
 Computes A * B^T. More...
 
static Vector mTvMultiply (const DynamicMatrix &matrix, const Vector &vector)
 Computes matrix^T * vector. More...
 
static DynamicMatrix adjacencyMatrix (const Graph &graph, double zero=0.0)
 Returns the (weighted) adjacency matrix of the (weighted) Graph graph. More...
 
static DynamicMatrix diagonalMatrix (const Vector &diagonalElements, double zero=0.0)
 Creates a diagonal matrix with dimension equal to the dimension of the Vector diagonalElements. More...
 
static DynamicMatrix incidenceMatrix (const Graph &graph, double zero=0.0)
 Returns the (weighted) incidence matrix of the (weighted) Graph graph. More...
 
static DynamicMatrix laplacianMatrix (const Graph &graph, double zero=0.0)
 Returns the (weighted) Laplacian matrix of the (weighteD) Graph graph. More...
 
static DynamicMatrix normalizedLaplacianMatrix (const Graph &graph, double zero=0.0)
 Returns the (weighted) normalized Laplacian matrix of the (weighted) Graph graph. More...
 

Protected Attributes

Graph graph
 
count nRows
 
count nCols
 
double zero
 

Detailed Description

The DynamicMatrix class represents a matrix that is optimized for sparse matrices and internally uses a graph data structure.

DynamicMatrix should be used when changes to the structure of the matrix are frequent.

Constructor & Destructor Documentation

NetworKit::DynamicMatrix::DynamicMatrix ( )

Default constructor.

NetworKit::DynamicMatrix::DynamicMatrix ( const count  dimension,
const double  zero = 0.0 
)

Constructs the Matrix with size dimension x dimension.

Parameters
dimensionDefines how many rows and columns this matrix has.
zeroThe zero element (default is 0.0).
NetworKit::DynamicMatrix::DynamicMatrix ( const count  nRows,
const count  nCols,
const double  zero = 0.0 
)

Constructs the Matrix with size nRows x nCols.

Parameters
nRowsNumber of rows.
nColsNumber of columns.
zeroThe zero element (default is 0.0).
NetworKit::DynamicMatrix::DynamicMatrix ( const count  dimension,
const std::vector< Triplet > &  triplets,
const double  zero = 0.0 
)

Constructs the dimension x dimension Matrix from the elements at position positions with values .

Parameters
dimensionDefines how many rows and columns this matrix has.
tripletsThe nonzero elements.
zeroThe zero element (default is 0.0).
NetworKit::DynamicMatrix::DynamicMatrix ( const count  nRows,
const count  nCols,
const std::vector< Triplet > &  triplets,
const double  zero = 0.0 
)

Constructs the nRows x nCols Matrix from the elements at position positions with values .

Parameters
nRowsDefines how many rows this matrix has.
nColsDefines how many columns this matrix has.
tripletsThe nonzero elements.
zeroThe zero element (default is 0.0).
NetworKit::DynamicMatrix::DynamicMatrix ( const DynamicMatrix other)
default

Default copy constructor.

NetworKit::DynamicMatrix::DynamicMatrix ( DynamicMatrix &&  other)
default

Default move constructor.

virtual NetworKit::DynamicMatrix::~DynamicMatrix ( )
virtualdefault

Default destructor.

Member Function Documentation

DynamicMatrix NetworKit::DynamicMatrix::adjacencyMatrix ( const Graph graph,
double  zero = 0.0 
)
static

Returns the (weighted) adjacency matrix of the (weighted) Graph graph.

Parameters
graph
template<typename F >
void NetworKit::DynamicMatrix::apply ( const F  unaryElementFunction)

Applies the unary function unaryElementFunction to each value in the matrix.

Note that it must hold that the function applied to the zero element of this matrix returns the zero element.

Parameters
unaryElementFunction
void NetworKit::DynamicMatrix::assign ( const std::vector< index > &  rowIndices,
const std::vector< index > &  columnIndices,
const DynamicMatrix source 
)

Assign the contents of the matrix source to this matrix at rows and columns specified by rowIndices and columnIndices.

That is, entry (i,j) of source is assigned to entry (rowIndices[i], columnIndices[j]) of this matrix. Note that the dimensions of and columnIndices must coincide with the number of rows and columns of source.

Parameters
rowIndices
columnIndices
source
Vector NetworKit::DynamicMatrix::column ( const index  j) const
Returns
Column j of this matrix as vector.
Vector NetworKit::DynamicMatrix::diagonal ( ) const
Returns
The main diagonal of this matrix.
DynamicMatrix NetworKit::DynamicMatrix::diagonalMatrix ( const Vector diagonalElements,
double  zero = 0.0 
)
static

Creates a diagonal matrix with dimension equal to the dimension of the Vector diagonalElements.

The values on the diagonal are the ones stored in diagonalElements (i.e. D(i,i) = diagonalElements[i]).

Parameters
diagonalElements
DynamicMatrix NetworKit::DynamicMatrix::extract ( const std::vector< index > &  rowIndices,
const std::vector< index > &  columnIndices 
) const

Extracts a matrix with rows and columns specified by rowIndices and columnIndices from this matrix.

The order of rows and columns is equal to the order in rowIndices and columnIndices. It is also possible to specify a row or column more than once to get duplicates.

Parameters
rowIndices
columnIndices
template<typename L >
void NetworKit::DynamicMatrix::forElementsInRow ( index  i,
handle 
) const
inline

Iterate over all elements in row i in the matrix and call handle(index column, double value)

template<typename L >
void NetworKit::DynamicMatrix::forNonZeroElementsInRow ( index  row,
handle 
) const
inline

Iterate over all non-zero elements of row row in the matrix and call handle(index row, index column, double value)

template<typename L >
void NetworKit::DynamicMatrix::forNonZeroElementsInRowOrder ( handle) const
inline

Iterate over all non-zero elements of the matrix in row order and call handle(index row, index column, double value).

double NetworKit::DynamicMatrix::getZero ( ) const
inline

Returns the zero element of the matrix.

DynamicMatrix NetworKit::DynamicMatrix::incidenceMatrix ( const Graph graph,
double  zero = 0.0 
)
static

Returns the (weighted) incidence matrix of the (weighted) Graph graph.

Parameters
graph
DynamicMatrix NetworKit::DynamicMatrix::laplacianMatrix ( const Graph graph,
double  zero = 0.0 
)
static

Returns the (weighted) Laplacian matrix of the (weighteD) Graph graph.

Parameters
graph
DynamicMatrix NetworKit::DynamicMatrix::mmTMultiply ( const DynamicMatrix A,
const DynamicMatrix B 
)
static

Computes A * B^T.

Parameters
A
B
DynamicMatrix NetworKit::DynamicMatrix::mTmMultiply ( const DynamicMatrix A,
const DynamicMatrix B 
)
static

Computes A^T * B.

Parameters
A
B
Vector NetworKit::DynamicMatrix::mTvMultiply ( const DynamicMatrix matrix,
const Vector vector 
)
static

Computes matrix^T * vector.

Parameters
matrix
vector
count NetworKit::DynamicMatrix::nnz ( ) const
Returns
Number of non-zeros in this matrix.
count NetworKit::DynamicMatrix::nnzInRow ( const index  i) const
Parameters
iThe row index.
Returns
Number of non-zeros in row i.
DynamicMatrix NetworKit::DynamicMatrix::normalizedLaplacianMatrix ( const Graph graph,
double  zero = 0.0 
)
static

Returns the (weighted) normalized Laplacian matrix of the (weighted) Graph graph.

Parameters
graph
count NetworKit::DynamicMatrix::numberOfColumns ( ) const
inline
Returns
Number of columns.
count NetworKit::DynamicMatrix::numberOfRows ( ) const
inline
Returns
Number of rows.
bool NetworKit::DynamicMatrix::operator!= ( const DynamicMatrix other) const
inline

Compares this matrix to other and returns false if the shape and zero element are the same as well as all entries, otherwise returns true.

Parameters
other
double NetworKit::DynamicMatrix::operator() ( const index  i,
const index  j 
) const
Returns
Value at matrix position (i,j).
DynamicMatrix NetworKit::DynamicMatrix::operator* ( const double  scalar) const

Multiplies this matrix with a scalar specified in scalar and returns the result.

Returns
The result of multiplying this matrix with scalar.
Vector NetworKit::DynamicMatrix::operator* ( const Vector vector) const

Multiplies this matrix with vector and returns the result.

Returns
The result of multiplying this matrix with vector.
DynamicMatrix NetworKit::DynamicMatrix::operator* ( const DynamicMatrix other) const

Multiplies this matrix with other and returns the result in a new matrix.

Returns
The result of multiplying this matrix with other.
DynamicMatrix & NetworKit::DynamicMatrix::operator*= ( const double  scalar)

Multiplies this matrix with a scalar specified in scalar.

Returns
Reference to this matrix.
DynamicMatrix NetworKit::DynamicMatrix::operator+ ( const DynamicMatrix other) const

Adds this matrix to other and returns the result.

Returns
The sum of this matrix and other.
DynamicMatrix & NetworKit::DynamicMatrix::operator+= ( const DynamicMatrix other)

Adds other to this matrix.

Returns
Reference to this matrix.
DynamicMatrix NetworKit::DynamicMatrix::operator- ( const DynamicMatrix other) const

Subtracts other from this matrix and returns the result.

Returns
The difference of this matrix and other.
DynamicMatrix & NetworKit::DynamicMatrix::operator-= ( const DynamicMatrix other)

Subtracts other from this matrix.

Returns
Reference to this matrix.
DynamicMatrix NetworKit::DynamicMatrix::operator/ ( const double  divisor) const

Divides this matrix by a divisor specified in divisor and returns the result in a new matrix.

Returns
The result of dividing this matrix by divisor.
DynamicMatrix & NetworKit::DynamicMatrix::operator/= ( const double  divisor)

Divides this matrix by a divisor specified in divisor.

Returns
Reference to this matrix.
DynamicMatrix& NetworKit::DynamicMatrix::operator= ( DynamicMatrix &&  other)
default

Default move assignment operator.

DynamicMatrix& NetworKit::DynamicMatrix::operator= ( const DynamicMatrix other)
default

Default copy assignment operator.

bool NetworKit::DynamicMatrix::operator== ( const DynamicMatrix other) const
inline

Compares this matrix to other and returns true if the shape and zero element are the same as well as all entries, otherwise returns false.

Parameters
other
template<typename L >
void NetworKit::DynamicMatrix::parallelForNonZeroElementsInRowOrder ( handle) const
inline

Iterate in parallel over all rows and call handle(index row, index column, double value) on non-zero elements of the matrix.

Vector NetworKit::DynamicMatrix::row ( const index  i) const
Returns
Row i of this matrix as vector.
void NetworKit::DynamicMatrix::setValue ( const index  i,
const index  j,
const double  value 
)

Set the matrix at position (i, j) to value.

DynamicMatrix NetworKit::DynamicMatrix::transpose ( ) const

Transposes this matrix and returns it.

Member Data Documentation

Graph NetworKit::DynamicMatrix::graph
protected
count NetworKit::DynamicMatrix::nCols
protected
count NetworKit::DynamicMatrix::nRows
protected
double NetworKit::DynamicMatrix::zero
protected

The documentation for this class was generated from the following files: