10#ifndef EIGEN_CWISE_NULLARY_OP_H
11#define EIGEN_CWISE_NULLARY_OP_H
34template<
typename NullaryOp,
typename PlainObjectType>
35struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
38 Flags = (traits<PlainObjectType>::Flags
43 CoeffReadCost = functor_traits<NullaryOp>::Cost
48template<
typename NullaryOp,
typename PlainObjectType>
49class CwiseNullaryOp : internal::no_assignment_operator,
50 public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type
54 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
55 EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
57 CwiseNullaryOp(Index rows, Index cols,
const NullaryOp& func = NullaryOp())
58 : m_rows(rows), m_cols(cols), m_functor(func)
60 eigen_assert(rows >= 0
61 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
63 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
66 EIGEN_STRONG_INLINE Index rows()
const {
return m_rows.value(); }
67 EIGEN_STRONG_INLINE Index cols()
const {
return m_cols.value(); }
69 EIGEN_STRONG_INLINE
const Scalar coeff(Index rows, Index cols)
const
71 return m_functor(rows, cols);
74 template<
int LoadMode>
75 EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col)
const
77 return m_functor.packetOp(row, col);
80 EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const
82 return m_functor(index);
85 template<
int LoadMode>
86 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const
88 return m_functor.packetOp(index);
92 const NullaryOp&
functor()
const {
return m_functor; }
95 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
96 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
97 const NullaryOp m_functor;
114template<
typename Derived>
115template<
typename CustomNullaryOp>
116EIGEN_STRONG_INLINE
const CwiseNullaryOp<CustomNullaryOp, Derived>
137template<
typename Derived>
138template<
typename CustomNullaryOp>
142 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
156template<
typename Derived>
157template<
typename CustomNullaryOp>
177template<
typename Derived>
199template<
typename Derived>
215template<
typename Derived>
219 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
240template<
typename Derived>
244 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
252template<
typename Derived>
256 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
257 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
274template<
typename Derived>
278 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
286template<
typename Derived>
290 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
291 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
296template<
typename Derived>
298(
const Scalar&
value, RealScalar prec)
const
300 for(
Index j = 0; j < cols(); ++j)
301 for(
Index i = 0; i < rows(); ++i)
302 if(!internal::isApprox(this->coeff(i, j),
value, prec))
310template<
typename Derived>
312(
const Scalar&
value, RealScalar prec)
const
321template<
typename Derived>
331template<
typename Derived>
346template<
typename Derived>
347EIGEN_STRONG_INLINE Derived&
365template<
typename Derived>
366EIGEN_STRONG_INLINE Derived&
386template<
typename Derived>
389 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
390 return derived() = Derived::NullaryExpr(size, internal::linspaced_op<Scalar,false>(low,high,size));
403template<
typename Derived>
406 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
426template<
typename Derived>
430 return Constant(rows, cols, Scalar(0));
449template<
typename Derived>
466template<
typename Derived>
481template<
typename Derived>
484 for(
Index j = 0; j < cols(); ++j)
485 for(
Index i = 0; i < rows(); ++i)
486 if(!internal::isMuchSmallerThan(this->coeff(i, j),
static_cast<Scalar
>(1), prec))
498template<
typename Derived>
513template<
typename Derived>
514EIGEN_STRONG_INLINE Derived&
531template<
typename Derived>
532EIGEN_STRONG_INLINE Derived&
555template<
typename Derived>
559 return Constant(rows, cols, Scalar(1));
578template<
typename Derived>
595template<
typename Derived>
610template<
typename Derived>
612(RealScalar prec)
const
624template<
typename Derived>
639template<
typename Derived>
640EIGEN_STRONG_INLINE Derived&
657template<
typename Derived>
658EIGEN_STRONG_INLINE Derived&
681template<
typename Derived>
698template<
typename Derived>
702 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
715template<
typename Derived>
717(RealScalar prec)
const
719 for(
Index j = 0; j < cols(); ++j)
721 for(
Index i = 0; i < rows(); ++i)
725 if(!internal::isApprox(this->coeff(i, j),
static_cast<Scalar
>(1), prec))
730 if(!internal::isMuchSmallerThan(this->coeff(i, j),
static_cast<RealScalar
>(1), prec))
740template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
741struct setIdentity_impl
743 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
745 return m = Derived::Identity(m.rows(), m.cols());
749template<
typename Derived>
750struct setIdentity_impl<Derived, true>
752 typedef typename Derived::Index Index;
753 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
756 const Index size = (std::min)(m.rows(), m.cols());
757 for(Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
771template<
typename Derived>
774 return internal::setIdentity_impl<Derived>::run(derived());
787template<
typename Derived>
790 derived().resize(rows, cols);
800template<
typename Derived>
803 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
804 return BasisReturnType(SquareMatrixType::Identity(size,size), i);
815template<
typename Derived>
818 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
819 return BasisReturnType(SquareMatrixType::Identity(),i);
828template<
typename Derived>
830{
return Derived::Unit(0); }
838template<
typename Derived>
840{
return Derived::Unit(1); }
848template<
typename Derived>
850{
return Derived::Unit(2); }
858template<
typename Derived>
860{
return Derived::Unit(3); }
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:51
const NullaryOp & functor() const
Definition CwiseNullaryOp.h:92
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:38
static const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
Definition CwiseNullaryOp.h:242
static const CwiseNullaryOp< CustomNullaryOp, Derived > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:117
Derived & setOnes()
Definition CwiseNullaryOp.h:625
static const ConstantReturnType Ones()
Definition CwiseNullaryOp.h:597
static const ConstantReturnType Zero()
Definition CwiseNullaryOp.h:468
Derived & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:332
DenseBase()
Definition DenseBase.h:513
internal::traits< Derived >::Index Index
The type of indices.
Definition DenseBase.h:51
bool isZero(RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:482
bool isOnes(RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:612
Derived & setZero()
Definition CwiseNullaryOp.h:499
CoeffReturnType value() const
Definition DenseBase.h:434
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:322
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition CwiseNullaryOp.h:179
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
Definition CwiseNullaryOp.h:387
bool isConstant(const Scalar &value, RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:312
@ RowsAtCompileTime
Definition DenseBase.h:92
@ ColsAtCompileTime
Definition DenseBase.h:98
bool isApproxToConstant(const Scalar &value, RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:298
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
static const IdentityReturnType Identity()
Definition CwiseNullaryOp.h:700
static const BasisReturnType UnitZ()
Definition CwiseNullaryOp.h:849
static const BasisReturnType UnitW()
Definition CwiseNullaryOp.h:859
static const BasisReturnType UnitX()
Definition CwiseNullaryOp.h:829
bool isIdentity(RealScalar prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:717
static const BasisReturnType UnitY()
Definition CwiseNullaryOp.h:839
static const BasisReturnType Unit(Index size, Index i)
Definition CwiseNullaryOp.h:801
Derived & setIdentity()
Definition CwiseNullaryOp.h:772
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:515
Derived & setOnes(Index size)
Definition CwiseNullaryOp.h:641
Derived & setConstant(Index size, const Scalar &value)
Definition CwiseNullaryOp.h:348
void resize(Index rows, Index cols)
Definition PlainObjectBase.h:219
const unsigned int PacketAccessBit
Definition Constants.h:76
const unsigned int LinearAccessBit
Definition Constants.h:112
const unsigned int EvalBeforeNestingBit
Definition Constants.h:53