CwiseNullaryOp.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CWISE_NULLARY_OP_H
11 #define EIGEN_CWISE_NULLARY_OP_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 template<typename NullaryOp, typename PlainObjectType>
17 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
18 {
19  enum {
21  };
22 };
23 
24 } // namespace internal
25 
59 template<typename NullaryOp, typename PlainObjectType>
60 class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
61 {
62  public:
63 
66 
68  CwiseNullaryOp(Index rows, Index cols, const NullaryOp& func = NullaryOp())
69  : m_rows(rows), m_cols(cols), m_functor(func)
70  {
71  eigen_assert(rows >= 0
72  && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
73  && cols >= 0
74  && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
75  }
76 
78  Index rows() const { return m_rows.value(); }
80  Index cols() const { return m_cols.value(); }
81 
84  const NullaryOp& functor() const { return m_functor; }
85 
86  protected:
89  const NullaryOp m_functor;
90 };
91 
92 
106 template<typename Derived>
107 template<typename CustomNullaryOp>
109 #ifndef EIGEN_PARSED_BY_DOXYGEN
111 #else
113 #endif
115 {
117 }
118 
137 template<typename Derived>
138 template<typename CustomNullaryOp>
140 #ifndef EIGEN_PARSED_BY_DOXYGEN
142 #else
144 #endif
146 {
148  if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, PlainObject>(1, size, func);
150 }
151 
161 template<typename Derived>
162 template<typename CustomNullaryOp>
164 #ifndef EIGEN_PARSED_BY_DOXYGEN
166 #else
168 #endif
169 DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
170 {
171  return CwiseNullaryOp<CustomNullaryOp, PlainObject>(RowsAtCompileTime, ColsAtCompileTime, func);
172 }
173 
187 template<typename Derived>
190 {
192 }
193 
209 template<typename Derived>
212 {
214 }
215 
225 template<typename Derived>
228 {
230  return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
231 }
232 
242 template<typename Derived>
245 {
248 }
249 
254 template<typename Derived>
257 {
260  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
261 }
262 
286 template<typename Derived>
289 {
292 }
293 
298 template<typename Derived>
301 {
304  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar>(low,high,Derived::SizeAtCompileTime));
305 }
306 
308 template<typename Derived>
310 (const Scalar& val, const RealScalar& prec) const
311 {
312  typename internal::nested_eval<Derived,1>::type self(derived());
313  for(Index j = 0; j < cols(); ++j)
314  for(Index i = 0; i < rows(); ++i)
315  if(!internal::isApprox(self.coeff(i, j), val, prec))
316  return false;
317  return true;
318 }
319 
323 template<typename Derived>
325 (const Scalar& val, const RealScalar& prec) const
326 {
327  return isApproxToConstant(val, prec);
328 }
329 
334 template<typename Derived>
336 {
337  setConstant(val);
338 }
339 
344 template<typename Derived>
346 {
347  return derived() = Constant(rows(), cols(), val);
348 }
349 
359 template<typename Derived>
362 {
363  resize(size);
364  return setConstant(val);
365 }
366 
378 template<typename Derived>
381 {
382  resize(rows, cols);
383  return setConstant(val);
384 }
385 
392 template<typename Derived>
395 {
396  return setConstant(rows(), cols, val);
397 }
398 
405 template<typename Derived>
408 {
409  return setConstant(rows, cols(), val);
410 }
411 
412 
429 template<typename Derived>
431 {
433  return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar>(low,high,newSize));
434 }
435 
449 template<typename Derived>
451 {
453  return setLinSpaced(size(), low, high);
454 }
455 
456 // zero:
457 
472 template<typename Derived>
475 {
476  return Constant(rows, cols, Scalar(0));
477 }
478 
495 template<typename Derived>
498 {
499  return Constant(size, Scalar(0));
500 }
501 
512 template<typename Derived>
515 {
516  return Constant(Scalar(0));
517 }
518 
527 template<typename Derived>
529 {
530  typename internal::nested_eval<Derived,1>::type self(derived());
531  for(Index j = 0; j < cols(); ++j)
532  for(Index i = 0; i < rows(); ++i)
533  if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<Scalar>(1), prec))
534  return false;
535  return true;
536 }
537 
545 template<typename Derived>
547 {
548  return setConstant(Scalar(0));
549 }
550 
560 template<typename Derived>
563 {
564  resize(newSize);
565  return setConstant(Scalar(0));
566 }
567 
578 template<typename Derived>
581 {
582  resize(rows, cols);
583  return setConstant(Scalar(0));
584 }
585 
592 template<typename Derived>
595 {
596  return setZero(rows(), cols);
597 }
598 
605 template<typename Derived>
608 {
609  return setZero(rows, cols());
610 }
611 
612 // ones:
613 
628 template<typename Derived>
631 {
632  return Constant(rows, cols, Scalar(1));
633 }
634 
651 template<typename Derived>
654 {
655  return Constant(newSize, Scalar(1));
656 }
657 
668 template<typename Derived>
671 {
672  return Constant(Scalar(1));
673 }
674 
683 template<typename Derived>
685 (const RealScalar& prec) const
686 {
687  return isApproxToConstant(Scalar(1), prec);
688 }
689 
697 template<typename Derived>
699 {
700  return setConstant(Scalar(1));
701 }
702 
712 template<typename Derived>
715 {
716  resize(newSize);
717  return setConstant(Scalar(1));
718 }
719 
730 template<typename Derived>
733 {
734  resize(rows, cols);
735  return setConstant(Scalar(1));
736 }
737 
744 template<typename Derived>
747 {
748  return setOnes(rows, cols());
749 }
750 
757 template<typename Derived>
760 {
761  return setOnes(rows(), cols);
762 }
763 
764 // Identity:
765 
780 template<typename Derived>
783 {
785 }
786 
797 template<typename Derived>
800 {
802  return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>());
803 }
804 
814 template<typename Derived>
816 (const RealScalar& prec) const
817 {
818  typename internal::nested_eval<Derived,1>::type self(derived());
819  for(Index j = 0; j < cols(); ++j)
820  {
821  for(Index i = 0; i < rows(); ++i)
822  {
823  if(i == j)
824  {
825  if(!internal::isApprox(self.coeff(i, j), static_cast<Scalar>(1), prec))
826  return false;
827  }
828  else
829  {
830  if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<RealScalar>(1), prec))
831  return false;
832  }
833  }
834  }
835  return true;
836 }
837 
838 namespace internal {
839 
840 template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
842 {
844  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
845  {
846  return m = Derived::Identity(m.rows(), m.cols());
847  }
848 };
849 
850 template<typename Derived>
851 struct setIdentity_impl<Derived, true>
852 {
854  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
855  {
856  m.setZero();
857  const Index size = numext::mini(m.rows(), m.cols());
858  for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
859  return m;
860  }
861 };
862 
863 } // end namespace internal
864 
872 template<typename Derived>
874 {
876 }
877 
888 template<typename Derived>
890 {
891  derived().resize(rows, cols);
892  return setIdentity();
893 }
894 
901 template<typename Derived>
903 {
905  return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
906 }
907 
916 template<typename Derived>
918 {
920  return BasisReturnType(SquareMatrixType::Identity(),i);
921 }
922 
929 template<typename Derived>
931 { return Derived::Unit(0); }
932 
939 template<typename Derived>
941 { return Derived::Unit(1); }
942 
949 template<typename Derived>
951 { return Derived::Unit(2); }
952 
959 template<typename Derived>
961 { return Derived::Unit(3); }
962 
971 template<typename Derived>
973 {
975  eigen_assert(i<size());
976  derived().setZero();
977  derived().coeffRef(i) = Scalar(1);
978  return derived();
979 }
980 
990 template<typename Derived>
992 {
994  eigen_assert(i<newSize);
995  derived().resize(newSize);
996  return setUnit(i);
997 }
998 
999 } // end namespace Eigen
1000 
1001 #endif // EIGEN_CWISE_NULLARY_OP_H
static EIGEN_DEVICE_FUNC const IdentityReturnType Identity()
Matrix3f m
Generic expression of a matrix where all coefficients are defined by a functor.
static EIGEN_DEVICE_FUNC const ConstantReturnType Ones()
static EIGEN_DEVICE_FUNC const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
EIGEN_DEVICE_FUNC bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
SCALAR Scalar
Definition: bench_gemm.cpp:46
static EIGEN_DEVICE_FUNC const BasisReturnType Unit(Index size, Index i)
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
EIGEN_DEVICE_FUNC Derived & setZero()
static EIGEN_DEVICE_FUNC const BasisReturnType UnitY()
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & run(Derived &m)
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
EIGEN_DEVICE_FUNC Derived & setOnes()
EIGEN_DEVICE_FUNC Derived & setUnit(Index i)
Set the coefficients of *this to the i-th unit (basis) vector.
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
static EIGEN_DEVICE_FUNC const BasisReturnType UnitW()
static EIGEN_DEVICE_FUNC const BasisReturnType UnitZ()
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
EIGEN_DEVICE_FUNC Derived & setOnes(Index size)
EIGEN_DEPRECATED static EIGEN_DEVICE_FUNC const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
const unsigned int RowMajorBit
Definition: Constants.h:66
m setIdentity(3, 3)
EIGEN_DEVICE_FUNC Derived & setConstant(const Scalar &value)
const NullaryOp m_functor
static EIGEN_DEVICE_FUNC const BasisReturnType UnitX()
v setLinSpaced(5, 0.5f, 1.5f)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
#define eigen_assert(x)
Definition: Macros.h:1037
v setOnes(3)
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
EIGEN_DEVICE_FUNC CwiseNullaryOp(Index rows, Index cols, const NullaryOp &func=NullaryOp())
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:147
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
NoChange_t
Definition: Constants.h:360
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & run(Derived &m)
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
v setConstant(3, 5)
int func(const int &a)
Definition: testDSF.cpp:221
static EIGEN_DEVICE_FUNC const ConstantReturnType Zero()
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:73
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Sequential_t
Definition: Constants.h:361
#define EIGEN_DEPRECATED
Definition: Macros.h:1058
EIGEN_DEVICE_FUNC Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
const int Dynamic
Definition: Constants.h:22
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static EIGEN_DEVICE_FUNC const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
v resize(3)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
EIGEN_DEVICE_FUNC bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC Derived & setIdentity()
std::ptrdiff_t j
internal::dense_xpr_base< CwiseNullaryOp >::type Base
Definition: pytypes.h:1370
EIGEN_DEVICE_FUNC bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
v setZero(3)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:06