Core/Block.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_BLOCK_H
12 #define EIGEN_BLOCK_H
13 
14 namespace Eigen {
15 
48 namespace internal {
49 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
50 struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
51 {
52  typedef typename traits<XprType>::Scalar Scalar;
57  enum{
60  RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
61  ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
62  MaxRowsAtCompileTime = BlockRows==0 ? 0
63  : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
64  : int(traits<XprType>::MaxRowsAtCompileTime),
65  MaxColsAtCompileTime = BlockCols==0 ? 0
66  : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
67  : int(traits<XprType>::MaxColsAtCompileTime),
68  XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
69  IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
70  : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
71  : XprTypeIsRowMajor,
72  HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
73  InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
74  InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
75  ? int(inner_stride_at_compile_time<XprType>::ret)
76  : int(outer_stride_at_compile_time<XprType>::ret),
77  OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
78  ? int(outer_stride_at_compile_time<XprType>::ret)
79  : int(inner_stride_at_compile_time<XprType>::ret),
80  MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
81  && (InnerStrideAtCompileTime == 1)
82  ? PacketAccessBit : 0,
83  MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0,
84  FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
85  FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
86  FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
87  Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
89  MaskPacketAccessBit |
90  MaskAlignedBit),
91  Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit
92  };
93 };
94 
95 template<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false,
97 
98 } // end namespace internal
99 
100 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, typename StorageKind> class BlockImpl;
101 
102 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class Block
103  : public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
104 {
106  public:
107  //typedef typename Impl::Base Base;
108  typedef Impl Base;
111 
114  inline Block(XprType& xpr, Index i) : Impl(xpr,i)
115  {
116  eigen_assert( (i>=0) && (
117  ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
118  ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
119  }
120 
123  inline Block(XprType& xpr, Index a_startRow, Index a_startCol)
124  : Impl(xpr, a_startRow, a_startCol)
125  {
126  EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
127  eigen_assert(a_startRow >= 0 && BlockRows >= 1 && a_startRow + BlockRows <= xpr.rows()
128  && a_startCol >= 0 && BlockCols >= 1 && a_startCol + BlockCols <= xpr.cols());
129  }
130 
133  inline Block(XprType& xpr,
134  Index a_startRow, Index a_startCol,
135  Index blockRows, Index blockCols)
136  : Impl(xpr, a_startRow, a_startCol, blockRows, blockCols)
137  {
138  eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
139  && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
140  eigen_assert(a_startRow >= 0 && blockRows >= 0 && a_startRow <= xpr.rows() - blockRows
141  && a_startCol >= 0 && blockCols >= 0 && a_startCol <= xpr.cols() - blockCols);
142  }
143 };
144 
145 // The generic default implementation for dense block simplu forward to the internal::BlockImpl_dense
146 // that must be specialized for direct and non-direct access...
147 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
148 class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
149  : public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
150 {
152  typedef typename XprType::Index Index;
153  public:
154  typedef Impl Base;
156  inline BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {}
157  inline BlockImpl(XprType& xpr, Index a_startRow, Index a_startCol) : Impl(xpr, a_startRow, a_startCol) {}
158  inline BlockImpl(XprType& xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
159  : Impl(xpr, a_startRow, a_startCol, blockRows, blockCols) {}
160 };
161 
162 namespace internal {
163 
165 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool HasDirectAccess> class BlockImpl_dense
166  : public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
167 {
169  public:
170 
174 
175  class InnerIterator;
176 
179  inline BlockImpl_dense(XprType& xpr, Index i)
180  : m_xpr(xpr),
181  // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
182  // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
183  // all other cases are invalid.
184  // The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
185  m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
186  m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
187  m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
188  m_blockCols(BlockCols==1 ? 1 : xpr.cols())
189  {}
190 
193  inline BlockImpl_dense(XprType& xpr, Index a_startRow, Index a_startCol)
194  : m_xpr(xpr), m_startRow(a_startRow), m_startCol(a_startCol),
195  m_blockRows(BlockRows), m_blockCols(BlockCols)
196  {}
197 
200  inline BlockImpl_dense(XprType& xpr,
201  Index a_startRow, Index a_startCol,
202  Index blockRows, Index blockCols)
203  : m_xpr(xpr), m_startRow(a_startRow), m_startCol(a_startCol),
204  m_blockRows(blockRows), m_blockCols(blockCols)
205  {}
206 
207  inline Index rows() const { return m_blockRows.value(); }
208  inline Index cols() const { return m_blockCols.value(); }
209 
210  inline Scalar& coeffRef(Index rowId, Index colId)
211  {
213  return m_xpr.const_cast_derived()
214  .coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
215  }
216 
217  inline const Scalar& coeffRef(Index rowId, Index colId) const
218  {
219  return m_xpr.derived()
220  .coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
221  }
222 
223  EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
224  {
225  return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
226  }
227 
228  inline Scalar& coeffRef(Index index)
229  {
231  return m_xpr.const_cast_derived()
232  .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
233  m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
234  }
235 
236  inline const Scalar& coeffRef(Index index) const
237  {
238  return m_xpr.const_cast_derived()
239  .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
240  m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
241  }
242 
243  inline const CoeffReturnType coeff(Index index) const
244  {
245  return m_xpr
246  .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
247  m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
248  }
249 
250  template<int LoadMode>
251  inline PacketScalar packet(Index rowId, Index colId) const
252  {
253  return m_xpr.template packet<Unaligned>
254  (rowId + m_startRow.value(), colId + m_startCol.value());
255  }
256 
257  template<int LoadMode>
258  inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
259  {
260  m_xpr.const_cast_derived().template writePacket<Unaligned>
261  (rowId + m_startRow.value(), colId + m_startCol.value(), val);
262  }
263 
264  template<int LoadMode>
265  inline PacketScalar packet(Index index) const
266  {
267  return m_xpr.template packet<Unaligned>
268  (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
269  m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
270  }
271 
272  template<int LoadMode>
273  inline void writePacket(Index index, const PacketScalar& val)
274  {
275  m_xpr.const_cast_derived().template writePacket<Unaligned>
276  (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
277  m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
278  }
279 
280  #ifdef EIGEN_PARSED_BY_DOXYGEN
281 
282  inline const Scalar* data() const;
283  inline Index innerStride() const;
284  inline Index outerStride() const;
285  #endif
286 
288  {
289  return m_xpr;
290  }
291 
292  Index startRow() const
293  {
294  return m_startRow.value();
295  }
296 
297  Index startCol() const
298  {
299  return m_startCol.value();
300  }
301 
302  protected:
303 
304  const typename XprType::Nested m_xpr;
309 };
310 
312 template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
313 class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
314  : public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
315 {
317  public:
318 
322 
325  inline BlockImpl_dense(XprType& xpr, Index i)
326  : Base(internal::const_cast_ptr(&xpr.coeffRef(
327  (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
328  (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)),
329  BlockRows==1 ? 1 : xpr.rows(),
330  BlockCols==1 ? 1 : xpr.cols()),
331  m_xpr(xpr)
332  {
333  init();
334  }
335 
338  inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
339  : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol))), m_xpr(xpr)
340  {
341  init();
342  }
343 
346  inline BlockImpl_dense(XprType& xpr,
347  Index startRow, Index startCol,
348  Index blockRows, Index blockCols)
349  : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol)), blockRows, blockCols),
350  m_xpr(xpr)
351  {
352  init();
353  }
354 
356  {
357  return m_xpr;
358  }
359 
361  inline Index innerStride() const
362  {
364  ? m_xpr.innerStride()
365  : m_xpr.outerStride();
366  }
367 
369  inline Index outerStride() const
370  {
371  return m_outerStride;
372  }
373 
374  #ifndef __SUNPRO_CC
375  // FIXME sunstudio is not friendly with the above friend...
376  // META-FIXME there is no 'friend' keyword around here. Is this obsolete?
377  protected:
378  #endif
379 
380  #ifndef EIGEN_PARSED_BY_DOXYGEN
381 
382  inline BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, Index blockCols)
383  : Base(data, blockRows, blockCols), m_xpr(xpr)
384  {
385  init();
386  }
387  #endif
388 
389  protected:
390  void init()
391  {
393  ? m_xpr.outerStride()
394  : m_xpr.innerStride();
395  }
396 
397  typename XprType::Nested m_xpr;
399 };
400 
401 } // end namespace internal
402 
403 } // end namespace Eigen
404 
405 #endif // EIGEN_BLOCK_H
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_blockRows
Definition: Core/Block.h:307
Base class for Map and Block expression with direct access.
internal::BlockImpl_dense< XprType, BlockRows, BlockCols, InnerPanel > Impl
Definition: Core/Block.h:151
#define EIGEN_STRONG_INLINE
const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: Core/Block.h:287
BlockImpl_dense(XprType &xpr, Index a_startRow, Index a_startCol)
Definition: Core/Block.h:193
Scalar & coeffRef(Index rowId, Index colId)
Definition: Core/Block.h:210
T * const_cast_ptr(const T *ptr)
Definition: XprHelper.h:344
const unsigned int DirectAccessBit
Definition: Constants.h:142
const unsigned int LvalueBit
Definition: Constants.h:131
Definition: LDLT.h:16
const CoeffReturnType coeff(Index index) const
Definition: Core/Block.h:243
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_blockCols
Definition: Core/Block.h:308
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
const unsigned int RowMajorBit
Definition: Constants.h:53
const unsigned int PacketAccessBit
Definition: Constants.h:81
BlockImpl_dense(XprType &xpr, const Scalar *data, Index blockRows, Index blockCols)
Definition: Core/Block.h:382
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
Definition: StaticAssert.h:191
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
void writePacket(Index rowId, Index colId, const PacketScalar &val)
Definition: Core/Block.h:258
Scalar & coeffRef(Index index)
Definition: Core/Block.h:228
BlockImpl(XprType &xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
Definition: Core/Block.h:158
EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
Definition: Core/Block.h:223
const unsigned int AlignedBit
Definition: Constants.h:147
const Scalar & coeffRef(Index index) const
Definition: Core/Block.h:236
const internal::variable_if_dynamic< Index, XprType::ColsAtCompileTime==1?0:Dynamic > m_startCol
Definition: Core/Block.h:306
const unsigned int HereditaryBits
Definition: Constants.h:152
const Scalar & coeffRef(Index rowId, Index colId) const
Definition: Core/Block.h:217
void writePacket(Index index, const PacketScalar &val)
Definition: Core/Block.h:273
BlockImpl_dense(XprType &xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
Definition: Core/Block.h:200
const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: Core/Block.h:355
Block< XprType, BlockRows, BlockCols, InnerPanel > BlockType
Definition: Core/Block.h:168
PacketScalar packet(Index index) const
Definition: Core/Block.h:265
const internal::variable_if_dynamic< Index, XprType::RowsAtCompileTime==1?0:Dynamic > m_startRow
Definition: Core/Block.h:305
Block(XprType &xpr, Index a_startRow, Index a_startCol)
Definition: Core/Block.h:123
internal::dense_xpr_base< BlockType >::type Base
Definition: Core/Block.h:171
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
An InnerIterator allows to loop over the element of a sparse (or dense) matrix or expression...
Expression of a fixed-size or dynamic-size block.
Definition: Core/Block.h:102
BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
Definition: Core/Block.h:105
BlockImpl_dense(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
Definition: Core/Block.h:346
const int Dynamic
Definition: Constants.h:21
PacketScalar packet(Index rowId, Index colId) const
Definition: Core/Block.h:251
#define eigen_assert(x)
Block(XprType &xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
Definition: Core/Block.h:133
const unsigned int LinearAccessBit
Definition: Constants.h:117
BlockImpl(XprType &xpr, Index a_startRow, Index a_startCol)
Definition: Core/Block.h:157
const XprType::Nested m_xpr
Definition: Core/Block.h:304


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:46