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

Represents a dense matrix. More...

#include <DenseMatrix.h>

Public Member Functions

 DenseMatrix ()
 Default constructor. More...
 
 DenseMatrix (const count dimension, double zero=0.0)
 Constructs the DenseMatrix with size dimension x dimension. More...
 
 DenseMatrix (const count nRows, const count nCols, double zero=0.0)
 Constructs the DenseMatrix with size nRows x nCols. More...
 
 DenseMatrix (const count dimension, const std::vector< Triplet > &triplets, double zero=0.0)
 Constructs the dimension x dimension DenseMatrix from the elements at position positions with values . More...
 
 DenseMatrix (const count nRows, const count nCols, const std::vector< Triplet > &triplets, double zero=0.0)
 Constructs the nRows x nCols DenseMatrix from the elements at position positions with values . More...
 
 DenseMatrix (const count nRows, const count nCols, const std::vector< double > &entries, double zero=0.0)
 Constructs an instance of DenseMatrix given the number of rows (nRows) and the number of columns (nCols) and its values (entries). More...
 
virtual ~DenseMatrix ()=default
 Default destructor. More...
 
 DenseMatrix (const DenseMatrix &other)=default
 Default copy constructor. More...
 
 DenseMatrix (DenseMatrix &&other)=default
 Default move constructor. More...
 
DenseMatrixoperator= (DenseMatrix &&other)=default
 Default copy assignment operator. More...
 
DenseMatrixoperator= (const DenseMatrix &other)=default
 Default move assignment operator. 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
 
DenseMatrix operator+ (const DenseMatrix &other) const
 Adds this matrix to other and returns the result. More...
 
DenseMatrixoperator+= (const DenseMatrix &other)
 Adds other to this matrix. More...
 
DenseMatrix operator- (const DenseMatrix &other) const
 Subtracts other from this matrix and returns the result. More...
 
DenseMatrixoperator-= (const DenseMatrix &other)
 Subtracts other from this matrix. More...
 
DenseMatrix operator* (const double &scalar) const
 Multiplies this matrix with a scalar specified in scalar and returns the result. More...
 
