10 #ifndef EIGEN_CWISE_NULLARY_OP_H
11 #define EIGEN_CWISE_NULLARY_OP_H
34 template<
typename NullaryOp,
typename PlainObjectType>
35 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
38 Flags = traits<PlainObjectType>::Flags &
RowMajorBit
43 template<
typename NullaryOp,
typename PlainObjectType>
44 class CwiseNullaryOp :
public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
48 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
52 CwiseNullaryOp(Index rows, Index cols,
const NullaryOp& func = NullaryOp())
53 : m_rows(rows), m_cols(cols), m_functor(func)
55 eigen_assert(rows >= 0
56 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
58 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
62 EIGEN_STRONG_INLINE Index rows()
const {
return m_rows.value(); }
64 EIGEN_STRONG_INLINE Index cols()
const {
return m_cols.value(); }
67 EIGEN_STRONG_INLINE
const Scalar coeff(Index rowId, Index colId)
const
69 return m_functor(rowId, colId);
72 template<
int LoadMode>
73 EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId)
const
75 return m_functor.packetOp(rowId, colId);
79 EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const
81 return m_functor(index);
84 template<
int LoadMode>
85 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const
87 return m_functor.packetOp(index);
92 const NullaryOp&
functor()
const {
return m_functor; }
95 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
96 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
97 const NullaryOp m_functor;
114 template<
typename Derived>
115 template<
typename CustomNullaryOp>
116 EIGEN_STRONG_INLINE
const CwiseNullaryOp<CustomNullaryOp, typename DenseBase<Derived>::PlainObject>
140 template<
typename Derived>
141 template<
typename CustomNullaryOp>
145 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
159 template<
typename Derived>
160 template<
typename CustomNullaryOp>
180 template<
typename Derived>
202 template<
typename Derived>
218 template<
typename Derived>
222 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
243 template<
typename Derived>
247 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
255 template<
typename Derived>
259 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
260 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
261 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar,false>(low,high,Derived::SizeAtCompileTime));
277 template<
typename Derived>
281 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
289 template<
typename Derived>
293 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
294 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
295 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar,true>(low,high,Derived::SizeAtCompileTime));
299 template<
typename Derived>
301 (
const Scalar& val,
const RealScalar& prec)
const
303 typename internal::nested_eval<Derived,1>::type
self(derived());
304 for(Index j = 0; j < cols(); ++j)
305 for(Index i = 0; i < rows(); ++i)
306 if(!internal::isApprox(
self.coeff(i, j), val, prec))
314 template<
typename Derived>
316 (
const Scalar& val,
const RealScalar& prec)
const
318 return isApproxToConstant(val, prec);
325 template<
typename Derived>
335 template<
typename Derived>
338 return derived() = Constant(rows(), cols(), val);
350 template<
typename Derived>
351 EIGEN_STRONG_INLINE Derived&
355 return setConstant(val);
369 template<
typename Derived>
370 EIGEN_STRONG_INLINE Derived&
374 return setConstant(val);
390 template<
typename Derived>
393 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
394 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,PacketScalar,false>(low,high,newSize));
407 template<
typename Derived>
410 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
411 return setLinSpaced(size(), low, high);
430 template<
typename Derived>
434 return Constant(rows, cols,
Scalar(0));
453 template<
typename Derived>
457 return Constant(size,
Scalar(0));
470 template<
typename Derived>
474 return Constant(
Scalar(0));
485 template<
typename Derived>
488 typename internal::nested_eval<Derived,1>::type
self(derived());
489 for(Index j = 0; j < cols(); ++j)
490 for(Index i = 0; i < rows(); ++i)
491 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<Scalar>(1), prec))
503 template<
typename Derived>
506 return setConstant(
Scalar(0));
518 template<
typename Derived>
519 EIGEN_STRONG_INLINE Derived&
523 return setConstant(Scalar(0));
536 template<
typename Derived>
537 EIGEN_STRONG_INLINE Derived&
541 return setConstant(Scalar(0));
560 template<
typename Derived>
564 return Constant(rows, cols,
Scalar(1));
583 template<
typename Derived>
587 return Constant(newSize,
Scalar(1));
600 template<
typename Derived>
604 return Constant(
Scalar(1));
615 template<
typename Derived>
617 (
const RealScalar& prec)
const
619 return isApproxToConstant(
Scalar(1), prec);
629 template<
typename Derived>
632 return setConstant(
Scalar(1));
644 template<
typename Derived>
645 EIGEN_STRONG_INLINE Derived&
649 return setConstant(Scalar(1));
662 template<
typename Derived>
663 EIGEN_STRONG_INLINE Derived&
667 return setConstant(Scalar(1));
686 template<
typename Derived>
703 template<
typename Derived>
707 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
720 template<
typename Derived>
722 (
const RealScalar& prec)
const
724 typename internal::nested_eval<Derived,1>::type
self(derived());
725 for(Index j = 0; j < cols(); ++j)
727 for(Index i = 0; i < rows(); ++i)
731 if(!internal::isApprox(
self.coeff(i, j), static_cast<Scalar>(1), prec))
736 if(!internal::isMuchSmallerThan(
self.coeff(i, j), static_cast<RealScalar>(1), prec))
746 template<
typename Derived,
bool Big = (Derived::SizeAtCompileTime>=16)>
747 struct setIdentity_impl
750 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
752 return m = Derived::Identity(m.rows(), m.cols());
756 template<
typename Derived>
757 struct setIdentity_impl<Derived, true>
760 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
763 const Index size = (std::min)(m.rows(), m.cols());
764 for(Index i = 0; i < size; ++i) m.coeffRef(i,i) =
typename Derived::Scalar(1);
778 template<
typename Derived>
781 return internal::setIdentity_impl<Derived>::run(derived());
794 template<
typename Derived>
797 derived().resize(rows, cols);
798 return setIdentity();
807 template<
typename Derived>
810 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
811 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
822 template<
typename Derived>
825 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
826 return BasisReturnType(SquareMatrixType::Identity(),i);
835 template<
typename Derived>
837 {
return Derived::Unit(0); }
845 template<
typename Derived>
847 {
return Derived::Unit(1); }
855 template<
typename Derived>
857 {
return Derived::Unit(2); }
865 template<
typename Derived>
867 {
return Derived::Unit(3); }
871 #endif // EIGEN_CWISE_NULLARY_OP_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:44
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:72
static const BasisReturnType UnitW()
Definition: CwiseNullaryOp.h:866
static const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
Definition: CwiseNullaryOp.h:245
Derived & setIdentity()
Definition: CwiseNullaryOp.h:779
const unsigned int RowMajorBit
Definition: Constants.h:53
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:182
Derived & setOnes(Index size)
Definition: CwiseNullaryOp.h:646
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:520
static const BasisReturnType UnitX()
Definition: CwiseNullaryOp.h:836
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:486
static const ConstantReturnType Zero()
Definition: CwiseNullaryOp.h:472
void fill(const Scalar &value)
Definition: CwiseNullaryOp.h:326
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:617
static const BasisReturnType UnitY()
Definition: CwiseNullaryOp.h:846
static const BasisReturnType Unit(Index size, Index i)
Definition: CwiseNullaryOp.h:808
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:722
static const ConstantReturnType Ones()
Definition: CwiseNullaryOp.h:602
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
Definition: CwiseNullaryOp.h:391
const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:92
Definition: Eigen_Colamd.h:54
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:316
static const IdentityReturnType Identity()
Definition: CwiseNullaryOp.h:705
Derived & setZero()
Definition: CwiseNullaryOp.h:504
Derived & setOnes()
Definition: CwiseNullaryOp.h:630
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: CwiseNullaryOp.h:301
Derived & setConstant(const Scalar &value)
Definition: CwiseNullaryOp.h:336
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
static const BasisReturnType UnitZ()
Definition: CwiseNullaryOp.h:856
Derived & setConstant(Index size, const Scalar &value)
Definition: CwiseNullaryOp.h:352