So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
MappedSparseBlockMatrix.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_MAPPED_SPARSEBLOCKMATRIX_HPP
13 #define BOGUS_MAPPED_SPARSEBLOCKMATRIX_HPP
14 
15 #include "CompressedSparseBlockIndex.hpp"
16 #include "SparseBlockMatrixBase.hpp"
17 #include "../Utils/CppTools.hpp"
18 
19 namespace bogus
20 {
21 
23 template < typename BlockT, int Flags, typename Index_ >
24 struct BlockMatrixTraits< MappedSparseBlockMatrix< BlockT, Flags, Index_ > >
25  : public BlockMatrixTraits< BlockObjectBase< MappedSparseBlockMatrix< BlockT, Flags, Index_ > > >
26 {
28  typedef typename BaseTraits::Index Index;
29  typedef typename BlockTraits< BlockT >::Scalar Scalar ;
30 
31  enum {
32  is_symmetric = !!( Flags & flags::SYMMETRIC ),
35  } ;
36 
37  typedef BlockT BlockType ;
38  typedef BOGUS_DEFAULT_BLOCK_PTR_TYPE BlockPtr ;
40 
41  enum {
42  is_compressed = 1,
43  is_col_major = !!( Flags & flags::COL_MAJOR ),
44  flags = Flags & ~flags::UNCOMPRESSED
45  } ;
46 
48 
49 } ;
50 
52 
67 template < typename BlockT, int Flags, typename Index_ >
68 class MappedSparseBlockMatrix : public SparseBlockMatrixBase< MappedSparseBlockMatrix< BlockT, Flags, Index_ > >
69 {
70 public:
72  typedef typename Base::Index Index ;
73  typedef typename Base::BlockPtr BlockPtr ;
74 
76  {
77  }
78 
79  template < typename Derived >
81  {
82  mapTo( source ) ;
83  }
84 
85  void mapTo(
86  std::size_t numberOfNonZeros,
87  const BlockT* dataPtr,
88  const Index* outerIndexPtr,
89  const Index* innerIndexPtr
90  )
91  {
92  Base::clear() ;
93 
94  Base::m_blocks.setData( dataPtr, numberOfNonZeros ) ;
95  Base::m_majorIndex.inner.setData( innerIndexPtr, numberOfNonZeros ) ;
96  Base::m_majorIndex.outer.setData( outerIndexPtr, Base::m_minorIndex.innerSize() + 1 ) ;
97 
98  Base::m_minorIndex.valid = Base::empty() ;
99  Base::Finalizer::finalize( *this ) ;
100  }
101 
102  template < typename Derived >
103  void mapTo( const SparseBlockMatrixBase< Derived > &source )
104  {
105  BOGUS_STATIC_ASSERT( (int) Base::Traits::flags == (int) Derived::Traits::flags,
106  OPERANDS_HAVE_INCONSISTENT_FLAGS ) ;
107 
108  Base::cloneDimensions( source ) ;
109  mapTo( source.nBlocks(),
110  source.data(),
111  source.majorIndex().outerIndexPtr(),
112  source.majorIndex().innerIndexPtr()
113  );
114 
115  }
116 
117 } ;
118 
119 // Specialization for block matrix of MappedSparseBlockMatrix
120 template < typename BlockT, int Flags, typename Index_ >
121 struct BlockTraits< MappedSparseBlockMatrix< BlockT, Flags, Index_ > >
122 {
124  typedef typename BlockType::Scalar Scalar ;
126  < typename BlockType::TransposeBlockType, Flags ^ flags::COL_MAJOR, Index_ >
128 
129  enum {
130  RowsAtCompileTime = internal::DYNAMIC,
131  ColsAtCompileTime = internal::DYNAMIC,
132  uses_plain_array_storage = 0,
135  } ;
136 } ;
137 
138 }
139 
140 #endif // SPARSEBLOCKMATRIX_HH
std::size_t nBlocks() const
Returns the number of (non-zero) blocks of the matrix.
Definition: SparseBlockMatrixBase.hpp:240
Definition: Traits.hpp:19
Uncompressed sparse block index.
Definition: SparseBlockIndex.hpp:86
Base class for matrix-like objects that define a block structure, but not a block type...
Definition: IterableBlockObject.hpp:22
Definition: Traits.hpp:29
Mapped Sparse Block Matrix.
Definition: MappedSparseBlockMatrix.hpp:68
Store only half the matrix, or rather the triangular part for which inner &lt;= outer,.
Definition: Constants.hpp:64
Use an uncompressed index.
Definition: Constants.hpp:56
Store and index blocks in a column major way.
Definition: Constants.hpp:58
void mapTo(std::size_t numberOfNonZeros, const BlockT *dataPtr, const Index *outerIndexPtr, const Index *innerIndexPtr)
Definition: MappedSparseBlockMatrix.hpp:85
Const mapped array, used for Mapped Block Matrices.
Definition: CppTools.hpp:145
const BlockType * data() const
Access to blocks data as a raw pointer.
Definition: BlockMatrixBase.hpp:91
Base class for SparseBlockMatrix.
Definition: SparseBlockMatrixBase.hpp:36