10 #ifndef EIGEN_CWISE_NULLARY_OP_H
11 #define EIGEN_CWISE_NULLARY_OP_H
34 template<
typename NullaryOp,
typename PlainObjectType>
35 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
38 Flags = (traits<PlainObjectType>::Flags
43 CoeffReadCost = functor_traits<NullaryOp>::Cost
48 template<
typename NullaryOp,
typename PlainObjectType>
50 public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type
54 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
57 CwiseNullaryOp(Index nbRows, Index nbCols,
const NullaryOp& func = NullaryOp())
58 : m_rows(nbRows), m_cols(nbCols), m_functor(func)
60 eigen_assert(nbRows >= 0
61 && (RowsAtCompileTime ==
Dynamic || RowsAtCompileTime == nbRows)
63 && (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == nbCols));
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 rowId, Index colId)
const
71 return m_functor(rowId, colId);
74 template<
int LoadMode>
75 EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId)
const
77 return m_functor.packetOp(rowId, colId);
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;
114 template<
typename Derived>
115 template<
typename CustomNullaryOp>
116 EIGEN_STRONG_INLINE
const CwiseNullaryOp<CustomNullaryOp, Derived>
137 template<
typename Derived>
138 template<
typename CustomNullaryOp>
142 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
156 template<
typename Derived>
157 template<
typename CustomNullaryOp>
177 template<
typename Derived>
199 template<
typename Derived>
215 template<
typename Derived>
219 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
240 template<
typename Derived>
244 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
252 template<
typename Derived>
256 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
257 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
274 template<
typename Derived>
278 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
286 template<
typename Derived>
290 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
291 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
296 template<
typename Derived>
298 (
const Scalar& val,
const 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), val, prec))
310 template<
typename Derived>
312 (
const Scalar& val,
const RealScalar& prec)
const
314 return isApproxToConstant(val, prec);
321 template<
typename Derived>
331 template<
typename Derived>
334 return derived() = Constant(rows(), cols(), val);
346 template<
typename Derived>
347 EIGEN_STRONG_INLINE Derived&
351 return setConstant(val);
365 template<
typename Derived>
366 EIGEN_STRONG_INLINE Derived&
369 resize(nbRows, nbCols);
370 return setConstant(val);
386 template<
typename Derived>
389 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
390 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,false>(low,high,newSize));
403 template<
typename Derived>
406 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
407 return setLinSpaced(size(), low, high);
426 template<
typename Derived>
430 return Constant(nbRows, nbCols, Scalar(0));
449 template<
typename Derived>
453 return Constant(size, Scalar(0));
466 template<
typename Derived>
470 return Constant(Scalar(0));
481 template<
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))
498 template<
typename Derived>
501 return setConstant(Scalar(0));
513 template<
typename Derived>
514 EIGEN_STRONG_INLINE Derived&
518 return setConstant(Scalar(0));
531 template<
typename Derived>
532 EIGEN_STRONG_INLINE Derived&
535 resize(nbRows, nbCols);
536 return setConstant(Scalar(0));
555 template<
typename Derived>
559 return Constant(nbRows, nbCols, Scalar(1));
578 template<
typename Derived>
582 return Constant(newSize, Scalar(1));
595 template<
typename Derived>
599 return Constant(Scalar(1));
610 template<
typename Derived>
612 (
const RealScalar& prec)
const
614 return isApproxToConstant(Scalar(1), prec);
624 template<
typename Derived>
627 return setConstant(Scalar(1));
639 template<
typename Derived>
640 EIGEN_STRONG_INLINE Derived&
644 return setConstant(Scalar(1));
657 template<
typename Derived>
658 EIGEN_STRONG_INLINE Derived&
661 resize(nbRows, nbCols);
662 return setConstant(Scalar(1));
681 template<
typename Derived>
698 template<
typename Derived>
702 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
715 template<
typename Derived>
717 (
const 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))
740 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
741 struct setIdentity_impl
743 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
745 return m = Derived::Identity(m.rows(), m.cols());
749 template<
typename Derived>
750 struct 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);
771 template<
typename Derived>
774 return internal::setIdentity_impl<Derived>::run(derived());
787 template<
typename Derived>
790 derived().resize(nbRows, nbCols);
791 return setIdentity();
800 template<
typename Derived>
803 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
804 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
815 template<
typename Derived>
818 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
819 return BasisReturnType(SquareMatrixType::Identity(),i);
828 template<
typename Derived>
830 {
return Derived::Unit(0); }
838 template<
typename Derived>
840 {
return Derived::Unit(1); }
848 template<
typename Derived>
850 {
return Derived::Unit(2); }
858 template<
typename Derived>
860 {
return Derived::Unit(3); }
864 #endif // EIGEN_CWISE_NULLARY_OP_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:49
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:58
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:641
static const CwiseNullaryOp< CustomNullaryOp, Derived > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition: CwiseNullaryOp.h:117
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:717
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:322
Derived & setOnes()
Definition: CwiseNullaryOp.h:625
Derived & setZero()
Definition: CwiseNullaryOp.h:499
const int Dynamic
Definition: Constants.h:21
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:849
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:482
const unsigned int PacketAccessBit
Definition: Constants.h:81
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:859
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:298
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
Definition: CwiseNullaryOp.h:387
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:332
const unsigned int LinearAccessBit
Definition: Constants.h:117
Derived & setConstant(Index size, const Scalar &value)
Definition: CwiseNullaryOp.h:348
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:829
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:92
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:312
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:597
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:612
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 IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:700
Derived & setIdentity()
Definition: CwiseNullaryOp.h:772
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:468
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:839
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:801
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition: CwiseNullaryOp.h:179
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:515