So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
LinearSolverBase.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 
12 #ifndef BOGUS_LINEAR_SOLVER_HPP
13 #define BOGUS_LINEAR_SOLVER_HPP
14 
15 #include <cassert>
16 
17 #include "../Block.fwd.hpp"
18 
19 namespace bogus {
20 
21 template < typename LSDerived >
22 struct LinearSolverTraits {} ;
23 
25 template < typename Derived >
27 {
28 
30  template < typename RhsT >
31  typename LinearSolverTraits< Derived >::template Result< RhsT >::Type
32  solve( const RhsT& rhs ) const
33  {
34  return derived().solve( rhs ) ;
35  }
36 
38  template < typename ResT, typename RhsT >
39  void solve( const RhsT& rhs, ResT& x ) const
40  {
41  derived().solve( rhs, x ) ;
42  }
43 
44  const Derived& derived() const
45  {
46  return static_cast< const Derived& >( *this ) ;
47  }
48 
49  Derived& derived() {
50  return static_cast< Derived& >( *this ) ;
51  }
52 
53 
54  typedef BlockTraits< typename LinearSolverTraits< Derived >::MatrixType > UnderlyingBlockTraits ;
55  typedef typename UnderlyingBlockTraits::Scalar Scalar ;
56  enum {
57  RowsAtCompileTime = UnderlyingBlockTraits::ColsAtCompileTime,
58  ColsAtCompileTime = UnderlyingBlockTraits::RowsAtCompileTime,
60  } ;
61 
62 } ;
63 
65 template < typename MatrixType >
66 struct LU : public LinearSolverBase< LU< MatrixType > >
67 {
68 } ;
69 
71 template < typename MatrixType >
72 struct LDLT : public LinearSolverBase< LDLT< MatrixType > >
73 {
74 } ;
75 
76 
78 
79 template< typename LhsBlockT, typename RhsBlockT, bool TransposeLhs, bool TransposeRhs >
80 struct BlockBlockProductTraits < LU < LhsBlockT >, RhsBlockT, TransposeLhs, TransposeRhs >
81 {
82  typedef typename LinearSolverTraits< LU < LhsBlockT > >::MatrixType LhsMatrixT ;
83  typedef typename BlockBlockProductTraits < LhsMatrixT, RhsBlockT, TransposeLhs, TransposeRhs >::ReturnType
84  ReturnType ;
85 } ;
86 
87 template< typename LhsBlockT, typename RhsBlockT, bool TransposeLhs, bool TransposeRhs >
88 struct BlockBlockProductTraits < LDLT < LhsBlockT >, RhsBlockT, TransposeLhs, TransposeRhs >
89 {
90  typedef typename LinearSolverTraits< LDLT < LhsBlockT > >::MatrixType LhsMatrixT ;
91  typedef typename BlockBlockProductTraits < LhsMatrixT, RhsBlockT, TransposeLhs, TransposeRhs >::ReturnType
92  ReturnType ;
93 } ;
94 
95 }// namespace bogus
96 
97 #endif
Definition: LinearSolverBase.hpp:22
Base class for linear solvers on base ( i.e. non-block ) matrices.
Definition: LinearSolverBase.hpp:26
Base class for LDLT factorizations.
Definition: LinearSolverBase.hpp:72
Number of rows spanned by a block at compile time ; useful for efficient segmentation.
Definition: Traits.hpp:37
Defines the return type of the product of two blocks potentially transposed.
Definition: Traits.hpp:64
Whether this block is equal to its transpose.
Definition: Traits.hpp:46
Number of cols spanned by a block at compile time ; useful for efficient segmentation.
Definition: Traits.hpp:39
Base class for LU factorizations.
Definition: LinearSolverBase.hpp:66
void solve(const RhsT &rhs, ResT &x) const
Finds the solution x of the linear system M * x = b.
Definition: LinearSolverBase.hpp:39
LinearSolverTraits< Derived >::template Result< RhsT >::Type solve(const RhsT &rhs) const
Returns the solution x of the linear system M * x = rhs.
Definition: LinearSolverBase.hpp:32