10 #ifndef EIGEN_CWISE_NULLARY_OP_H
11 #define EIGEN_CWISE_NULLARY_OP_H
13 #include "./InternalHeaderCheck.h"
18 template<
typename NullaryOp,
typename PlainObjectType>
19 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
22 Flags = traits<PlainObjectType>::Flags &
RowMajorBit
61 template<
typename NullaryOp,
typename PlainObjectType>
62 class CwiseNullaryOp :
public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
66 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
71 : m_rows(rows), m_cols(cols), m_functor(func)
73 eigen_assert(rows >= 0
74 && (RowsAtCompileTime ==
Dynamic || RowsAtCompileTime == rows)
76 && (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == cols));
79 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
80 Index rows()
const {
return m_rows.value(); }
81 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
82 Index cols()
const {
return m_cols.value(); }
86 const NullaryOp&
functor()
const {
return m_functor; }
89 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
90 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
91 const NullaryOp m_functor;
108 template<
typename Derived>
109 template<
typename CustomNullaryOp>
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
111 #ifndef EIGEN_PARSED_BY_DOXYGEN
112 const CwiseNullaryOp<CustomNullaryOp,typename DenseBase<Derived>::PlainObject>
114 const CwiseNullaryOp<CustomNullaryOp,PlainObject>
139 template<
typename Derived>
140 template<
typename CustomNullaryOp>
141 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
142 #ifndef EIGEN_PARSED_BY_DOXYGEN
149 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
163 template<
typename Derived>
164 template<
typename CustomNullaryOp>
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
166 #ifndef EIGEN_PARSED_BY_DOXYGEN
189 template<
typename Derived>
211 template<
typename Derived>
227 template<
typename Derived>
231 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
244 template<
typename Derived>
248 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
256 template<
typename Derived>
260 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
261 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
288 template<
typename Derived>
292 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
300 template<
typename Derived>
304 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
305 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
310 template<
typename Derived>
312 (
const Scalar& val,
const RealScalar& prec)
const
314 typename internal::nested_eval<Derived,1>::type
self(derived());
315 for(
Index j = 0; j < cols(); ++j)
316 for(
Index i = 0; i < rows(); ++i)
317 if(!internal::isApprox(
self.coeff(i, j), val, prec))
325 template<
typename Derived>
327 (
const Scalar& val,
const RealScalar& prec)
const
329 return isApproxToConstant(val, prec);
336 template<
typename Derived>
346 template<
typename Derived>
349 return derived() = Constant(rows(), cols(), val);
361 template<
typename Derived>
362 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
366 return setConstant(val);
380 template<
typename Derived>
381 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
385 return setConstant(val);
394 template<
typename Derived>
395 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
398 return setConstant(rows(), cols, val);
407 template<
typename Derived>
408 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
411 return setConstant(rows, cols(), val);
431 template<
typename Derived>
434 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
435 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
451 template<
typename Derived>
454 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
455 return setLinSpaced(size(), low, high);
474 template<
typename Derived>
478 return Constant(rows, cols,
Scalar(0));
497 template<
typename Derived>
501 return Constant(size,
Scalar(0));
514 template<
typename Derived>
518 return Constant(
Scalar(0));
529 template<
typename Derived>
532 typename internal::nested_eval<Derived,1>::type
self(derived());
533 for(
Index j = 0; j < cols(); ++j)
534 for(
Index i = 0; i < rows(); ++i)
535 if(!internal::isMuchSmallerThan(
self.coeff(i, j),
static_cast<Scalar>(1), prec))
547 template<
typename Derived>
550 return setConstant(
Scalar(0));
562 template<
typename Derived>
563 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
567 return setConstant(Scalar(0));
580 template<
typename Derived>
581 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
585 return setConstant(Scalar(0));
594 template<
typename Derived>
595 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
598 return setZero(rows(), cols);
607 template<
typename Derived>
608 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
611 return setZero(rows, cols());
630 template<
typename Derived>
634 return Constant(rows, cols,
Scalar(1));
653 template<
typename Derived>
657 return Constant(newSize,
Scalar(1));
670 template<
typename Derived>
674 return Constant(
Scalar(1));
685 template<
typename Derived>
687 (
const RealScalar& prec)
const
689 return isApproxToConstant(
Scalar(1), prec);
699 template<
typename Derived>
702 return setConstant(
Scalar(1));
714 template<
typename Derived>
715 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
719 return setConstant(Scalar(1));
732 template<
typename Derived>
733 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
737 return setConstant(Scalar(1));
746 template<
typename Derived>
747 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
750 return setOnes(rows, cols());
759 template<
typename Derived>
760 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
763 return setOnes(rows(), cols);
782 template<
typename Derived>
799 template<
typename Derived>
803 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
816 template<
typename Derived>
818 (
const RealScalar& prec)
const
820 typename internal::nested_eval<Derived,1>::type
self(derived());
821 for(
Index j = 0; j < cols(); ++j)
823 for(
Index i = 0; i < rows(); ++i)
827 if(!internal::isApprox(
self.coeff(i, j),
static_cast<Scalar>(1), prec))
832 if(!internal::isMuchSmallerThan(
self.coeff(i, j),
static_cast<RealScalar
>(1), prec))
842 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
843 struct setIdentity_impl
846 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
848 return m = Derived::Identity(m.rows(), m.cols());
852 template<
typename Derived>
853 struct setIdentity_impl<Derived, true>
856 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
859 const Index size = numext::mini(m.rows(), m.cols());
860 for(
Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
874 template<
typename Derived>
877 return internal::setIdentity_impl<Derived>::run(derived());
890 template<
typename Derived>
893 derived().resize(rows, cols);
894 return setIdentity();
903 template<
typename Derived>
906 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
907 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
918 template<
typename Derived>
921 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
922 return BasisReturnType(SquareMatrixType::Identity(),i);
931 template<
typename Derived>
933 {
return Derived::Unit(0); }
941 template<
typename Derived>
943 {
return Derived::Unit(1); }
951 template<
typename Derived>
953 {
return Derived::Unit(2); }
961 template<
typename Derived>
963 {
return Derived::Unit(3); }
973 template<
typename Derived>
976 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
977 eigen_assert(i<size());
979 derived().coeffRef(i) =
Scalar(1);
992 template<
typename Derived>
995 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
996 eigen_assert(i<newSize);
997 derived().resize(newSize);
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:63
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:86
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:42
static EIGEN_DEPRECATED const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition: CwiseNullaryOp.h:246
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:327
Derived & setOnes()
Definition: CwiseNullaryOp.h:700
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:672
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition: CwiseNullaryOp.h:116
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:516
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:432
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition: CwiseNullaryOp.h:191
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:337
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:687
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:347
Derived & setZero()
Definition: CwiseNullaryOp.h:548
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:530
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:312
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:942
Derived & setIdentity()
Definition: CwiseNullaryOp.h:875
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:818
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:932
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:801
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:952
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:904
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition: CwiseNullaryOp.h:974
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:962
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:716
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:363
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:564
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41