renaming (MatrixType ---> whatever appropriate)

and documentation improvements
This commit is contained in:
Benoit Jacob 2010-04-18 22:14:55 -04:00
parent 34b14c48f3
commit 504a31f643
11 changed files with 191 additions and 305 deletions

View File

@ -30,7 +30,7 @@
* *
* \brief Expression of a fixed-size or dynamic-size block * \brief Expression of a fixed-size or dynamic-size block
* *
* \param MatrixType the type of the object in which we are taking a block * \param XprType the type of the expression in which we are taking a block
* \param BlockRows the number of rows of the block we are taking at compile time (optional) * \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) * \param BlockCols the number of columns of the block we are taking at compile time (optional)
* \param _DirectAccessStatus \internal used for partial specialization * \param _DirectAccessStatus \internal used for partial specialization
@ -47,7 +47,7 @@
* \include class_Block.cpp * \include class_Block.cpp
* Output: \verbinclude class_Block.out * Output: \verbinclude class_Block.out
* *
* \note Even though this expression has dynamic size, in the case where \a MatrixType * \note Even though this expression has dynamic size, in the case where \a XprType
* has fixed size, this expression inherits a fixed maximal size which means that evaluating * has fixed size, this expression inherits a fixed maximal size which means that evaluating
* it does not cause a dynamic memory allocation. * it does not cause a dynamic memory allocation.
* *
@ -57,99 +57,99 @@
* *
* \sa DenseBase::block(int,int,int,int), DenseBase::block(int,int), class VectorBlock * \sa DenseBase::block(int,int,int,int), DenseBase::block(int,int), class VectorBlock
*/ */
template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessStatus> template<typename XprType, int BlockRows, int BlockCols, int _DirectAccessStatus>
struct ei_traits<Block<MatrixType, BlockRows, BlockCols, _DirectAccessStatus> > : ei_traits<MatrixType> struct ei_traits<Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> > : ei_traits<XprType>
{ {
typedef typename ei_traits<MatrixType>::Scalar Scalar; typedef typename ei_traits<XprType>::Scalar Scalar;
typedef typename ei_traits<MatrixType>::StorageKind StorageKind; typedef typename ei_traits<XprType>::StorageKind StorageKind;
typedef typename ei_traits<MatrixType>::XprKind XprKind; typedef typename ei_traits<XprType>::XprKind XprKind;
typedef typename ei_nested<MatrixType>::type MatrixTypeNested; typedef typename ei_nested<XprType>::type XprTypeNested;
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; typedef typename ei_unref<XprTypeNested>::type _XprTypeNested;
enum{ enum{
MatrixRows = ei_traits<MatrixType>::RowsAtCompileTime, MatrixRows = ei_traits<XprType>::RowsAtCompileTime,
MatrixCols = ei_traits<MatrixType>::ColsAtCompileTime, MatrixCols = ei_traits<XprType>::ColsAtCompileTime,
RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows, RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols, ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
MaxRowsAtCompileTime = BlockRows==0 ? 0 MaxRowsAtCompileTime = BlockRows==0 ? 0
: RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
: int(ei_traits<MatrixType>::MaxRowsAtCompileTime), : int(ei_traits<XprType>::MaxRowsAtCompileTime),
MaxColsAtCompileTime = BlockCols==0 ? 0 MaxColsAtCompileTime = BlockCols==0 ? 0
: ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
: int(ei_traits<MatrixType>::MaxColsAtCompileTime), : int(ei_traits<XprType>::MaxColsAtCompileTime),
MatrixTypeIsRowMajor = (int(ei_traits<MatrixType>::Flags)&RowMajorBit) != 0, XprTypeIsRowMajor = (int(ei_traits<XprType>::Flags)&RowMajorBit) != 0,
IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
: (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
: MatrixTypeIsRowMajor, : XprTypeIsRowMajor,
HasSameStorageOrderAsMatrixType = (IsRowMajor == MatrixTypeIsRowMajor), HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
InnerSize = MatrixTypeIsRowMajor // notice how it's MatrixTypeIsRowMajor here, not IsRowMajor. Inner size is computed wrt the host matrix's storage order. InnerSize = XprTypeIsRowMajor // notice how it's XprTypeIsRowMajor here, not IsRowMajor. Inner size is computed wrt the host matrix's storage order.
? int(ColsAtCompileTime) : int(RowsAtCompileTime), ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
InnerStrideAtCompileTime = HasSameStorageOrderAsMatrixType InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
? int(ei_inner_stride_at_compile_time<MatrixType>::ret) ? int(ei_inner_stride_at_compile_time<XprType>::ret)
: int(ei_outer_stride_at_compile_time<MatrixType>::ret), : int(ei_outer_stride_at_compile_time<XprType>::ret),
OuterStrideAtCompileTime = HasSameStorageOrderAsMatrixType OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
? int(ei_outer_stride_at_compile_time<MatrixType>::ret) ? int(ei_outer_stride_at_compile_time<XprType>::ret)
: int(ei_inner_stride_at_compile_time<MatrixType>::ret), : int(ei_inner_stride_at_compile_time<XprType>::ret),
MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % ei_packet_traits<Scalar>::size) == 0) MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % ei_packet_traits<Scalar>::size) == 0)
&& (InnerStrideAtCompileTime == 1) && (InnerStrideAtCompileTime == 1)
? PacketAccessBit : 0, ? PacketAccessBit : 0,
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
Flags0 = ei_traits<MatrixType>::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit), Flags0 = ei_traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit),
Flags1 = Flags0 | FlagsLinearAccessBit, Flags1 = Flags0 | FlagsLinearAccessBit,
Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0) Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0)
}; };
}; };
template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessStatus> class Block template<typename XprType, int BlockRows, int BlockCols, int _DirectAccessStatus> class Block
: public ei_dense_xpr_base<Block<MatrixType, BlockRows, BlockCols, _DirectAccessStatus> >::type : public ei_dense_xpr_base<Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> >::type
{ {
public: public:
typedef typename MatrixType::template MakeBase< Block<MatrixType, BlockRows, BlockCols, _DirectAccessStatus> >::Type Base; typedef typename XprType::template MakeBase< Block<XprType, BlockRows, BlockCols, _DirectAccessStatus> >::Type Base;
EIGEN_DENSE_PUBLIC_INTERFACE(Block) EIGEN_DENSE_PUBLIC_INTERFACE(Block)
class InnerIterator; class InnerIterator;
/** Column or Row constructor /** Column or Row constructor
*/ */
inline Block(const MatrixType& matrix, int i) inline Block(const XprType& xpr, int i)
: m_matrix(matrix), : m_xpr(xpr),
// It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime, // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime,
// and it is a column if and only if BlockRows==MatrixType::RowsAtCompileTime and BlockCols==1, // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1,
// all other cases are invalid. // all other cases are invalid.
// The case a 1x1 matrix seems ambiguous, but the result is the same anyway. // The case a 1x1 matrix seems ambiguous, but the result is the same anyway.
m_startRow( (BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) ? i : 0), m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
m_startCol( (BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
m_blockRows(BlockRows==1 ? 1 : matrix.rows()), m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
m_blockCols(BlockCols==1 ? 1 : matrix.cols()) m_blockCols(BlockCols==1 ? 1 : xpr.cols())
{ {
ei_assert( (i>=0) && ( ei_assert( (i>=0) && (
((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows()) ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols()))); ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
} }
/** Fixed-size constructor /** Fixed-size constructor
*/ */
inline Block(const MatrixType& matrix, int startRow, int startCol) inline Block(const XprType& xpr, int startRow, int startCol)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol), : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
m_blockRows(BlockRows), m_blockCols(BlockCols) m_blockRows(BlockRows), m_blockCols(BlockCols)
{ {
EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows() ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols()); && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
} }
/** Dynamic-size constructor /** Dynamic-size constructor
*/ */
inline Block(const MatrixType& matrix, inline Block(const XprType& xpr,
int startRow, int startCol, int startRow, int startCol,
int blockRows, int blockCols) int blockRows, int blockCols)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol), : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
m_blockRows(blockRows), m_blockCols(blockCols) m_blockRows(blockRows), m_blockCols(blockCols)
{ {
ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows) ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols)); && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= matrix.rows() ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
&& startCol >= 0 && blockCols >= 0 && startCol + blockCols <= matrix.cols()); && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
} }
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
@ -159,25 +159,25 @@ template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessSta
inline Scalar& coeffRef(int row, int col) inline Scalar& coeffRef(int row, int col)
{ {
return m_matrix.const_cast_derived() return m_xpr.const_cast_derived()
.coeffRef(row + m_startRow.value(), col + m_startCol.value()); .coeffRef(row + m_startRow.value(), col + m_startCol.value());
} }
inline const CoeffReturnType coeff(int row, int col) const inline const CoeffReturnType coeff(int row, int col) const
{ {
return m_matrix.coeff(row + m_startRow.value(), col + m_startCol.value()); return m_xpr.coeff(row + m_startRow.value(), col + m_startCol.value());
} }
inline Scalar& coeffRef(int index) inline Scalar& coeffRef(int index)
{ {
return m_matrix.const_cast_derived() return m_xpr.const_cast_derived()
.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
} }
inline const CoeffReturnType coeff(int index) const inline const CoeffReturnType coeff(int index) const
{ {
return m_matrix return m_xpr
.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
} }
@ -185,21 +185,21 @@ template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessSta
template<int LoadMode> template<int LoadMode>
inline PacketScalar packet(int row, int col) const inline PacketScalar packet(int row, int col) const
{ {
return m_matrix.template packet<Unaligned> return m_xpr.template packet<Unaligned>
(row + m_startRow.value(), col + m_startCol.value()); (row + m_startRow.value(), col + m_startCol.value());
} }
template<int LoadMode> template<int LoadMode>
inline void writePacket(int row, int col, const PacketScalar& x) inline void writePacket(int row, int col, const PacketScalar& x)
{ {
m_matrix.const_cast_derived().template writePacket<Unaligned> m_xpr.const_cast_derived().template writePacket<Unaligned>
(row + m_startRow.value(), col + m_startCol.value(), x); (row + m_startRow.value(), col + m_startCol.value(), x);
} }
template<int LoadMode> template<int LoadMode>
inline PacketScalar packet(int index) const inline PacketScalar packet(int index) const
{ {
return m_matrix.template packet<Unaligned> return m_xpr.template packet<Unaligned>
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
} }
@ -207,7 +207,7 @@ template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessSta
template<int LoadMode> template<int LoadMode>
inline void writePacket(int index, const PacketScalar& x) inline void writePacket(int index, const PacketScalar& x)
{ {
m_matrix.const_cast_derived().template writePacket<Unaligned> m_xpr.const_cast_derived().template writePacket<Unaligned>
(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), x); m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), x);
} }
@ -221,17 +221,17 @@ template<typename MatrixType, int BlockRows, int BlockCols, int _DirectAccessSta
protected: protected:
const typename MatrixType::Nested m_matrix; const typename XprType::Nested m_xpr;
const ei_int_if_dynamic<MatrixType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow; const ei_int_if_dynamic<XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
const ei_int_if_dynamic<MatrixType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol; const ei_int_if_dynamic<XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
const ei_int_if_dynamic<RowsAtCompileTime> m_blockRows; const ei_int_if_dynamic<RowsAtCompileTime> m_blockRows;
const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols; const ei_int_if_dynamic<ColsAtCompileTime> m_blockCols;
}; };
/** \internal */ /** \internal */
template<typename MatrixType, int BlockRows, int BlockCols> template<typename XprType, int BlockRows, int BlockCols>
class Block<MatrixType,BlockRows,BlockCols,HasDirectAccess> class Block<XprType,BlockRows,BlockCols,HasDirectAccess>
: public MapBase<Block<MatrixType, BlockRows, BlockCols,HasDirectAccess> > : public MapBase<Block<XprType, BlockRows, BlockCols,HasDirectAccess> >
{ {
public: public:
@ -242,56 +242,56 @@ class Block<MatrixType,BlockRows,BlockCols,HasDirectAccess>
/** Column or Row constructor /** Column or Row constructor
*/ */
inline Block(const MatrixType& matrix, int i) inline Block(const XprType& xpr, int i)
: Base(&matrix.const_cast_derived().coeffRef( : Base(&xpr.const_cast_derived().coeffRef(
(BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) ? i : 0, (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
(BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
BlockRows==1 ? 1 : matrix.rows(), BlockRows==1 ? 1 : xpr.rows(),
BlockCols==1 ? 1 : matrix.cols()), BlockCols==1 ? 1 : xpr.cols()),
m_matrix(matrix) m_xpr(xpr)
{ {
ei_assert( (i>=0) && ( ei_assert( (i>=0) && (
((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows()) ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols()))); ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
} }
/** Fixed-size constructor /** Fixed-size constructor
*/ */
inline Block(const MatrixType& matrix, int startRow, int startCol) inline Block(const XprType& xpr, int startRow, int startCol)
: Base(&matrix.const_cast_derived().coeffRef(startRow,startCol)), m_matrix(matrix) : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol)), m_xpr(xpr)
{ {
ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= matrix.rows() ei_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
&& startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= matrix.cols()); && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
} }
/** Dynamic-size constructor /** Dynamic-size constructor
*/ */
inline Block(const MatrixType& matrix, inline Block(const XprType& xpr,
int startRow, int startCol, int startRow, int startCol,
int blockRows, int blockCols) int blockRows, int blockCols)
: Base(&matrix.const_cast_derived().coeffRef(startRow,startCol), blockRows, blockCols), : Base(&xpr.const_cast_derived().coeffRef(startRow,startCol), blockRows, blockCols),
m_matrix(matrix) m_xpr(xpr)
{ {
ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows) ei_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
&& (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols)); && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= matrix.rows() ei_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
&& startCol >= 0 && blockCols >= 0 && startCol + blockCols <= matrix.cols()); && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
} }
/** \sa MapBase::innerStride() */ /** \sa MapBase::innerStride() */
inline int innerStride() const inline int innerStride() const
{ {
return ei_traits<Block>::HasSameStorageOrderAsMatrixType return ei_traits<Block>::HasSameStorageOrderAsXprType
? m_matrix.innerStride() ? m_xpr.innerStride()
: m_matrix.outerStride(); : m_xpr.outerStride();
} }
/** \sa MapBase::outerStride() */ /** \sa MapBase::outerStride() */
inline int outerStride() const inline int outerStride() const
{ {
return ei_traits<Block>::HasSameStorageOrderAsMatrixType return ei_traits<Block>::HasSameStorageOrderAsXprType
? m_matrix.outerStride() ? m_xpr.outerStride()
: m_matrix.innerStride(); : m_xpr.innerStride();
} }
#ifndef __SUNPRO_CC #ifndef __SUNPRO_CC
@ -302,13 +302,13 @@ class Block<MatrixType,BlockRows,BlockCols,HasDirectAccess>
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
/** \internal used by allowAligned() */ /** \internal used by allowAligned() */
inline Block(const MatrixType& matrix, const Scalar* data, int blockRows, int blockCols) inline Block(const XprType& xpr, const Scalar* data, int blockRows, int blockCols)
: Base(data, blockRows, blockCols), m_matrix(matrix) : Base(data, blockRows, blockCols), m_xpr(xpr)
{} {}
#endif #endif
protected: protected:
const typename MatrixType::Nested m_matrix; const typename XprType::Nested m_xpr;
}; };
/** \returns a dynamic-size expression of a block in *this. /** \returns a dynamic-size expression of a block in *this.

View File

@ -36,38 +36,38 @@
* *
* \sa \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished() * \sa \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished()
*/ */
template<typename MatrixType> template<typename XprType>
struct CommaInitializer struct CommaInitializer
{ {
typedef typename ei_traits<MatrixType>::Scalar Scalar; typedef typename ei_traits<XprType>::Scalar Scalar;
inline CommaInitializer(MatrixType& mat, const Scalar& s) inline CommaInitializer(XprType& xpr, const Scalar& s)
: m_matrix(mat), m_row(0), m_col(1), m_currentBlockRows(1) : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1)
{ {
m_matrix.coeffRef(0,0) = s; m_xpr.coeffRef(0,0) = s;
} }
template<typename OtherDerived> template<typename OtherDerived>
inline CommaInitializer(MatrixType& mat, const DenseBase<OtherDerived>& other) inline CommaInitializer(XprType& xpr, const DenseBase<OtherDerived>& other)
: m_matrix(mat), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows())
{ {
m_matrix.block(0, 0, other.rows(), other.cols()) = other; m_xpr.block(0, 0, other.rows(), other.cols()) = other;
} }
/* inserts a scalar value in the target matrix */ /* inserts a scalar value in the target matrix */
CommaInitializer& operator,(const Scalar& s) CommaInitializer& operator,(const Scalar& s)
{ {
if (m_col==m_matrix.cols()) if (m_col==m_xpr.cols())
{ {
m_row+=m_currentBlockRows; m_row+=m_currentBlockRows;
m_col = 0; m_col = 0;
m_currentBlockRows = 1; m_currentBlockRows = 1;
ei_assert(m_row<m_matrix.rows() ei_assert(m_row<m_xpr.rows()
&& "Too many rows passed to comma initializer (operator<<)"); && "Too many rows passed to comma initializer (operator<<)");
} }
ei_assert(m_col<m_matrix.cols() ei_assert(m_col<m_xpr.cols()
&& "Too many coefficients passed to comma initializer (operator<<)"); && "Too many coefficients passed to comma initializer (operator<<)");
ei_assert(m_currentBlockRows==1); ei_assert(m_currentBlockRows==1);
m_matrix.coeffRef(m_row, m_col++) = s; m_xpr.coeffRef(m_row, m_col++) = s;
return *this; return *this;
} }
@ -75,31 +75,31 @@ struct CommaInitializer
template<typename OtherDerived> template<typename OtherDerived>
CommaInitializer& operator,(const DenseBase<OtherDerived>& other) CommaInitializer& operator,(const DenseBase<OtherDerived>& other)
{ {
if (m_col==m_matrix.cols()) if (m_col==m_xpr.cols())
{ {
m_row+=m_currentBlockRows; m_row+=m_currentBlockRows;
m_col = 0; m_col = 0;
m_currentBlockRows = other.rows(); m_currentBlockRows = other.rows();
ei_assert(m_row+m_currentBlockRows<=m_matrix.rows() ei_assert(m_row+m_currentBlockRows<=m_xpr.rows()
&& "Too many rows passed to comma initializer (operator<<)"); && "Too many rows passed to comma initializer (operator<<)");
} }
ei_assert(m_col<m_matrix.cols() ei_assert(m_col<m_xpr.cols()
&& "Too many coefficients passed to comma initializer (operator<<)"); && "Too many coefficients passed to comma initializer (operator<<)");
ei_assert(m_currentBlockRows==other.rows()); ei_assert(m_currentBlockRows==other.rows());
if (OtherDerived::SizeAtCompileTime != Dynamic) if (OtherDerived::SizeAtCompileTime != Dynamic)
m_matrix.template block<OtherDerived::RowsAtCompileTime != Dynamic ? OtherDerived::RowsAtCompileTime : 1, m_xpr.template block<OtherDerived::RowsAtCompileTime != Dynamic ? OtherDerived::RowsAtCompileTime : 1,
OtherDerived::ColsAtCompileTime != Dynamic ? OtherDerived::ColsAtCompileTime : 1> OtherDerived::ColsAtCompileTime != Dynamic ? OtherDerived::ColsAtCompileTime : 1>
(m_row, m_col) = other; (m_row, m_col) = other;
else else
m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other; m_xpr.block(m_row, m_col, other.rows(), other.cols()) = other;
m_col += other.cols(); m_col += other.cols();
return *this; return *this;
} }
inline ~CommaInitializer() inline ~CommaInitializer()
{ {
ei_assert((m_row+m_currentBlockRows) == m_matrix.rows() ei_assert((m_row+m_currentBlockRows) == m_xpr.rows()
&& m_col == m_matrix.cols() && m_col == m_xpr.cols()
&& "Too few coefficients passed to comma initializer (operator<<)"); && "Too few coefficients passed to comma initializer (operator<<)");
} }
@ -110,9 +110,9 @@ struct CommaInitializer
* quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished()); * quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished());
* \endcode * \endcode
*/ */
inline MatrixType& finished() { return m_matrix; } inline XprType& finished() { return m_xpr; }
MatrixType& m_matrix; // target matrix XprType& m_xpr; // target expression
int m_row; // current row id int m_row; // current row id
int m_col; // current col id int m_col; // current col id
int m_currentBlockRows; // current block height int m_currentBlockRows; // current block height

