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 
33 namespace internal {
34 template<typename NullaryOp, typename PlainObjectType>
35 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
36 {
37  enum {
39  & ( HereditaryBits
44  };
45 };
46 }
47 
48 template<typename NullaryOp, typename PlainObjectType>
50  public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type
51 {
52  public:
53 
56 
57  CwiseNullaryOp(Index nbRows, Index nbCols, const NullaryOp& func = NullaryOp())
58  : m_rows(nbRows), m_cols(nbCols), m_functor(func)
59  {
60  eigen_assert(nbRows >= 0
61  && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == nbRows)
62  && nbCols >= 0
63  && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == nbCols));
64  }
65 
66  EIGEN_STRONG_INLINE Index rows() const { return m_rows.value(); }
67  EIGEN_STRONG_INLINE Index cols() const { return m_cols.value(); }
68 
69  EIGEN_STRONG_INLINE const Scalar coeff(Index rowId, Index colId) const
70  {
71  return m_functor(rowId, colId);
72  }
73 
74  template<int LoadMode>
75  EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
76  {
77  return m_functor.packetOp(rowId, colId);
78  }
79 
80  EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
81  {
82  return m_functor(index);
83  }
84 
85  template<int LoadMode>
86  EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
87  {
88  return m_functor.packetOp(index);
89  }
90 
92  const NullaryOp& functor() const { return m_functor; }
93 
94  protected:
97  const NullaryOp m_functor;
98 };
99 
100 
114 template<typename Derived>
115 template<typename CustomNullaryOp>
117 DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func)
118 {
119  return CwiseNullaryOp<CustomNullaryOp, Derived>(rows, cols, func);
120 }
121 
137 template<typename Derived>
138 template<typename CustomNullaryOp>
140 DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func)
141 {
143  if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, Derived>(1, size, func);
144  else return CwiseNullaryOp<CustomNullaryOp, Derived>(size, 1, func);
145 }
146 
156 template<typename Derived>
157 template<typename CustomNullaryOp>
159 DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
160 {
161  return CwiseNullaryOp<CustomNullaryOp, Derived>(RowsAtCompileTime, ColsAtCompileTime, func);
162 }
163 
177 template<typename Derived>
179 DenseBase<Derived>::Constant(Index nbRows, Index nbCols, const Scalar& value)
180 {
182 }
183 
199 template<typename Derived>
202 {
204 }
205 
215 template<typename Derived>
218 {
220  return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
221 }
222 
240 template<typename Derived>
243 {
246 }
247 
252 template<typename Derived>
255 {
258  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,false>(low,high,Derived::SizeAtCompileTime));
259 }
260 
274 template<typename Derived>
276 DenseBase<Derived>::LinSpaced(Index size, const Scalar& low, const Scalar& high)
277 {
280 }
281 
286 template<typename Derived>
289 {
292  return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,true>(low,high,Derived::SizeAtCompileTime));
293 }
294 
296 template<typename Derived>
298 (const Scalar& val, const RealScalar& prec) const
299 {
300  for(Index j = 0; j < cols(); ++j)
301  for(Index i = 0; i < rows(); ++i)
302  if(!internal::isApprox(this->coeff(i, j), val, prec))
303  return false;
304  return true;
305 }
306 
310 template<typename Derived>
312 (const Scalar& val, const RealScalar& prec) const
313 {
314  return isApproxToConstant(val, prec);
315 }
316 
321 template<typename Derived>
323 {
324  setConstant(val);
325 }
326 
331 template<typename Derived>
333 {
334  return derived() = Constant(rows(), cols(), val);
335 }
336 
346 template<typename Derived>
347 EIGEN_STRONG_INLINE Derived&
349 {
350  resize(size);
351  return setConstant(val);
352 }
353 
365 template<typename Derived>
366 EIGEN_STRONG_INLINE Derived&
368 {
369  resize(nbRows, nbCols);
370  return setConstant(val);
371 }
372 
386 template<typename Derived>
387 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high)
388 {
390  return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,false>(low,high,newSize));
391 }
392 
403 template<typename Derived>
405 {
407  return setLinSpaced(size(), low, high);
408 }
409 
410 // zero:
411 
426 template<typename Derived>
429 {
430  return Constant(nbRows, nbCols, Scalar(0));
431 }
432 
449 template<typename Derived>
452 {
453  return Constant(size, Scalar(0));
454 }
455 
466 template<typename Derived>
469 {
470  return Constant(Scalar(0));
471 }
472 
481 template<typename Derived>
482 bool DenseBase<Derived>::isZero(const RealScalar& prec) const
483 {
484  for(Index j = 0; j < cols(); ++j)
485  for(Index i = 0; i < rows(); ++i)
486  if(!internal::isMuchSmallerThan(this->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_STRONG_INLINE Derived&
516 {
517  resize(newSize);
518  return setConstant(Scalar(0));
519 }
520 
531 template<typename Derived>
532 EIGEN_STRONG_INLINE Derived&
534 {
535  resize(nbRows, nbCols);
536  return setConstant(Scalar(0));
537 }
538 
539 // ones:
540 
555 template<typename Derived>
558 {
559  return Constant(nbRows, nbCols, Scalar(1));
560 }
561 
578 template<typename Derived>
581 {
582  return Constant(newSize, Scalar(1));
583 }
584 
595 template<typename Derived>
598 {
599  return Constant(Scalar(1));
600 }
601 
610 template<typename Derived>
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_STRONG_INLINE Derived&
642 {
643  resize(newSize);
644  return setConstant(Scalar(1));
645 }
646 
657 template<typename Derived>
658 EIGEN_STRONG_INLINE Derived&
660 {
661  resize(nbRows, nbCols);
662  return setConstant(Scalar(1));
663 }
664 
665 // Identity:
666 
681 template<typename Derived>
684 {
686 }
687 
698 template<typename Derived>
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  for(Index j = 0; j < cols(); ++j)
720  {
721  for(Index i = 0; i < rows(); ++i)
722  {
723  if(i == j)
724  {
725  if(!internal::isApprox(this->coeff(i, j), static_cast<Scalar>(1), prec))
726  return false;
727  }
728  else
729  {
730  if(!internal::isMuchSmallerThan(this->coeff(i, j), static_cast<RealScalar>(1), prec))
731  return false;
732  }
733  }
734  }
735  return true;
736 }
737 
738 namespace internal {
739 
740 template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
742 {
743  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
744  {
745  return m = Derived::Identity(m.rows(), m.cols());
746  }
747 };
748 
749 template<typename Derived>
750 struct setIdentity_impl<Derived, true>
751 {
752  typedef typename Derived::Index Index;
753  static EIGEN_STRONG_INLINE Derived& run(Derived& m)
754  {
755  m.setZero();
756  const Index size = (std::min)(m.rows(), m.cols());
757  for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
758  return m;
759  }
760 };
761 
762 } // end namespace internal
763 
771 template<typename Derived>
773 {
775 }
776 
787 template<typename Derived>
789 {
790  derived().resize(nbRows, nbCols);
791  return setIdentity();
792 }
793 
800 template<typename Derived>
802 {
804  return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
805 }
806 
815 template<typename Derived>
817 {
819  return BasisReturnType(SquareMatrixType::Identity(),i);
820 }
821 
828 template<typename Derived>
830 { return Derived::Unit(0); }
831 
838 template<typename Derived>
840 { return Derived::Unit(1); }
841 
848 template<typename Derived>
850 { return Derived::Unit(2); }
851 
858 template<typename Derived>
860 { return Derived::Unit(3); }
861 
862 } // end namespace Eigen
863 
864 #endif // EIGEN_CWISE_NULLARY_OP_H
Generic expression of a matrix where all coefficients are defined by a functor.
static EIGEN_STRONG_INLINE Derived & run(Derived &m)
void fill(const Scalar &value)
internal::traits< Derived >::Scalar Scalar
const internal::variable_if_dynamic< Index, ColsAtCompileTime > m_cols
static const CwiseNullaryOp< CustomNullaryOp, Derived > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
#define EIGEN_STRONG_INLINE
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:63
static const BasisReturnType UnitW()
Derived & setConstant(const Scalar &value)
Derived & setIdentity()
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
Derived & setOnes()
static const SequentialLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
Derived & setZero()
internal::traits< Derived >::Index Index
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
const internal::variable_if_dynamic< Index, RowsAtCompileTime > m_rows
static const BasisReturnType UnitY()
const unsigned int PacketAccessBit
const NullaryOp m_functor
EIGEN_STRONG_INLINE const Scalar coeff(Index rowId, Index colId) const
const unsigned int HereditaryBits
bool isZero(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static EIGEN_STRONG_INLINE Derived & run(Derived &m)
static const ConstantReturnType Zero()
EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
Derived & setLinSpaced(Index size, const Scalar &low, const Scalar &high)
Sets a linearly space vector.
EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
bool isApprox(const Scalar &x, const Scalar &y, typename NumTraits< Scalar >::Real precision=NumTraits< Scalar >::dummy_precision())
EIGEN_STRONG_INLINE Index cols() const
#define EIGEN_STATIC_ASSERT_FIXED_SIZE(TYPE)
Definition: StaticAssert.h:131
bool isOnes(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
static const BasisReturnType UnitZ()
Derived & setZero(Index size)
bool isIdentity(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Derived & setConstant(Index size, const Scalar &value)
static const IdentityReturnType Identity()
const NullaryOp & functor() const
Derived & setOnes(Index size)
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:65
bool isConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
Expression of a fixed-size or dynamic-size block.
Definition: Core/Block.h:102
static const ConstantReturnType Ones()
bool isApproxToConstant(const Scalar &value, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
const unsigned int EvalBeforeNestingBit
static const BasisReturnType UnitX()
static const ConstantReturnType Constant(Index rows, Index cols, const Scalar &value)
#define eigen_assert(x)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:126
static const BasisReturnType Unit(Index size, Index i)
const unsigned int LinearAccessBit
EIGEN_STRONG_INLINE Index rows() const
internal::dense_xpr_base< CwiseNullaryOp >::type Base


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32