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 
67  EIGEN_DEVICE_FUNC
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 
77  EIGEN_DEVICE_FUNC
78  EIGEN_STRONG_INLINE Index rows() const { return m_rows.value(); }
79  EIGEN_DEVICE_FUNC
80  EIGEN_STRONG_INLINE Index cols() const { return m_cols.value(); }
81 
83  EIGEN_DEVICE_FUNC
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 DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func)
110 {
111  return CwiseNullaryOp<CustomNullaryOp, PlainObject>(rows, cols, func);
112 }
113 
132 template<typename Derived>
133 template<typename CustomNullaryOp>
135 DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func)
136 {
138  if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, PlainObject>(1, size, func);
140 }
141 
151 template<typename Derived>
152 template<typename CustomNullaryOp>
154 DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
155 {
156  return CwiseNullaryOp<CustomNullaryOp, PlainObject>(RowsAtCompileTime, ColsAtCompileTime, func);
157 }
158 
172 template<typename Derived>
175 {
177 }
178 
194 template<typename Derived>
195 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
197 {
199 }
200 
210 template<typename Derived>
211 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
213 {
215  return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
216 }
217 
222 template<typename Derived>
225 {
228 }
229 
234 template<typename Derived>
237 {
240  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar>(low,high,Derived::SizeAtCompileTime));
241 }
242 
266 template<typename Derived>
269 {
272 }
273 
278 template<typename Derived>
281 {
284  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,PacketScalar>(low,high,Derived::SizeAtCompileTime));
285 }
286 
288 template<typename Derived>
289 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isApproxToConstant
290 (const Scalar& val, const RealScalar& prec) const
291 {
292  typename internal::nested_eval<Derived,1>::type self(derived());
293  for(Index j = 0; j < cols(); ++j)
294  for(Index i = 0; i < rows(); ++i)
295  if(!internal::isApprox(self.coeff(i, j), val, prec))
296  return false;
297  return true;
298 }
299 
303 template<typename Derived>
304 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isConstant
305 (const Scalar& val, const RealScalar& prec) const
306 {
307  return isApproxToConstant(val, prec);
308 }
309 
314 template<typename Derived>
315 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void DenseBase<Derived>::fill(const Scalar& val)
316 {
317  setConstant(val);
318 }
319 
324 template<typename Derived>
325 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& val)
326 {
327  return derived() = Constant(rows(), cols(), val);
328 }
329 
339 template<typename Derived>
340 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
342 {
343  resize(size);
344  return setConstant(val);
345 }
346 
358 template<typename Derived>
359 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
361 {
362  resize(rows, cols);
363  return setConstant(val);
364 }
365 
382 template<typename Derived>
383 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high)
384 {
386  return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,PacketScalar>(low,high,newSize));
387 }
388 
402 template<typename Derived>
403 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(const Scalar& low, const Scalar& high)
404 {
406  return setLinSpaced(size(), low, high);
407 }
408 
409 // zero:
410 
425 template<typename Derived>
426 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
428 {
429  return Constant(rows, cols, Scalar(0));
430 }
431 
448 template<typename Derived>
449 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
451 {
452  return Constant(size, Scalar(0));
453 }
454 
465 template<typename Derived>
466 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
468 {
469  return Constant(Scalar(0));
470 }
471 
480 template<typename Derived>
481 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isZero(const RealScalar& prec) const
482 {
483  typename internal::nested_eval<Derived,1>::type self(derived());
484  for(Index j = 0; j < cols(); ++j)
485  for(Index i = 0; i < rows(); ++i)
486  if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<Scalar>(1), prec))
487  return false;
488  return true;
489 }
490 
498 template<typename Derived>
500 {
501  return setConstant(Scalar(0));
502 }
503 
513 template<typename Derived>
514 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
516 {
517  resize(newSize);
518  return setConstant(Scalar(0));
519 }
520 
531 template<typename Derived>
532 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
534 {
535  resize(rows, cols);
536  return setConstant(Scalar(0));
537 }
538 
539 // ones:
540 
555 template<typename Derived>
556 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
558 {
559  return Constant(rows, cols, Scalar(1));
560 }
561 
578 template<typename Derived>
579 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
581 {
582  return Constant(newSize, Scalar(1));
583 }
584 
595 template<typename Derived>
596 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
598 {
599  return Constant(Scalar(1));
600 }
601 
610 template<typename Derived>
611 EIGEN_DEVICE_FUNC bool DenseBase<Derived>::isOnes
612 (const RealScalar& prec) const
613 {
614  return isApproxToConstant(Scalar(1), prec);
615 }
616 
624 template<typename Derived>
626 {
627  return setConstant(Scalar(1));
628 }
629 
639 template<typename Derived>
640 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
642 {
643  resize(newSize);
644  return setConstant(Scalar(1));
645 }
646 
657 template<typename Derived>
658 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived&
660 {
661  resize(rows, cols);
662  return setConstant(Scalar(1));
663 }
664 
665 // Identity:
666 
681 template<typename Derived>
682 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
684 {
686 }
687 
698 template<typename Derived>
699 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
701 {
703  return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>());
704 }
705 
715 template<typename Derived>
717 (const RealScalar& prec) const
718 {
719  typename internal::nested_eval<Derived,1>::type self(derived());
720  for(Index j = 0; j < cols(); ++j)
721  {
722  for(Index i = 0; i < rows(); ++i)
723  {
724  if(i == j)
725  {
726  if(!internal::isApprox(self.coeff(i, j), static_cast<Scalar>(1), prec))
727  return false;
728  }
729  else
730  {
731  if(!internal::isMuchSmallerThan(self.coeff(i, j), static_cast<RealScalar>(1), prec))
732  return false;
733  }
734  }
735  }
736  return true;
737 }
738 
739 namespace internal {
740 
741 template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
743 {
744  EIGEN_DEVICE_FUNC
745  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
746  {
747  return m = Derived::Identity(m.rows(), m.cols());
748  }
749 };
750 
751 template<typename Derived>
752 struct setIdentity_impl<Derived, true>
753 {
754  EIGEN_DEVICE_FUNC
755  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
756  {
757  m.setZero();
758  const Index size = numext::mini(m.rows(), m.cols());
759  for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
760  return m;
761  }
762 };
763 
764 } // end namespace internal
765 
773 template<typename Derived>
775 {
777 }
778 
789 template<typename Derived>
790 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity(Index rows, Index cols)
791 {
792  derived().resize(rows, cols);
793  return setIdentity();
794 }
795 
802 template<typename Derived>
804 {
806  return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
807 }
808 
817 template<typename Derived>
819 {
821  return BasisReturnType(SquareMatrixType::Identity(),i);
822 }
823 
830 template<typename Derived>
832 { return Derived::Unit(0); }
833 
840 template<typename Derived>
842 { return Derived::Unit(1); }
843 
850 template<typename Derived>
852 { return Derived::Unit(2); }
853 
860 template<typename Derived>
862 { return Derived::Unit(3); }
863 
864 } // end namespace Eigen
865 
866 #endif // EIGEN_CWISE_NULLARY_OP_H
static EIGEN_DEVICE_FUNC const IdentityReturnType Identity()
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 BasisReturnType Unit(Index size, Index i)
internal::traits< Derived >::Scalar Scalar
void setIdentity(geometry_msgs::Transform &tx)
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
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
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & run(Derived &m)
EIGEN_DEVICE_FUNC void fill(const Scalar &value)
EIGEN_DEVICE_FUNC Derived & setOnes()
Definition: LDLT.h:16
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
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)
const unsigned int RowMajorBit
Definition: Constants.h:61
EIGEN_DEVICE_FUNC Derived & setConstant(const Scalar &value)
const NullaryOp m_functor
static EIGEN_DEVICE_FUNC const BasisReturnType UnitX()
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
#define eigen_assert(x)
Definition: Macros.h:577
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:142
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
EIGEN_DEVICE_FUNC bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static EIGEN_DEVICE_FUNC const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & run(Derived &m)
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:351
EIGEN_DEVICE_FUNC bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly spaced vector.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:867
EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
const int Dynamic
Definition: Constants.h:21
static EIGEN_DEVICE_FUNC const CwiseNullaryOp< CustomNullaryOp, PlainObject > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
static EIGEN_DEVICE_FUNC const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
EIGEN_DEVICE_FUNC bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:137
EIGEN_DEVICE_FUNC Derived & setIdentity()
internal::dense_xpr_base< CwiseNullaryOp >::type Base


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:08