10 #ifndef EIGEN_CWISE_NULLARY_OP_H 11 #define EIGEN_CWISE_NULLARY_OP_H 14 #include "./InternalHeaderCheck.h" 19 template <
typename NullaryOp,
typename PlainObjectType>
20 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType> {
21 enum { Flags = traits<PlainObjectType>::Flags &
RowMajorBit };
62 template <
typename NullaryOp,
typename PlainObjectType>
63 class CwiseNullaryOp :
public internal::dense_xpr_base<CwiseNullaryOp<NullaryOp, PlainObjectType> >::type,
64 internal::no_assignment_operator {
66 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
70 : m_rows(rows), m_cols(cols), m_functor(func) {
71 eigen_assert(rows >= 0 && (RowsAtCompileTime ==
Dynamic || RowsAtCompileTime == rows) && cols >= 0 &&
72 (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == cols));
75 :
CwiseNullaryOp(RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? size : 1, func) {
76 EIGEN_STATIC_ASSERT(CwiseNullaryOp::IsVectorAtCompileTime, YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
79 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
Index rows()
const {
return m_rows.value(); }
80 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
Index cols()
const {
return m_cols.value(); }
83 EIGEN_DEVICE_FUNC
const NullaryOp&
functor()
const {
return m_functor; }
86 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
87 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
88 const NullaryOp m_functor;
104 template <
typename Derived>
105 template <
typename CustomNullaryOp>
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
107 #ifndef EIGEN_PARSED_BY_DOXYGEN 108 const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
110 const CwiseNullaryOp<CustomNullaryOp, PlainObject>
134 template <
typename Derived>
135 template <
typename CustomNullaryOp>
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
137 #ifndef EIGEN_PARSED_BY_DOXYGEN 143 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
144 if (RowsAtCompileTime == 1)
159 template <
typename Derived>
160 template <
typename CustomNullaryOp>
161 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
162 #ifndef EIGEN_PARSED_BY_DOXYGEN 184 template <
typename Derived>
205 template <
typename Derived>
220 template <
typename Derived>
223 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
225 internal::scalar_constant_op<Scalar>(value));
237 template <
typename Derived>
240 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
248 template <
typename Derived>
251 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
252 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
254 internal::linspaced_op<Scalar>(low, high, Derived::SizeAtCompileTime));
280 template <
typename Derived>
283 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
291 template <
typename Derived>
294 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
295 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
297 internal::linspaced_op<Scalar>(low, high, Derived::SizeAtCompileTime));
300 template <
typename Derived>
303 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
307 template <
typename Derived>
308 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename DenseBase<Derived>::RandomAccessEqualSpacedReturnType
309 DenseBase<Derived>::EqualSpaced(
const Scalar& low,
const Scalar& step) {
310 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
315 template <
typename Derived>
317 typename internal::nested_eval<Derived, 1>::type
self(derived());
318 for (
Index j = 0; j < cols(); ++j)
319 for (
Index i = 0; i < rows(); ++i)
320 if (!internal::isApprox(
self.coeff(i, j), val, prec))
return false;
327 template <
typename Derived>
329 return isApproxToConstant(val, prec);
336 template <
typename Derived>
346 template <
typename Derived>
348 internal::eigen_fill_impl<Derived>::run(derived(), val);
362 template <
typename Derived>
365 return setConstant(val);
380 template <
typename Derived>
384 return setConstant(val);
394 template <
typename Derived>
397 return setConstant(rows(), cols, val);
407 template <
typename Derived>
410 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>
451 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
452 return setLinSpaced(size(), low, high);
455 template <
typename Derived>
457 const Scalar& step) {
458 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
459 return derived() = Derived::NullaryExpr(newSize, internal::equalspaced_op<Scalar>(low, step));
461 template <
typename Derived>
462 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(
const Scalar& low,
463 const Scalar& step) {
464 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
465 return setEqualSpaced(size(), low, step);
484 template <
typename Derived>
487 return ZeroReturnType(rows, cols);
506 template <
typename Derived>
509 return ZeroReturnType(size);
522 template <
typename Derived>
524 return ZeroReturnType(RowsAtCompileTime, ColsAtCompileTime);
535 template <
typename Derived>
537 typename internal::nested_eval<Derived, 1>::type
self(derived());
538 for (
Index j = 0; j < cols(); ++j)
539 for (
Index i = 0; i < rows(); ++i)
540 if (!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<Scalar>(1), prec))
return false;
551 template <
typename Derived>
553 internal::eigen_zero_impl<Derived>::run(derived());
566 template <
typename Derived>
582 template <
typename Derived>
595 template <
typename Derived>
597 return setZero(rows(), cols);
607 template <
typename Derived>
609 return setZero(rows, cols());
628 template <
typename Derived>
631 return Constant(rows, cols,
Scalar(1));
650 template <
typename Derived>
653 return Constant(newSize,
Scalar(1));
666 template <
typename Derived>
668 return Constant(
Scalar(1));
679 template <
typename Derived>
681 return isApproxToConstant(
Scalar(1), prec);
691 template <
typename Derived>
693 return setConstant(
Scalar(1));
705 template <
typename Derived>
708 return setConstant(Scalar(1));
721 template <
typename Derived>
724 return setConstant(Scalar(1));
734 template <
typename Derived>
736 return setOnes(rows, cols());
746 template <
typename Derived>
748 return setOnes(rows(), cols);
767 template <
typename Derived>
783 template <
typename Derived>
786 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
799 template <
typename Derived>
801 typename internal::nested_eval<Derived, 1>::type
self(derived());
802 for (
Index j = 0; j < cols(); ++j) {
803 for (
Index i = 0; i < rows(); ++i) {
805 if (!internal::isApprox(
self.coeff(i, j), static_cast<Scalar>(1), prec))
return false;
807 if (!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<RealScalar>(1), prec))
return false;
816 template <
typename Derived,
bool Big = (Derived::SizeAtCompileTime >= 16)>
817 struct setIdentity_impl {
818 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
819 return m = Derived::Identity(m.rows(), m.cols());
823 template <
typename Derived>
824 struct setIdentity_impl<Derived, true> {
825 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
827 const Index size = numext::mini(m.rows(), m.cols());
828 for (
Index i = 0; i < size; ++i) m.coeffRef(i, i) =
typename Derived::Scalar(1);
842 template <
typename Derived>
844 return internal::setIdentity_impl<Derived>::run(derived());
857 template <
typename Derived>
859 derived().resize(rows, cols);
860 return setIdentity();
869 template <
typename Derived>
872 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
873 return BasisReturnType(SquareMatrixType::Identity(newSize, newSize), i);
884 template <
typename Derived>
887 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
888 return BasisReturnType(SquareMatrixType::Identity(), i);
898 template <
typename Derived>
900 return Derived::Unit(0);
910 template <
typename Derived>
912 return Derived::Unit(1);
922 template <
typename Derived>
924 return Derived::Unit(2);
934 template <
typename Derived>
936 return Derived::Unit(3);
947 template <
typename Derived>
949 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
950 eigen_assert(i < size());
952 derived().coeffRef(i) =
Scalar(1);
965 template <
typename Derived>
967 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
968 eigen_assert(i < newSize);
969 derived().resize(newSize);
975 #endif // EIGEN_CWISE_NULLARY_OP_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:63
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:536
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
static const ZeroReturnType Zero()
Definition: CwiseNullaryOp.h:523
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:935
static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition: CwiseNullaryOp.h:239
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Derived & setIdentity()
Definition: CwiseNullaryOp.h:843
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
const unsigned int RowMajorBit
Definition: Constants.h:70
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:38
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition: CwiseNullaryOp.h:186
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:706
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:567
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:899
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition: CwiseNullaryOp.h:112
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:337
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:328
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:911
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:363
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:870
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:667
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:430
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:785
Derived & setZero()
Definition: CwiseNullaryOp.h:552
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:316
Derived & setOnes()
Definition: CwiseNullaryOp.h:692
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:347
const int Dynamic
Definition: Constants.h:25
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:800
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:83
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:680
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:923
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition: CwiseNullaryOp.h:948