So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
BlockObjectBase.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_BLOCKOBJECTBASE_HPP
13 #define BOGUS_BLOCKOBJECTBASE_HPP
14 
15 #include "../Block.fwd.hpp"
16 
17 namespace bogus
18 {
19 
21 template < typename Derived >
23 {
25  const Derived& derived() const
26  {
27  return static_cast< const Derived& >( *this ) ;
28  }
30  Derived& derived()
31  {
32  return static_cast< Derived& >( *this ) ;
33  }
34 
35  typedef BlockMatrixTraits< Derived > Traits ;
36 
37  typedef typename Traits::Index Index ;
38  typedef typename Traits::Scalar Scalar ;
39  typedef typename Traits::ConstTransposeReturnType ConstTransposeReturnType ;
40  typedef typename Traits::TransposeObjectType TransposeObjectType ;
41  enum { is_transposed = Traits::is_transposed } ;
42 
43  typedef typename Traits::PlainObjectType PlainObjectType ;
44 
46  Index rows() const { return derived().rows() ; }
48  Index cols() const { return derived().cols() ; }
49 
51  Index blockRows( Index row ) const { return derived().blockRows( row ) ; }
53  Index blockCols( Index col ) const { return derived().blockCols( col ) ; }
54 
56  Index rowsOfBlocks() const { return derived().rowsOfBlocks() ; }
58  Index colsOfBlocks() const { return derived().colsOfBlocks() ; }
59 
61  const Index *rowOffsets( ) const { return derived().rowOffsets( ) ; }
63  const Index *colOffsets( ) const { return derived().colOffsets( ) ; }
64 
66  Index rowOffset( Index row ) const { return rowOffsets()[ row ] ; }
68  Index colOffset( Index col ) const { return colOffsets()[ col ] ; }
69 
71  ConstTransposeReturnType transpose() const { return derived().transpose() ; }
72 
74 
77  template < bool DoTranspose, typename RhsT, typename ResT >
78  void multiply( const RhsT& rhs, ResT& res, Scalar alpha = 1, Scalar beta = 0 ) const
79  {
80  derived().template multiply< DoTranspose >( rhs, res, alpha, beta ) ;
81  }
82 
83  // To use as block type
84  enum {
85  RowsAtCompileTime = internal::DYNAMIC,
86  ColsAtCompileTime = internal::DYNAMIC,
87  is_self_transpose = Traits::is_symmetric
88  } ;
89 };
90 
92 
93 template< typename Derived >
94 struct BlockMatrixTraits< BlockObjectBase< Derived > > {
95 
97  typedef BOGUS_DEFAULT_INDEX_TYPE Index ;
98 
102 
104 
105  enum {
106  is_symmetric = 0,
107  is_transposed = 0,
108  is_temporary = 0
109  } ;
110 
111  enum {
113  RowsPerBlock = internal::DYNAMIC,
115  ColsPerBlock = internal::DYNAMIC
116  };
117 
119  typedef Derived PlainObjectType ;
120 } ;
121 
122 }
123 
124 #endif // BLOCKMATRIX_HPP
Index blockRows(Index row) const
Returns the number of rows of a given block row.
Definition: BlockObjectBase.hpp:51
Index rowsOfBlocks() const
Returns the number of block rows of the matrix.
Definition: BlockObjectBase.hpp:56
Definition: Traits.hpp:19
ConstTransposeReturnType transpose() const
Return a const transposed view of this object.
Definition: BlockObjectBase.hpp:71
void multiply(const RhsT &rhs, ResT &res, Scalar alpha=1, Scalar beta=0) const
Performs a matrix vector multiplication.
Definition: BlockObjectBase.hpp:78
Index cols() const
Returns the total number of columns of the matrix ( expanding blocks )
Definition: BlockObjectBase.hpp:48
const Derived & derived() const
Returns a const reference to the implementation.
Definition: BlockObjectBase.hpp:25
Index colsOfBlocks() const
Returns the number of block columns of the matrix.
Definition: BlockObjectBase.hpp:58
const Index * colOffsets() const
Returns an array containing the first index of each column.
Definition: BlockObjectBase.hpp:63
Base class for Transpose views of a BlockObjectBase.
Definition: Expressions.hpp:22
Definition: Expressions.hpp:134
const Index * rowOffsets() const
Returns an array containing the first index of each row.
Definition: BlockObjectBase.hpp:61
Base class for anything block.
Definition: BlockObjectBase.hpp:22
Index rows() const
Returns the total number of rows of the matrix ( expanding blocks )
Definition: BlockObjectBase.hpp:46
int Index
Index type – for accessing elements, defining offsets, etc.
Definition: BlockObjectBase.hpp:97
TransposeObjectType ConstTransposeReturnType
Type returned by the transpose() method.
Definition: BlockObjectBase.hpp:103
Index rowOffset(Index row) const
Returns an array containing the first index of a given row.
Definition: BlockObjectBase.hpp:66
Transpose< Derived > TransposeObjectType
Type representing the transpose of this object.
Definition: BlockObjectBase.hpp:100
Derived & derived()
Returns a reference to the implementation.
Definition: BlockObjectBase.hpp:30
Derived PlainObjectType
Type in which the expression may be evaluated into.
Definition: BlockObjectBase.hpp:119
Index colOffset(Index col) const
Returns an array containing the first index of a given columns.
Definition: BlockObjectBase.hpp:68
Index blockCols(Index col) const
Returns the number of columns of a given block columns.
Definition: BlockObjectBase.hpp:53