10#ifndef EIGEN_CWISE_NULLARY_OP_H
11#define EIGEN_CWISE_NULLARY_OP_H
14#include "./InternalHeaderCheck.h"
19template <
typename NullaryOp,
typename PlainObjectType>
20struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType> {
21 enum { Flags = traits<PlainObjectType>::Flags &
RowMajorBit };
62template <
typename NullaryOp,
typename PlainObjectType>
63class 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;
67 EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
69 EIGEN_DEVICE_FUNC CwiseNullaryOp(
Index rows,
Index cols,
const NullaryOp& func = NullaryOp())
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));
74 EIGEN_DEVICE_FUNC CwiseNullaryOp(
Index size,
const NullaryOp& func = NullaryOp())
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;
104template <
typename Derived>
105template <
typename CustomNullaryOp>
106EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
107#ifndef EIGEN_PARSED_BY_DOXYGEN
108 const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
110 const CwiseNullaryOp<CustomNullaryOp, PlainObject>
134template <
typename Derived>
135template <
typename CustomNullaryOp>
136EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
137#ifndef EIGEN_PARSED_BY_DOXYGEN
143 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
159template <
typename Derived>
160template <
typename CustomNullaryOp>
161EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
162#ifndef EIGEN_PARSED_BY_DOXYGEN
184template <
typename Derived>
205template <
typename Derived>
220template <
typename Derived>
223 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
225 internal::scalar_constant_op<Scalar>(
value));
237template <
typename Derived>
240 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
248template <
typename Derived>
251 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
252 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
280template <typename Derived>
281EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename
DenseBase<Derived>::RandomAccessLinSpacedReturnType
283 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
291template <
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));
300template <
typename Derived>
302DenseBase<Derived>::EqualSpaced(
Index size,
const Scalar& low,
const Scalar& step) {
303 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
307template <
typename Derived>
309DenseBase<Derived>::EqualSpaced(
const Scalar& low,
const Scalar& step) {
310 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
315template <
typename Derived>
317 typename internal::nested_eval<Derived, 1>::type self(derived());
319 for (
Index i = 0; i < rows(); ++i)
320 if (!internal::isApprox(self.coeff(i, j), val, prec))
return false;
327template <
typename Derived>
336template <
typename Derived>
346template <
typename Derived>
348 internal::eigen_fill_impl<Derived>::run(derived(), val);
362template <
typename Derived>
380template <
typename Derived>
394template <
typename Derived>
407template <
typename Derived>
429template <
typename Derived>
432 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
433 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low, high, newSize));
449template <
typename Derived>
451 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
455template <
typename Derived>
456EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(
Index newSize,
const Scalar& low,
458 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
459 return derived() = Derived::NullaryExpr(newSize, internal::equalspaced_op<Scalar>(low, step));
461template <
typename Derived>
462EIGEN_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);
484template <
typename Derived>
487 return ZeroReturnType(rows, cols);
506template <
typename Derived>
509 return ZeroReturnType(size);
522template <
typename Derived>
535template <
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;
551template <
typename Derived>
553 internal::eigen_zero_impl<Derived>::run(derived());
566template <
typename Derived>
582template <
typename Derived>
595template <
typename Derived>
607template <
typename Derived>
628template <
typename Derived>
650template <
typename Derived>
653 return Constant(newSize, Scalar(1));
666template <
typename Derived>
668 return Constant(Scalar(1));
679template <
typename Derived>
691template <
typename Derived>
705template <
typename Derived>
721template <
typename Derived>
734template <
typename Derived>
746template <
typename Derived>
767template <
typename Derived>
783template <
typename Derived>
786 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
799template <
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;
816template <
typename Derived,
bool Big = (Derived::SizeAtCompileTime >= 16)>
817struct setIdentity_impl {
818 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
819 return m = Derived::Identity(m.rows(), m.cols());
823template <
typename Derived>
824struct 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);
842template <
typename Derived>
844 return internal::setIdentity_impl<Derived>::run(derived());
857template <
typename Derived>
859 derived().resize(rows, cols);
869template <
typename Derived>
872 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
873 return BasisReturnType(SquareMatrixType::Identity(newSize, newSize), i);
884template <
typename Derived>
887 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
888 return BasisReturnType(SquareMatrixType::Identity(), i);
898template <
typename Derived>
900 return Derived::Unit(0);
910template <
typename Derived>
912 return Derived::Unit(1);
922template <
typename Derived>
924 return Derived::Unit(2);
934template <
typename Derived>
936 return Derived::Unit(3);
947template <
typename Derived>
949 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
950 eigen_assert(i < size());
952 derived().coeffRef(i) =
Scalar(1);
965template <
typename Derived>
967 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
968 eigen_assert(i < newSize);
969 derived().resize(newSize);
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:64
const NullaryOp & functor() const
Definition CwiseNullaryOp.h:83
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:44
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:328
Derived & setOnes()
Definition CwiseNullaryOp.h:692
static const ConstantReturnType Ones()
Definition CwiseNullaryOp.h:667
void resize(Index newSize)
Definition DenseBase.h:228
static const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Definition CwiseNullaryOp.h:112
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition CwiseNullaryOp.h:430
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition CwiseNullaryOp.h:186
CoeffReturnType value() const
Definition DenseBase.h:486
@ SizeAtCompileTime
Definition DenseBase.h:108
@ ColsAtCompileTime
Definition DenseBase.h:102
@ RowsAtCompileTime
Definition DenseBase.h:96
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:337
constexpr DenseBase()=default
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:680
ArrayWrapper< ExpressionType > & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:347
static const ZeroReturnType Zero()
Definition CwiseNullaryOp.h:523
static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition CwiseNullaryOp.h:239
Derived & setZero()
Definition CwiseNullaryOp.h:552
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:536
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:316
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
static const BasisReturnType UnitY()
Definition CwiseNullaryOp.h:911
Derived & setIdentity()
Definition CwiseNullaryOp.h:843
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:800
static const BasisReturnType UnitX()
Definition CwiseNullaryOp.h:899
static const IdentityReturnType Identity()
Definition CwiseNullaryOp.h:785
static const BasisReturnType UnitZ()
Definition CwiseNullaryOp.h:923
static const BasisReturnType Unit(Index size, Index i)
Definition CwiseNullaryOp.h:870
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition CwiseNullaryOp.h:948
static const BasisReturnType UnitW()
Definition CwiseNullaryOp.h:935
Derived & setOnes(Index size)
Definition CwiseNullaryOp.h:706
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:363
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:567
constexpr void resize(Index rows, Index cols)
Definition PlainObjectBase.h:268
const unsigned int RowMajorBit
Definition Constants.h:70
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:82
const int Dynamic
Definition Constants.h:25