1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library
2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra.
3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla
8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed
9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#ifndef EIGEN_BLOCK_H
12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#define EIGEN_BLOCK_H
13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace Eigen {
15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/** \class Block
17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \ingroup Core_Module
18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \brief Expression of a fixed-size or dynamic-size block
20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
21c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \param XprType the type of the expression in which we are taking a block
22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \param BlockRows the number of rows of the block we are taking at compile time (optional)
23c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \param BlockCols the number of columns of the block we are taking at compile time (optional)
24c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
25c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * This class represents an expression of either a fixed-size or dynamic-size block. It is the return
26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block<int,int>(Index,Index) and
27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * most of the time this is the only way it is used.
28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * However, if you want to directly maniputate block expressions,
30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * for instance if you want to write a function returning such an expression, you
31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * will need to use this class.
32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * Here is an example illustrating the dynamic case:
34c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \include class_Block.cpp
35c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * Output: \verbinclude class_Block.out
36c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \note Even though this expression has dynamic size, in the case where \a XprType
38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * has fixed size, this expression inherits a fixed maximal size which means that evaluating
39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * it does not cause a dynamic memory allocation.
40c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * Here is an example illustrating the fixed-size case:
42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \include class_FixedBlock.cpp
43c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * Output: \verbinclude class_FixedBlock.out
44c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock
46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace internal {
497faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
507faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezstruct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename traits<XprType>::Scalar Scalar;
53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename traits<XprType>::StorageKind StorageKind;
54c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename traits<XprType>::XprKind XprKind;
55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename nested<XprType>::type XprTypeNested;
56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
57c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  enum{
58c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MatrixRows = traits<XprType>::RowsAtCompileTime,
59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MatrixCols = traits<XprType>::ColsAtCompileTime,
60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MaxRowsAtCompileTime = BlockRows==0 ? 0
63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                         : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                         : int(traits<XprType>::MaxRowsAtCompileTime),
65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MaxColsAtCompileTime = BlockCols==0 ? 0
66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                         : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                         : int(traits<XprType>::MaxColsAtCompileTime),
68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath               : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath               : XprTypeIsRowMajor,
72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                             ? int(inner_stride_at_compile_time<XprType>::ret)
76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                             : int(outer_stride_at_compile_time<XprType>::ret),
77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                             ? int(outer_stride_at_compile_time<XprType>::ret)
79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                             : int(inner_stride_at_compile_time<XprType>::ret),
80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                       && (InnerStrideAtCompileTime == 1)
82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                        ? PacketAccessBit : 0,
83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ? AlignedBit : 0,
847faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (traits<XprType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                                        DirectAccessBit |
89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                                        MaskPacketAccessBit |
90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                                        MaskAlignedBit),
91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit
92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  };
93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
957faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows=Dynamic, int BlockCols=Dynamic, bool InnerPanel = false,
967faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez         bool HasDirectAccess = internal::has_direct_access<XprType>::ret> class BlockImpl_dense;
977faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
987faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} // end namespace internal
99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
1007faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, typename StorageKind> class BlockImpl;
101c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
1027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel> class Block
1037faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  : public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
1047faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{
1057faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl;
1067faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  public:
1077faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    //typedef typename Impl::Base Base;
1087faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef Impl Base;
1097faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_GENERIC_PUBLIC_INTERFACE(Block)
1107faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
1117faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
112c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Column or Row constructor
113c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
1147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline Block(XprType& xpr, Index i) : Impl(xpr,i)
115c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
116c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      eigen_assert( (i>=0) && (
117c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
118c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
119c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
120c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
121c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Fixed-size constructor
122c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
1237faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline Block(XprType& xpr, Index a_startRow, Index a_startCol)
1247faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : Impl(xpr, a_startRow, a_startCol)
125c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
126c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
1277faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      eigen_assert(a_startRow >= 0 && BlockRows >= 1 && a_startRow + BlockRows <= xpr.rows()
1287faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez             && a_startCol >= 0 && BlockCols >= 1 && a_startCol + BlockCols <= xpr.cols());
129c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
130c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
131c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Dynamic-size constructor
132c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
133c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Block(XprType& xpr,
1347faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez          Index a_startRow, Index a_startCol,
135c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          Index blockRows, Index blockCols)
1367faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : Impl(xpr, a_startRow, a_startCol, blockRows, blockCols)
137c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
138c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
139c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
1407faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      eigen_assert(a_startRow >= 0 && blockRows >= 0 && a_startRow  <= xpr.rows() - blockRows
1417faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez          && a_startCol >= 0 && blockCols >= 0 && a_startCol <= xpr.cols() - blockCols);
142c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
1437faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez};
1447faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1457faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// The generic default implementation for dense block simplu forward to the internal::BlockImpl_dense
1467faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez// that must be specialized for direct and non-direct access...
1477faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
1487faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezclass BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
1497faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  : public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
1507faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{
1517faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl;
1527faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef typename XprType::Index Index;
1537faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  public:
1547faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef Impl Base;
1557faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
1567faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {}
1577faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl(XprType& xpr, Index a_startRow, Index a_startCol) : Impl(xpr, a_startRow, a_startCol) {}
1587faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl(XprType& xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
1597faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : Impl(xpr, a_startRow, a_startCol, blockRows, blockCols) {}
1607faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez};
161c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
1627faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeznamespace internal {
1637faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1647faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \internal Internal implementation of dense Blocks in the general case. */
1657faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeztemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel, bool HasDirectAccess> class BlockImpl_dense
1667faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  : public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
1677faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez{
1687faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
1697faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  public:
1707faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1717faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef typename internal::dense_xpr_base<BlockType>::type Base;
1727faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
1737faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
1747faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1757faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    class InnerIterator;
1767faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1777faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    /** Column or Row constructor
1787faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      */
1797faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr, Index i)
1807faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : m_xpr(xpr),
1817faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
1827faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
1837faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        // all other cases are invalid.
1847faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        // The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
1857faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
1867faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
1877faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
1887faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez        m_blockCols(BlockCols==1 ? 1 : xpr.cols())
1897faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    {}
1907faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1917faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    /** Fixed-size constructor
1927faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      */
1937faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr, Index a_startRow, Index a_startCol)
1947faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : m_xpr(xpr), m_startRow(a_startRow), m_startCol(a_startCol),
1957faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez                    m_blockRows(BlockRows), m_blockCols(BlockCols)
1967faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    {}
1977faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
1987faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    /** Dynamic-size constructor
1997faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      */
2007faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr,
2017faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez          Index a_startRow, Index a_startCol,
2027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez          Index blockRows, Index blockCols)
2037faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      : m_xpr(xpr), m_startRow(a_startRow), m_startCol(a_startCol),
2047faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez                    m_blockRows(blockRows), m_blockCols(blockCols)
2057faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    {}
206c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
207c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index rows() const { return m_blockRows.value(); }
208c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index cols() const { return m_blockCols.value(); }
209c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
2107faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline Scalar& coeffRef(Index rowId, Index colId)
211c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
212c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      EIGEN_STATIC_ASSERT_LVALUE(XprType)
213c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.const_cast_derived()
2147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez               .coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
215c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
216c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
2177faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline const Scalar& coeffRef(Index rowId, Index colId) const
218c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
219c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.derived()
2207faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez               .coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
221c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
222c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
2237faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const
224c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
2257faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
226c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
227c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
228c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Scalar& coeffRef(Index index)
229c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
230c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      EIGEN_STATIC_ASSERT_LVALUE(XprType)
231c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.const_cast_derived()
232c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
233c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                       m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
234c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
235c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
236c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const Scalar& coeffRef(Index index) const
237c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
238c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.const_cast_derived()
239c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
240c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                       m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
241c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
242c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
243c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const CoeffReturnType coeff(Index index) const
244c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
245c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr
246c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
247c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                    m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
248c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
249c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
250c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<int LoadMode>
2517faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline PacketScalar packet(Index rowId, Index colId) const
252c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
253c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.template packet<Unaligned>
2547faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez              (rowId + m_startRow.value(), colId + m_startCol.value());
255c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
256c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
257c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<int LoadMode>
2587faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
259c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
260c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_xpr.const_cast_derived().template writePacket<Unaligned>
2617faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez              (rowId + m_startRow.value(), colId + m_startCol.value(), val);
262c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
263c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
264c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<int LoadMode>
265c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline PacketScalar packet(Index index) const
266c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
267c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr.template packet<Unaligned>
268c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath              (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
269c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath               m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
270c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
271c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
272c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    template<int LoadMode>
2737faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline void writePacket(Index index, const PacketScalar& val)
274c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
275c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      m_xpr.const_cast_derived().template writePacket<Unaligned>
276c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath         (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
2777faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez          m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
278c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
279c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
280c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    #ifdef EIGEN_PARSED_BY_DOXYGEN
281c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** \sa MapBase::data() */
282c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline const Scalar* data() const;
283c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index innerStride() const;
284c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index outerStride() const;
285c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    #endif
286c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
287c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression() const
288c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
289c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr;
290c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
291c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
292c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Index startRow() const
293c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
294c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_startRow.value();
295c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
296c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
297c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Index startCol() const
298c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
299c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_startCol.value();
300c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
301c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
302c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  protected:
303c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
304c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const typename XprType::Nested m_xpr;
305c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const internal::variable_if_dynamic<Index, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
306c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const internal::variable_if_dynamic<Index, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
307c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_blockRows;
308c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_blockCols;
309c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
310c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
3117faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \internal Internal implementation of dense Blocks in the direct access case.*/
312c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
3137faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandezclass BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
3147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  : public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
315c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
3167faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
317c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  public:
318c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
3197faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    typedef MapBase<BlockType> Base;
3207faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
3217faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
322c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
323c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Column or Row constructor
324c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
3257faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr, Index i)
326c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : Base(internal::const_cast_ptr(&xpr.coeffRef(
327c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath              (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
328c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath              (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)),
329c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             BlockRows==1 ? 1 : xpr.rows(),
330c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             BlockCols==1 ? 1 : xpr.cols()),
331c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        m_xpr(xpr)
332c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
333c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      init();
334c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
335c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
336c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Fixed-size constructor
337c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
3387faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
339c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol))), m_xpr(xpr)
340c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
341c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      init();
342c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
343c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
344c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** Dynamic-size constructor
345c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      */
3467faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr,
347c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          Index startRow, Index startCol,
348c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          Index blockRows, Index blockCols)
349c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol)), blockRows, blockCols),
350c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        m_xpr(xpr)
351c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
352c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      init();
353c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
354c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
355c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression() const
356c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
357c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_xpr;
358c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
359c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
360c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** \sa MapBase::innerStride() */
361c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index innerStride() const
362c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
3637faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      return internal::traits<BlockType>::HasSameStorageOrderAsXprType
364c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             ? m_xpr.innerStride()
365c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath             : m_xpr.outerStride();
366c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
367c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
368c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** \sa MapBase::outerStride() */
369c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    inline Index outerStride() const
370c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
371c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      return m_outerStride;
372c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
373c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
374c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  #ifndef __SUNPRO_CC
375c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  // FIXME sunstudio is not friendly with the above friend...
376c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  // META-FIXME there is no 'friend' keyword around here. Is this obsolete?
377c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  protected:
378c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  #endif
379c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
380c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    #ifndef EIGEN_PARSED_BY_DOXYGEN
381c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    /** \internal used by allowAligned() */
3827faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez    inline BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, Index blockCols)
383c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      : Base(data, blockRows, blockCols), m_xpr(xpr)
384c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
385c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      init();
386c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
387c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    #endif
388c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
389c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  protected:
390c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    void init()
391c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
3927faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez      m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
393c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                    ? m_xpr.outerStride()
394c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                    : m_xpr.innerStride();
395c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
396c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
397c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    typename XprType::Nested m_xpr;
398c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Index m_outerStride;
399c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
400c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
4017faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} // end namespace internal
4027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez
403c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} // end namespace Eigen
404c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
405c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#endif // EIGEN_BLOCK_H
406