10 #ifndef EIGEN_CWISE_NULLARY_OP_H 11 #define EIGEN_CWISE_NULLARY_OP_H 16 template<
typename NullaryOp,
typename PlainObjectType>
17 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
20 Flags = traits<PlainObjectType>::Flags &
RowMajorBit 42 template<
typename NullaryOp,
typename PlainObjectType>
43 class CwiseNullaryOp :
public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
47 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
52 : m_rows(rows), m_cols(cols), m_functor(func)
54 eigen_assert(rows >= 0
55 && (RowsAtCompileTime ==
Dynamic || RowsAtCompileTime == rows)
57 && (ColsAtCompileTime ==
Dynamic || ColsAtCompileTime == cols));
61 EIGEN_STRONG_INLINE
Index rows()
const {
return m_rows.value(); }
63 EIGEN_STRONG_INLINE
Index cols()
const {
return m_cols.value(); }
66 EIGEN_STRONG_INLINE
const Scalar coeff(
Index rowId,
Index colId)
const 68 return m_functor(rowId, colId);
71 template<
int LoadMode>
72 EIGEN_STRONG_INLINE PacketScalar packet(
Index rowId,
Index colId)
const 74 return m_functor.packetOp(rowId, colId);
78 EIGEN_STRONG_INLINE
const Scalar coeff(
Index index)
const 80 return m_functor(index);
83 template<
int LoadMode>
84 EIGEN_STRONG_INLINE PacketScalar packet(
Index index)
const 86 return m_functor.packetOp(index);
91 const NullaryOp&
functor()
const {
return m_functor; }
94 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
95 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
96 const NullaryOp m_functor;
113 template<
typename Derived>
114 template<
typename CustomNullaryOp>
139 template<
typename Derived>
140 template<
typename CustomNullaryOp>
144 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
158 template<
typename Derived>
159 template<
typename CustomNullaryOp>
179 template<
typename Derived>
201 template<
typename Derived>
217 template<
typename Derived>
221 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
242 template<
typename Derived>
246 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
254 template<
typename Derived>
258 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
259 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
260 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar,false>(low,high,Derived::SizeAtCompileTime));
276 template<
typename Derived>
280 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
288 template<
typename Derived>
292 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
293 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
294 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar,true>(low,high,Derived::SizeAtCompileTime));
298 template<
typename Derived>
300 (
const Scalar& val,
const RealScalar& prec)
const 302 typename internal::nested_eval<Derived,1>::type
self(derived());
303 for(
Index j = 0; j < cols(); ++j)
304 for(
Index i = 0; i < rows(); ++i)
305 if(!internal::isApprox(
self.coeff(i, j), val, prec))
313 template<
typename Derived>
315 (
const Scalar& val,
const RealScalar& prec)
const 317 return isApproxToConstant(val, prec);
324 template<
typename Derived>
334 template<
typename Derived>
337 return derived() = Constant(rows(), cols(), val);
349 template<
typename Derived>
350 EIGEN_STRONG_INLINE Derived&
354 return setConstant(val);
368 template<
typename Derived>
369 EIGEN_STRONG_INLINE Derived&
373 return setConstant(val);
389 template<
typename Derived>
392 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
393 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,PacketScalar,false>(low,high,newSize));
406 template<
typename Derived>
409 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
410 return setLinSpaced(size(), low, high);
429 template<
typename Derived>
433 return Constant(rows, cols,
Scalar(0));
452 template<
typename Derived>
456 return Constant(size,
Scalar(0));
469 template<
typename Derived>
473 return Constant(
Scalar(0));
484 template<
typename Derived>
487 typename internal::nested_eval<Derived,1>::type
self(derived());
488 for(
Index j = 0; j < cols(); ++j)
489 for(
Index i = 0; i < rows(); ++i)
490 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<Scalar>(1), prec))
502 template<
typename Derived>
505 return setConstant(
Scalar(0));
517 template<
typename Derived>
518 EIGEN_STRONG_INLINE Derived&
522 return setConstant(
Scalar(0));
535 template<
typename Derived>
536 EIGEN_STRONG_INLINE Derived&
540 return setConstant(
Scalar(0));
559 template<
typename Derived>
563 return Constant(rows, cols,
Scalar(1));
582 template<
typename Derived>
586 return Constant(newSize,
Scalar(1));
599 template<
typename Derived>
603 return Constant(
Scalar(1));
614 template<
typename Derived>
616 (
const RealScalar& prec)
const 618 return isApproxToConstant(
Scalar(1), prec);
628 template<
typename Derived>
631 return setConstant(
Scalar(1));
643 template<
typename Derived>
644 EIGEN_STRONG_INLINE Derived&
648 return setConstant(
Scalar(1));
661 template<
typename Derived>
662 EIGEN_STRONG_INLINE Derived&
666 return setConstant(
Scalar(1));
685 template<
typename Derived>
702 template<
typename Derived>
706 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
719 template<
typename Derived>
721 (
const RealScalar& prec)
const 723 typename internal::nested_eval<Derived,1>::type
self(derived());
724 for(
Index j = 0; j < cols(); ++j)
726 for(
Index i = 0; i < rows(); ++i)
730 if(!internal::isApprox(
self.coeff(i, j), static_cast<Scalar>(1), prec))
735 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<RealScalar>(1), prec))
745 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
746 struct setIdentity_impl
749 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
751 return m = Derived::Identity(m.rows(), m.cols());
755 template<
typename Derived>
756 struct setIdentity_impl<Derived, true>
759 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
762 const Index size = (std::min)(m.rows(), m.cols());
763 for(
Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
777 template<
typename Derived>
780 return internal::setIdentity_impl<Derived>::run(derived());
793 template<
typename Derived>
796 derived().resize(rows, cols);
797 return setIdentity();
806 template<
typename Derived>
809 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
810 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
821 template<
typename Derived>
824 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
825 return BasisReturnType(SquareMatrixType::Identity(),i);
834 template<
typename Derived>
836 {
return Derived::Unit(0); }
844 template<
typename Derived>
846 {
return Derived::Unit(1); }
854 template<
typename Derived>
856 {
return Derived::Unit(2); }
864 template<
typename Derived>
866 {
return Derived::Unit(3); }
870 #endif // EIGEN_CWISE_NULLARY_OP_H Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:43
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:485
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:865
static const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:244
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Derived & setIdentity()
Definition: CwiseNullaryOp.h:778
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
const unsigned int RowMajorBit
Definition: Constants.h:61
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
Definition: CwiseNullaryOp.h:181
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:645
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:519
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:835
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:471
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:325
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:315
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:845
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:351
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:807
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:601
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
Definition: CwiseNullaryOp.h:390
Definition: Eigen_Colamd.h:50
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:704
Derived & setZero()
Definition: CwiseNullaryOp.h:503
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:300
Derived & setOnes()
Definition: CwiseNullaryOp.h:629
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:335
const int Dynamic
Definition: Constants.h:21
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:721
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:91
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:616
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:855