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));
78 EIGEN_STRONG_INLINE
Index rows()
const {
return m_rows.value(); }
80 EIGEN_STRONG_INLINE
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>
132 template<
typename Derived>
133 template<
typename CustomNullaryOp>
137 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
151 template<
typename Derived>
152 template<
typename CustomNullaryOp>
172 template<
typename Derived>
194 template<
typename Derived>
210 template<
typename Derived>
214 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
222 template<
typename Derived>
226 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
234 template<
typename Derived>
238 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
239 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
266 template<
typename Derived>
270 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
278 template<
typename Derived>
282 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
283 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
288 template<
typename Derived>
290 (
const Scalar& val,
const RealScalar& prec)
const 292 typename internal::nested_eval<Derived,1>::type
self(derived());
293 for(
Index j = 0; j < cols(); ++j)
294 for(
Index i = 0; i < rows(); ++i)
295 if(!internal::isApprox(
self.coeff(i, j), val, prec))
303 template<
typename Derived>
305 (
const Scalar& val,
const RealScalar& prec)
const 307 return isApproxToConstant(val, prec);
314 template<
typename Derived>
324 template<
typename Derived>
327 return derived() = Constant(rows(), cols(), val);
339 template<
typename Derived>
340 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
344 return setConstant(val);
358 template<
typename Derived>
359 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
363 return setConstant(val);
382 template<
typename Derived>
385 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
386 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,PacketScalar>(low,high,newSize));
402 template<
typename Derived>
405 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
406 return setLinSpaced(size(), low, high);
425 template<
typename Derived>
429 return Constant(rows, cols,
Scalar(0));
448 template<
typename Derived>
452 return Constant(size,
Scalar(0));
465 template<
typename Derived>
469 return Constant(
Scalar(0));
480 template<
typename Derived>
483 typename internal::nested_eval<Derived,1>::type
self(derived());
484 for(
Index j = 0; j < cols(); ++j)
485 for(
Index i = 0; i < rows(); ++i)
486 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<Scalar>(1), prec))
498 template<
typename Derived>
501 return setConstant(
Scalar(0));
513 template<
typename Derived>
514 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
518 return setConstant(
Scalar(0));
531 template<
typename Derived>
532 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
536 return setConstant(
Scalar(0));
555 template<
typename Derived>
559 return Constant(rows, cols,
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_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
644 return setConstant(
Scalar(1));
657 template<
typename Derived>
658 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
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 typename internal::nested_eval<Derived,1>::type
self(derived());
720 for(
Index j = 0; j < cols(); ++j)
722 for(
Index i = 0; i < rows(); ++i)
726 if(!internal::isApprox(
self.coeff(i, j), static_cast<Scalar>(1), prec))
731 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<RealScalar>(1), prec))
741 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
742 struct setIdentity_impl
745 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
747 return m = Derived::Identity(m.rows(), m.cols());
751 template<
typename Derived>
752 struct setIdentity_impl<Derived, true>
755 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
758 const Index size = numext::mini(m.rows(), m.cols());
759 for(
Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
773 template<
typename Derived>
776 return internal::setIdentity_impl<Derived>::run(derived());
789 template<
typename Derived>
792 derived().resize(rows, cols);
793 return setIdentity();
802 template<
typename Derived>
805 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
806 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
817 template<
typename Derived>
820 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
821 return BasisReturnType(SquareMatrixType::Identity(),i);
830 template<
typename Derived>
832 {
return Derived::Unit(0); }
840 template<
typename Derived>
842 {
return Derived::Unit(1); }
850 template<
typename Derived>
852 {
return Derived::Unit(2); }
860 template<
typename Derived>
862 {
return Derived::Unit(3); }
866 #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:481
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:861
static const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition: CwiseNullaryOp.h:224
Namespace containing all symbols from the Eigen library.
Definition: Core:287
Derived & setIdentity()
Definition: CwiseNullaryOp.h:774
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:38
const unsigned int RowMajorBit
Definition: Constants.h:61
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:174
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:641
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:515
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:831
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:467
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:315
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:305
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:841
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:341
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:803
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:597
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:383
Definition: Eigen_Colamd.h:50
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:700
Derived & setZero()
Definition: CwiseNullaryOp.h:499
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:290
Derived & setOnes()
Definition: CwiseNullaryOp.h:625
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:325
const int Dynamic
Definition: Constants.h:21
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:717
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:84
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:612
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:851