View File

@ -28,18 +28,19 @@
/** \class CwiseBinaryOp /** \class CwiseBinaryOp
* *
* \brief Generic expression of a coefficient-wise operator between two matrices or vectors * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions
* *
* \param BinaryOp template functor implementing the operator * \param BinaryOp template functor implementing the operator
* \param Lhs the type of the left-hand side * \param Lhs the type of the left-hand side
* \param Rhs the type of the right-hand side * \param Rhs the type of the right-hand side
* *
* This class represents an expression of a generic binary operator of two matrices or vectors. * This class represents an expression where a coefficient-wise binary operator is applied to two expressions.
* It is the return type of the operator+, operator-, and the Cwise methods, and most * It is the return type of binary operators, by which we mean only those binary operators where
* of the time this is the only way it is used. * both the left-hand side and the right-hand side are Eigen expressions.
* For example, the return type of matrix1+matrix2 is a CwiseBinaryOp.
* *
* However, if you want to write a function returning such an expression, you * Most of the time, this is the only way that it is used, so you typically don't have to name
* will need to use this class. * CwiseBinaryOp types explicitly.
* *
* \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp * \sa MatrixBase::binaryExpr(const MatrixBase<OtherDerived> &,const CustomBinaryOp &) const, class CwiseUnaryOp, class CwiseNullaryOp
*/ */

View File

@ -30,9 +30,10 @@
* \brief Generic expression of a matrix where all coefficients are defined by a functor * \brief Generic expression of a matrix where all coefficients are defined by a functor
* *
* \param NullaryOp template functor implementing the operator * \param NullaryOp template functor implementing the operator
* \param PlainObjectType the underlying plain matrix/array type
* *
* This class represents an expression of a generic nullary operator. * This class represents an expression of a generic nullary operator.
* It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() functions, * It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods,
* and most of the time this is the only way it is used. * and most of the time this is the only way it is used.
* *
* However, if you want to write a function returning such an expression, you * However, if you want to write a function returning such an expression, you
@ -40,11 +41,11 @@
* *
* \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr() * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr()
*/ */
template<typename NullaryOp, typename MatrixType> template<typename NullaryOp, typename PlainObjectType>
struct ei_traits<CwiseNullaryOp<NullaryOp, MatrixType> > : ei_traits<MatrixType> struct ei_traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : ei_traits<PlainObjectType>
{ {
enum { enum {
Flags = (ei_traits<MatrixType>::Flags Flags = (ei_traits<PlainObjectType>::Flags
& ( HereditaryBits & ( HereditaryBits
| (ei_functor_has_linear_access<NullaryOp>::ret ? LinearAccessBit : 0) | (ei_functor_has_linear_access<NullaryOp>::ret ? LinearAccessBit : 0)
| (ei_functor_traits<NullaryOp>::PacketAccess ? PacketAccessBit : 0))) | (ei_functor_traits<NullaryOp>::PacketAccess ? PacketAccessBit : 0)))
@ -53,13 +54,13 @@ struct ei_traits<CwiseNullaryOp<NullaryOp, MatrixType> > : ei_traits<MatrixType>
}; };
}; };
template<typename NullaryOp, typename MatrixType> template<typename NullaryOp, typename PlainObjectType>
class CwiseNullaryOp : ei_no_assignment_operator, class CwiseNullaryOp : ei_no_assignment_operator,
public MatrixType::template MakeBase< CwiseNullaryOp<NullaryOp, MatrixType> >::Type public PlainObjectType::template MakeBase< CwiseNullaryOp<NullaryOp, PlainObjectType> >::Type
{ {
public: public:
typedef typename MatrixType::template MakeBase< CwiseNullaryOp<NullaryOp, MatrixType> >::Type Base; typedef typename PlainObjectType::template MakeBase< CwiseNullaryOp<NullaryOp, PlainObjectType> >::Type Base;
EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp) EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
CwiseNullaryOp(int rows, int cols, const NullaryOp& func = NullaryOp()) CwiseNullaryOp(int rows, int cols, const NullaryOp& func = NullaryOp())

View File

@ -28,79 +28,84 @@
/** \class CwiseUnaryOp /** \class CwiseUnaryOp
* *
* \brief Generic expression of a coefficient-wise unary operator of a matrix or a vector * \brief Generic expression where a coefficient-wise unary operator is applied to an expression
* *
* \param UnaryOp template functor implementing the operator * \param UnaryOp template functor implementing the operator
* \param MatrixType the type of the matrix we are applying the unary operator * \param XprType the type of the expression to which we are applying the unary operator
* *
* This class represents an expression of a generic unary operator of a matrix or a vector. * This class represents an expression where a unary operator is applied to an expression.
* It is the return type of the unary operator-, of a matrix or a vector, and most * It is the return type of all operations taking exactly 1 input expression, regardless of the
* of the time this is the only way it is used. * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix
* is considered unary, because only the right-hand side is an expression, and its
* return type is a specialization of CwiseUnaryOp.
*
* Most of the time, this is the only way that it is used, so you typically don't have to name
* CwiseUnaryOp types explicitly.
* *
* \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp
*/ */
template<typename UnaryOp, typename MatrixType> template<typename UnaryOp, typename XprType>
struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> > struct ei_traits<CwiseUnaryOp<UnaryOp, XprType> >
: ei_traits<MatrixType> : ei_traits<XprType>
{ {
typedef typename ei_result_of< typedef typename ei_result_of<
UnaryOp(typename MatrixType::Scalar) UnaryOp(typename XprType::Scalar)
>::type Scalar; >::type Scalar;
typedef typename MatrixType::Nested MatrixTypeNested; typedef typename XprType::Nested XprTypeNested;
typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested; typedef typename ei_unref<XprTypeNested>::type _XprTypeNested;
enum { enum {
Flags = _MatrixTypeNested::Flags & ( Flags = _XprTypeNested::Flags & (
HereditaryBits | LinearAccessBit | AlignedBit HereditaryBits | LinearAccessBit | AlignedBit
| (ei_functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)), | (ei_functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0)),
CoeffReadCost = _MatrixTypeNested::CoeffReadCost + ei_functor_traits<UnaryOp>::Cost CoeffReadCost = _XprTypeNested::CoeffReadCost + ei_functor_traits<UnaryOp>::Cost
}; };
}; };
template<typename UnaryOp, typename MatrixType, typename StorageKind> template<typename UnaryOp, typename XprType, typename StorageKind>
class CwiseUnaryOpImpl; class CwiseUnaryOpImpl;
template<typename UnaryOp, typename MatrixType> template<typename UnaryOp, typename XprType>
class CwiseUnaryOp : ei_no_assignment_operator, class CwiseUnaryOp : ei_no_assignment_operator,
public CwiseUnaryOpImpl<UnaryOp, MatrixType, typename ei_traits<MatrixType>::StorageKind> public CwiseUnaryOpImpl<UnaryOp, XprType, typename ei_traits<XprType>::StorageKind>
{ {
public: public:
typedef typename CwiseUnaryOpImpl<UnaryOp, MatrixType,typename ei_traits<MatrixType>::StorageKind>::Base Base; typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename ei_traits<XprType>::StorageKind>::Base Base;
EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryOp) EIGEN_GENERIC_PUBLIC_INTERFACE_NEW(CwiseUnaryOp)
inline CwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp()) inline CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
: m_matrix(mat), m_functor(func) {} : m_xpr(xpr), m_functor(func) {}
EIGEN_STRONG_INLINE int rows() const { return m_matrix.rows(); } EIGEN_STRONG_INLINE int rows() const { return m_xpr.rows(); }
EIGEN_STRONG_INLINE int cols() const { return m_matrix.cols(); } EIGEN_STRONG_INLINE int cols() const { return m_xpr.cols(); }
/** \returns the functor representing the unary operation */ /** \returns the functor representing the unary operation */
const UnaryOp& functor() const { return m_functor; } const UnaryOp& functor() const { return m_functor; }
/** \returns the nested expression */ /** \returns the nested expression */
const typename ei_cleantype<typename MatrixType::Nested>::type& const typename ei_cleantype<typename XprType::Nested>::type&
nestedExpression() const { return m_matrix; } nestedExpression() const { return m_xpr; }
/** \returns the nested expression */ /** \returns the nested expression */
typename ei_cleantype<typename MatrixType::Nested>::type& typename ei_cleantype<typename XprType::Nested>::type&
nestedExpression() { return m_matrix.const_cast_derived(); } nestedExpression() { return m_xpr.const_cast_derived(); }
protected: protected:
const typename MatrixType::Nested m_matrix; const typename XprType::Nested m_xpr;
const UnaryOp m_functor; const UnaryOp m_functor;
}; };
// This is the generic implementation for dense storage. // This is the generic implementation for dense storage.
// It can be used for any matrix types implementing the dense concept. // It can be used for any expression types implementing the dense concept.
template<typename UnaryOp, typename MatrixType> template<typename UnaryOp, typename XprType>
class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense> class CwiseUnaryOpImpl<UnaryOp,XprType,Dense>
: public MatrixType::template MakeBase< CwiseUnaryOp<UnaryOp, MatrixType> >::Type : public XprType::template MakeBase< CwiseUnaryOp<UnaryOp, XprType> >::Type
{ {
typedef CwiseUnaryOp<UnaryOp, MatrixType> Derived; typedef CwiseUnaryOp<UnaryOp, XprType> Derived;
public: public:
typedef typename MatrixType::template MakeBase< CwiseUnaryOp<UnaryOp, MatrixType> >::Type Base; typedef typename XprType::template MakeBase< CwiseUnaryOp<UnaryOp, XprType> >::Type Base;
EIGEN_DENSE_PUBLIC_INTERFACE(Derived) EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const

View File

@ -30,7 +30,7 @@
* *
* \brief A matrix or vector expression mapping an existing array of data. * \brief A matrix or vector expression mapping an existing array of data.
* *
* \param MatrixType the equivalent matrix type of the mapped data * \param PlainObjectType the equivalent matrix type of the mapped data
* \param Options specifies whether the pointer is \c Aligned, or \c Unaligned. * \param Options specifies whether the pointer is \c Aligned, or \c Unaligned.
* The default is \c Unaligned. * The default is \c Unaligned.
* \param StrideType optionnally specifies strides. By default, Map assumes the memory layout * \param StrideType optionnally specifies strides. By default, Map assumes the memory layout
@ -73,11 +73,11 @@
* *
* \sa Matrix::Map() * \sa Matrix::Map()
*/ */
template<typename MatrixType, int Options, typename StrideType> template<typename PlainObjectType, int Options, typename StrideType>
struct ei_traits<Map<MatrixType, Options, StrideType> > struct ei_traits<Map<PlainObjectType, Options, StrideType> >
: public ei_traits<MatrixType> : public ei_traits<PlainObjectType>
{ {
typedef typename MatrixType::Scalar Scalar; typedef typename PlainObjectType::Scalar Scalar;
enum { enum {
InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime, InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime,
OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime, OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime,
@ -85,21 +85,21 @@ struct ei_traits<Map<MatrixType, Options, StrideType> >
HasNoOuterStride = OuterStrideAtCompileTime == 0, HasNoOuterStride = OuterStrideAtCompileTime == 0,
HasNoStride = HasNoInnerStride && HasNoOuterStride, HasNoStride = HasNoInnerStride && HasNoOuterStride,
IsAligned = int(int(Options)&Aligned)==Aligned, IsAligned = int(int(Options)&Aligned)==Aligned,
IsDynamicSize = MatrixType::SizeAtCompileTime==Dynamic, IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
KeepsPacketAccess = bool(HasNoInnerStride) KeepsPacketAccess = bool(HasNoInnerStride)
&& ( bool(IsDynamicSize) && ( bool(IsDynamicSize)
|| HasNoOuterStride || HasNoOuterStride
|| ( OuterStrideAtCompileTime!=Dynamic || ( OuterStrideAtCompileTime!=Dynamic
&& ((int(OuterStrideAtCompileTime)*sizeof(Scalar))%16)==0 ) ), && ((int(OuterStrideAtCompileTime)*sizeof(Scalar))%16)==0 ) ),
Flags0 = ei_traits<MatrixType>::Flags, Flags0 = ei_traits<PlainObjectType>::Flags,
Flags1 = IsAligned ? int(Flags0) | AlignedBit : int(Flags0) & ~AlignedBit, Flags1 = IsAligned ? int(Flags0) | AlignedBit : int(Flags0) & ~AlignedBit,
Flags2 = HasNoStride ? int(Flags1) : int(Flags1 & ~LinearAccessBit), Flags2 = HasNoStride ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
Flags = KeepsPacketAccess ? int(Flags2) : (int(Flags2) & ~PacketAccessBit) Flags = KeepsPacketAccess ? int(Flags2) : (int(Flags2) & ~PacketAccessBit)
}; };
}; };
template<typename MatrixType, int Options, typename StrideType> class Map template<typename PlainObjectType, int Options, typename StrideType> class Map
: public MapBase<Map<MatrixType, Options, StrideType> > : public MapBase<Map<PlainObjectType, Options, StrideType> >
{ {
public: public:
@ -128,7 +128,7 @@ template<typename MatrixType, int Options, typename StrideType> class Map
inline Map(const Scalar* data, const StrideType& stride = StrideType()) inline Map(const Scalar* data, const StrideType& stride = StrideType())
: Base(data), m_stride(stride) : Base(data), m_stride(stride)
{ {
MatrixType::Base::_check_template_params(); PlainObjectType::Base::_check_template_params();
} }
/** Constructor in the dynamic-size vector case. /** Constructor in the dynamic-size vector case.
@ -140,7 +140,7 @@ template<typename MatrixType, int Options, typename StrideType> class Map
inline Map(const Scalar* data, int size, const StrideType& stride = StrideType()) inline Map(const Scalar* data, int size, const StrideType& stride = StrideType())
: Base(data, size), m_stride(stride) : Base(data, size), m_stride(stride)
{ {
MatrixType::Base::_check_template_params(); PlainObjectType::Base::_check_template_params();
} }
/** Constructor in the dynamic-size matrix case. /** Constructor in the dynamic-size matrix case.
@ -153,7 +153,7 @@ template<typename MatrixType, int Options, typename StrideType> class Map
inline Map(const Scalar* data, int rows, int cols, const StrideType& stride = StrideType()) inline Map(const Scalar* data, int rows, int cols, const StrideType& stride = StrideType())
: Base(data, rows, cols), m_stride(stride) : Base(data, rows, cols), m_stride(stride)
{ {
MatrixType::Base::_check_template_params(); PlainObjectType::Base::_check_template_params();
} }

View File

@ -1,4 +1,3 @@
/** \returns an expression of the coefficient wise product of \c *this and \a other /** \returns an expression of the coefficient wise product of \c *this and \a other
* *
* \sa MatrixBase::cwiseProduct * \sa MatrixBase::cwiseProduct
@ -88,13 +87,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
* \sa all(), any(), isApprox(), isMuchSmallerThan() * \sa all(), any(), isApprox(), isMuchSmallerThan()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to) EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
// template<typename ExpressionType>
// template<typename OtherDerived>
// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
// operator==(const MatrixBase<OtherDerived> &other) const
// {
// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived());
// }
/** \returns an expression of the coefficient-wise != operator of *this and \a other /** \returns an expression of the coefficient-wise != operator of *this and \a other
* *
@ -109,95 +101,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
* \sa all(), any(), isApprox(), isMuchSmallerThan() * \sa all(), any(), isApprox(), isMuchSmallerThan()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to) EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to)
// template<typename ExpressionType>
// template<typename OtherDerived>
// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
// operator!=(const MatrixBase<OtherDerived> &other) const
// {
// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived());
// }
// comparisons to scalar value
#if 0
/** \returns an expression of the coefficient-wise \< operator of *this and a scalar \a s
*
* \sa operator<(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
operator<(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
/** \returns an expression of the coefficient-wise \<= operator of *this and a scalar \a s
*
* \sa operator<=(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
operator<=(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
/** \returns an expression of the coefficient-wise \> operator of *this and a scalar \a s
*
* \sa operator>(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
operator>(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
/** \returns an expression of the coefficient-wise \>= operator of *this and a scalar \a s
*
* \sa operator>=(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
operator>=(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
/** \returns an expression of the coefficient-wise == operator of *this and a scalar \a s
*
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is
* generally a far better idea to use a fuzzy comparison as provided by isApprox() and
* isMuchSmallerThan().
*
* \sa operator==(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
operator==(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
/** \returns an expression of the coefficient-wise != operator of *this and a scalar \a s
*
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is
* generally a far better idea to use a fuzzy comparison as provided by isApprox() and
* isMuchSmallerThan().
*
* \sa operator!=(const MatrixBase<OtherDerived> &) const
*/
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
operator!=(Scalar s) const
{
return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)(_expression(),
typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
}
#endif
// scalar addition // scalar addition
@ -220,18 +123,6 @@ operator+(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>&
return other + scalar; return other + scalar;
} }
/** Adds the given \a scalar to each coeff of this expression.
*
* Example: \include Cwise_plus_equal.cpp
* Output: \verbinclude Cwise_plus_equal.out
*
* \sa operator+(), operator-=()
*/
// inline Derived& operator+=(const Scalar& scalar)
// {
// return derived() = *this + scalar;
// }
/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar /** \returns an expression of \c *this with each coeff decremented by the constant \a scalar
* *
* Example: \include Cwise_minus.cpp * Example: \include Cwise_minus.cpp
@ -250,15 +141,3 @@ operator-(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>&
{ {
return (-other) + scalar; return (-other) + scalar;
} }
/** Substracts the given \a scalar from each coeff of this expression.
*
* Example: \include Cwise_minus_equal.cpp
* Output: \verbinclude Cwise_minus_equal.out
*
* \sa operator+=(), operator-()
*/
// inline Derived& operator-=(const Scalar& scalar)
// {
// return derived() = *this - scalar;
// }

View File

@ -29,7 +29,7 @@
* *
* \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-().
* *
* \sa class CwiseBinaryOp, MatrixBase::operator-=() * \sa class CwiseBinaryOp, operator-=()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator-,ei_scalar_difference_op) EIGEN_MAKE_CWISE_BINARY_OP(operator-,ei_scalar_difference_op)
@ -37,7 +37,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator-,ei_scalar_difference_op)
* *
* \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). * \note If you want to add a given scalar to all coefficients, see Cwise::operator+().
* *
* \sa class CwiseBinaryOp, MatrixBase::operator+=() * \sa class CwiseBinaryOp, operator+=()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator+,ei_scalar_sum_op) EIGEN_MAKE_CWISE_BINARY_OP(operator+,ei_scalar_sum_op)
@ -50,7 +50,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator+,ei_scalar_sum_op)
* \include class_CwiseBinaryOp.cpp * \include class_CwiseBinaryOp.cpp
* Output: \verbinclude class_CwiseBinaryOp.out * Output: \verbinclude class_CwiseBinaryOp.out
* *
* \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct * \sa class CwiseBinaryOp, operator+, operator-, cwiseProduct
*/ */
template<typename CustomBinaryOp, typename OtherDerived> template<typename CustomBinaryOp, typename OtherDerived>
EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>

View File

@ -27,28 +27,28 @@
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
/** \internal Represents a scalar multiple of a matrix */ /** \internal Represents a scalar multiple of an expression */
typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType; typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType;
/** \internal Represents a quotient of a matrix by a scalar*/ /** \internal Represents a quotient of an expression by a scalar*/
typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType; typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType;
/** \internal the return type of MatrixBase::conjugate() */ /** \internal the return type of conjugate() */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
const CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>, const CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
const Derived& const Derived&
>::ret ConjugateReturnType; >::ret ConjugateReturnType;
/** \internal the return type of MatrixBase::real() const */ /** \internal the return type of real() const */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
const CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived>, const CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived>,
const Derived& const Derived&
>::ret RealReturnType; >::ret RealReturnType;
/** \internal the return type of MatrixBase::real() */ /** \internal the return type of real() */
typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex,
CwiseUnaryView<ei_scalar_real_op<Scalar>, Derived>, CwiseUnaryView<ei_scalar_real_op<Scalar>, Derived>,
Derived& Derived&
>::ret NonConstRealReturnType; >::ret NonConstRealReturnType;
/** \internal the return type of MatrixBase::imag() const */ /** \internal the return type of imag() const */
typedef CwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType; typedef CwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType;
/** \internal the return type of MatrixBase::imag() */ /** \internal the return type of imag() */
typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnType; typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnType;
#endif // not EIGEN_PARSED_BY_DOXYGEN #endif // not EIGEN_PARSED_BY_DOXYGEN
@ -139,7 +139,7 @@ imag() const { return derived(); }
* \include class_CwiseUnaryOp.cpp * \include class_CwiseUnaryOp.cpp
* Output: \verbinclude class_CwiseUnaryOp.out * Output: \verbinclude class_CwiseUnaryOp.out
* *
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs * \sa class CwiseUnaryOp, class CwiseBinarOp
*/ */
template<typename CustomUnaryOp> template<typename CustomUnaryOp>
inline const CwiseUnaryOp<CustomUnaryOp, Derived> inline const CwiseUnaryOp<CustomUnaryOp, Derived>
@ -157,7 +157,7 @@ unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
* \include class_CwiseUnaryOp.cpp * \include class_CwiseUnaryOp.cpp
* Output: \verbinclude class_CwiseUnaryOp.out * Output: \verbinclude class_CwiseUnaryOp.out
* *
* \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs * \sa class CwiseUnaryOp, class CwiseBinarOp
*/ */
template<typename CustomViewOp> template<typename CustomViewOp>
inline const CwiseUnaryView<CustomViewOp, Derived> inline const CwiseUnaryView<CustomViewOp, Derived>

