So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
IterableBlockObject.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2016 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_ITERABLE_BLOCK_OBJECT
13 #define BOGUS_ITERABLE_BLOCK_OBJECT
14 
15 #include "BlockObjectBase.hpp"
16 #include "../Utils/CppTools.hpp"
17 
18 namespace bogus {
19 
21 template < typename Derived >
22 class IterableBlockObject : public BlockObjectBase< Derived >
23 {
24 public:
26  typedef typename Traits::Index Index ;
27  typedef typename Traits::Scalar Scalar ;
28 
30  using Base::derived ;
31 
33  Index size() const
34  { return derived().size() ; }
35 
37  template < bool DoTranspose, typename RhsT, typename ResT >
38  void rowMultiply( const Index row, const RhsT& rhs, ResT& res ) const
39  {
40  rowMultiplyPrecompose< DoTranspose >( row, rhs, res, make_constant_array(1) ) ;
41  }
42  template < bool DoTranspose, typename RhsT, typename ResT, typename PreOp >
43  void rowMultiplyPrecompose( const Index row, const RhsT& rhs, ResT& res, const PreOp &op ) const
44  {
45  derived().template rowMultiplyPrecompose< DoTranspose >( row, rhs, res, op ) ;
46  }
47 
49  template < bool DoTranspose, typename RhsT, typename ResT >
50  void colMultiply( const Index col, const RhsT& rhs, ResT& res ) const
51  {
52  colMultiplyPostcompose< DoTranspose >( col, rhs, res, make_constant_array(1) ) ;
53  }
54  template < bool DoTranspose, typename RhsT, typename ResT, typename PostOp >
55  void colMultiplyPostcompose( const Index col, const RhsT& rhs, ResT& res, const PostOp &op ) const
56  {
57  derived().template colMultiplyPostcompose< DoTranspose >( col, rhs, res, op ) ;
58  }
59 
61  template <typename Func>
62  void eachBlockOfRow( const Index row, Func func ) const
63  { derived().template eachBlockOfRow<Func>(row, func) ; }
64 
66  template <typename Func>
67  void eachBlockOfCol( const Index col, Func func ) const
68  { derived().template eachBlockOfCol<Func>(col, func) ; }
69 
70 } ;
71 
72 
73 } //bogus
74 
75 #endif
void eachBlockOfRow(const Index row, Func func) const
Iterates over each block of a given row. Calls func( col, block )
Definition: IterableBlockObject.hpp:62
Definition: Traits.hpp:19
const Derived & derived() const
Returns a const reference to the implementation.
Definition: BlockObjectBase.hpp:25
Base class for matrix-like objects that define a block structure, but not a block type...
Definition: IterableBlockObject.hpp:22
void colMultiply(const Index col, const RhsT &rhs, ResT &res) const
Multiplication with a single column.
Definition: IterableBlockObject.hpp:50
void eachBlockOfCol(const Index col, Func func) const
Iterates over each block of a given col. Calls func( row, block )
Definition: IterableBlockObject.hpp:67
Base class for anything block.
Definition: BlockObjectBase.hpp:22
void rowMultiply(const Index row, const RhsT &rhs, ResT &res) const
Multiplication with a single row.
Definition: IterableBlockObject.hpp:38
Index size() const
Returns the total number of blocks of the matrix.
Definition: IterableBlockObject.hpp:33