Eigne Matrix Class Library
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/Core/Random.h@1:3b8049da21b8, 2019-09-24 (annotated)
- Committer:
- jsoh91
- Date:
- Tue Sep 24 00:18:23 2019 +0000
- Revision:
- 1:3b8049da21b8
- Parent:
- 0:13a5d365ba16
ignore and revise some of error parts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 0:13a5d365ba16 | 1 | // This file is part of Eigen, a lightweight C++ template library |
ykuroda | 0:13a5d365ba16 | 2 | // for linear algebra. |
ykuroda | 0:13a5d365ba16 | 3 | // |
ykuroda | 0:13a5d365ba16 | 4 | // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> |
ykuroda | 0:13a5d365ba16 | 5 | // |
ykuroda | 0:13a5d365ba16 | 6 | // This Source Code Form is subject to the terms of the Mozilla |
ykuroda | 0:13a5d365ba16 | 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
ykuroda | 0:13a5d365ba16 | 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
ykuroda | 0:13a5d365ba16 | 9 | |
ykuroda | 0:13a5d365ba16 | 10 | #ifndef EIGEN_RANDOM_H |
ykuroda | 0:13a5d365ba16 | 11 | #define EIGEN_RANDOM_H |
ykuroda | 0:13a5d365ba16 | 12 | |
ykuroda | 0:13a5d365ba16 | 13 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 14 | |
ykuroda | 0:13a5d365ba16 | 15 | namespace internal { |
ykuroda | 0:13a5d365ba16 | 16 | |
ykuroda | 0:13a5d365ba16 | 17 | template<typename Scalar> struct scalar_random_op { |
ykuroda | 0:13a5d365ba16 | 18 | EIGEN_EMPTY_STRUCT_CTOR(scalar_random_op) |
ykuroda | 0:13a5d365ba16 | 19 | template<typename Index> |
ykuroda | 0:13a5d365ba16 | 20 | inline const Scalar operator() (Index, Index = 0) const { return random<Scalar>(); } |
ykuroda | 0:13a5d365ba16 | 21 | }; |
ykuroda | 0:13a5d365ba16 | 22 | |
ykuroda | 0:13a5d365ba16 | 23 | template<typename Scalar> |
ykuroda | 0:13a5d365ba16 | 24 | struct functor_traits<scalar_random_op<Scalar> > |
ykuroda | 0:13a5d365ba16 | 25 | { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false, IsRepeatable = false }; }; |
ykuroda | 0:13a5d365ba16 | 26 | |
ykuroda | 0:13a5d365ba16 | 27 | } // end namespace internal |
ykuroda | 0:13a5d365ba16 | 28 | |
ykuroda | 0:13a5d365ba16 | 29 | /** \returns a random matrix expression |
ykuroda | 0:13a5d365ba16 | 30 | * |
ykuroda | 0:13a5d365ba16 | 31 | * The parameters \a rows and \a cols are the number of rows and of columns of |
ykuroda | 0:13a5d365ba16 | 32 | * the returned matrix. Must be compatible with this MatrixBase type. |
ykuroda | 0:13a5d365ba16 | 33 | * |
ykuroda | 0:13a5d365ba16 | 34 | * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, |
ykuroda | 0:13a5d365ba16 | 35 | * it is redundant to pass \a rows and \a cols as arguments, so Random() should be used |
ykuroda | 0:13a5d365ba16 | 36 | * instead. |
ykuroda | 0:13a5d365ba16 | 37 | * |
ykuroda | 0:13a5d365ba16 | 38 | * Example: \include MatrixBase_random_int_int.cpp |
ykuroda | 0:13a5d365ba16 | 39 | * Output: \verbinclude MatrixBase_random_int_int.out |
ykuroda | 0:13a5d365ba16 | 40 | * |
ykuroda | 0:13a5d365ba16 | 41 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into |
ykuroda | 0:13a5d365ba16 | 42 | * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected |
ykuroda | 0:13a5d365ba16 | 43 | * behavior with expressions involving random matrices. |
ykuroda | 0:13a5d365ba16 | 44 | * |
ykuroda | 0:13a5d365ba16 | 45 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index), MatrixBase::Random() |
ykuroda | 0:13a5d365ba16 | 46 | */ |
ykuroda | 0:13a5d365ba16 | 47 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 48 | inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived> |
ykuroda | 0:13a5d365ba16 | 49 | DenseBase<Derived>::Random(Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 50 | { |
ykuroda | 0:13a5d365ba16 | 51 | return NullaryExpr(rows, cols, internal::scalar_random_op<Scalar>()); |
ykuroda | 0:13a5d365ba16 | 52 | } |
ykuroda | 0:13a5d365ba16 | 53 | |
ykuroda | 0:13a5d365ba16 | 54 | /** \returns a random vector expression |
ykuroda | 0:13a5d365ba16 | 55 | * |
ykuroda | 0:13a5d365ba16 | 56 | * The parameter \a size is the size of the returned vector. |
ykuroda | 0:13a5d365ba16 | 57 | * Must be compatible with this MatrixBase type. |
ykuroda | 0:13a5d365ba16 | 58 | * |
ykuroda | 0:13a5d365ba16 | 59 | * \only_for_vectors |
ykuroda | 0:13a5d365ba16 | 60 | * |
ykuroda | 0:13a5d365ba16 | 61 | * This variant is meant to be used for dynamic-size vector types. For fixed-size types, |
ykuroda | 0:13a5d365ba16 | 62 | * it is redundant to pass \a size as argument, so Random() should be used |
ykuroda | 0:13a5d365ba16 | 63 | * instead. |
ykuroda | 0:13a5d365ba16 | 64 | * |
ykuroda | 0:13a5d365ba16 | 65 | * Example: \include MatrixBase_random_int.cpp |
ykuroda | 0:13a5d365ba16 | 66 | * Output: \verbinclude MatrixBase_random_int.out |
ykuroda | 0:13a5d365ba16 | 67 | * |
ykuroda | 0:13a5d365ba16 | 68 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into |
ykuroda | 0:13a5d365ba16 | 69 | * a temporary vector whenever it is nested in a larger expression. This prevents unexpected |
ykuroda | 0:13a5d365ba16 | 70 | * behavior with expressions involving random matrices. |
ykuroda | 0:13a5d365ba16 | 71 | * |
ykuroda | 0:13a5d365ba16 | 72 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index,Index), MatrixBase::Random() |
ykuroda | 0:13a5d365ba16 | 73 | */ |
ykuroda | 0:13a5d365ba16 | 74 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 75 | inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived> |
ykuroda | 0:13a5d365ba16 | 76 | DenseBase<Derived>::Random(Index size) |
ykuroda | 0:13a5d365ba16 | 77 | { |
ykuroda | 0:13a5d365ba16 | 78 | return NullaryExpr(size, internal::scalar_random_op<Scalar>()); |
ykuroda | 0:13a5d365ba16 | 79 | } |
ykuroda | 0:13a5d365ba16 | 80 | |
ykuroda | 0:13a5d365ba16 | 81 | /** \returns a fixed-size random matrix or vector expression |
ykuroda | 0:13a5d365ba16 | 82 | * |
ykuroda | 0:13a5d365ba16 | 83 | * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you |
ykuroda | 0:13a5d365ba16 | 84 | * need to use the variants taking size arguments. |
ykuroda | 0:13a5d365ba16 | 85 | * |
ykuroda | 0:13a5d365ba16 | 86 | * Example: \include MatrixBase_random.cpp |
ykuroda | 0:13a5d365ba16 | 87 | * Output: \verbinclude MatrixBase_random.out |
ykuroda | 0:13a5d365ba16 | 88 | * |
ykuroda | 0:13a5d365ba16 | 89 | * This expression has the "evaluate before nesting" flag so that it will be evaluated into |
ykuroda | 0:13a5d365ba16 | 90 | * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected |
ykuroda | 0:13a5d365ba16 | 91 | * behavior with expressions involving random matrices. |
ykuroda | 0:13a5d365ba16 | 92 | * |
ykuroda | 0:13a5d365ba16 | 93 | * \sa MatrixBase::setRandom(), MatrixBase::Random(Index,Index), MatrixBase::Random(Index) |
ykuroda | 0:13a5d365ba16 | 94 | */ |
ykuroda | 0:13a5d365ba16 | 95 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 96 | inline const CwiseNullaryOp<internal::scalar_random_op<typename internal::traits<Derived>::Scalar>, Derived> |
ykuroda | 0:13a5d365ba16 | 97 | DenseBase<Derived>::Random() |
ykuroda | 0:13a5d365ba16 | 98 | { |
ykuroda | 0:13a5d365ba16 | 99 | return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op<Scalar>()); |
ykuroda | 0:13a5d365ba16 | 100 | } |
ykuroda | 0:13a5d365ba16 | 101 | |
ykuroda | 0:13a5d365ba16 | 102 | /** Sets all coefficients in this expression to random values. |
ykuroda | 0:13a5d365ba16 | 103 | * |
ykuroda | 0:13a5d365ba16 | 104 | * Example: \include MatrixBase_setRandom.cpp |
ykuroda | 0:13a5d365ba16 | 105 | * Output: \verbinclude MatrixBase_setRandom.out |
ykuroda | 0:13a5d365ba16 | 106 | * |
ykuroda | 0:13a5d365ba16 | 107 | * \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index) |
ykuroda | 0:13a5d365ba16 | 108 | */ |
ykuroda | 0:13a5d365ba16 | 109 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 110 | inline Derived& DenseBase<Derived>::setRandom() |
ykuroda | 0:13a5d365ba16 | 111 | { |
ykuroda | 0:13a5d365ba16 | 112 | return *this = Random(rows(), cols()); |
ykuroda | 0:13a5d365ba16 | 113 | } |
ykuroda | 0:13a5d365ba16 | 114 | |
ykuroda | 0:13a5d365ba16 | 115 | /** Resizes to the given \a newSize, and sets all coefficients in this expression to random values. |
ykuroda | 0:13a5d365ba16 | 116 | * |
ykuroda | 0:13a5d365ba16 | 117 | * \only_for_vectors |
ykuroda | 0:13a5d365ba16 | 118 | * |
ykuroda | 0:13a5d365ba16 | 119 | * Example: \include Matrix_setRandom_int.cpp |
ykuroda | 0:13a5d365ba16 | 120 | * Output: \verbinclude Matrix_setRandom_int.out |
ykuroda | 0:13a5d365ba16 | 121 | * |
ykuroda | 0:13a5d365ba16 | 122 | * \sa MatrixBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, MatrixBase::Random() |
ykuroda | 0:13a5d365ba16 | 123 | */ |
ykuroda | 0:13a5d365ba16 | 124 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 125 | EIGEN_STRONG_INLINE Derived& |
ykuroda | 0:13a5d365ba16 | 126 | PlainObjectBase<Derived>::setRandom(Index newSize) |
ykuroda | 0:13a5d365ba16 | 127 | { |
ykuroda | 0:13a5d365ba16 | 128 | resize(newSize); |
ykuroda | 0:13a5d365ba16 | 129 | return setRandom(); |
ykuroda | 0:13a5d365ba16 | 130 | } |
ykuroda | 0:13a5d365ba16 | 131 | |
ykuroda | 0:13a5d365ba16 | 132 | /** Resizes to the given size, and sets all coefficients in this expression to random values. |
ykuroda | 0:13a5d365ba16 | 133 | * |
ykuroda | 0:13a5d365ba16 | 134 | * \param nbRows the new number of rows |
ykuroda | 0:13a5d365ba16 | 135 | * \param nbCols the new number of columns |
ykuroda | 0:13a5d365ba16 | 136 | * |
ykuroda | 0:13a5d365ba16 | 137 | * Example: \include Matrix_setRandom_int_int.cpp |
ykuroda | 0:13a5d365ba16 | 138 | * Output: \verbinclude Matrix_setRandom_int_int.out |
ykuroda | 0:13a5d365ba16 | 139 | * |
ykuroda | 0:13a5d365ba16 | 140 | * \sa MatrixBase::setRandom(), setRandom(Index), class CwiseNullaryOp, MatrixBase::Random() |
ykuroda | 0:13a5d365ba16 | 141 | */ |
ykuroda | 0:13a5d365ba16 | 142 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 143 | EIGEN_STRONG_INLINE Derived& |
ykuroda | 0:13a5d365ba16 | 144 | PlainObjectBase<Derived>::setRandom(Index nbRows, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 145 | { |
ykuroda | 0:13a5d365ba16 | 146 | resize(nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 147 | return setRandom(); |
ykuroda | 0:13a5d365ba16 | 148 | } |
ykuroda | 0:13a5d365ba16 | 149 | |
ykuroda | 0:13a5d365ba16 | 150 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 151 | |
ykuroda | 0:13a5d365ba16 | 152 | #endif // EIGEN_RANDOM_H |