DenseMatrixoperator*= (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...
 
DenseMatrix operator* (const DenseMatrix &other) const
 Multiplies this matrix with other and returns the result in a new matrix. More...
 
DenseMatrix operator/ (const double &divisor) const
 Divides this matrix by a divisor specified in divisor and returns the result in a new matrix. More...
 
DenseMatrixoperator/= (const double &divisor)
 Divides this matrix by a divisor specified in divisor. More...
 
DenseMatrix transpose () const
 Transposes this matrix and returns it. More...
 
DenseMatrix 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 DenseMatrix &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 forElementsInRow (index row, L handle) const
 Iterate over all non-zero elements of row row in the matrix and call handler(index column, double value) More...
 
template<typename L >
void parallelForElementsInRow (index row, L handle) const
 Iterate in parallel over all non-zero elements of row row in the matrix and call handler(index column, double value) More...
 
template<typename L >
void forElementsInRowOrder (L handle) const
 Iterate over all non-zero elements of the matrix in row order and call handler (lambda closure). More...
 
template<typename L >
void parallelForElementsInRowOrder (L handle) const
 Iterate in parallel over all rows and call handler (lambda closure) on non-zero elements of 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 handler(index column, double value). More...
 
template<typename L >
void parallelForNonZeroElementsInRow (index row, L handle) const
 Iterate in parallel over all non-zero elements of row row in the matrix and call handler(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 handler (lambda closure). More...
 
template<typename L >
void parallelForNonZeroElementsInRowOrder (L handle) const
 Iterate in parallel over all rows and call handler (lambda closure) on non-zero elements of the matrix. More...
 

Static Public Member Functions

static void LUDecomposition (DenseMatrix &matrix)
 Decomposes the given matrix into lower L and upper U matrix (in-place). More...
 
static Vector LUSolve (const DenseMatrix &LU, const Vector &b)
 Computes the solution vector x to the system LU * x = b where LU is a matrix decomposed into L and U. More...
 
template<typename L >
static DenseMatrix binaryOperator (const DenseMatrix &A, const DenseMatrix &B, L binaryOp)
 Computes A binaryOp B on the elements of matrix A and matrix B. More...
 

Detailed Description

Represents a dense matrix.

Use this matrix to run LU decompositions and LU solves. Note that most matrices are rather sparse s.t. CSRMatrix might be a better representation.

Constructor & Destructor Documentation

NetworKit::DenseMatrix::DenseMatrix ( )

Default constructor.

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

Constructs the DenseMatrix with size dimension x dimension.

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

Constructs the DenseMatrix with size nRows x nCols.

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

Constructs the dimension x dimension DenseMatrix 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::DenseMatrix::DenseMatrix ( const count  nRows,
const count  nCols,
const std::vector< Triplet > &  triplets,
double  zero = 0.0 
)

Constructs the nRows x nCols DenseMatrix 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::DenseMatrix::DenseMatrix ( const count  nRows,
const count  nCols,
const std::vector< double > &  entries,
double  zero = 0.0 
)

Constructs an instance of DenseMatrix given the number of rows (nRows) and the number of columns (nCols) and its values (entries).

Parameters
nRowsNumber of rows.
nColsNumber of columns.
entriesEntries of the matrix.
zeroThe zero element (default is 0.0).
Note
The size of the entries vector should be equal to nRows * nCols.
virtual NetworKit::DenseMatrix::~DenseMatrix ( )
virtualdefault

Default destructor.

NetworKit::DenseMatrix::DenseMatrix ( const DenseMatrix other)
default

Default copy constructor.

NetworKit::DenseMatrix::DenseMatrix ( DenseMatrix &&  other)
default

Default move constructor.

Member Function Documentation

template<typename F >
void NetworKit::DenseMatrix::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::DenseMatrix::assign ( const std::vector< index > &  rowIndices,
const std::vector< index > &  columnIndices,
const DenseMatrix 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
template<typename L >
DenseMatrix NetworKit::DenseMatrix::binaryOperator ( const DenseMatrix A,
const DenseMatrix B,
binaryOp 
)
inlinestatic

Computes A binaryOp B on the elements of matrix A and matrix B.

Parameters
A
B
binaryOpFunction handling (double, double) -> double
Returns
A binaryOp B.
Note
A and B must have the same dimensions.
Vector NetworKit::DenseMatrix::column ( const index  j) const
Returns
Column j of this matrix as vector.
Vector NetworKit::DenseMatrix::diagonal ( ) const
Returns
The main diagonal of this matrix.
DenseMatrix NetworKit::DenseMatrix::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::DenseMatrix::forElementsInRow ( index  row,
handle 
) const
inline

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

template<typename L >
void NetworKit::DenseMatrix::forElementsInRowOrder ( handle) const
inline

Iterate over all non-zero elements of the matrix in row order and call handler (lambda closure).

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

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

Note
This is a DenseMatrix! Therefore this operation needs O(numberOfRows()) time regardless of the number of non-zeros actually present.
template<typename L >
void NetworKit::DenseMatrix::forNonZeroElementsInRowOrder ( handle) const
inline

Iterate over all non-zero elements of the matrix in row order and call handler (lambda closure).

Note
This is a DenseMatrix! Therefore this operation needs O(numberOfRows() * numberOfColumns()) time regardless of the number of non-zeros actually present.
double NetworKit::DenseMatrix::getZero ( ) const
inline

Returns the zero element of the matrix.

void NetworKit::DenseMatrix::LUDecomposition ( DenseMatrix matrix)
static

Decomposes the given matrix into lower L and upper U matrix (in-place).

Parameters
matrixThe matrix to decompose into LU.
Vector NetworKit::DenseMatrix::LUSolve ( const DenseMatrix LU,
const Vector b 
)
static

Computes the solution vector x to the system LU * x = b where LU is a matrix decomposed into L and U.

Parameters
LUMatrix decomposed into lower L and upper U matrix.
bRight-hand side.
Returns
Solution vector x to the linear equation system LU * x = b.
count NetworKit::DenseMatrix::nnz ( ) const
Returns
Number of non-zeros in this matrix.
Note
This function takes nRows * nCols operations.
count NetworKit::DenseMatrix::nnzInRow ( const index  i) const
Parameters
iThe row index.
Returns
Number of non-zeros in row i.
Note
This function is linear in the number of columns of the matrix.
count NetworKit::DenseMatrix::numberOfColumns ( ) const
inline
Returns
Number of columns.
count NetworKit::DenseMatrix::numberOfRows ( ) const
inline
Returns
Number of rows.
double NetworKit::DenseMatrix::operator() ( const index  i,
const index  j 
) const
Returns
Value at matrix position (i,j).
DenseMatrix NetworKit::DenseMatrix::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::DenseMatrix::operator* ( const Vector vector) const

Multiplies this matrix with vector and returns the result.

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

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

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

Multiplies this matrix with a scalar specified in scalar.

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

Adds this matrix to other and returns the result.

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

Adds other to this matrix.

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

Subtracts other from this matrix and returns the result.

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

Subtracts other from this matrix.

Returns
Reference to this matrix.
DenseMatrix NetworKit::DenseMatrix::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.
DenseMatrix & NetworKit::DenseMatrix::operator/= ( const double &  divisor)

Divides this matrix by a divisor specified in divisor.

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

Default copy assignment operator.

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

Default move assignment operator.

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

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

template<typename L >
void NetworKit::DenseMatrix::parallelForElementsInRowOrder ( handle) const
inline

Iterate in parallel over all rows and call handler (lambda closure) on non-zero elements of the matrix.

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

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

Note
This is a DenseMatrix! Therefore this operation needs O(numberOfRows()) sequential time regardless of the number of non-zeros actually present.
template<typename L >
void NetworKit::DenseMatrix::parallelForNonZeroElementsInRowOrder ( handle) const
inline

Iterate in parallel over all rows and call handler (lambda closure) on non-zero elements of the matrix.

Note
This is a DenseMatrix! Therefore this operation needs O(numberOfRows() * numberOfColumns()) sequential time regardless of the number of non-zeros actually present.
Vector NetworKit::DenseMatrix::row ( const index  i) const
Returns
Row i of this matrix as vector.
void NetworKit::DenseMatrix::setValue ( const index  i,
const index  j,
const double  value 
)

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

DenseMatrix NetworKit::DenseMatrix::transpose ( ) const

Transposes this matrix and returns it.


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