CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::LinearSystemInterface< T_InterfaceTypes > Struct Template Reference

#include <linearSystemInterface.hpp>

Inheritance diagram for codi::LinearSystemInterface< T_InterfaceTypes >:

Public Types

using InterfaceTypes = T_InterfaceTypes
 See LinearSystemInterface.
 
using Matrix = typename InterfaceTypes::Matrix
 See LinearSystemInterfaceTypes.
 
using MatrixIdentifier = typename InterfaceTypes::MatrixIdentifier
 See LinearSystemInterfaceTypes.
 
using MatrixReal = typename InterfaceTypes::MatrixReal
 See LinearSystemInterfaceTypes.
 
using Type = typename InterfaceTypes::Type
 See LinearSystemInterfaceTypes.
 
using Vector = typename InterfaceTypes::Vector
 See LinearSystemInterfaceTypes.
 
using VectorIdentifier = typename InterfaceTypes::VectorIdentifier
 See LinearSystemInterfaceTypes.
 
using VectorReal = typename InterfaceTypes::VectorReal
 See LinearSystemInterfaceTypes.
 

Public Member Functions

Mandatory: Implementations for matrix and vector creation and deletion.
template<typename M >
MatrixRealcreateMatrixReal (M *mat)
 
template<typename M >
MatrixIdentifiercreateMatrixIdentifier (M *mat)
 
template<typename V >
VectorRealcreateVectorReal (V *vec)
 
template<typename V >
VectorIdentifiercreateVectorIdentifier (V *vec)
 
void deleteMatrixReal (MatrixReal *A_v)
 Delete a real matrix.
 
void deleteMatrixIdentifier (MatrixIdentifier *A_id)
 Delete an identifier matrix.
 
void deleteVectorReal (VectorReal *vec_v)
 Delete a real Vector.
 
void deleteVectorIdentifier (VectorIdentifier *vec_id)
 Delete an identifier vector.
 
Mandatory: Implementations for matrix and vector iterations.
template<typename Func , typename MatrixA , typename MatrixB >
void iterateMatrix (Func func, MatrixA *matA, MatrixB *matB)
 Iterate over all elements in the matrices at the same time.
 
template<typename Func , typename MatrixA , typename MatrixB , typename MatrixC >
void iterateMatrix (Func func, MatrixA *matA, MatrixB *matB, MatrixC *matC)
 Iterate over all elements in the matrices at the same time.
 
template<typename Func , typename VectorA , typename VectorB >
void iterateVector (Func func, VectorA *vecA, VectorB *vecB)
 Iterate over all elements in the vectors at the same time.
 
template<typename Func , typename VectorA , typename VectorB , typename VectorC >
void iterateVector (Func func, VectorA *vecA, VectorB *vecB, VectorC *vecC)
 Iterate over all elements in the vectors at the same time.
 
template<typename Func , typename VectorA , typename VectorB , typename VectorC , typename VectorD >
void iterateVector (Func func, VectorA *vecA, VectorB *vecB, VectorC *vecC, VectorD *vecD)
 Iterate over all elements in the vectors at the same time.
 
Mandatory: Implementations for the linear system solve.
void solveSystem (MatrixReal const *A, VectorReal const *b, VectorReal *x)
 
Optional: Implementation for reverse mode AD.
template<typename Func >
void iterateDyadic (Func func, MatrixIdentifier *mat_id, VectorReal *x_v, VectorReal *b_b)
 
MatrixRealtransposeMatrix (MatrixReal *A_v)
 Create a transposed matrix.
 
Optional: Implementation for forward mode AD.
void subtractMultiply (VectorReal *t, VectorReal const *b_d, MatrixReal const *A_d, VectorReal const *x)
 Computes t = b_d - A_d * x.
 
Optional: Implementations for specializations of the algorithm.
void solveSystemPrimal (MatrixReal const *A, VectorReal const *b, VectorReal *x)
 

Detailed Description

template<typename T_InterfaceTypes>
struct codi::LinearSystemInterface< T_InterfaceTypes >

The interface defines all mandatory and optional functions that are required by the LinearSystemSolverHandler. Implementations need to define all mandatory functions, the optional ones either depend on the use case and on specifics of the algorithm. For more details see LinearSystemSolverHandler.

