10 #ifndef EIGEN_CWISE_NULLARY_OP_H 11 #define EIGEN_CWISE_NULLARY_OP_H 16 template<
typename NullaryOp,
typename PlainObjectType>
17 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
20 Flags = traits<PlainObjectType>::Flags &
RowMajorBit 59 template<
typename NullaryOp,
typename PlainObjectType>
60 class CwiseNullaryOp :
public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
64 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
69 : m_rows(rows), m_cols(cols), m_functor(func)
71 eigen_assert(rows >= 0
72 && (RowsAtCompileTime ==
Dynamic || RowsAtCompileTime == rows)
74 && (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == cols));
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
78 Index rows()
const {
return m_rows.value(); }
79 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
80 Index cols()
const {
return m_cols.value(); }
84 const NullaryOp&
functor()
const {
return m_functor; }
87 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
88 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
89 const NullaryOp m_functor;
106 template<
typename Derived>
107 template<
typename CustomNullaryOp>
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
109 #ifndef EIGEN_PARSED_BY_DOXYGEN 137 template<
typename Derived>
138 template<
typename CustomNullaryOp>
139 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
140 #ifndef EIGEN_PARSED_BY_DOXYGEN 147 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
161 template<
typename Derived>
162 template<
typename CustomNullaryOp>
163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
164 #ifndef EIGEN_PARSED_BY_DOXYGEN 187 template<
typename Derived>
209 template<
typename Derived>
225 template<
typename Derived>
229 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
242 template<
typename Derived>
246 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
254 template<
typename Derived>
258 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
259 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
286 template<
typename Derived>
290 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
298 template<
typename Derived>
302 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
303 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
308 template<
typename Derived>
310 (
const Scalar& val,
const RealScalar& prec)
const 312 typename internal::nested_eval<Derived,1>::type
self(derived());
313 for(
Index j = 0; j < cols(); ++j)
314 for(
Index i = 0; i < rows(); ++i)
315 if(!internal::isApprox(
self.coeff(i, j), val, prec))
323 template<
typename Derived>
325 (
const Scalar& val,
const RealScalar& prec)
const 327 return isApproxToConstant(val, prec);
334 template<
typename Derived>
344 template<
typename Derived>
347 return derived() = Constant(rows(), cols(), val);
359 template<
typename Derived>
360 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
364 return setConstant(val);
378 template<
typename Derived>
379 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
383 return setConstant(val);
392 template<
typename Derived>
393 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
396 return setConstant(rows(), cols, val);
405 template<
typename Derived>
406 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
409 return setConstant(rows, cols(), val);
429 template<
typename Derived>
432 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
433 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
449 template<
typename Derived>
452 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
453 return setLinSpaced(size(), low, high);
472 template<
typename Derived>
476 return Constant(rows, cols,
Scalar(0));
495 template<
typename Derived>
499 return Constant(size,
Scalar(0));
512 template<
typename Derived>
516 return Constant(
Scalar(0));
527 template<
typename Derived>
530 typename internal::nested_eval<Derived,1>::type
self(derived());
531 for(
Index j = 0; j < cols(); ++j)
532 for(
Index i = 0; i < rows(); ++i)
533 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<Scalar>(1), prec))
545 template<
typename Derived>
548 return setConstant(
Scalar(0));
560 template<
typename Derived>
561 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
565 return setConstant(Scalar(0));
578 template<
typename Derived>
579 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
583 return setConstant(Scalar(0));
592 template<
typename Derived>
593 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
596 return setZero(rows(), cols);
605 template<
typename Derived>
606 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
609 return setZero(rows, cols());
628 template<
typename Derived>
632 return Constant(rows, cols,
Scalar(1));
651 template<
typename Derived>
655 return Constant(newSize,
Scalar(1));
668 template<
typename Derived>
672 return Constant(
Scalar(1));
683 template<
typename Derived>
685 (
const RealScalar& prec)
const 687 return isApproxToConstant(
Scalar(1), prec);
697 template<
typename Derived>
700 return setConstant(
Scalar(1));
712 template<
typename Derived>
713 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
717 return setConstant(Scalar(1));
730 template<
typename Derived>
731 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
735 return setConstant(Scalar(1));
744 template<
typename Derived>
745 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
748 return setOnes(rows, cols());
757 template<
typename Derived>
758 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
761 return setOnes(rows(), cols);
780 template<
typename Derived>
797 template<
typename Derived>
801 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
814 template<
typename Derived>
816 (
const RealScalar& prec)
const 818 typename internal::nested_eval<Derived,1>::type
self(derived());
819 for(
Index j = 0; j < cols(); ++j)
821 for(
Index i = 0; i < rows(); ++i)
825 if(!internal::isApprox(
self.coeff(i, j), static_cast<Scalar>(1), prec))
830 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<RealScalar>(1), prec))
840 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
841 struct setIdentity_impl
844 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
846 return m = Derived::Identity(m.rows(), m.cols());
850 template<
typename Derived>
851 struct setIdentity_impl<Derived, true>
854 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
857 const Index size = numext::mini(m.rows(), m.cols());
858 for(
Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
872 template<
typename Derived>
875 return internal::setIdentity_impl<Derived>::run(derived());
888 template<
typename Derived>
891 derived().resize(rows, cols);
892 return setIdentity();
901 template<
typename Derived>
904 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
905 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
916 template<
typename Derived>
919 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
920 return BasisReturnType(SquareMatrixType::Identity(),i);
929 template<
typename Derived>
931 {
return Derived::Unit(0); }
939 template<
typename Derived>
941 {
return Derived::Unit(1); }
949 template<
typename Derived>
951 {
return Derived::Unit(2); }
959 template<
typename Derived>
961 {
return Derived::Unit(3); }
971 template<
typename Derived>
974 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
975 eigen_assert(i<size());
977 derived().coeffRef(i) =
Scalar(1);
990 template<
typename Derived>
993 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
994 eigen_assert(i<newSize);
995 derived().resize(newSize);
1001 #endif // EIGEN_CWISE_NULLARY_OP_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:60
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:528
static EIGEN_DEPRECATED const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition: CwiseNullaryOp.h:244
internal::traits< Solve< Decomposition, RhsType > >::Scalar Scalar
Definition: DenseBase.h:66
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:960
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Derived & setIdentity()
Definition: CwiseNullaryOp.h:873
const unsigned int RowMajorBit
Definition: Constants.h:66
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition: CwiseNullaryOp.h:189
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:714
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:930
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition: CwiseNullaryOp.h:114
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:514
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:335
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:325
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:940
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:361
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:902
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:670
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:430
Definition: Eigen_Colamd.h:50
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:799
Derived & setZero()
Definition: CwiseNullaryOp.h:546
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:310
Derived & setOnes()
Definition: CwiseNullaryOp.h:698
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:345
const int Dynamic
Definition: Constants.h:22
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:816
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:84
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:685
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:950
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition: CwiseNullaryOp.h:972