Discontinuous Galerkin Library
#include "dg/algorithm.h"
Collaboration diagram for Dense matrix formats:

Classes

class  dg::Operator< T >
 A square nxn matrix. More...
 

Functions

template<class ContainerType >
auto dg::asDenseMatrix (const std::vector< const ContainerType * > &in)
 Lightweight DenseMatrix for dg::blas2::gemv. More...
 
template<class ContainerType >
auto dg::asDenseMatrix (const std::vector< const ContainerType * > &in, unsigned size)
 Lightweight DenseMatrix for dg::blas2::gemv. More...
 
template<class ContainerType >
std::vector< const ContainerType * > dg::asPointers (const std::vector< ContainerType > &in)
 Convert a vector of vectors to a vector of pointers. More...
 
template<class T >
dg::create::lu_pivot (dg::Operator< T > &m, std::vector< unsigned > &p)
 LU Decomposition with partial pivoting. More...
 
template<class T >
void dg::create::lu_solve (const dg::Operator< T > &lu, const std::vector< unsigned > &p, std::vector< T > &b)
 Solve the linear system with the LU decomposition. More...
 
template<class T >
dg::Operator< T > dg::create::inverse (const dg::Operator< T > &in)
 Compute the inverse of a square matrix. More...
 
template<class T >
dg::Operator< T > dg::invert (const dg::Operator< T > &in)
 Alias for dg::create::inverse. Compute inverse of square matrix. More...
 

Detailed Description

Function Documentation

◆ asDenseMatrix() [1/2]

template<class ContainerType >
auto dg::asDenseMatrix ( const std::vector< const ContainerType * > &  in)

Lightweight DenseMatrix for dg::blas2::gemv.

The philosophy is that a column matrix is represented by a std::vector of pointers and can be multiplied with a coefficient vector

\[ \vec y = V \vec c = \sum_i c_i \vec v_{i} \]

where \( v_i\) are the columns of \( V\)

std::vector<Container> matrix( 10, x);
std::vector<const Container*> matrix_ptrs = dg::asPointers(matrix);
std::vector<value_type> coeffs( 10, 0.5);
dg::blas2::gemv( 1., dg::asDenseMatrix(matrix_ptrs), coeffs, 0., x);
void gemv(get_value_type< ContainerType1 > alpha, MatrixType &&M, const ContainerType1 &x, get_value_type< ContainerType1 > beta, ContainerType2 &y)
; (alias for symv)
Definition: blas2.h:299
std::vector< const ContainerType * > asPointers(const std::vector< ContainerType > &in)
Convert a vector of vectors to a vector of pointers.
Definition: densematrix.h:100
auto asDenseMatrix(const std::vector< const ContainerType * > &in)
Lightweight DenseMatrix for dg::blas2::gemv.
Definition: densematrix.h:70
Note
the implemented summation algorithm is a pairwise summation algorithm optimized for small sized number of columns ( <= 64)
Parameters
ina collection of pointers that form the columns of the dense matrix
Returns
an opaque type that internally adds a Tag that tells the compiler that the std::vector is to be interpreted as a dense matrix and call the correct implementation.
Template Parameters
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system

◆ asDenseMatrix() [2/2]

template<class ContainerType >
auto dg::asDenseMatrix ( const std::vector< const ContainerType * > &  in,
unsigned  size 
)

Lightweight DenseMatrix for dg::blas2::gemv.

The philosophy is that a column matrix is represented by a std::vector of pointers and can be multiplied with a coefficient vector

\[ \vec y = V \vec c = \sum_i c_i \vec v_{i} \]

where \( v_i\) are the columns of \( V\)

std::vector<Container> matrix( 10, x);
std::vector<const Container*> matrix_ptrs = dg::asPointers(matrix);
std::vector<value_type> coeffs( 10, 0.5);
dg::blas2::gemv( 1., dg::asDenseMatrix(matrix_ptrs), coeffs, 0., x);
Note
the implemented summation algorithm is a pairwise summation algorithm optimized for small sized number of columns ( <= 64)
Parameters
ina collection of pointers that form the columns of the dense matrix
Returns
an opaque type that internally adds a Tag that tells the compiler that the std::vector is to be interpreted as a dense matrix and call the correct implementation.
Template Parameters
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system
Parameters
sizeonly the first size pointers are used in the matrix (i.e. the number of columns is size)

◆ asPointers()

template<class ContainerType >
std::vector< const ContainerType * > dg::asPointers ( const std::vector< ContainerType > &  in)

Convert a vector of vectors to a vector of pointers.

A convenience function that can be used in combination with asDenseMatrix

std::vector<Container> matrix( 10, x);
std::vector<const Container*> matrix_ptrs = dg::asPointers(matrix);
std::vector<value_type> coeffs( 10, 0.5);
dg::blas2::gemv( 1., dg::asDenseMatrix(matrix_ptrs), coeffs, 0., x);
Parameters
ina collection of vectors that form the columns of the dense matrix
Returns
a vector of pointers with ptrs[i] = &in[i]
Attention
DO NOT HOLD POINTERS AS PRIVATE DATA MEMBERS IN A CLASS unless you also plan to overload the copy and assignment operators
Template Parameters
ContainerTypeAny class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag. Among others
  • dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
  • std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
  • double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them
See also
See The dg dispatch system for a detailed explanation of our type dispatch system

◆ inverse()

template<class T >
dg::Operator< T > dg::create::inverse ( const dg::Operator< T > &  in)

Compute the inverse of a square matrix.

using lu decomposition in combination with our accurate scalar products

Template Parameters
Tvalue type
Parameters
ininput matrix
Returns
the inverse of in if it exists
Exceptions
std::runtime_errorif in is singular

◆ invert()

template<class T >
dg::Operator< T > dg::invert ( const dg::Operator< T > &  in)

Alias for dg::create::inverse. Compute inverse of square matrix.

using lu decomposition in combination with our accurate scalar products

Template Parameters
Tvalue type
Parameters
ininput matrix
Returns
the inverse of in if it exists
Exceptions
std::runtime_errorif in is singular

◆ lu_pivot()

template<class T >
T dg::create::lu_pivot ( dg::Operator< T > &  m,
std::vector< unsigned > &  p 
)

LU Decomposition with partial pivoting.

Template Parameters
Tvalue type
Exceptions
std::runtime_errorif the matrix is singular
Parameters
mcontains lu decomposition of input on output (inplace transformation)
pcontains the pivot elements on output
Returns
determinant of m
Note
uses extended accuracy of dg::exblas which makes it quite robust against almost singular matrices
See also
dg::create::lu_solve

◆ lu_solve()

template<class T >
void dg::create::lu_solve ( const dg::Operator< T > &  lu,
const std::vector< unsigned > &  p,
std::vector< T > &  b 
)

Solve the linear system with the LU decomposition.

Template Parameters
Tvalue type
Parameters
luresult of dg::create::lu_pivot
ppivot vector from dg::create::lu_pivot
bright hand side (contains solution on output)