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
*
* \ param MatrixType the type of the object 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
*
2008-01-13 23:17:51 +00:00
* \ note Even though this expression has dynamic size , in the case where \ a MatrixType
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
*/
2009-11-20 16:30:14 +01:00
template < typename MatrixType , int BlockRows , int BlockCols , int _DirectAccessStatus >
2009-12-17 19:28:54 +01:00
struct ei_traits < Block < MatrixType , BlockRows , BlockCols , _DirectAccessStatus > > : ei_traits < MatrixType >
2008-03-12 17:17:36 +00:00
{
2009-04-09 12:06:13 +00:00
typedef typename ei_traits < MatrixType > : : Scalar Scalar ;
2010-04-16 10:13:32 -04:00
typedef typename ei_traits < MatrixType > : : StorageKind StorageKind ;
typedef typename ei_traits < MatrixType > : : XprKind XprKind ;
2009-04-09 12:06:13 +00:00
typedef typename ei_nested < MatrixType > : : type MatrixTypeNested ;
2008-09-02 15:28:49 +00:00
typedef typename ei_unref < MatrixTypeNested > : : type _MatrixTypeNested ;
2008-03-12 17:17:36 +00:00
enum {
2010-04-16 10:13:32 -04:00
MatrixRows = ei_traits < MatrixType > : : RowsAtCompileTime ,
MatrixCols = ei_traits < MatrixType > : : ColsAtCompileTime ,
RowsAtCompileTime = MatrixRows = = 0 ? 0 : BlockRows ,
ColsAtCompileTime = MatrixCols = = 0 ? 0 : BlockCols ,
MaxRowsAtCompileTime = BlockRows = = 0 ? 0
: RowsAtCompileTime ! = Dynamic ? int ( RowsAtCompileTime )
: int ( ei_traits < MatrixType > : : MaxRowsAtCompileTime ) ,
MaxColsAtCompileTime = BlockCols = = 0 ? 0
: ColsAtCompileTime ! = Dynamic ? int ( ColsAtCompileTime )
: int ( ei_traits < MatrixType > : : MaxColsAtCompileTime ) ,
2010-03-21 11:28:03 -04:00
MatrixTypeIsRowMajor = ( int ( ei_traits < MatrixType > : : Flags ) & RowMajorBit ) ! = 0 ,
2010-04-16 10:13:32 -04:00
IsRowMajor = ( MaxRowsAtCompileTime = = 1 & & MaxColsAtCompileTime ! = 1 ) ? 1
: ( MaxColsAtCompileTime = = 1 & & MaxRowsAtCompileTime ! = 1 ) ? 0
2010-03-21 11:28:03 -04:00
: MatrixTypeIsRowMajor ,
2010-04-16 10:13:32 -04:00
HasSameStorageOrderAsMatrixType = ( IsRowMajor = = MatrixTypeIsRowMajor ) ,
InnerSize = MatrixTypeIsRowMajor // notice how it's MatrixTypeIsRowMajor here, not IsRowMajor. Inner size is computed wrt the host matrix's storage order.
? int ( ColsAtCompileTime ) : int ( RowsAtCompileTime ) ,
InnerStrideAtCompileTime = HasSameStorageOrderAsMatrixType
? int ( ei_inner_stride_at_compile_time < MatrixType > : : ret )
: int ( ei_outer_stride_at_compile_time < MatrixType > : : ret ) ,
OuterStrideAtCompileTime = HasSameStorageOrderAsMatrixType
? int ( ei_outer_stride_at_compile_time < MatrixType > : : ret )
: int ( ei_inner_stride_at_compile_time < MatrixType > : : 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-03-09 00:16:07 -05:00
Flags0 = ei_traits < MatrixType > : : Flags & ( HereditaryBits | MaskPacketAccessBit | DirectAccessBit ) ,
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
2009-11-20 16:30:14 +01:00
template < typename MatrixType , int BlockRows , int BlockCols , int _DirectAccessStatus > class Block
2010-04-16 10:13:32 -04:00
: public ei_dense_xpr_base < Block < MatrixType , BlockRows , BlockCols , _DirectAccessStatus > > : : type
2007-12-05 08:57:23 +00:00
{
public :
2008-03-12 17:17:36 +00:00
2010-01-06 17:16:30 +01:00
typedef typename MatrixType : : template MakeBase < Block < MatrixType , 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
*/
2008-05-12 17:34:46 +00:00
inline Block ( const MatrixType & matrix , int i )
2008-03-12 18:10:52 +00:00
: m_matrix ( matrix ) ,
// It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime,
// and it is a column if and only if BlockRows==MatrixType::RowsAtCompileTime and BlockCols==1,
// 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.
2008-03-12 18:10:52 +00:00
m_startRow ( ( BlockRows = = 1 ) & & ( BlockCols = = MatrixType : : ColsAtCompileTime ) ? i : 0 ) ,
m_startCol ( ( BlockRows = = MatrixType : : RowsAtCompileTime ) & & ( BlockCols = = 1 ) ? i : 0 ) ,
2010-02-25 21:01:52 -05:00
m_blockRows ( BlockRows = = 1 ? 1 : matrix . rows ( ) ) ,
m_blockCols ( BlockCols = = 1 ? 1 : matrix . cols ( ) )
2008-03-12 18:10:52 +00:00
{
2008-03-26 08:48:04 +00:00
ei_assert ( ( i > = 0 ) & & (
2008-03-12 18:10:52 +00:00
( ( BlockRows = = 1 ) & & ( BlockCols = = MatrixType : : ColsAtCompileTime ) & & i < matrix . rows ( ) )
| | ( ( BlockRows = = MatrixType : : RowsAtCompileTime ) & & ( BlockCols = = 1 ) & & i < matrix . cols ( ) ) ) ) ;
}
2008-02-29 13:56:40 +00:00
/** Fixed-size constructor
*/
2008-05-12 17:34:46 +00:00
inline Block ( const MatrixType & matrix , int startRow , int startCol )
2008-07-21 12:40:56 +00:00
: m_matrix ( matrix ) , 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 )
2008-03-26 08:48:04 +00:00
ei_assert ( startRow > = 0 & & BlockRows > = 1 & & startRow + BlockRows < = matrix . rows ( )
2009-07-21 11:19:52 +02:00
& & startCol > = 0 & & BlockCols > = 1 & & startCol + BlockCols < = matrix . 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
*/
2008-05-12 17:34:46 +00:00
inline Block ( const MatrixType & matrix ,
2008-01-13 20:19:14 +00:00
int startRow , int startCol ,
int blockRows , int blockCols )
: m_matrix ( matrix ) , m_startRow ( startRow ) , m_startCol ( startCol ) ,
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 ) ) ;
2009-07-21 11:19:52 +02:00
ei_assert ( startRow > = 0 & & blockRows > = 0 & & startRow + blockRows < = matrix . rows ( )
& & startCol > = 0 & & blockCols > = 0 & & startCol + blockCols < = matrix . 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
{
2008-03-13 20:36:01 +00:00
return m_matrix . const_cast_derived ( )
. 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
{
2008-01-13 22:48:57 +00:00
return m_matrix . 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
{
return m_matrix . const_cast_derived ( )
. 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
{
return m_matrix
. 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
{
2008-07-09 22:30:18 +00:00
return m_matrix . template packet < Unaligned >
( 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
{
2008-07-09 22:30:18 +00:00
m_matrix . const_cast_derived ( ) . template writePacket < Unaligned >
( 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
{
2008-07-09 22:30:18 +00:00
return m_matrix . template packet < Unaligned >
( 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
{
2008-06-27 01:22:35 +00:00
m_matrix . 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
2008-04-10 09:01:28 +00:00
const typename MatrixType : : Nested m_matrix ;
2008-06-27 01:22:35 +00:00
const ei_int_if_dynamic < MatrixType : : RowsAtCompileTime = = 1 ? 0 : Dynamic > m_startRow ;
const ei_int_if_dynamic < MatrixType : : ColsAtCompileTime = = 1 ? 0 : Dynamic > m_startCol ;
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 */
2009-11-20 16:30:14 +01:00
template < typename MatrixType , int BlockRows , int BlockCols >
class Block < MatrixType , BlockRows , BlockCols , HasDirectAccess >
2010-04-16 10:13:32 -04:00
: public MapBase < Block < MatrixType , 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
*/
inline Block ( const MatrixType & matrix , int i )
2008-08-09 18:41:24 +00:00
: Base ( & matrix . const_cast_derived ( ) . coeffRef (
( BlockRows = = 1 ) & & ( BlockCols = = MatrixType : : ColsAtCompileTime ) ? i : 0 ,
( BlockRows = = MatrixType : : RowsAtCompileTime ) & & ( BlockCols = = 1 ) ? i : 0 ) ,
BlockRows = = 1 ? 1 : matrix . rows ( ) ,
BlockCols = = 1 ? 1 : matrix . cols ( ) ) ,
m_matrix ( matrix )
2008-07-12 22:59:34 +00:00
{
ei_assert ( ( i > = 0 ) & & (
( ( BlockRows = = 1 ) & & ( BlockCols = = MatrixType : : ColsAtCompileTime ) & & i < matrix . rows ( ) )
| | ( ( BlockRows = = MatrixType : : RowsAtCompileTime ) & & ( BlockCols = = 1 ) & & i < matrix . cols ( ) ) ) ) ;
}
/** Fixed-size constructor
*/
inline Block ( const MatrixType & matrix , int startRow , int startCol )
2008-08-09 18:41:24 +00:00
: Base ( & matrix . const_cast_derived ( ) . coeffRef ( startRow , startCol ) ) , m_matrix ( matrix )
2008-07-12 22:59:34 +00:00
{
ei_assert ( startRow > = 0 & & BlockRows > = 1 & & startRow + BlockRows < = matrix . rows ( )
2008-08-09 18:41:24 +00:00
& & startCol > = 0 & & BlockCols > = 1 & & startCol + BlockCols < = matrix . cols ( ) ) ;
2008-07-12 22:59:34 +00:00
}
/** Dynamic-size constructor
*/
inline Block ( const MatrixType & matrix ,
int startRow , int startCol ,
int blockRows , int blockCols )
2008-08-09 18:41:24 +00:00
: Base ( & matrix . const_cast_derived ( ) . coeffRef ( startRow , startCol ) , blockRows , blockCols ) ,
m_matrix ( matrix )
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 ) ) ;
2009-07-21 11:19:52 +02:00
ei_assert ( startRow > = 0 & & blockRows > = 0 & & startRow + blockRows < = matrix . rows ( )
& & startCol > = 0 & & blockCols > = 0 & & startCol + blockCols < = matrix . 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-16 10:13:32 -04:00
return ei_traits < Block > : : HasSameStorageOrderAsMatrixType
? m_matrix . innerStride ( )
: m_matrix . 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-16 10:13:32 -04:00
return ei_traits < Block > : : HasSameStorageOrderAsMatrixType
? m_matrix . outerStride ( )
: m_matrix . 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() */
inline Block ( const MatrixType & matrix , const Scalar * data , int blockRows , int blockCols )
: Base ( data , blockRows , blockCols ) , m_matrix ( matrix )
{ }
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 :
2008-07-12 22:59:34 +00:00
const typename MatrixType : : Nested m_matrix ;
} ;
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