2007-12-05 08:57:23 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2007-12-05 08:57:23 +00:00
|
|
|
//
|
2008-03-03 10:52:44 +00:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
2010-02-26 09:03:13 -05:00
|
|
|
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2007-12-05 08:57:23 +00:00
|
|
|
//
|
2008-02-28 15:44:45 +00:00
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
2008-03-04 12:34:58 +00:00
|
|
|
// License as published by the Free Software Foundation; either
|
2008-02-28 15:44:45 +00:00
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2008-03-04 12:34:58 +00:00
|
|
|
// published by the Free Software Foundation; either version 2 of
|
2008-02-28 15:44:45 +00:00
|
|
|
// the License, or (at your option) any later version.
|
2007-12-05 08:57:23 +00:00
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 15:44:45 +00:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
2007-12-05 08:57:23 +00:00
|
|
|
//
|
2008-03-03 11:02:52 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
2008-02-28 15:44:45 +00:00
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
2007-12-05 08:57:23 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_BLOCK_H
|
|
|
|
|
#define EIGEN_BLOCK_H
|
|
|
|
|
|
2007-12-24 11:14:25 +00:00
|
|
|
/** \class Block
|
|
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* \brief Expression of a fixed-size or dynamic-size block
|
2007-12-24 11:14:25 +00:00
|
|
|
*
|
2010-04-18 22:14:55 -04:00
|
|
|
* \param XprType the type of the expression in which we are taking a block
|
2008-02-29 13:56:40 +00:00
|
|
|
* \param BlockRows the number of rows of the block we are taking at compile time (optional)
|
|
|
|
|
* \param BlockCols the number of columns of the block we are taking at compile time (optional)
|
2008-08-09 18:41:24 +00:00
|
|
|
* \param _DirectAccessStatus \internal used for partial specialization
|
2007-12-24 11:14:25 +00:00
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* This class represents an expression of either a fixed-size or dynamic-size block. It is the return
|
2009-12-04 23:17:14 +01:00
|
|
|
* type of DenseBase::block(int,int,int,int) and DenseBase::block<int,int>(int,int) and
|
2008-02-29 13:56:40 +00:00
|
|
|
* most of the time this is the only way it is used.
|
2007-12-24 11:14:25 +00:00
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* However, if you want to directly maniputate block expressions,
|
2007-12-24 11:14:25 +00:00
|
|
|
* for instance if you want to write a function returning such an expression, you
|
|
|
|
|
* will need to use this class.
|
|
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* Here is an example illustrating the dynamic case:
|
2007-12-24 11:14:25 +00:00
|
|
|
* \include class_Block.cpp
|
|
|
|
|
* Output: \verbinclude class_Block.out
|
|
|
|
|
*
|
2010-04-18 22:14:55 -04:00
|
|
|
* \note Even though this expression has dynamic size, in the case where \a XprType
|
2008-01-13 22:48:57 +00:00
|
|
|
* has fixed size, this expression inherits a fixed maximal size which means that evaluating
|
|
|
|
|
* it does not cause a dynamic memory allocation.
|
|
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* Here is an example illustrating the fixed-size case:
|
|
|
|
|
* \include class_FixedBlock.cpp
|
|
|
|
|
* Output: \verbinclude class_FixedBlock.out
|
|
|
|
|
*
|
2009-12-04 23:17:14 +01:00
|
|
|
* \sa DenseBase::block(int,int,int,int), DenseBase::block(int,int), class VectorBlock
|
2007-12-24 11:14:25 +00:00
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename XprType, int BlockRows, int BlockCols, int _DirectAccessStatus>
|
|
|
|
|
struct ei_traits<Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> > : ei_traits<XprType>
|
2008-03-12 17:17:36 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
typedef typename ei_traits<XprType>::Scalar Scalar;
|
|
|
|
|
typedef typename ei_traits<XprType>::StorageKind StorageKind;
|
|
|
|
|
typedef typename ei_traits<XprType>::XprKind XprKind;
|
|
|
|
|
typedef typename ei_nested<XprType>::type XprTypeNested;
|
|
|
|
|
typedef typename ei_unref<XprTypeNested>::type _XprTypeNested;
|
2008-03-12 17:17:36 +00:00
|
|
|
enum{
|
2010-04-18 22:14:55 -04:00
|
|
|
MatrixRows = ei_traits<XprType>::RowsAtCompileTime,
|
|
|
|
|
MatrixCols = ei_traits<XprType>::ColsAtCompileTime,
|
2010-04-16 10:13:32 -04:00
|
|
|
RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
|
|
|
|
|
ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
|
|
|
|
|
MaxRowsAtCompileTime = BlockRows==0 ? 0
|
|
|
|
|
: RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
|
2010-04-18 22:14:55 -04:00
|
|
|
: int(ei_traits<XprType>::MaxRowsAtCompileTime),
|
2010-04-16 10:13:32 -04:00
|
|
|
MaxColsAtCompileTime = BlockCols==0 ? 0
|
|
|
|
|
: ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
|
2010-04-18 22:14:55 -04:00
|
|
|
: int(ei_traits<XprType>::MaxColsAtCompileTime),
|
|
|
|
|
XprTypeIsRowMajor = (int(ei_traits<XprType>::Flags)&RowMajorBit) != 0,
|
2010-04-16 10:13:32 -04:00
|
|
|
IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
|
|
|
|
|
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
|
2010-04-18 22:14:55 -04:00
|
|
|
: XprTypeIsRowMajor,
|
|
|
|
|
HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
|
|
|
|
|
InnerSize = XprTypeIsRowMajor // notice how it's XprTypeIsRowMajor here, not IsRowMajor. Inner size is computed wrt the host matrix's storage order.
|
2010-04-16 10:13:32 -04:00
|
|
|
? int(ColsAtCompileTime) : int(RowsAtCompileTime),
|
2010-04-18 22:14:55 -04:00
|
|
|
InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
|
|
|
|
|
? int(ei_inner_stride_at_compile_time<XprType>::ret)
|
|
|
|
|
: int(ei_outer_stride_at_compile_time<XprType>::ret),
|
|
|
|
|
OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
|
|
|
|
|
? int(ei_outer_stride_at_compile_time<XprType>::ret)
|
|
|
|
|
: int(ei_inner_stride_at_compile_time<XprType>::ret),
|
2010-03-09 00:16:07 -05:00
|
|
|
MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % ei_packet_traits<Scalar>::size) == 0)
|
2010-04-16 10:13:32 -04:00
|
|
|
&& (InnerStrideAtCompileTime == 1)
|
2008-06-26 16:06:41 +00:00
|
|
|
? PacketAccessBit : 0,
|
|
|
|
|
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
2010-04-18 22:14:55 -04:00
|
|
|
Flags0 = ei_traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit),
|
2010-03-09 00:16:07 -05:00
|
|
|
Flags1 = Flags0 | FlagsLinearAccessBit,
|
|
|
|
|
Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0)
|
2008-03-12 17:17:36 +00:00
|
|
|
};
|
|
|
|
|
};
|
2008-03-10 17:23:11 +00:00
|
|
|
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename XprType, int BlockRows, int BlockCols, int _DirectAccessStatus> class Block
|
|
|
|
|
: public ei_dense_xpr_base<Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> >::type
|
2007-12-05 08:57:23 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2010-04-18 22:14:55 -04:00
|
|
|
typedef typename XprType::template MakeBase< Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> >::Type Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Block)
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2008-09-02 15:28:49 +00:00
|
|
|
class InnerIterator;
|
|
|
|
|
|
2008-03-12 18:10:52 +00:00
|
|
|
/** Column or Row constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr, int i)
|
|
|
|
|
: m_xpr(xpr),
|
|
|
|
|
// It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
|
|
|
|
|
// and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
|
2008-03-12 18:10:52 +00:00
|
|
|
// all other cases are invalid.
|
2008-06-02 02:06:33 +00:00
|
|
|
// The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
|
2010-04-18 22:14:55 -04:00
|
|
|
m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
|
|
|
|
|
m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
|
|
|
|
m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
|
|
|
|
|
m_blockCols(BlockCols==1 ? 1 : xpr.cols())
|
2008-03-12 18:10:52 +00:00
|
|
|
{
|
2008-03-26 08:48:04 +00:00
|
|
|
ei_assert( (i>=0) && (
|
2010-04-18 22:14:55 -04:00
|
|
|
((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
|
|
|
|
|
||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
|
2008-03-12 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
2008-02-29 13:56:40 +00:00
|
|
|
/** Fixed-size constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr, int startRow, int startCol)
|
|
|
|
|
: m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
|
2010-02-25 21:01:52 -05:00
|
|
|
m_blockRows(BlockRows), m_blockCols(BlockCols)
|
2008-02-29 13:56:40 +00:00
|
|
|
{
|
2009-03-31 16:07:12 +00:00
|
|
|
EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
|
2010-04-18 22:14:55 -04:00
|
|
|
ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
|
|
|
|
|
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
|
2008-02-29 13:56:40 +00:00
|
|
|
}
|
2008-03-03 11:02:52 +00:00
|
|
|
|
2008-02-29 13:56:40 +00:00
|
|
|
/** Dynamic-size constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr,
|
2008-01-13 20:19:14 +00:00
|
|
|
int startRow, int startCol,
|
|
|
|
|
int blockRows, int blockCols)
|
2010-04-18 22:14:55 -04:00
|
|
|
: m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
|
2008-01-13 20:19:14 +00:00
|
|
|
m_blockRows(blockRows), m_blockCols(blockCols)
|
2007-12-05 08:57:23 +00:00
|
|
|
{
|
2008-06-02 02:06:33 +00:00
|
|
|
ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
|
|
|
|
|
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
|
2010-04-18 22:14:55 -04:00
|
|
|
ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
|
|
|
|
|
&& startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
|
2007-12-05 08:57:23 +00:00
|
|
|
}
|
2008-03-03 11:02:52 +00:00
|
|
|
|
2007-12-05 08:57:23 +00:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
|
2008-03-03 11:02:52 +00:00
|
|
|
|
2008-06-26 20:08:16 +00:00
|
|
|
inline int rows() const { return m_blockRows.value(); }
|
|
|
|
|
inline int cols() const { return m_blockCols.value(); }
|
2008-01-06 13:17:07 +00:00
|
|
|
|
2008-06-26 20:08:16 +00:00
|
|
|
inline Scalar& coeffRef(int row, int col)
|
2007-12-05 08:57:23 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr.const_cast_derived()
|
2008-03-13 20:36:01 +00:00
|
|
|
.coeffRef(row + m_startRow.value(), col + m_startCol.value());
|
2007-12-05 08:57:23 +00:00
|
|
|
}
|
2008-03-03 11:02:52 +00:00
|
|
|
|
2009-04-01 14:07:38 +00:00
|
|
|
inline const CoeffReturnType coeff(int row, int col) const
|
2007-12-05 08:57:23 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr.coeff(row + m_startRow.value(), col + m_startCol.value());
|
2007-12-05 08:57:23 +00:00
|
|
|
}
|
2008-03-03 11:02:52 +00:00
|
|
|
|
2008-06-26 20:08:16 +00:00
|
|
|
inline Scalar& coeffRef(int index)
|
2008-06-26 16:06:41 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr.const_cast_derived()
|
2008-06-26 16:06:41 +00:00
|
|
|
.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-01 14:07:38 +00:00
|
|
|
inline const CoeffReturnType coeff(int index) const
|
2008-06-26 16:06:41 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr
|
2008-06-26 16:06:41 +00:00
|
|
|
.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-05 10:23:29 +00:00
|
|
|
template<int LoadMode>
|
2008-06-26 20:08:16 +00:00
|
|
|
inline PacketScalar packet(int row, int col) const
|
2008-05-05 10:23:29 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr.template packet<Unaligned>
|
2008-07-09 22:30:18 +00:00
|
|
|
(row + m_startRow.value(), col + m_startCol.value());
|
2008-05-05 10:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2008-06-26 20:08:16 +00:00
|
|
|
inline void writePacket(int row, int col, const PacketScalar& x)
|
2008-05-05 10:23:29 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
m_xpr.const_cast_derived().template writePacket<Unaligned>
|
2008-07-09 22:30:18 +00:00
|
|
|
(row + m_startRow.value(), col + m_startCol.value(), x);
|
2008-05-05 10:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-26 16:06:41 +00:00
|
|
|
template<int LoadMode>
|
2008-06-26 20:08:16 +00:00
|
|
|
inline PacketScalar packet(int index) const
|
2008-06-26 16:06:41 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return m_xpr.template packet<Unaligned>
|
2008-07-09 22:30:18 +00:00
|
|
|
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
|
2008-06-26 16:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2008-06-26 20:08:16 +00:00
|
|
|
inline void writePacket(int index, const PacketScalar& x)
|
2008-06-26 16:06:41 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
m_xpr.const_cast_derived().template writePacket<Unaligned>
|
2008-06-26 16:06:41 +00:00
|
|
|
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
|
|
|
|
|
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), x);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-31 17:07:54 +02:00
|
|
|
#ifdef EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
/** \sa MapBase::data() */
|
|
|
|
|
inline const Scalar* data() const;
|
2010-02-18 20:42:38 -05:00
|
|
|
inline int innerStride() const;
|
|
|
|
|
inline int outerStride() const;
|
2009-08-31 17:07:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
2007-12-05 08:57:23 +00:00
|
|
|
protected:
|
2008-02-29 13:56:40 +00:00
|
|
|
|
2010-04-18 22:14:55 -04:00
|
|
|
const typename XprType::Nested m_xpr;
|
|
|
|
|
const ei_int_if_dynamic<XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
|
|
|
|
|
const ei_int_if_dynamic<XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
|
2008-06-27 01:22:35 +00:00
|
|
|
const ei_int_if_dynamic<RowsAtCompileTime> m_blockRows;
|
|
|
|
|
const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols;
|
2007-12-05 08:57:23 +00:00
|
|
|
};
|
|
|
|
|
|
2008-07-12 22:59:34 +00:00
|
|
|
/** \internal */
|
2010-04-18 22:14:55 -04:00
|
|
|
template<typename XprType, int BlockRows, int BlockCols>
|
|
|
|
|
class Block<XprType,BlockRows,BlockCols,HasDirectAccess>
|
|
|
|
|
: public MapBase<Block<XprType, BlockRows, BlockCols,HasDirectAccess> >
|
2008-07-12 22:59:34 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2010-04-16 10:13:32 -04:00
|
|
|
typedef MapBase<Block> Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Block)
|
2008-08-09 18:41:24 +00:00
|
|
|
|
|
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
|
|
|
|
|
|
2008-07-12 22:59:34 +00:00
|
|
|
/** Column or Row constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr, int i)
|
|
|
|
|
: Base(&xpr.const_cast_derived().coeffRef(
|
|
|
|
|
(BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
|
|
|
|
|
(BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
|
|
|
|
BlockRows==1 ? 1 : xpr.rows(),
|
|
|
|
|
BlockCols==1 ? 1 : xpr.cols()),
|
|
|
|
|
m_xpr(xpr)
|
2008-07-12 22:59:34 +00:00
|
|
|
{
|
|
|
|
|
ei_assert( (i>=0) && (
|
2010-04-18 22:14:55 -04:00
|
|
|
((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
|
|
|
|
|
||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
|
2008-07-12 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Fixed-size constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr, int startRow, int startCol)
|
|
|
|
|
: Base(&xpr.const_cast_derived().coeffRef(startRow,startCol)), m_xpr(xpr)
|
2008-07-12 22:59:34 +00:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
|
|
|
|
|
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
|
2008-07-12 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Dynamic-size constructor
|
|
|
|
|
*/
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr,
|
2008-07-12 22:59:34 +00:00
|
|
|
int startRow, int startCol,
|
|
|
|
|
int blockRows, int blockCols)
|
2010-04-18 22:14:55 -04:00
|
|
|
: Base(&xpr.const_cast_derived().coeffRef(startRow,startCol), blockRows, blockCols),
|
|
|
|
|
m_xpr(xpr)
|
2008-07-12 22:59:34 +00:00
|
|
|
{
|
|
|
|
|
ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
|
2008-08-09 18:41:24 +00:00
|
|
|
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
|
2010-04-18 22:14:55 -04:00
|
|
|
ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
|
|
|
|
|
&& startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
|
2008-07-12 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
/** \sa MapBase::innerStride() */
|
|
|
|
|
inline int innerStride() const
|
|
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return ei_traits<Block>::HasSameStorageOrderAsXprType
|
|
|
|
|
? m_xpr.innerStride()
|
|
|
|
|
: m_xpr.outerStride();
|
2010-02-18 20:42:38 -05:00
|
|
|
}
|
2010-04-16 10:13:32 -04:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
/** \sa MapBase::outerStride() */
|
|
|
|
|
inline int outerStride() const
|
2009-08-31 17:07:54 +02:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
return ei_traits<Block>::HasSameStorageOrderAsXprType
|
|
|
|
|
? m_xpr.outerStride()
|
|
|
|
|
: m_xpr.innerStride();
|
2009-08-31 17:07:54 +02:00
|
|
|
}
|
2008-07-12 22:59:34 +00:00
|
|
|
|
2009-07-10 16:10:03 +02:00
|
|
|
#ifndef __SUNPRO_CC
|
|
|
|
|
// FIXME sunstudio is not friendly with the above friend...
|
2010-02-18 20:42:38 -05:00
|
|
|
// META-FIXME there is no 'friend' keyword around here. Is this obsolete?
|
2008-07-12 22:59:34 +00:00
|
|
|
protected:
|
2009-07-10 16:10:03 +02:00
|
|
|
#endif
|
2008-07-12 22:59:34 +00:00
|
|
|
|
2009-07-10 16:10:03 +02:00
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
2008-08-09 18:41:24 +00:00
|
|
|
/** \internal used by allowAligned() */
|
2010-04-18 22:14:55 -04:00
|
|
|
inline Block(const XprType& xpr, const Scalar* data, int blockRows, int blockCols)
|
|
|
|
|
: Base(data, blockRows, blockCols), m_xpr(xpr)
|
2008-08-09 18:41:24 +00:00
|
|
|
{}
|
2009-07-10 16:10:03 +02:00
|
|
|
#endif
|
2008-08-09 18:41:24 +00:00
|
|
|
|
2009-07-10 16:10:03 +02:00
|
|
|
protected:
|
2010-04-18 22:14:55 -04:00
|
|
|
const typename XprType::Nested m_xpr;
|
2008-07-12 22:59:34 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-13 20:19:14 +00:00
|
|
|
/** \returns a dynamic-size expression of a block in *this.
|
2007-12-25 17:20:58 +00:00
|
|
|
*
|
2007-12-24 11:14:25 +00:00
|
|
|
* \param startRow the first row in the block
|
|
|
|
|
* \param startCol the first column in the block
|
2008-01-13 20:19:14 +00:00
|
|
|
* \param blockRows the number of rows in the block
|
|
|
|
|
* \param blockCols the number of columns in the block
|
2007-12-24 11:14:25 +00:00
|
|
|
*
|
2008-01-13 22:48:57 +00:00
|
|
|
* Example: \include MatrixBase_block_int_int_int_int.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_block_int_int_int_int.out
|
2007-12-24 11:14:25 +00:00
|
|
|
*
|
2008-01-13 23:17:51 +00:00
|
|
|
* \note Even though the returned expression has dynamic size, in the case
|
|
|
|
|
* when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
|
|
|
|
|
* which means that evaluating it does not cause a dynamic memory allocation.
|
|
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* \sa class Block, block(int,int)
|
2007-12-24 11:14:25 +00:00
|
|
|
*/
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline typename BlockReturnType<Derived>::Type DenseBase<Derived>
|
2008-01-13 20:19:14 +00:00
|
|
|
::block(int startRow, int startCol, int blockRows, int blockCols)
|
2007-12-25 17:20:58 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), startRow, startCol, blockRows, blockCols);
|
2007-12-25 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-13 22:48:57 +00:00
|
|
|
/** This is the const version of block(int,int,int,int). */
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline const typename BlockReturnType<Derived>::Type DenseBase<Derived>
|
2008-01-13 20:19:14 +00:00
|
|
|
::block(int startRow, int startCol, int blockRows, int blockCols) const
|
2007-12-05 08:57:23 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), startRow, startCol, blockRows, blockCols);
|
2007-12-05 08:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-13 22:48:57 +00:00
|
|
|
/** \returns a dynamic-size expression of a corner of *this.
|
|
|
|
|
*
|
2008-01-13 23:17:51 +00:00
|
|
|
* \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
|
|
|
|
|
* \a Eigen::BottomLeft, \a Eigen::BottomRight.
|
2008-01-13 22:48:57 +00:00
|
|
|
* \param cRows the number of rows in the corner
|
|
|
|
|
* \param cCols the number of columns in the corner
|
|
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_corner_enum_int_int.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_corner_enum_int_int.out
|
|
|
|
|
*
|
2008-01-13 23:17:51 +00:00
|
|
|
* \note Even though the returned expression has dynamic size, in the case
|
|
|
|
|
* when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
|
|
|
|
|
* which means that evaluating it does not cause a dynamic memory allocation.
|
|
|
|
|
*
|
2008-01-13 22:48:57 +00:00
|
|
|
* \sa class Block, block(int,int,int,int)
|
|
|
|
|
*/
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline typename BlockReturnType<Derived>::Type DenseBase<Derived>
|
2008-01-13 22:48:57 +00:00
|
|
|
::corner(CornerType type, int cRows, int cCols)
|
|
|
|
|
{
|
2008-04-12 17:37:27 +00:00
|
|
|
switch(type)
|
|
|
|
|
{
|
2008-05-03 12:21:23 +00:00
|
|
|
default:
|
|
|
|
|
ei_assert(false && "Bad corner type.");
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopLeft:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), 0, 0, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopRight:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), 0, cols() - cCols, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case BottomLeft:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, 0, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case BottomRight:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
}
|
2008-01-13 22:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of corner(CornerType, int, int).*/
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2008-07-29 16:33:07 +00:00
|
|
|
inline const typename BlockReturnType<Derived>::Type
|
2009-12-04 23:17:14 +01:00
|
|
|
DenseBase<Derived>::corner(CornerType type, int cRows, int cCols) const
|
2008-01-13 22:48:57 +00:00
|
|
|
{
|
2008-04-12 17:37:27 +00:00
|
|
|
switch(type)
|
|
|
|
|
{
|
2008-05-03 12:21:23 +00:00
|
|
|
default:
|
|
|
|
|
ei_assert(false && "Bad corner type.");
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopLeft:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), 0, 0, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopRight:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), 0, cols() - cCols, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case BottomLeft:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, 0, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
case BottomRight:
|
2008-07-29 16:33:07 +00:00
|
|
|
return typename BlockReturnType<Derived>::Type(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
|
2008-04-12 17:37:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns a fixed-size expression of a corner of *this.
|
|
|
|
|
*
|
|
|
|
|
* \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
|
|
|
|
|
* \a Eigen::BottomLeft, \a Eigen::BottomRight.
|
|
|
|
|
*
|
|
|
|
|
* The template parameters CRows and CCols arethe number of rows and columns in the corner.
|
|
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_template_int_int_corner_enum.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_template_int_int_corner_enum.out
|
|
|
|
|
*
|
|
|
|
|
* \sa class Block, block(int,int,int,int)
|
|
|
|
|
*/
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
template<int CRows, int CCols>
|
2008-07-29 16:33:07 +00:00
|
|
|
inline typename BlockReturnType<Derived, CRows, CCols>::Type
|
2009-12-04 23:17:14 +01:00
|
|
|
DenseBase<Derived>::corner(CornerType type)
|
2008-04-12 17:37:27 +00:00
|
|
|
{
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
2008-05-03 12:21:23 +00:00
|
|
|
default:
|
|
|
|
|
ei_assert(false && "Bad corner type.");
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopLeft:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), 0, 0);
|
|
|
|
|
case TopRight:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
|
|
|
|
|
case BottomLeft:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
|
|
|
|
|
case BottomRight:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of corner<int, int>(CornerType).*/
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
template<int CRows, int CCols>
|
2008-07-29 16:33:07 +00:00
|
|
|
inline const typename BlockReturnType<Derived, CRows, CCols>::Type
|
2009-12-04 23:17:14 +01:00
|
|
|
DenseBase<Derived>::corner(CornerType type) const
|
2008-04-12 17:37:27 +00:00
|
|
|
{
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
2008-05-03 12:21:23 +00:00
|
|
|
default:
|
|
|
|
|
ei_assert(false && "Bad corner type.");
|
2008-04-12 17:37:27 +00:00
|
|
|
case TopLeft:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), 0, 0);
|
|
|
|
|
case TopRight:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
|
|
|
|
|
case BottomLeft:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
|
|
|
|
|
case BottomRight:
|
|
|
|
|
return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
|
|
|
|
|
}
|
2008-01-13 22:48:57 +00:00
|
|
|
}
|
2008-01-13 20:19:14 +00:00
|
|
|
|
2008-02-29 13:56:40 +00:00
|
|
|
/** \returns a fixed-size expression of a block in *this.
|
|
|
|
|
*
|
|
|
|
|
* The template parameters \a BlockRows and \a BlockCols are the number of
|
|
|
|
|
* rows and columns in the block.
|
|
|
|
|
*
|
|
|
|
|
* \param startRow the first row in the block
|
|
|
|
|
* \param startCol the first column in the block
|
|
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_block_int_int.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_block_int_int.out
|
|
|
|
|
*
|
2008-05-29 03:12:30 +00:00
|
|
|
* \note since block is a templated member, the keyword template has to be used
|
2008-03-03 10:52:44 +00:00
|
|
|
* if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode
|
|
|
|
|
*
|
2008-02-29 13:56:40 +00:00
|
|
|
* \sa class Block, block(int,int,int,int)
|
|
|
|
|
*/
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2008-02-29 13:56:40 +00:00
|
|
|
template<int BlockRows, int BlockCols>
|
2008-07-29 16:33:07 +00:00
|
|
|
inline typename BlockReturnType<Derived, BlockRows, BlockCols>::Type
|
2009-12-04 23:17:14 +01:00
|
|
|
DenseBase<Derived>::block(int startRow, int startCol)
|
2008-02-29 13:56:40 +00:00
|
|
|
{
|
2008-03-13 20:36:01 +00:00
|
|
|
return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
|
2008-02-29 13:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of block<>(int, int). */
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2008-02-29 13:56:40 +00:00
|
|
|
template<int BlockRows, int BlockCols>
|
2008-07-29 16:33:07 +00:00
|
|
|
inline const typename BlockReturnType<Derived, BlockRows, BlockCols>::Type
|
2009-12-04 23:17:14 +01:00
|
|
|
DenseBase<Derived>::block(int startRow, int startCol) const
|
2008-02-29 13:56:40 +00:00
|
|
|
{
|
2008-03-13 20:36:01 +00:00
|
|
|
return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
|
2008-02-29 13:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-12 18:10:52 +00:00
|
|
|
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
|
|
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_col.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_col.out
|
|
|
|
|
*
|
|
|
|
|
* \sa row(), class Block */
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline typename DenseBase<Derived>::ColXpr
|
|
|
|
|
DenseBase<Derived>::col(int i)
|
2008-03-12 18:10:52 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return ColXpr(derived(), i);
|
2008-03-12 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of col(). */
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline const typename DenseBase<Derived>::ColXpr
|
|
|
|
|
DenseBase<Derived>::col(int i) const
|
2008-03-12 18:10:52 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return ColXpr(derived(), i);
|
2008-03-12 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
|
|
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_row.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_row.out
|
|
|
|
|
*
|
|
|
|
|
* \sa col(), class Block */
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline typename DenseBase<Derived>::RowXpr
|
|
|
|
|
DenseBase<Derived>::row(int i)
|
2008-03-12 18:10:52 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return RowXpr(derived(), i);
|
2008-03-12 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of row(). */
|
|
|
|
|
template<typename Derived>
|
2009-12-04 23:17:14 +01:00
|
|
|
inline const typename DenseBase<Derived>::RowXpr
|
|
|
|
|
DenseBase<Derived>::row(int i) const
|
2008-03-12 18:10:52 +00:00
|
|
|
{
|
2008-07-29 16:33:07 +00:00
|
|
|
return RowXpr(derived(), i);
|
2008-03-12 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-05 08:57:23 +00:00
|
|
|
#endif // EIGEN_BLOCK_H
|