11#ifndef EIGEN_CWISE_NULLARY_OP_H
12#define EIGEN_CWISE_NULLARY_OP_H
15#include "./InternalHeaderCheck.h"
20template <
typename NullaryOp,
typename PlainObjectType>
21struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType> {
22 enum { Flags = traits<PlainObjectType>::Flags &
RowMajorBit };
63template <
typename NullaryOp,
typename PlainObjectType>
64class CwiseNullaryOp :
public internal::dense_xpr_base<CwiseNullaryOp<NullaryOp, PlainObjectType> >::type,
65 internal::no_assignment_operator {
67 using Base =
typename internal::dense_xpr_base<CwiseNullaryOp>::type;
68 EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
70 EIGEN_DEVICE_FUNC
constexpr CwiseNullaryOp(Index rows, Index cols,
const NullaryOp& func = NullaryOp())
71 : m_rows(rows), m_cols(cols), m_functor(func) {
72 eigen_assert(rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && cols >= 0 &&
73 (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
75 EIGEN_DEVICE_FUNC
constexpr CwiseNullaryOp(Index size,
const NullaryOp& func = NullaryOp())
76 : CwiseNullaryOp(RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? size : 1, func) {
77 EIGEN_STATIC_ASSERT(CwiseNullaryOp::IsVectorAtCompileTime, YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX);
80 EIGEN_DEVICE_FUNC
constexpr Index rows()
const {
return m_rows.value(); }
81 EIGEN_DEVICE_FUNC
constexpr Index cols()
const {
return m_cols.value(); }
84 EIGEN_DEVICE_FUNC
constexpr 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;
105template <
typename Derived>
106template <
typename CustomNullaryOp>
107EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
108#ifndef EIGEN_PARSED_BY_DOXYGEN
109 const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
111 const CwiseNullaryOp<CustomNullaryOp, PlainObject>
135template <
typename Derived>
136template <
typename CustomNullaryOp>
137EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
138#ifndef EIGEN_PARSED_BY_DOXYGEN
144 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
161template <
typename Derived>
162template <
typename CustomNullaryOp>
163EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
164#ifndef EIGEN_PARSED_BY_DOXYGEN
184template <
typename Derived>
203template <
typename Derived>
216template <
typename Derived>
219 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
221 internal::scalar_constant_op<Scalar>(
value));
233template <
typename Derived>
236 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
244template <
typename Derived>
247 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
248 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
276template <typename Derived>
277EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename
DenseBase<Derived>::RandomAccessLinSpacedReturnType
279 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
287template <
typename Derived>
290 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
291 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
293 internal::linspaced_op<Scalar>(low, high, Derived::SizeAtCompileTime));
296template <
typename Derived>
298DenseBase<Derived>::EqualSpaced(Index size,
const Scalar& low,
const Scalar& step) {
299 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
303template <
typename Derived>
305DenseBase<Derived>::EqualSpaced(
const Scalar& low,
const Scalar& step) {
306 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
313template <
typename Derived>
322template <
typename Derived>
332template <
typename Derived>
334 internal::eigen_fill_impl<Derived>::run(derived(), val);
348template <
typename Derived>
366template <
typename Derived>
380template <
typename Derived>
393template <
typename Derived>
415template <
typename Derived>
418 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
419 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low, high, newSize));
435template <
typename Derived>
437 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
441template <
typename Derived>
442EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(Index newSize,
const Scalar& low,
443 const Scalar& step) {
444 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
445 return derived() = Derived::NullaryExpr(newSize, internal::equalspaced_op<Scalar>(low, step));
447template <
typename Derived>
448EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(
const Scalar& low,
449 const Scalar& step) {
450 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
451 return setEqualSpaced(size(), low, step);
470template <
typename Derived>
472 Index rows, Index cols) {
473 return ZeroReturnType(rows, cols);
492template <
typename Derived>
495 return ZeroReturnType(size);
508template <
typename Derived>
520template <
typename Derived>
522 internal::eigen_zero_impl<Derived>::run(derived());
535template <
typename Derived>
551template <
typename Derived>
564template <
typename Derived>
576template <
typename Derived>
597template <
typename Derived>
599 Index rows, Index cols) {
619template <
typename Derived>
635template <
typename Derived>
648template <
typename Derived>
660template <
typename Derived>
674template <
typename Derived>
690template <
typename Derived>
703template <
typename Derived>
715template <
typename Derived>
736template <
typename Derived>
752template <
typename Derived>
755 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
768template <
typename Derived>
770 typename internal::nested_eval<Derived, 1>::type self(derived());
771 for (Index j = 0; j < cols(); ++j) {
772 for (Index i = 0; i < rows(); ++i) {
774 if (!internal::isApprox(self.coeff(i, j),
static_cast<Scalar>(1), prec))
return false;
776 if (!internal::isMuchSmallerThan(self.coeff(i, j),
static_cast<RealScalar
>(1), prec))
return false;
785template <
typename Derived,
bool Big = (Derived::SizeAtCompileTime >= 16)>
786struct setIdentity_impl {
787 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
788 return m = Derived::Identity(m.rows(), m.cols());
792template <
typename Derived>
793struct setIdentity_impl<Derived, true> {
794 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
796 const Index size = numext::mini(m.rows(), m.cols());
797 for (Index i = 0; i < size; ++i) m.coeffRef(i, i) =
typename Derived::Scalar(1);
811template <
typename Derived>
813 return internal::setIdentity_impl<Derived>::run(derived());
826template <
typename Derived>
828 derived().resize(rows, cols);
838template <
typename Derived>
840 Index newSize, Index i) {
841 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
842 return BasisReturnType(SquareMatrixType::Identity(newSize, newSize), i);
853template <
typename Derived>
856 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
857 return BasisReturnType(SquareMatrixType::Identity(), i);
867template <
typename Derived>
869 return Derived::Unit(0);
879template <
typename Derived>
881 return Derived::Unit(1);
891template <
typename Derived>
893 return Derived::Unit(2);
903template <
typename Derived>
905 return Derived::Unit(3);
916template <
typename Derived>
918 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
919 eigen_assert(i < size());
921 derived().coeffRef(i) =
Scalar(1);
934template <
typename Derived>
936 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
937 eigen_assert(i < newSize);
938 derived().resize(newSize);
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:65
constexpr const NullaryOp & functor() const
Definition CwiseNullaryOp.h:84
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:45
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:314
Derived & setOnes()
Definition CwiseNullaryOp.h:661
static const ConstantReturnType Ones()
Definition CwiseNullaryOp.h:636
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:113
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition CwiseNullaryOp.h:416
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition CwiseNullaryOp.h:186
CoeffReturnType value() const
Definition DenseBase.h:450
@ SizeAtCompileTime
Definition DenseBase.h:109
@ ColsAtCompileTime
Definition DenseBase.h:103
@ RowsAtCompileTime
Definition DenseBase.h:97
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:323
constexpr DenseBase()=default
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:649
typename internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:63
ArrayWrapper< ExpressionType > & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:333
static const ZeroReturnType Zero()
Definition CwiseNullaryOp.h:509
static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition CwiseNullaryOp.h:235
Derived & setZero()
Definition CwiseNullaryOp.h:521
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Visitor.h:696
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
static const BasisReturnType UnitY()
Definition CwiseNullaryOp.h:880
Derived & setIdentity()
Definition CwiseNullaryOp.h:812
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:769
static const BasisReturnType UnitX()
Definition CwiseNullaryOp.h:868
static const IdentityReturnType Identity()
Definition CwiseNullaryOp.h:754
static const BasisReturnType UnitZ()
Definition CwiseNullaryOp.h:892
static const BasisReturnType Unit(Index size, Index i)
Definition CwiseNullaryOp.h:839
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition CwiseNullaryOp.h:917
static const BasisReturnType UnitW()
Definition CwiseNullaryOp.h:904
Derived & setOnes(Index size)
Definition CwiseNullaryOp.h:675
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:349
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:536
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:282
constexpr unsigned int RowMajorBit
Definition Constants.h:71