So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
SparseBlockIndexComputer.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_SPARSE_BLOCK_INDEX_COMPUTER_HPP
13 #define BOGUS_SPARSE_BLOCK_INDEX_COMPUTER_HPP
14 
15 #include "CompoundSparseBlockIndex.hpp"
16 
17 namespace bogus
18 {
19 
20 // Index getter
21 
22 template < typename Derived, bool Major >
24 {
27 
28  static ReturnType& get( MatrixType& matrix )
29  {
30  return matrix.m_minorIndex ;
31  }
32 
33  static const ReturnType& get( const MatrixType& matrix )
34  {
35  return matrix.minorIndex() ;
36  }
37 
38  static const ReturnType&
39  getOrCompute( const MatrixType& matrix,
40  typename MatrixType::UncompressedIndexType& tempIndex
41  )
42  {
43  return matrix.getOrComputeMinorIndex( tempIndex ) ;
44  }
45 } ;
46 
47 template < typename Derived >
48 struct SparseBlockIndexGetter< Derived, true >
49 {
51  typedef typename MatrixType::MajorIndexType ReturnType ;
52 
53  static ReturnType& get( MatrixType& matrix )
54  {
55  return matrix.m_majorIndex ;
56  }
57  static const ReturnType& get( const MatrixType& matrix )
58  {
59  return matrix.majorIndex() ;
60  }
61 
62  static const ReturnType&
63  getOrCompute( const MatrixType& matrix,
65  {
66  return matrix.majorIndex() ;
67  }
68 } ;
69 
70 
71 // Index computer
72 
73 template < typename MatrixType, bool ColWise, bool Transpose,
76 {
78  enum { is_major = (ColWise != Transpose) == bool( Traits::is_col_major ) } ;
80  typedef typename Getter::ReturnType ReturnType ;
81 
83  : m_matrix( matrix.derived() )
84  {}
85 
86  const ReturnType& get( )
87  {
88  return Getter::getOrCompute( m_matrix, m_aux ) ;
89  }
90 
91 private:
92  const MatrixType& m_matrix ;
93  typename MatrixType::UncompressedIndexType m_aux ;
94 } ;
95 
96 template < typename MatrixType, bool ColWise, bool Transpose >
97 struct SparseBlockIndexComputer< MatrixType, ColWise, Transpose, true >
98 {
100  enum { is_major = (ColWise == bool( Traits::is_col_major )) } ;
101  typedef CompoundSparseBlockIndex<
102  typename MatrixType::MajorIndexType,
103  typename MatrixType::MinorIndexType,
104  bool( is_major ) >
105  ReturnType ;
106 
108  : m_index( matrix.majorIndex(), matrix.minorIndex() )
109  {
110  assert( matrix.minorIndex().valid ) ;
111  }
112 
113  const ReturnType& get( )
114  {
115  return m_index ;
116  }
117 
118 private:
119  ReturnType m_index ;
120 } ;
121 
122 
123 }
124 
125 #endif
Definition: Traits.hpp:19
Uncompressed sparse block index.
Definition: SparseBlockIndex.hpp:86
const Derived & derived() const
Returns a const reference to the implementation.
Definition: BlockObjectBase.hpp:25
Definition: SparseBlockIndexComputer.hpp:23
Base class for Transpose views of a BlockObjectBase.
Definition: Expressions.hpp:22
Definition: CompoundSparseBlockIndex.hpp:23
Definition: SparseBlockIndexComputer.hpp:75
Base class for SparseBlockMatrix.
Definition: SparseBlockMatrixBase.hpp:36