10#ifndef EIGEN_CWISE_NULLARY_OP_H
11#define EIGEN_CWISE_NULLARY_OP_H
13#include "./InternalHeaderCheck.h"
18template<
typename NullaryOp,
typename PlainObjectType>
19struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
22 Flags = traits<PlainObjectType>::Flags &
RowMajorBit
61template<
typename NullaryOp,
typename PlainObjectType>
62class 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;
108template<
typename Derived>
109template<
typename CustomNullaryOp>
110EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
111#ifndef EIGEN_PARSED_BY_DOXYGEN
112const CwiseNullaryOp<CustomNullaryOp,typename DenseBase<Derived>::PlainObject>
114const CwiseNullaryOp<CustomNullaryOp,PlainObject>
139template<
typename Derived>
140template<
typename CustomNullaryOp>
141EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
142#ifndef EIGEN_PARSED_BY_DOXYGEN
149 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
163template<
typename Derived>
164template<
typename CustomNullaryOp>
165EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
166#ifndef EIGEN_PARSED_BY_DOXYGEN
189template<
typename Derived>
211template<
typename Derived>
227template<
typename Derived>
231 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
244template<
typename Derived>
248 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
256template<
typename Derived>
260 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
261 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
262 return
DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<
Scalar>(low,high,Derived::SizeAtCompileTime));
288template<typename Derived>
289EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename
DenseBase<Derived>::RandomAccessLinSpacedReturnType
292 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
300template<
typename Derived>
304 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
305 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
310template<
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))
325template<
typename Derived>
327(
const Scalar& val,
const RealScalar& prec)
const
329 return isApproxToConstant(val, prec);
336template<
typename Derived>
346template<
typename Derived>
349 return derived() = Constant(rows(), cols(), val);
361template<
typename Derived>
362EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
366 return setConstant(val);
380template<
typename Derived>
381EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
385 return setConstant(val);
394template<
typename Derived>
395EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
398 return setConstant(rows(), cols, val);
407template<
typename Derived>
408EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
411 return setConstant(rows, cols(), val);
431template<
typename Derived>
434 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
435 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
451template<
typename Derived>
454 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
455 return setLinSpaced(size(), low, high);
474template<
typename Derived>
478 return Constant(rows, cols,
Scalar(0));
497template<
typename Derived>
501 return Constant(size,
Scalar(0));
514template<
typename Derived>
518 return Constant(
Scalar(0));
529template<
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))
547template<
typename Derived>
550 return setConstant(
Scalar(0));
562template<
typename Derived>
563EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
567 return setConstant(Scalar(0));
580template<
typename Derived>
581EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
585 return setConstant(Scalar(0));
594template<
typename Derived>
595EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
598 return setZero(rows(), cols);
607template<
typename Derived>
608EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
611 return setZero(rows, cols());
630template<
typename Derived>
634 return Constant(rows, cols,
Scalar(1));
653template<
typename Derived>
657 return Constant(newSize,
Scalar(1));
670template<
typename Derived>
674 return Constant(
Scalar(1));
685template<
typename Derived>
687(
const RealScalar& prec)
const
689 return isApproxToConstant(
Scalar(1), prec);
699template<
typename Derived>
702 return setConstant(
Scalar(1));
714template<
typename Derived>
715EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
719 return setConstant(
Scalar(1));
732template<
typename Derived>
733EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
737 return setConstant(Scalar(1));
746template<
typename Derived>
747EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
750 return setOnes(rows, cols());
759template<
typename Derived>
760EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
763 return setOnes(rows(), cols);
782template<
typename Derived>
799template<
typename Derived>
803 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
816template<
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))
842template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
843struct setIdentity_impl
846 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
848 return m = Derived::Identity(m.rows(), m.cols());
852template<
typename Derived>
853struct 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);
874template<
typename Derived>
877 return internal::setIdentity_impl<Derived>::run(derived());
890template<
typename Derived>
893 derived().resize(rows, cols);
894 return setIdentity();
903template<
typename Derived>
906 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
907 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
918template<
typename Derived>
921 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
922 return BasisReturnType(SquareMatrixType::Identity(),i);
931template<
typename Derived>
933{
return Derived::Unit(0); }
941template<
typename Derived>
943{
return Derived::Unit(1); }
951template<
typename Derived>
953{
return Derived::Unit(2); }
961template<
typename Derived>
963{
return Derived::Unit(3); }
973template<
typename Derived>
976 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
977 eigen_assert(i<size());
979 derived().coeffRef(i) =
Scalar(1);
992template<
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: B01_Experimental.dox:1
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