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 EIGEN_CONSTEXPR
Index rows()
const {
return m_rows.value(); }
80 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_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>
238EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename DenseBase<
239 Derived>::RandomAccessLinSpacedReturnType
241 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
249template <
typename Derived>
250EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename DenseBase<
251 Derived>::RandomAccessLinSpacedReturnType
253 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
254 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
256 internal::linspaced_op<Scalar>(low, high, Derived::SizeAtCompileTime));
282template <
typename Derived>
285 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
293template <
typename Derived>
296 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
297 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
299 internal::linspaced_op<Scalar>(low, high, Derived::SizeAtCompileTime));
302template <
typename Derived>
304DenseBase<Derived>::EqualSpaced(
Index size,
const Scalar& low,
const Scalar& step) {
305 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
309template <typename Derived>
310EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename
DenseBase<Derived>::RandomAccessEqualSpacedReturnType
312 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
317template <
typename Derived>
319 typename internal::nested_eval<Derived, 1>::type self(derived());
320 for (
Index j = 0; j < cols(); ++j)
321 for (
Index i = 0; i < rows(); ++i)
322 if (!internal::isApprox(self.coeff(i, j), val, prec))
return false;
329template <
typename Derived>
338template <
typename Derived>
348template <
typename Derived>
350 internal::eigen_fill_impl<Derived>::run(derived(), val);
364template <
typename Derived>
382template <
typename Derived>
396template <
typename Derived>
409template <
typename Derived>
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>
453 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
457template <
typename Derived>
458EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(
Index newSize,
const Scalar& low,
460 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
461 return derived() = Derived::NullaryExpr(newSize, internal::equalspaced_op<Scalar>(low, step));
463template <
typename Derived>
464EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setEqualSpaced(
const Scalar& low,
465 const Scalar& step) {
466 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
467 return setEqualSpaced(size(), low, step);
486template <
typename Derived>
489 return ZeroReturnType(rows, cols);
508template <
typename Derived>
511 return ZeroReturnType(size);
524template <
typename Derived>
537template <
typename Derived>
539 typename internal::nested_eval<Derived, 1>::type self(derived());
540 for (
Index j = 0; j < cols(); ++j)
541 for (
Index i = 0; i < rows(); ++i)
542 if (!internal::isMuchSmallerThan(self.coeff(i, j),
static_cast<Scalar>(1), prec))
return false;
553template <
typename Derived>
555 internal::eigen_zero_impl<Derived>::run(derived());
568template <
typename Derived>
584template <
typename Derived>
597template <
typename Derived>
609template <
typename Derived>
630template <
typename Derived>
652template <
typename Derived>
655 return Constant(newSize, Scalar(1));
668template <
typename Derived>
681template <
typename Derived>
693template <
typename Derived>
707template <
typename Derived>
723template <
typename Derived>
736template <
typename Derived>
748template <
typename Derived>
769template <
typename Derived>
785template <
typename Derived>
788 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
801template <
typename Derived>
803 typename internal::nested_eval<Derived, 1>::type self(derived());
804 for (
Index j = 0; j < cols(); ++j) {
805 for (
Index i = 0; i < rows(); ++i) {
807 if (!internal::isApprox(self.coeff(i, j),
static_cast<Scalar>(1), prec))
return false;
809 if (!internal::isMuchSmallerThan(self.coeff(i, j),
static_cast<RealScalar
>(1), prec))
return false;
818template <
typename Derived,
bool Big = (Derived::SizeAtCompileTime >= 16)>
819struct setIdentity_impl {
820 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
821 return m = Derived::Identity(m.rows(), m.cols());
825template <
typename Derived>
826struct setIdentity_impl<Derived, true> {
827 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Derived& run(Derived& m) {
829 const Index size = numext::mini(m.rows(), m.cols());
830 for (
Index i = 0; i < size; ++i) m.coeffRef(i, i) =
typename Derived::Scalar(1);
844template <
typename Derived>
846 return internal::setIdentity_impl<Derived>::run(derived());
859template <
typename Derived>
861 derived().resize(rows, cols);
871template <
typename Derived>
874 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
875 return BasisReturnType(SquareMatrixType::Identity(newSize, newSize), i);
886template <
typename Derived>
889 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
890 return BasisReturnType(SquareMatrixType::Identity(), i);
900template <
typename Derived>
902 return Derived::Unit(0);
912template <
typename Derived>
914 return Derived::Unit(1);
924template <
typename Derived>
926 return Derived::Unit(2);
936template <
typename Derived>
938 return Derived::Unit(3);
949template <
typename Derived>
951 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
952 eigen_assert(i < size());
954 derived().coeffRef(i) =
Scalar(1);
967template <
typename Derived>
969 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
970 eigen_assert(i < newSize);
971 derived().resize(newSize);
Generic expression of a matrix where all coefficients are defined by a functor.
Definition ForwardDeclarations.h:104
const NullaryOp & functor() const
Definition CwiseNullaryOp.h:83
Base class for all dense matrices, vectors, and arrays.
Definition ForwardDeclarations.h:59
static EIGEN_DEPRECATED const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Definition CwiseNullaryOp.h:240
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:330
Derived & setOnes()
Definition CwiseNullaryOp.h:694
static const ConstantReturnType Ones()
Definition CwiseNullaryOp.h:669
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:432
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
@ ColsAtCompileTime
Definition DenseBase.h:102
@ RowsAtCompileTime
Definition DenseBase.h:96
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition CwiseNullaryOp.h:186
CoeffReturnType value() const
Definition DenseBase.h:481
void fill(const Scalar &value)
Definition CwiseNullaryOp.h:339
constexpr DenseBase()=default
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:682
ArrayWrapper< ExpressionType > & setConstant(const Scalar &value)
Definition CwiseNullaryOp.h:349
static const ZeroReturnType Zero()
Definition CwiseNullaryOp.h:525
Derived & setZero()
Definition CwiseNullaryOp.h:554
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:538
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:318
Base class for all dense matrices, vectors, and expressions.
Definition ForwardDeclarations.h:73
static const BasisReturnType UnitY()
Definition CwiseNullaryOp.h:913
Derived & setIdentity()
Definition CwiseNullaryOp.h:845
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition CwiseNullaryOp.h:802
static const BasisReturnType UnitX()
Definition CwiseNullaryOp.h:901
static const IdentityReturnType Identity()
Definition CwiseNullaryOp.h:787
static const BasisReturnType UnitZ()
Definition CwiseNullaryOp.h:925
static const BasisReturnType Unit(Index size, Index i)
Definition CwiseNullaryOp.h:872
Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Definition CwiseNullaryOp.h:950
static const BasisReturnType UnitW()
Definition CwiseNullaryOp.h:937
Derived & setOnes(Index size)
Definition CwiseNullaryOp.h:708
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:365
Derived & setZero(Index size)
Definition CwiseNullaryOp.h:569
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