If the interface has been specialized, it can be called with:

codi::solveLinearSystem({Specialization}, A, rhs, sol, hints);
void solveLinearSystem(LSInterface lsi, typename LSInterface::Matrix &A, typename LSInterface::Vector &b, typename LSInterface::Vector &x, LinearSystemSolverHints hints=LinearSystemSolverHints::ALL())
Definition: linearSystemHandler.hpp:770

The hints parameter is optional, but can be used to improve the runtime and memory. The set of flags that can be passed as hints is defined in LinearSystemSolverFlags.

  • ReverseEvaluation: Prepare for a reverse mode evaluation. Stores A_v_trans.
  • ForwardEvaluation: Prepare for a forward mode evaluation. Stores A_v.
  • PrimalEvaluation: Prepare for a primal reevaluation. Stores A_v.
  • ProvidePrimalSolution: Read x_v before the system is solved and provide it to the solveSystem or solveSystemPrimal methods (only during the primal computation, not in the external function implementations).
  • RecomputePrimalInForwardEvaluation: In the AD forward mode also solve the primal linear system again.

See Example 21 - Special handling of linear system solvers for an example with the Eigen implementation.

Mandatory methods

Optional methods

Template Parameters
T_InterfaceTypesThe definition of LinearSystemInterfaceTypes for the implementation.

Member Function Documentation

◆ createMatrixIdentifier()

template<typename T_InterfaceTypes >
template<typename M >
MatrixIdentifier * codi::LinearSystemInterface< T_InterfaceTypes >::createMatrixIdentifier ( M *  mat)

Create an identifier matrix from an existing one. Values do not need to be copied.

Template Parameters
MM is either Matrix or MatrixIdentifier.

◆ createMatrixReal()

template<typename T_InterfaceTypes >
template<typename M >
MatrixReal * codi::LinearSystemInterface< T_InterfaceTypes >::createMatrixReal ( M *  mat)

Create a real matrix from an existing one. Values do not need to be copied.

Template Parameters
MM is either Matrix or MatrixIdentifier.

◆ createVectorIdentifier()

template<typename T_InterfaceTypes >
template<typename V >
VectorIdentifier * codi::LinearSystemInterface< T_InterfaceTypes >::createVectorIdentifier ( V *  vec)

Create an identifier vector from an existing one. Values do not need to be copied.

Template Parameters
VV is either Vector or VectorIdentifier.

◆ createVectorReal()

template<typename T_InterfaceTypes >
template<typename V >
VectorReal * codi::LinearSystemInterface< T_InterfaceTypes >::createVectorReal ( V *  vec)

Create a real vector from an existing one. Values do not need to be copied.

Template Parameters
VV is either Vector or VectorIdentifier.

◆ iterateDyadic()

template<typename T_InterfaceTypes >
template<typename Func >
void codi::LinearSystemInterface< T_InterfaceTypes >::iterateDyadic ( Func  func,
MatrixIdentifier mat_id,
VectorReal x_v,
VectorReal b_b 
)
inline

Iterate over all elements in mat_id and provide the elements in b_b and x_v . For element (i,j) func needs to be called with func(mat_id(i,j), b_b(i), x_v(j)) . For sparse matrices, only the elements of the sparsity pattern need to be considered. Used for e.g. the computation of the dyadic product $A=x_v*b_b^T$.

◆ solveSystem()

template<typename T_InterfaceTypes >
void codi::LinearSystemInterface< T_InterfaceTypes >::solveSystem ( MatrixReal const *  A,
VectorReal const *  b,
VectorReal x 
)

Solve the linear system with the real valued matrices and vectors. Solves Ax = b for x.

◆ solveSystemPrimal()

template<typename T_InterfaceTypes >
void codi::LinearSystemInterface< T_InterfaceTypes >::solveSystemPrimal ( MatrixReal const *  A,
VectorReal const *  b,
VectorReal x 
)
inline

Solve the linear system with the real valued matrices and vectors. Implementation that is called in the primal routine. If not specialized solveSystem is called. Solves Ax = b for x.


The documentation for this struct was generated from the following file: