Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType > Class Template Reference

Generic expression of a matrix where all coefficients are defined by a functor. More...

Inherits internal::dense_xpr_base::type, and Eigen::internal::no_assignment_operator.

Public Types

typedef internal::dense_xpr_base< CwiseNullaryOp >::type Base
 

Public Member Functions

EIGEN_CONSTEXPR Index cols () const
 
 CwiseNullaryOp (Index rows, Index cols, const NullaryOp &func=NullaryOp())
 
const NullaryOp & functor () const
 
EIGEN_CONSTEXPR Index rows () const
 

Protected Attributes

const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
 
const NullaryOp m_functor
 
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
 

Detailed Description

template<typename NullaryOp, typename PlainObjectType>
class Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >

Generic expression of a matrix where all coefficients are defined by a functor.

Template Parameters
NullaryOptemplate functor implementing the operator
PlainObjectTypethe underlying plain matrix/array type

This class represents an expression of a generic nullary operator. 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.

However, if you want to write a function returning such an expression, you will need to use this class.

The functor NullaryOp must expose one of the following method:

operator()() if the procedural generation does not depend on the coefficient entries (e.g., random numbers)
operator()(Index i) if the procedural generation makes sense for vectors only and that it depends on the coefficient index i (e.g., linspace)
operator()(Index i,Index j) if the procedural generation depends on the matrix coordinates i, j (e.g., to generate a checkerboard with 0 and 1)

It is also possible to expose the last two operators if the generation makes sense for matrices but can be optimized for vectors.

See DenseBase::NullaryExpr(Index,const CustomNullaryOp&) for an example binding C++11 random number generators.

A nullary expression can also be used to implement custom sophisticated matrix manipulations that cannot be covered by the existing set of natively supported matrix manipulations. See this page for some examples and additional explanations on the behavior of CwiseNullaryOp.

See also
class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr

Definition at line 62 of file CwiseNullaryOp.h.

Member Typedef Documentation

◆ Base

template<typename NullaryOp , typename PlainObjectType >
typedef internal::dense_xpr_base<CwiseNullaryOp>::type Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::Base

Definition at line 66 of file CwiseNullaryOp.h.

Constructor & Destructor Documentation

◆ CwiseNullaryOp()

template<typename NullaryOp , typename PlainObjectType >
Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::CwiseNullaryOp ( Index  rows,
Index  cols,
const NullaryOp &  func = NullaryOp() 
)
inline

Definition at line 70 of file CwiseNullaryOp.h.

71  : m_rows(rows), m_cols(cols), m_functor(func)
72  {
73  eigen_assert(rows >= 0
74  && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
75  && cols >= 0
76  && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
77  }
#define eigen_assert(x)
Definition: Macros.h:902
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
EIGEN_CONSTEXPR Index rows() const
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
const NullaryOp m_functor
EIGEN_CONSTEXPR Index cols() const
const int Dynamic
Definition: Constants.h:24

Member Function Documentation

◆ cols()

template<typename NullaryOp , typename PlainObjectType >
EIGEN_CONSTEXPR Index Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::cols ( ) const
inline

Definition at line 82 of file CwiseNullaryOp.h.

82 { return m_cols.value(); }

◆ functor()

template<typename NullaryOp , typename PlainObjectType >
const NullaryOp& Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::functor ( ) const
inline
Returns
the functor representing the nullary operation

Definition at line 86 of file CwiseNullaryOp.h.

86 { return m_functor; }

◆ rows()

template<typename NullaryOp , typename PlainObjectType >
EIGEN_CONSTEXPR Index Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::rows ( ) const
inline

Definition at line 80 of file CwiseNullaryOp.h.

80 { return m_rows.value(); }

Member Data Documentation

◆ m_cols

template<typename NullaryOp , typename PlainObjectType >
const internal::variable_if_dynamic<Index, ColsAtCompileTime> Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::m_cols
protected

Definition at line 90 of file CwiseNullaryOp.h.

◆ m_functor

template<typename NullaryOp , typename PlainObjectType >
const NullaryOp Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::m_functor
protected

Definition at line 91 of file CwiseNullaryOp.h.

◆ m_rows

template<typename NullaryOp , typename PlainObjectType >
const internal::variable_if_dynamic<Index, RowsAtCompileTime> Eigen::CwiseNullaryOp< NullaryOp, PlainObjectType >::m_rows
protected

Definition at line 89 of file CwiseNullaryOp.h.


The documentation for this class was generated from the following file: