So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
EigenProblemTraits.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_EIGEN_PROBLEM_TRAITS_HPP
13 #define BOGUS_EIGEN_PROBLEM_TRAITS_HPP
14 
15 #include "EigenMatrixTraits.hpp"
16 
17 namespace bogus
18 {
19 
20 template < typename Scalar_ >
21 struct ProblemTraits
22 {
23  typedef Scalar_ Scalar ;
24 
25  typedef Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > DynVector ;
26  typedef Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > DynMatrix ;
27  template < typename OtherMatrix >
28  struct MutableClone
29  {
30  typedef Eigen::Matrix< Scalar,
31  OtherMatrix::RowsAtCompileTime,
32  OtherMatrix::ColsAtCompileTime > Type ;
33  } ;
34 
35 } ;
36 
37 template< DenseIndexType Dimension, typename Scalar_ >
38 struct LocalProblemTraits : public ProblemTraits< Scalar_ >
39 {
40  enum { dimension = Dimension } ;
41 
42  typedef Scalar_ Scalar ;
43  typedef Eigen::Matrix< Scalar, Dimension, 1 > Vector ;
44  typedef Eigen::Array< Scalar, Dimension, 1 > Array ;
45  typedef Eigen::Matrix< Scalar, Dimension, Dimension > Matrix ;
46 
47  typedef typename MatrixTraits< Matrix >::LUType LUType ;
49 
50  typedef Eigen::Matrix< Scalar, Dimension-1, Dimension-1 > TgMatrix ;
51 
52  static Scalar np( const Vector & v )
53  { return v[0] ; }
54  static Scalar& np( Vector & v )
55  { return v[0] ; }
56 
57  static typename Vector::template ConstFixedSegmentReturnType< Dimension - 1 >::Type
58  tp( const Vector & v ) { return v.template segment< Dimension - 1 >( 1 ) ; }
59  static typename Vector::template FixedSegmentReturnType< Dimension - 1 >::Type
60  tp( Vector & v ) { return v.template segment< Dimension - 1 >( 1 ) ; }
61 
62  static typename Matrix::ColXpr
63  nc( Matrix & m ) { return m.col( 0 ) ; }
64  static Eigen::Block< Matrix, Dimension, Dimension -1 >
65  tc( Matrix & m ) { return m.template block< Dimension, Dimension - 1 >( 0, 1 ) ; }
66 
67  static Scalar&
68  nnb( Matrix & m ) { return m( 0, 0 ) ; }
69  static Eigen::Block< Matrix, Dimension - 1, Dimension -1 >
70  ttb( Matrix & m ) { return m.template block< Dimension - 1, Dimension - 1 >( 1, 1 ) ; }
71  static Eigen::Block< Matrix, Dimension - 1, 1 >
72  tnb( Matrix & m ) { return m.template block< Dimension - 1, 1 >( 1, 0 ) ; }
73  static Eigen::Block< Matrix, 1, Dimension -1 >
74  ntb( Matrix & m ) { return m.template block< 1, Dimension - 1 >( 0, 1 ) ; }
75 } ;
76 
77 template< typename Scalar >
78 struct LocalProblemTraits< Eigen::Dynamic, Scalar > : public ProblemTraits< Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > >
79 {
80  typedef Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix ;
82 
83  typedef typename Base::DynVector Vector ;
84  typedef typename Base::DynMatrix TgMatrix ;
85 
86  static Scalar np( const Vector & v )
87  { return v[0] ; }
88  static Scalar& np( Vector & v )
89  { return v[0] ; }
90 
91  static typename Vector::ConstSegmentReturnType
92  tp( const Vector & v ) { return v.segment( 1, v.rows() - 1 ) ; }
93  static typename Vector::SegmentReturnType
94  tp( Vector & v ) { return v.segment( 1, v.rows() - 1 ) ; }
95 
96  static typename Matrix::ColXpr
97  nc( Matrix & m ) { return m.col( 0 ) ; }
98  static Eigen::Block< Matrix >
99  tc( Matrix & m ) { return m.block( 0, 1, m.rows(), m.cols()-1 ) ; }
100 
101  static Scalar&
102  nnb( Matrix & m ) { return m( 0, 0 ) ; }
103  static Eigen::Block< Matrix >
104  ttb( Matrix & m ) { return m.block( 1, 1, m.rows()-1, m.cols()-1 ) ; }
105  static Eigen::Block< Matrix >
106  tnb( Matrix & m ) { return m.block( 1, 0, m.rows()-1, 1 ) ; }
107  static Eigen::Block< Matrix >
108  ntb( Matrix & m ) { return m.block( 0, 1, 1, m.cols()-1 ) ; }
109 } ;
110 
111 
112 } //namespace bogus
113 
114 #endif
Definition: EigenProblemTraits.hpp:28
Base class for LDLT factorizations.
Definition: LinearSolverBase.hpp:72
Definition: BlockSolvers.fwd.hpp:33
Base class for LU factorizations.
Definition: LinearSolverBase.hpp:66
Definition: EigenProblemTraits.hpp:38