View File

@ -43,13 +43,13 @@ cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
* *
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types. * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
* generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
* MatrixBase::isMuchSmallerThan(). * isMuchSmallerThan().
* *
* Example: \include MatrixBase_cwiseEqual.cpp * Example: \include MatrixBase_cwiseEqual.cpp
* Output: \verbinclude MatrixBase_cwiseEqual.out * Output: \verbinclude MatrixBase_cwiseEqual.out
* *
* \sa MatrixBase::cwiseNotEqual(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() * \sa cwiseNotEqual(), isApprox(), isMuchSmallerThan()
*/ */
template<typename OtherDerived> template<typename OtherDerived>
inline const CwiseBinaryOp<std::equal_to<Scalar>, Derived, OtherDerived> inline const CwiseBinaryOp<std::equal_to<Scalar>, Derived, OtherDerived>
@ -62,13 +62,13 @@ cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
* *
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types. * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
* generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
* MatrixBase::isMuchSmallerThan(). * isMuchSmallerThan().
* *
* Example: \include MatrixBase_cwiseNotEqual.cpp * Example: \include MatrixBase_cwiseNotEqual.cpp
* Output: \verbinclude MatrixBase_cwiseNotEqual.out * Output: \verbinclude MatrixBase_cwiseNotEqual.out
* *
* \sa MatrixBase::cwiseEqual(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() * \sa cwiseEqual(), isApprox(), isMuchSmallerThan()
*/ */
template<typename OtherDerived> template<typename OtherDerived>
inline const CwiseBinaryOp<std::not_equal_to<Scalar>, Derived, OtherDerived> inline const CwiseBinaryOp<std::not_equal_to<Scalar>, Derived, OtherDerived>

View File

@ -69,8 +69,8 @@ cwiseInverse() const { return derived(); }
* *
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types. * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
* generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
* MatrixBase::isMuchSmallerThan(). * isMuchSmallerThan().
* *
* \sa cwiseEqual(const MatrixBase<OtherDerived> &) const * \sa cwiseEqual(const MatrixBase<OtherDerived> &) const
*/ */