Eigne Matrix Class Library

Dependents:   MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more

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?

UserRevisionLine numberNew 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-2010 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_CWISE_NULLARY_OP_H
ykuroda 0:13a5d365ba16 11 #define EIGEN_CWISE_NULLARY_OP_H
ykuroda 0:13a5d365ba16 12
ykuroda 0:13a5d365ba16 13 namespace Eigen {
ykuroda 0:13a5d365ba16 14
ykuroda 0:13a5d365ba16 15 /** \class CwiseNullaryOp
ykuroda 0:13a5d365ba16 16 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 17 *
ykuroda 0:13a5d365ba16 18 * \brief Generic expression of a matrix where all coefficients are defined by a functor
ykuroda 0:13a5d365ba16 19 *
ykuroda 0:13a5d365ba16 20 * \param NullaryOp template functor implementing the operator
ykuroda 0:13a5d365ba16 21 * \param PlainObjectType the underlying plain matrix/array type
ykuroda 0:13a5d365ba16 22 *
ykuroda 0:13a5d365ba16 23 * This class represents an expression of a generic nullary operator.
ykuroda 0:13a5d365ba16 24 * It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods,
ykuroda 0:13a5d365ba16 25 * and most of the time this is the only way it is used.
ykuroda 0:13a5d365ba16 26 *
ykuroda 0:13a5d365ba16 27 * However, if you want to write a function returning such an expression, you
ykuroda 0:13a5d365ba16 28 * will need to use this class.
ykuroda 0:13a5d365ba16 29 *
ykuroda 0:13a5d365ba16 30 * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr()
ykuroda 0:13a5d365ba16 31 */
ykuroda 0:13a5d365ba16 32
ykuroda 0:13a5d365ba16 33 namespace internal {
ykuroda 0:13a5d365ba16 34 template<typename NullaryOp, typename PlainObjectType>
ykuroda 0:13a5d365ba16 35 struct traits<CwiseNullaryOp<NullaryOp, PlainObjectType> > : traits<PlainObjectType>
ykuroda 0:13a5d365ba16 36 {
ykuroda 0:13a5d365ba16 37 enum {
ykuroda 0:13a5d365ba16 38 Flags = (traits<PlainObjectType>::Flags
ykuroda 0:13a5d365ba16 39 & ( HereditaryBits
ykuroda 0:13a5d365ba16 40 | (functor_has_linear_access<NullaryOp>::ret ? LinearAccessBit : 0)
ykuroda 0:13a5d365ba16 41 | (functor_traits<NullaryOp>::PacketAccess ? PacketAccessBit : 0)))
ykuroda 0:13a5d365ba16 42 | (functor_traits<NullaryOp>::IsRepeatable ? 0 : EvalBeforeNestingBit),
ykuroda 0:13a5d365ba16 43 CoeffReadCost = functor_traits<NullaryOp>::Cost
ykuroda 0:13a5d365ba16 44 };
ykuroda 0:13a5d365ba16 45 };
ykuroda 0:13a5d365ba16 46 }
ykuroda 0:13a5d365ba16 47
ykuroda 0:13a5d365ba16 48 template<typename NullaryOp, typename PlainObjectType>
ykuroda 0:13a5d365ba16 49 class CwiseNullaryOp : internal::no_assignment_operator,
ykuroda 0:13a5d365ba16 50 public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type
ykuroda 0:13a5d365ba16 51 {
ykuroda 0:13a5d365ba16 52 public:
ykuroda 0:13a5d365ba16 53
ykuroda 0:13a5d365ba16 54 typedef typename internal::dense_xpr_base<CwiseNullaryOp>::type Base;
ykuroda 0:13a5d365ba16 55 EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp)
ykuroda 0:13a5d365ba16 56
ykuroda 0:13a5d365ba16 57 CwiseNullaryOp(Index nbRows, Index nbCols, const NullaryOp& func = NullaryOp())
ykuroda 0:13a5d365ba16 58 : m_rows(nbRows), m_cols(nbCols), m_functor(func)
ykuroda 0:13a5d365ba16 59 {
ykuroda 0:13a5d365ba16 60 eigen_assert(nbRows >= 0
ykuroda 0:13a5d365ba16 61 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == nbRows)
ykuroda 0:13a5d365ba16 62 && nbCols >= 0
ykuroda 0:13a5d365ba16 63 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == nbCols));
ykuroda 0:13a5d365ba16 64 }
ykuroda 0:13a5d365ba16 65
ykuroda 0:13a5d365ba16 66 EIGEN_STRONG_INLINE Index rows() const { return m_rows.value(); }
ykuroda 0:13a5d365ba16 67 EIGEN_STRONG_INLINE Index cols() const { return m_cols.value(); }
ykuroda 0:13a5d365ba16 68
ykuroda 0:13a5d365ba16 69 EIGEN_STRONG_INLINE const Scalar coeff(Index rowId, Index colId) const
ykuroda 0:13a5d365ba16 70 {
ykuroda 0:13a5d365ba16 71 return m_functor(rowId, colId);
ykuroda 0:13a5d365ba16 72 }
ykuroda 0:13a5d365ba16 73
ykuroda 0:13a5d365ba16 74 template<int LoadMode>
ykuroda 0:13a5d365ba16 75 EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const
ykuroda 0:13a5d365ba16 76 {
ykuroda 0:13a5d365ba16 77 return m_functor.packetOp(rowId, colId);
ykuroda 0:13a5d365ba16 78 }
ykuroda 0:13a5d365ba16 79
ykuroda 0:13a5d365ba16 80 EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
ykuroda 0:13a5d365ba16 81 {
ykuroda 0:13a5d365ba16 82 return m_functor(index);
ykuroda 0:13a5d365ba16 83 }
ykuroda 0:13a5d365ba16 84
ykuroda 0:13a5d365ba16 85 template<int LoadMode>
ykuroda 0:13a5d365ba16 86 EIGEN_STRONG_INLINE PacketScalar packet(Index index) const
ykuroda 0:13a5d365ba16 87 {
ykuroda 0:13a5d365ba16 88 return m_functor.packetOp(index);
ykuroda 0:13a5d365ba16 89 }
ykuroda 0:13a5d365ba16 90
ykuroda 0:13a5d365ba16 91 /** \returns the functor representing the nullary operation */
ykuroda 0:13a5d365ba16 92 const NullaryOp& functor() const { return m_functor; }
ykuroda 0:13a5d365ba16 93
ykuroda 0:13a5d365ba16 94 protected:
ykuroda 0:13a5d365ba16 95 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
ykuroda 0:13a5d365ba16 96 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
ykuroda 0:13a5d365ba16 97 const NullaryOp m_functor;
ykuroda 0:13a5d365ba16 98 };
ykuroda 0:13a5d365ba16 99
ykuroda 0:13a5d365ba16 100
ykuroda 0:13a5d365ba16 101 /** \returns an expression of a matrix defined by a custom functor \a func
ykuroda 0:13a5d365ba16 102 *
ykuroda 0:13a5d365ba16 103 * The parameters \a rows and \a cols are the number of rows and of columns of
ykuroda 0:13a5d365ba16 104 * the returned matrix. Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 105 *
ykuroda 0:13a5d365ba16 106 * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
ykuroda 0:13a5d365ba16 107 * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
ykuroda 0:13a5d365ba16 108 * instead.
ykuroda 0:13a5d365ba16 109 *
ykuroda 0:13a5d365ba16 110 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 111 *
ykuroda 0:13a5d365ba16 112 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 113 */
ykuroda 0:13a5d365ba16 114 template<typename Derived>
ykuroda 0:13a5d365ba16 115 template<typename CustomNullaryOp>
ykuroda 0:13a5d365ba16 116 EIGEN_STRONG_INLINE const CwiseNullaryOp<CustomNullaryOp, Derived>
ykuroda 0:13a5d365ba16 117 DenseBase<Derived>::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func)
ykuroda 0:13a5d365ba16 118 {
ykuroda 0:13a5d365ba16 119 return CwiseNullaryOp<CustomNullaryOp, Derived>(rows, cols, func);
ykuroda 0:13a5d365ba16 120 }
ykuroda 0:13a5d365ba16 121
ykuroda 0:13a5d365ba16 122 /** \returns an expression of a matrix defined by a custom functor \a func
ykuroda 0:13a5d365ba16 123 *
ykuroda 0:13a5d365ba16 124 * The parameter \a size is the size of the returned vector.
ykuroda 0:13a5d365ba16 125 * Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 126 *
ykuroda 0:13a5d365ba16 127 * \only_for_vectors
ykuroda 0:13a5d365ba16 128 *
ykuroda 0:13a5d365ba16 129 * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
ykuroda 0:13a5d365ba16 130 * it is redundant to pass \a size as argument, so Zero() should be used
ykuroda 0:13a5d365ba16 131 * instead.
ykuroda 0:13a5d365ba16 132 *
ykuroda 0:13a5d365ba16 133 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 134 *
ykuroda 0:13a5d365ba16 135 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 136 */
ykuroda 0:13a5d365ba16 137 template<typename Derived>
ykuroda 0:13a5d365ba16 138 template<typename CustomNullaryOp>
ykuroda 0:13a5d365ba16 139 EIGEN_STRONG_INLINE const CwiseNullaryOp<CustomNullaryOp, Derived>
ykuroda 0:13a5d365ba16 140 DenseBase<Derived>::NullaryExpr(Index size, const CustomNullaryOp& func)
ykuroda 0:13a5d365ba16 141 {
ykuroda 0:13a5d365ba16 142 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 143 if(RowsAtCompileTime == 1) return CwiseNullaryOp<CustomNullaryOp, Derived>(1, size, func);
ykuroda 0:13a5d365ba16 144 else return CwiseNullaryOp<CustomNullaryOp, Derived>(size, 1, func);
ykuroda 0:13a5d365ba16 145 }
ykuroda 0:13a5d365ba16 146
ykuroda 0:13a5d365ba16 147 /** \returns an expression of a matrix defined by a custom functor \a func
ykuroda 0:13a5d365ba16 148 *
ykuroda 0:13a5d365ba16 149 * This variant is only for fixed-size DenseBase types. For dynamic-size types, you
ykuroda 0:13a5d365ba16 150 * need to use the variants taking size arguments.
ykuroda 0:13a5d365ba16 151 *
ykuroda 0:13a5d365ba16 152 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 153 *
ykuroda 0:13a5d365ba16 154 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 155 */
ykuroda 0:13a5d365ba16 156 template<typename Derived>
ykuroda 0:13a5d365ba16 157 template<typename CustomNullaryOp>
ykuroda 0:13a5d365ba16 158 EIGEN_STRONG_INLINE const CwiseNullaryOp<CustomNullaryOp, Derived>
ykuroda 0:13a5d365ba16 159 DenseBase<Derived>::NullaryExpr(const CustomNullaryOp& func)
ykuroda 0:13a5d365ba16 160 {
ykuroda 0:13a5d365ba16 161 return CwiseNullaryOp<CustomNullaryOp, Derived>(RowsAtCompileTime, ColsAtCompileTime, func);
ykuroda 0:13a5d365ba16 162 }
ykuroda 0:13a5d365ba16 163
ykuroda 0:13a5d365ba16 164 /** \returns an expression of a constant matrix of value \a value
ykuroda 0:13a5d365ba16 165 *
ykuroda 0:13a5d365ba16 166 * The parameters \a nbRows and \a nbCols are the number of rows and of columns of
ykuroda 0:13a5d365ba16 167 * the returned matrix. Must be compatible with this DenseBase type.
ykuroda 0:13a5d365ba16 168 *
ykuroda 0:13a5d365ba16 169 * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
ykuroda 0:13a5d365ba16 170 * it is redundant to pass \a nbRows and \a nbCols as arguments, so Zero() should be used
ykuroda 0:13a5d365ba16 171 * instead.
ykuroda 0:13a5d365ba16 172 *
ykuroda 0:13a5d365ba16 173 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 174 *
ykuroda 0:13a5d365ba16 175 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 176 */
ykuroda 0:13a5d365ba16 177 template<typename Derived>
ykuroda 0:13a5d365ba16 178 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 179 DenseBase<Derived>::Constant(Index nbRows, Index nbCols, const Scalar& value)
ykuroda 0:13a5d365ba16 180 {
ykuroda 0:13a5d365ba16 181 return DenseBase<Derived>::NullaryExpr(nbRows, nbCols, internal::scalar_constant_op<Scalar>(value));
ykuroda 0:13a5d365ba16 182 }
ykuroda 0:13a5d365ba16 183
ykuroda 0:13a5d365ba16 184 /** \returns an expression of a constant matrix of value \a value
ykuroda 0:13a5d365ba16 185 *
ykuroda 0:13a5d365ba16 186 * The parameter \a size is the size of the returned vector.
ykuroda 0:13a5d365ba16 187 * Must be compatible with this DenseBase type.
ykuroda 0:13a5d365ba16 188 *
ykuroda 0:13a5d365ba16 189 * \only_for_vectors
ykuroda 0:13a5d365ba16 190 *
ykuroda 0:13a5d365ba16 191 * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
ykuroda 0:13a5d365ba16 192 * it is redundant to pass \a size as argument, so Zero() should be used
ykuroda 0:13a5d365ba16 193 * instead.
ykuroda 0:13a5d365ba16 194 *
ykuroda 0:13a5d365ba16 195 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 196 *
ykuroda 0:13a5d365ba16 197 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 198 */
ykuroda 0:13a5d365ba16 199 template<typename Derived>
ykuroda 0:13a5d365ba16 200 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 201 DenseBase<Derived>::Constant(Index size, const Scalar& value)
ykuroda 0:13a5d365ba16 202 {
ykuroda 0:13a5d365ba16 203 return DenseBase<Derived>::NullaryExpr(size, internal::scalar_constant_op<Scalar>(value));
ykuroda 0:13a5d365ba16 204 }
ykuroda 0:13a5d365ba16 205
ykuroda 0:13a5d365ba16 206 /** \returns an expression of a constant matrix of value \a value
ykuroda 0:13a5d365ba16 207 *
ykuroda 0:13a5d365ba16 208 * This variant is only for fixed-size DenseBase types. For dynamic-size types, you
ykuroda 0:13a5d365ba16 209 * need to use the variants taking size arguments.
ykuroda 0:13a5d365ba16 210 *
ykuroda 0:13a5d365ba16 211 * The template parameter \a CustomNullaryOp is the type of the functor.
ykuroda 0:13a5d365ba16 212 *
ykuroda 0:13a5d365ba16 213 * \sa class CwiseNullaryOp
ykuroda 0:13a5d365ba16 214 */
ykuroda 0:13a5d365ba16 215 template<typename Derived>
ykuroda 0:13a5d365ba16 216 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 217 DenseBase<Derived>::Constant(const Scalar& value)
ykuroda 0:13a5d365ba16 218 {
ykuroda 0:13a5d365ba16 219 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
ykuroda 0:13a5d365ba16 220 return DenseBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_constant_op<Scalar>(value));
ykuroda 0:13a5d365ba16 221 }
ykuroda 0:13a5d365ba16 222
ykuroda 0:13a5d365ba16 223 /**
ykuroda 0:13a5d365ba16 224 * \brief Sets a linearly space vector.
ykuroda 0:13a5d365ba16 225 *
ykuroda 0:13a5d365ba16 226 * The function generates 'size' equally spaced values in the closed interval [low,high].
ykuroda 0:13a5d365ba16 227 * This particular version of LinSpaced() uses sequential access, i.e. vector access is
ykuroda 0:13a5d365ba16 228 * assumed to be a(0), a(1), ..., a(size). This assumption allows for better vectorization
ykuroda 0:13a5d365ba16 229 * and yields faster code than the random access version.
ykuroda 0:13a5d365ba16 230 *
ykuroda 0:13a5d365ba16 231 * When size is set to 1, a vector of length 1 containing 'high' is returned.
ykuroda 0:13a5d365ba16 232 *
ykuroda 0:13a5d365ba16 233 * \only_for_vectors
ykuroda 0:13a5d365ba16 234 *
ykuroda 0:13a5d365ba16 235 * Example: \include DenseBase_LinSpaced_seq.cpp
ykuroda 0:13a5d365ba16 236 * Output: \verbinclude DenseBase_LinSpaced_seq.out
ykuroda 0:13a5d365ba16 237 *
ykuroda 0:13a5d365ba16 238 * \sa setLinSpaced(Index,const Scalar&,const Scalar&), LinSpaced(Index,Scalar,Scalar), CwiseNullaryOp
ykuroda 0:13a5d365ba16 239 */
ykuroda 0:13a5d365ba16 240 template<typename Derived>
ykuroda 0:13a5d365ba16 241 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::SequentialLinSpacedReturnType
ykuroda 0:13a5d365ba16 242 DenseBase<Derived>::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 243 {
ykuroda 0:13a5d365ba16 244 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 245 return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar,false>(low,high,size));
ykuroda 0:13a5d365ba16 246 }
ykuroda 0:13a5d365ba16 247
ykuroda 0:13a5d365ba16 248 /**
ykuroda 0:13a5d365ba16 249 * \copydoc DenseBase::LinSpaced(Sequential_t, Index, const Scalar&, const Scalar&)
ykuroda 0:13a5d365ba16 250 * Special version for fixed size types which does not require the size parameter.
ykuroda 0:13a5d365ba16 251 */
ykuroda 0:13a5d365ba16 252 template<typename Derived>
ykuroda 0:13a5d365ba16 253 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::SequentialLinSpacedReturnType
ykuroda 0:13a5d365ba16 254 DenseBase<Derived>::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 255 {
ykuroda 0:13a5d365ba16 256 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 257 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
ykuroda 0:13a5d365ba16 258 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,false>(low,high,Derived::SizeAtCompileTime));
ykuroda 0:13a5d365ba16 259 }
ykuroda 0:13a5d365ba16 260
ykuroda 0:13a5d365ba16 261 /**
ykuroda 0:13a5d365ba16 262 * \brief Sets a linearly space vector.
ykuroda 0:13a5d365ba16 263 *
ykuroda 0:13a5d365ba16 264 * The function generates 'size' equally spaced values in the closed interval [low,high].
ykuroda 0:13a5d365ba16 265 * When size is set to 1, a vector of length 1 containing 'high' is returned.
ykuroda 0:13a5d365ba16 266 *
ykuroda 0:13a5d365ba16 267 * \only_for_vectors
ykuroda 0:13a5d365ba16 268 *
ykuroda 0:13a5d365ba16 269 * Example: \include DenseBase_LinSpaced.cpp
ykuroda 0:13a5d365ba16 270 * Output: \verbinclude DenseBase_LinSpaced.out
ykuroda 0:13a5d365ba16 271 *
ykuroda 0:13a5d365ba16 272 * \sa setLinSpaced(Index,const Scalar&,const Scalar&), LinSpaced(Sequential_t,Index,const Scalar&,const Scalar&,Index), CwiseNullaryOp
ykuroda 0:13a5d365ba16 273 */
ykuroda 0:13a5d365ba16 274 template<typename Derived>
ykuroda 0:13a5d365ba16 275 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
ykuroda 0:13a5d365ba16 276 DenseBase<Derived>::LinSpaced(Index size, const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 277 {
ykuroda 0:13a5d365ba16 278 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 279 return DenseBase<Derived>::NullaryExpr(size, internal::linspaced_op<Scalar,true>(low,high,size));
ykuroda 0:13a5d365ba16 280 }
ykuroda 0:13a5d365ba16 281
ykuroda 0:13a5d365ba16 282 /**
ykuroda 0:13a5d365ba16 283 * \copydoc DenseBase::LinSpaced(Index, const Scalar&, const Scalar&)
ykuroda 0:13a5d365ba16 284 * Special version for fixed size types which does not require the size parameter.
ykuroda 0:13a5d365ba16 285 */
ykuroda 0:13a5d365ba16 286 template<typename Derived>
ykuroda 0:13a5d365ba16 287 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::RandomAccessLinSpacedReturnType
ykuroda 0:13a5d365ba16 288 DenseBase<Derived>::LinSpaced(const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 289 {
ykuroda 0:13a5d365ba16 290 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 291 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
ykuroda 0:13a5d365ba16 292 return DenseBase<Derived>::NullaryExpr(Derived::SizeAtCompileTime, internal::linspaced_op<Scalar,true>(low,high,Derived::SizeAtCompileTime));
ykuroda 0:13a5d365ba16 293 }
ykuroda 0:13a5d365ba16 294
ykuroda 0:13a5d365ba16 295 /** \returns true if all coefficients in this matrix are approximately equal to \a val, to within precision \a prec */
ykuroda 0:13a5d365ba16 296 template<typename Derived>
ykuroda 0:13a5d365ba16 297 bool DenseBase<Derived>::isApproxToConstant
ykuroda 0:13a5d365ba16 298 (const Scalar& val, const RealScalar& prec) const
ykuroda 0:13a5d365ba16 299 {
ykuroda 0:13a5d365ba16 300 for(Index j = 0; j < cols(); ++j)
ykuroda 0:13a5d365ba16 301 for(Index i = 0; i < rows(); ++i)
ykuroda 0:13a5d365ba16 302 if(!internal::isApprox(this->coeff(i, j), val, prec))
ykuroda 0:13a5d365ba16 303 return false;
ykuroda 0:13a5d365ba16 304 return true;
ykuroda 0:13a5d365ba16 305 }
ykuroda 0:13a5d365ba16 306
ykuroda 0:13a5d365ba16 307 /** This is just an alias for isApproxToConstant().
ykuroda 0:13a5d365ba16 308 *
ykuroda 0:13a5d365ba16 309 * \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */
ykuroda 0:13a5d365ba16 310 template<typename Derived>
ykuroda 0:13a5d365ba16 311 bool DenseBase<Derived>::isConstant
ykuroda 0:13a5d365ba16 312 (const Scalar& val, const RealScalar& prec) const
ykuroda 0:13a5d365ba16 313 {
ykuroda 0:13a5d365ba16 314 return isApproxToConstant(val, prec);
ykuroda 0:13a5d365ba16 315 }
ykuroda 0:13a5d365ba16 316
ykuroda 0:13a5d365ba16 317 /** Alias for setConstant(): sets all coefficients in this expression to \a val.
ykuroda 0:13a5d365ba16 318 *
ykuroda 0:13a5d365ba16 319 * \sa setConstant(), Constant(), class CwiseNullaryOp
ykuroda 0:13a5d365ba16 320 */
ykuroda 0:13a5d365ba16 321 template<typename Derived>
ykuroda 0:13a5d365ba16 322 EIGEN_STRONG_INLINE void DenseBase<Derived>::fill(const Scalar& val)
ykuroda 0:13a5d365ba16 323 {
ykuroda 0:13a5d365ba16 324 setConstant(val);
ykuroda 0:13a5d365ba16 325 }
ykuroda 0:13a5d365ba16 326
ykuroda 0:13a5d365ba16 327 /** Sets all coefficients in this expression to \a value.
ykuroda 0:13a5d365ba16 328 *
ykuroda 0:13a5d365ba16 329 * \sa fill(), setConstant(Index,const Scalar&), setConstant(Index,Index,const Scalar&), setZero(), setOnes(), Constant(), class CwiseNullaryOp, setZero(), setOnes()
ykuroda 0:13a5d365ba16 330 */
ykuroda 0:13a5d365ba16 331 template<typename Derived>
ykuroda 0:13a5d365ba16 332 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setConstant(const Scalar& val)
ykuroda 0:13a5d365ba16 333 {
ykuroda 0:13a5d365ba16 334 return derived() = Constant(rows(), cols(), val);
ykuroda 0:13a5d365ba16 335 }
ykuroda 0:13a5d365ba16 336
ykuroda 0:13a5d365ba16 337 /** Resizes to the given \a size, and sets all coefficients in this expression to the given \a value.
ykuroda 0:13a5d365ba16 338 *
ykuroda 0:13a5d365ba16 339 * \only_for_vectors
ykuroda 0:13a5d365ba16 340 *
ykuroda 0:13a5d365ba16 341 * Example: \include Matrix_setConstant_int.cpp
ykuroda 0:13a5d365ba16 342 * Output: \verbinclude Matrix_setConstant_int.out
ykuroda 0:13a5d365ba16 343 *
ykuroda 0:13a5d365ba16 344 * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
ykuroda 0:13a5d365ba16 345 */
ykuroda 0:13a5d365ba16 346 template<typename Derived>
ykuroda 0:13a5d365ba16 347 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 348 PlainObjectBase<Derived>::setConstant(Index size, const Scalar& val)
ykuroda 0:13a5d365ba16 349 {
ykuroda 0:13a5d365ba16 350 resize(size);
ykuroda 0:13a5d365ba16 351 return setConstant(val);
ykuroda 0:13a5d365ba16 352 }
ykuroda 0:13a5d365ba16 353
ykuroda 0:13a5d365ba16 354 /** Resizes to the given size, and sets all coefficients in this expression to the given \a value.
ykuroda 0:13a5d365ba16 355 *
ykuroda 0:13a5d365ba16 356 * \param nbRows the new number of rows
ykuroda 0:13a5d365ba16 357 * \param nbCols the new number of columns
ykuroda 0:13a5d365ba16 358 * \param val the value to which all coefficients are set
ykuroda 0:13a5d365ba16 359 *
ykuroda 0:13a5d365ba16 360 * Example: \include Matrix_setConstant_int_int.cpp
ykuroda 0:13a5d365ba16 361 * Output: \verbinclude Matrix_setConstant_int_int.out
ykuroda 0:13a5d365ba16 362 *
ykuroda 0:13a5d365ba16 363 * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, MatrixBase::Constant(const Scalar&)
ykuroda 0:13a5d365ba16 364 */
ykuroda 0:13a5d365ba16 365 template<typename Derived>
ykuroda 0:13a5d365ba16 366 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 367 PlainObjectBase<Derived>::setConstant(Index nbRows, Index nbCols, const Scalar& val)
ykuroda 0:13a5d365ba16 368 {
ykuroda 0:13a5d365ba16 369 resize(nbRows, nbCols);
ykuroda 0:13a5d365ba16 370 return setConstant(val);
ykuroda 0:13a5d365ba16 371 }
ykuroda 0:13a5d365ba16 372
ykuroda 0:13a5d365ba16 373 /**
ykuroda 0:13a5d365ba16 374 * \brief Sets a linearly space vector.
ykuroda 0:13a5d365ba16 375 *
ykuroda 0:13a5d365ba16 376 * The function generates 'size' equally spaced values in the closed interval [low,high].
ykuroda 0:13a5d365ba16 377 * When size is set to 1, a vector of length 1 containing 'high' is returned.
ykuroda 0:13a5d365ba16 378 *
ykuroda 0:13a5d365ba16 379 * \only_for_vectors
ykuroda 0:13a5d365ba16 380 *
ykuroda 0:13a5d365ba16 381 * Example: \include DenseBase_setLinSpaced.cpp
ykuroda 0:13a5d365ba16 382 * Output: \verbinclude DenseBase_setLinSpaced.out
ykuroda 0:13a5d365ba16 383 *
ykuroda 0:13a5d365ba16 384 * \sa CwiseNullaryOp
ykuroda 0:13a5d365ba16 385 */
ykuroda 0:13a5d365ba16 386 template<typename Derived>
ykuroda 0:13a5d365ba16 387 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(Index newSize, const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 388 {
ykuroda 0:13a5d365ba16 389 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 390 return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op<Scalar,false>(low,high,newSize));
ykuroda 0:13a5d365ba16 391 }
ykuroda 0:13a5d365ba16 392
ykuroda 0:13a5d365ba16 393 /**
ykuroda 0:13a5d365ba16 394 * \brief Sets a linearly space vector.
ykuroda 0:13a5d365ba16 395 *
ykuroda 0:13a5d365ba16 396 * The function fill *this with equally spaced values in the closed interval [low,high].
ykuroda 0:13a5d365ba16 397 * When size is set to 1, a vector of length 1 containing 'high' is returned.
ykuroda 0:13a5d365ba16 398 *
ykuroda 0:13a5d365ba16 399 * \only_for_vectors
ykuroda 0:13a5d365ba16 400 *
ykuroda 0:13a5d365ba16 401 * \sa setLinSpaced(Index, const Scalar&, const Scalar&), CwiseNullaryOp
ykuroda 0:13a5d365ba16 402 */
ykuroda 0:13a5d365ba16 403 template<typename Derived>
ykuroda 0:13a5d365ba16 404 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setLinSpaced(const Scalar& low, const Scalar& high)
ykuroda 0:13a5d365ba16 405 {
ykuroda 0:13a5d365ba16 406 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 407 return setLinSpaced(size(), low, high);
ykuroda 0:13a5d365ba16 408 }
ykuroda 0:13a5d365ba16 409
ykuroda 0:13a5d365ba16 410 // zero:
ykuroda 0:13a5d365ba16 411
ykuroda 0:13a5d365ba16 412 /** \returns an expression of a zero matrix.
ykuroda 0:13a5d365ba16 413 *
ykuroda 0:13a5d365ba16 414 * The parameters \a rows and \a cols are the number of rows and of columns of
ykuroda 0:13a5d365ba16 415 * the returned matrix. Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 416 *
ykuroda 0:13a5d365ba16 417 * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
ykuroda 0:13a5d365ba16 418 * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used
ykuroda 0:13a5d365ba16 419 * instead.
ykuroda 0:13a5d365ba16 420 *
ykuroda 0:13a5d365ba16 421 * Example: \include MatrixBase_zero_int_int.cpp
ykuroda 0:13a5d365ba16 422 * Output: \verbinclude MatrixBase_zero_int_int.out
ykuroda 0:13a5d365ba16 423 *
ykuroda 0:13a5d365ba16 424 * \sa Zero(), Zero(Index)
ykuroda 0:13a5d365ba16 425 */
ykuroda 0:13a5d365ba16 426 template<typename Derived>
ykuroda 0:13a5d365ba16 427 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 428 DenseBase<Derived>::Zero(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 429 {
ykuroda 0:13a5d365ba16 430 return Constant(nbRows, nbCols, Scalar(0));
ykuroda 0:13a5d365ba16 431 }
ykuroda 0:13a5d365ba16 432
ykuroda 0:13a5d365ba16 433 /** \returns an expression of a zero vector.
ykuroda 0:13a5d365ba16 434 *
ykuroda 0:13a5d365ba16 435 * The parameter \a size is the size of the returned vector.
ykuroda 0:13a5d365ba16 436 * Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 437 *
ykuroda 0:13a5d365ba16 438 * \only_for_vectors
ykuroda 0:13a5d365ba16 439 *
ykuroda 0:13a5d365ba16 440 * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
ykuroda 0:13a5d365ba16 441 * it is redundant to pass \a size as argument, so Zero() should be used
ykuroda 0:13a5d365ba16 442 * instead.
ykuroda 0:13a5d365ba16 443 *
ykuroda 0:13a5d365ba16 444 * Example: \include MatrixBase_zero_int.cpp
ykuroda 0:13a5d365ba16 445 * Output: \verbinclude MatrixBase_zero_int.out
ykuroda 0:13a5d365ba16 446 *
ykuroda 0:13a5d365ba16 447 * \sa Zero(), Zero(Index,Index)
ykuroda 0:13a5d365ba16 448 */
ykuroda 0:13a5d365ba16 449 template<typename Derived>
ykuroda 0:13a5d365ba16 450 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 451 DenseBase<Derived>::Zero(Index size)
ykuroda 0:13a5d365ba16 452 {
ykuroda 0:13a5d365ba16 453 return Constant(size, Scalar(0));
ykuroda 0:13a5d365ba16 454 }
ykuroda 0:13a5d365ba16 455
ykuroda 0:13a5d365ba16 456 /** \returns an expression of a fixed-size zero matrix or vector.
ykuroda 0:13a5d365ba16 457 *
ykuroda 0:13a5d365ba16 458 * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
ykuroda 0:13a5d365ba16 459 * need to use the variants taking size arguments.
ykuroda 0:13a5d365ba16 460 *
ykuroda 0:13a5d365ba16 461 * Example: \include MatrixBase_zero.cpp
ykuroda 0:13a5d365ba16 462 * Output: \verbinclude MatrixBase_zero.out
ykuroda 0:13a5d365ba16 463 *
ykuroda 0:13a5d365ba16 464 * \sa Zero(Index), Zero(Index,Index)
ykuroda 0:13a5d365ba16 465 */
ykuroda 0:13a5d365ba16 466 template<typename Derived>
ykuroda 0:13a5d365ba16 467 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 468 DenseBase<Derived>::Zero()
ykuroda 0:13a5d365ba16 469 {
ykuroda 0:13a5d365ba16 470 return Constant(Scalar(0));
ykuroda 0:13a5d365ba16 471 }
ykuroda 0:13a5d365ba16 472
ykuroda 0:13a5d365ba16 473 /** \returns true if *this is approximately equal to the zero matrix,
ykuroda 0:13a5d365ba16 474 * within the precision given by \a prec.
ykuroda 0:13a5d365ba16 475 *
ykuroda 0:13a5d365ba16 476 * Example: \include MatrixBase_isZero.cpp
ykuroda 0:13a5d365ba16 477 * Output: \verbinclude MatrixBase_isZero.out
ykuroda 0:13a5d365ba16 478 *
ykuroda 0:13a5d365ba16 479 * \sa class CwiseNullaryOp, Zero()
ykuroda 0:13a5d365ba16 480 */
ykuroda 0:13a5d365ba16 481 template<typename Derived>
ykuroda 0:13a5d365ba16 482 bool DenseBase<Derived>::isZero(const RealScalar& prec) const
ykuroda 0:13a5d365ba16 483 {
ykuroda 0:13a5d365ba16 484 for(Index j = 0; j < cols(); ++j)
ykuroda 0:13a5d365ba16 485 for(Index i = 0; i < rows(); ++i)
ykuroda 0:13a5d365ba16 486 if(!internal::isMuchSmallerThan(this->coeff(i, j), static_cast<Scalar>(1), prec))
ykuroda 0:13a5d365ba16 487 return false;
ykuroda 0:13a5d365ba16 488 return true;
ykuroda 0:13a5d365ba16 489 }
ykuroda 0:13a5d365ba16 490
ykuroda 0:13a5d365ba16 491 /** Sets all coefficients in this expression to zero.
ykuroda 0:13a5d365ba16 492 *
ykuroda 0:13a5d365ba16 493 * Example: \include MatrixBase_setZero.cpp
ykuroda 0:13a5d365ba16 494 * Output: \verbinclude MatrixBase_setZero.out
ykuroda 0:13a5d365ba16 495 *
ykuroda 0:13a5d365ba16 496 * \sa class CwiseNullaryOp, Zero()
ykuroda 0:13a5d365ba16 497 */
ykuroda 0:13a5d365ba16 498 template<typename Derived>
ykuroda 0:13a5d365ba16 499 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setZero()
ykuroda 0:13a5d365ba16 500 {
ykuroda 0:13a5d365ba16 501 return setConstant(Scalar(0));
ykuroda 0:13a5d365ba16 502 }
ykuroda 0:13a5d365ba16 503
ykuroda 0:13a5d365ba16 504 /** Resizes to the given \a size, and sets all coefficients in this expression to zero.
ykuroda 0:13a5d365ba16 505 *
ykuroda 0:13a5d365ba16 506 * \only_for_vectors
ykuroda 0:13a5d365ba16 507 *
ykuroda 0:13a5d365ba16 508 * Example: \include Matrix_setZero_int.cpp
ykuroda 0:13a5d365ba16 509 * Output: \verbinclude Matrix_setZero_int.out
ykuroda 0:13a5d365ba16 510 *
ykuroda 0:13a5d365ba16 511 * \sa DenseBase::setZero(), setZero(Index,Index), class CwiseNullaryOp, DenseBase::Zero()
ykuroda 0:13a5d365ba16 512 */
ykuroda 0:13a5d365ba16 513 template<typename Derived>
ykuroda 0:13a5d365ba16 514 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 515 PlainObjectBase<Derived>::setZero(Index newSize)
ykuroda 0:13a5d365ba16 516 {
ykuroda 0:13a5d365ba16 517 resize(newSize);
ykuroda 0:13a5d365ba16 518 return setConstant(Scalar(0));
ykuroda 0:13a5d365ba16 519 }
ykuroda 0:13a5d365ba16 520
ykuroda 0:13a5d365ba16 521 /** Resizes to the given size, and sets all coefficients in this expression to zero.
ykuroda 0:13a5d365ba16 522 *
ykuroda 0:13a5d365ba16 523 * \param nbRows the new number of rows
ykuroda 0:13a5d365ba16 524 * \param nbCols the new number of columns
ykuroda 0:13a5d365ba16 525 *
ykuroda 0:13a5d365ba16 526 * Example: \include Matrix_setZero_int_int.cpp
ykuroda 0:13a5d365ba16 527 * Output: \verbinclude Matrix_setZero_int_int.out
ykuroda 0:13a5d365ba16 528 *
ykuroda 0:13a5d365ba16 529 * \sa DenseBase::setZero(), setZero(Index), class CwiseNullaryOp, DenseBase::Zero()
ykuroda 0:13a5d365ba16 530 */
ykuroda 0:13a5d365ba16 531 template<typename Derived>
ykuroda 0:13a5d365ba16 532 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 533 PlainObjectBase<Derived>::setZero(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 534 {
ykuroda 0:13a5d365ba16 535 resize(nbRows, nbCols);
ykuroda 0:13a5d365ba16 536 return setConstant(Scalar(0));
ykuroda 0:13a5d365ba16 537 }
ykuroda 0:13a5d365ba16 538
ykuroda 0:13a5d365ba16 539 // ones:
ykuroda 0:13a5d365ba16 540
ykuroda 0:13a5d365ba16 541 /** \returns an expression of a matrix where all coefficients equal one.
ykuroda 0:13a5d365ba16 542 *
ykuroda 0:13a5d365ba16 543 * The parameters \a nbRows and \a nbCols are the number of rows and of columns of
ykuroda 0:13a5d365ba16 544 * the returned matrix. Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 545 *
ykuroda 0:13a5d365ba16 546 * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
ykuroda 0:13a5d365ba16 547 * it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used
ykuroda 0:13a5d365ba16 548 * instead.
ykuroda 0:13a5d365ba16 549 *
ykuroda 0:13a5d365ba16 550 * Example: \include MatrixBase_ones_int_int.cpp
ykuroda 0:13a5d365ba16 551 * Output: \verbinclude MatrixBase_ones_int_int.out
ykuroda 0:13a5d365ba16 552 *
ykuroda 0:13a5d365ba16 553 * \sa Ones(), Ones(Index), isOnes(), class Ones
ykuroda 0:13a5d365ba16 554 */
ykuroda 0:13a5d365ba16 555 template<typename Derived>
ykuroda 0:13a5d365ba16 556 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 557 DenseBase<Derived>::Ones(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 558 {
ykuroda 0:13a5d365ba16 559 return Constant(nbRows, nbCols, Scalar(1));
ykuroda 0:13a5d365ba16 560 }
ykuroda 0:13a5d365ba16 561
ykuroda 0:13a5d365ba16 562 /** \returns an expression of a vector where all coefficients equal one.
ykuroda 0:13a5d365ba16 563 *
ykuroda 0:13a5d365ba16 564 * The parameter \a newSize is the size of the returned vector.
ykuroda 0:13a5d365ba16 565 * Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 566 *
ykuroda 0:13a5d365ba16 567 * \only_for_vectors
ykuroda 0:13a5d365ba16 568 *
ykuroda 0:13a5d365ba16 569 * This variant is meant to be used for dynamic-size vector types. For fixed-size types,
ykuroda 0:13a5d365ba16 570 * it is redundant to pass \a size as argument, so Ones() should be used
ykuroda 0:13a5d365ba16 571 * instead.
ykuroda 0:13a5d365ba16 572 *
ykuroda 0:13a5d365ba16 573 * Example: \include MatrixBase_ones_int.cpp
ykuroda 0:13a5d365ba16 574 * Output: \verbinclude MatrixBase_ones_int.out
ykuroda 0:13a5d365ba16 575 *
ykuroda 0:13a5d365ba16 576 * \sa Ones(), Ones(Index,Index), isOnes(), class Ones
ykuroda 0:13a5d365ba16 577 */
ykuroda 0:13a5d365ba16 578 template<typename Derived>
ykuroda 0:13a5d365ba16 579 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 580 DenseBase<Derived>::Ones(Index newSize)
ykuroda 0:13a5d365ba16 581 {
ykuroda 0:13a5d365ba16 582 return Constant(newSize, Scalar(1));
ykuroda 0:13a5d365ba16 583 }
ykuroda 0:13a5d365ba16 584
ykuroda 0:13a5d365ba16 585 /** \returns an expression of a fixed-size matrix or vector where all coefficients equal one.
ykuroda 0:13a5d365ba16 586 *
ykuroda 0:13a5d365ba16 587 * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
ykuroda 0:13a5d365ba16 588 * need to use the variants taking size arguments.
ykuroda 0:13a5d365ba16 589 *
ykuroda 0:13a5d365ba16 590 * Example: \include MatrixBase_ones.cpp
ykuroda 0:13a5d365ba16 591 * Output: \verbinclude MatrixBase_ones.out
ykuroda 0:13a5d365ba16 592 *
ykuroda 0:13a5d365ba16 593 * \sa Ones(Index), Ones(Index,Index), isOnes(), class Ones
ykuroda 0:13a5d365ba16 594 */
ykuroda 0:13a5d365ba16 595 template<typename Derived>
ykuroda 0:13a5d365ba16 596 EIGEN_STRONG_INLINE const typename DenseBase<Derived>::ConstantReturnType
ykuroda 0:13a5d365ba16 597 DenseBase<Derived>::Ones()
ykuroda 0:13a5d365ba16 598 {
ykuroda 0:13a5d365ba16 599 return Constant(Scalar(1));
ykuroda 0:13a5d365ba16 600 }
ykuroda 0:13a5d365ba16 601
ykuroda 0:13a5d365ba16 602 /** \returns true if *this is approximately equal to the matrix where all coefficients
ykuroda 0:13a5d365ba16 603 * are equal to 1, within the precision given by \a prec.
ykuroda 0:13a5d365ba16 604 *
ykuroda 0:13a5d365ba16 605 * Example: \include MatrixBase_isOnes.cpp
ykuroda 0:13a5d365ba16 606 * Output: \verbinclude MatrixBase_isOnes.out
ykuroda 0:13a5d365ba16 607 *
ykuroda 0:13a5d365ba16 608 * \sa class CwiseNullaryOp, Ones()
ykuroda 0:13a5d365ba16 609 */
ykuroda 0:13a5d365ba16 610 template<typename Derived>
ykuroda 0:13a5d365ba16 611 bool DenseBase<Derived>::isOnes
ykuroda 0:13a5d365ba16 612 (const RealScalar& prec) const
ykuroda 0:13a5d365ba16 613 {
ykuroda 0:13a5d365ba16 614 return isApproxToConstant(Scalar(1), prec);
ykuroda 0:13a5d365ba16 615 }
ykuroda 0:13a5d365ba16 616
ykuroda 0:13a5d365ba16 617 /** Sets all coefficients in this expression to one.
ykuroda 0:13a5d365ba16 618 *
ykuroda 0:13a5d365ba16 619 * Example: \include MatrixBase_setOnes.cpp
ykuroda 0:13a5d365ba16 620 * Output: \verbinclude MatrixBase_setOnes.out
ykuroda 0:13a5d365ba16 621 *
ykuroda 0:13a5d365ba16 622 * \sa class CwiseNullaryOp, Ones()
ykuroda 0:13a5d365ba16 623 */
ykuroda 0:13a5d365ba16 624 template<typename Derived>
ykuroda 0:13a5d365ba16 625 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::setOnes()
ykuroda 0:13a5d365ba16 626 {
ykuroda 0:13a5d365ba16 627 return setConstant(Scalar(1));
ykuroda 0:13a5d365ba16 628 }
ykuroda 0:13a5d365ba16 629
ykuroda 0:13a5d365ba16 630 /** Resizes to the given \a newSize, and sets all coefficients in this expression to one.
ykuroda 0:13a5d365ba16 631 *
ykuroda 0:13a5d365ba16 632 * \only_for_vectors
ykuroda 0:13a5d365ba16 633 *
ykuroda 0:13a5d365ba16 634 * Example: \include Matrix_setOnes_int.cpp
ykuroda 0:13a5d365ba16 635 * Output: \verbinclude Matrix_setOnes_int.out
ykuroda 0:13a5d365ba16 636 *
ykuroda 0:13a5d365ba16 637 * \sa MatrixBase::setOnes(), setOnes(Index,Index), class CwiseNullaryOp, MatrixBase::Ones()
ykuroda 0:13a5d365ba16 638 */
ykuroda 0:13a5d365ba16 639 template<typename Derived>
ykuroda 0:13a5d365ba16 640 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 641 PlainObjectBase<Derived>::setOnes(Index newSize)
ykuroda 0:13a5d365ba16 642 {
ykuroda 0:13a5d365ba16 643 resize(newSize);
ykuroda 0:13a5d365ba16 644 return setConstant(Scalar(1));
ykuroda 0:13a5d365ba16 645 }
ykuroda 0:13a5d365ba16 646
ykuroda 0:13a5d365ba16 647 /** Resizes to the given size, and sets all coefficients in this expression to one.
ykuroda 0:13a5d365ba16 648 *
ykuroda 0:13a5d365ba16 649 * \param nbRows the new number of rows
ykuroda 0:13a5d365ba16 650 * \param nbCols the new number of columns
ykuroda 0:13a5d365ba16 651 *
ykuroda 0:13a5d365ba16 652 * Example: \include Matrix_setOnes_int_int.cpp
ykuroda 0:13a5d365ba16 653 * Output: \verbinclude Matrix_setOnes_int_int.out
ykuroda 0:13a5d365ba16 654 *
ykuroda 0:13a5d365ba16 655 * \sa MatrixBase::setOnes(), setOnes(Index), class CwiseNullaryOp, MatrixBase::Ones()
ykuroda 0:13a5d365ba16 656 */
ykuroda 0:13a5d365ba16 657 template<typename Derived>
ykuroda 0:13a5d365ba16 658 EIGEN_STRONG_INLINE Derived&
ykuroda 0:13a5d365ba16 659 PlainObjectBase<Derived>::setOnes(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 660 {
ykuroda 0:13a5d365ba16 661 resize(nbRows, nbCols);
ykuroda 0:13a5d365ba16 662 return setConstant(Scalar(1));
ykuroda 0:13a5d365ba16 663 }
ykuroda 0:13a5d365ba16 664
ykuroda 0:13a5d365ba16 665 // Identity:
ykuroda 0:13a5d365ba16 666
ykuroda 0:13a5d365ba16 667 /** \returns an expression of the identity matrix (not necessarily square).
ykuroda 0:13a5d365ba16 668 *
ykuroda 0:13a5d365ba16 669 * The parameters \a nbRows and \a nbCols are the number of rows and of columns of
ykuroda 0:13a5d365ba16 670 * the returned matrix. Must be compatible with this MatrixBase type.
ykuroda 0:13a5d365ba16 671 *
ykuroda 0:13a5d365ba16 672 * This variant is meant to be used for dynamic-size matrix types. For fixed-size types,
ykuroda 0:13a5d365ba16 673 * it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used
ykuroda 0:13a5d365ba16 674 * instead.
ykuroda 0:13a5d365ba16 675 *
ykuroda 0:13a5d365ba16 676 * Example: \include MatrixBase_identity_int_int.cpp
ykuroda 0:13a5d365ba16 677 * Output: \verbinclude MatrixBase_identity_int_int.out
ykuroda 0:13a5d365ba16 678 *
ykuroda 0:13a5d365ba16 679 * \sa Identity(), setIdentity(), isIdentity()
ykuroda 0:13a5d365ba16 680 */
ykuroda 0:13a5d365ba16 681 template<typename Derived>
ykuroda 0:13a5d365ba16 682 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
ykuroda 0:13a5d365ba16 683 MatrixBase<Derived>::Identity(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 684 {
ykuroda 0:13a5d365ba16 685 return DenseBase<Derived>::NullaryExpr(nbRows, nbCols, internal::scalar_identity_op<Scalar>());
ykuroda 0:13a5d365ba16 686 }
ykuroda 0:13a5d365ba16 687
ykuroda 0:13a5d365ba16 688 /** \returns an expression of the identity matrix (not necessarily square).
ykuroda 0:13a5d365ba16 689 *
ykuroda 0:13a5d365ba16 690 * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you
ykuroda 0:13a5d365ba16 691 * need to use the variant taking size arguments.
ykuroda 0:13a5d365ba16 692 *
ykuroda 0:13a5d365ba16 693 * Example: \include MatrixBase_identity.cpp
ykuroda 0:13a5d365ba16 694 * Output: \verbinclude MatrixBase_identity.out
ykuroda 0:13a5d365ba16 695 *
ykuroda 0:13a5d365ba16 696 * \sa Identity(Index,Index), setIdentity(), isIdentity()
ykuroda 0:13a5d365ba16 697 */
ykuroda 0:13a5d365ba16 698 template<typename Derived>
ykuroda 0:13a5d365ba16 699 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::IdentityReturnType
ykuroda 0:13a5d365ba16 700 MatrixBase<Derived>::Identity()
ykuroda 0:13a5d365ba16 701 {
ykuroda 0:13a5d365ba16 702 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived)
ykuroda 0:13a5d365ba16 703 return MatrixBase<Derived>::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op<Scalar>());
ykuroda 0:13a5d365ba16 704 }
ykuroda 0:13a5d365ba16 705
ykuroda 0:13a5d365ba16 706 /** \returns true if *this is approximately equal to the identity matrix
ykuroda 0:13a5d365ba16 707 * (not necessarily square),
ykuroda 0:13a5d365ba16 708 * within the precision given by \a prec.
ykuroda 0:13a5d365ba16 709 *
ykuroda 0:13a5d365ba16 710 * Example: \include MatrixBase_isIdentity.cpp
ykuroda 0:13a5d365ba16 711 * Output: \verbinclude MatrixBase_isIdentity.out
ykuroda 0:13a5d365ba16 712 *
ykuroda 0:13a5d365ba16 713 * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), setIdentity()
ykuroda 0:13a5d365ba16 714 */
ykuroda 0:13a5d365ba16 715 template<typename Derived>
ykuroda 0:13a5d365ba16 716 bool MatrixBase<Derived>::isIdentity
ykuroda 0:13a5d365ba16 717 (const RealScalar& prec) const
ykuroda 0:13a5d365ba16 718 {
ykuroda 0:13a5d365ba16 719 for(Index j = 0; j < cols(); ++j)
ykuroda 0:13a5d365ba16 720 {
ykuroda 0:13a5d365ba16 721 for(Index i = 0; i < rows(); ++i)
ykuroda 0:13a5d365ba16 722 {
ykuroda 0:13a5d365ba16 723 if(i == j)
ykuroda 0:13a5d365ba16 724 {
ykuroda 0:13a5d365ba16 725 if(!internal::isApprox(this->coeff(i, j), static_cast<Scalar>(1), prec))
ykuroda 0:13a5d365ba16 726 return false;
ykuroda 0:13a5d365ba16 727 }
ykuroda 0:13a5d365ba16 728 else
ykuroda 0:13a5d365ba16 729 {
ykuroda 0:13a5d365ba16 730 if(!internal::isMuchSmallerThan(this->coeff(i, j), static_cast<RealScalar>(1), prec))
ykuroda 0:13a5d365ba16 731 return false;
ykuroda 0:13a5d365ba16 732 }
ykuroda 0:13a5d365ba16 733 }
ykuroda 0:13a5d365ba16 734 }
ykuroda 0:13a5d365ba16 735 return true;
ykuroda 0:13a5d365ba16 736 }
ykuroda 0:13a5d365ba16 737
ykuroda 0:13a5d365ba16 738 namespace internal {
ykuroda 0:13a5d365ba16 739
ykuroda 0:13a5d365ba16 740 template<typename Derived, bool Big = (Derived::SizeAtCompileTime>=16)>
ykuroda 0:13a5d365ba16 741 struct setIdentity_impl
ykuroda 0:13a5d365ba16 742 {
ykuroda 0:13a5d365ba16 743 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
ykuroda 0:13a5d365ba16 744 {
ykuroda 0:13a5d365ba16 745 return m = Derived::Identity(m.rows(), m.cols());
ykuroda 0:13a5d365ba16 746 }
ykuroda 0:13a5d365ba16 747 };
ykuroda 0:13a5d365ba16 748
ykuroda 0:13a5d365ba16 749 template<typename Derived>
ykuroda 0:13a5d365ba16 750 struct setIdentity_impl<Derived, true>
ykuroda 0:13a5d365ba16 751 {
ykuroda 0:13a5d365ba16 752 typedef typename Derived::Index Index;
ykuroda 0:13a5d365ba16 753 static EIGEN_STRONG_INLINE Derived& run(Derived& m)
ykuroda 0:13a5d365ba16 754 {
ykuroda 0:13a5d365ba16 755 m.setZero();
ykuroda 0:13a5d365ba16 756 const Index size = (std::min)(m.rows(), m.cols());
ykuroda 0:13a5d365ba16 757 for(Index i = 0; i < size; ++i) m.coeffRef(i,i) = typename Derived::Scalar(1);
ykuroda 0:13a5d365ba16 758 return m;
ykuroda 0:13a5d365ba16 759 }
ykuroda 0:13a5d365ba16 760 };
ykuroda 0:13a5d365ba16 761
ykuroda 0:13a5d365ba16 762 } // end namespace internal
ykuroda 0:13a5d365ba16 763
ykuroda 0:13a5d365ba16 764 /** Writes the identity expression (not necessarily square) into *this.
ykuroda 0:13a5d365ba16 765 *
ykuroda 0:13a5d365ba16 766 * Example: \include MatrixBase_setIdentity.cpp
ykuroda 0:13a5d365ba16 767 * Output: \verbinclude MatrixBase_setIdentity.out
ykuroda 0:13a5d365ba16 768 *
ykuroda 0:13a5d365ba16 769 * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), isIdentity()
ykuroda 0:13a5d365ba16 770 */
ykuroda 0:13a5d365ba16 771 template<typename Derived>
ykuroda 0:13a5d365ba16 772 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity()
ykuroda 0:13a5d365ba16 773 {
ykuroda 0:13a5d365ba16 774 return internal::setIdentity_impl<Derived>::run(derived());
ykuroda 0:13a5d365ba16 775 }
ykuroda 0:13a5d365ba16 776
ykuroda 0:13a5d365ba16 777 /** \brief Resizes to the given size, and writes the identity expression (not necessarily square) into *this.
ykuroda 0:13a5d365ba16 778 *
ykuroda 0:13a5d365ba16 779 * \param nbRows the new number of rows
ykuroda 0:13a5d365ba16 780 * \param nbCols the new number of columns
ykuroda 0:13a5d365ba16 781 *
ykuroda 0:13a5d365ba16 782 * Example: \include Matrix_setIdentity_int_int.cpp
ykuroda 0:13a5d365ba16 783 * Output: \verbinclude Matrix_setIdentity_int_int.out
ykuroda 0:13a5d365ba16 784 *
ykuroda 0:13a5d365ba16 785 * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Identity()
ykuroda 0:13a5d365ba16 786 */
ykuroda 0:13a5d365ba16 787 template<typename Derived>
ykuroda 0:13a5d365ba16 788 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::setIdentity(Index nbRows, Index nbCols)
ykuroda 0:13a5d365ba16 789 {
ykuroda 0:13a5d365ba16 790 derived().resize(nbRows, nbCols);
ykuroda 0:13a5d365ba16 791 return setIdentity();
ykuroda 0:13a5d365ba16 792 }
ykuroda 0:13a5d365ba16 793
ykuroda 0:13a5d365ba16 794 /** \returns an expression of the i-th unit (basis) vector.
ykuroda 0:13a5d365ba16 795 *
ykuroda 0:13a5d365ba16 796 * \only_for_vectors
ykuroda 0:13a5d365ba16 797 *
ykuroda 0:13a5d365ba16 798 * \sa MatrixBase::Unit(Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 799 */
ykuroda 0:13a5d365ba16 800 template<typename Derived>
ykuroda 0:13a5d365ba16 801 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index newSize, Index i)
ykuroda 0:13a5d365ba16 802 {
ykuroda 0:13a5d365ba16 803 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 804 return BasisReturnType(SquareMatrixType::Identity(newSize,newSize), i);
ykuroda 0:13a5d365ba16 805 }
ykuroda 0:13a5d365ba16 806
ykuroda 0:13a5d365ba16 807 /** \returns an expression of the i-th unit (basis) vector.
ykuroda 0:13a5d365ba16 808 *
ykuroda 0:13a5d365ba16 809 * \only_for_vectors
ykuroda 0:13a5d365ba16 810 *
ykuroda 0:13a5d365ba16 811 * This variant is for fixed-size vector only.
ykuroda 0:13a5d365ba16 812 *
ykuroda 0:13a5d365ba16 813 * \sa MatrixBase::Unit(Index,Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 814 */
ykuroda 0:13a5d365ba16 815 template<typename Derived>
ykuroda 0:13a5d365ba16 816 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::Unit(Index i)
ykuroda 0:13a5d365ba16 817 {
ykuroda 0:13a5d365ba16 818 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
ykuroda 0:13a5d365ba16 819 return BasisReturnType(SquareMatrixType::Identity(),i);
ykuroda 0:13a5d365ba16 820 }
ykuroda 0:13a5d365ba16 821
ykuroda 0:13a5d365ba16 822 /** \returns an expression of the X axis unit vector (1{,0}^*)
ykuroda 0:13a5d365ba16 823 *
ykuroda 0:13a5d365ba16 824 * \only_for_vectors
ykuroda 0:13a5d365ba16 825 *
ykuroda 0:13a5d365ba16 826 * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 827 */
ykuroda 0:13a5d365ba16 828 template<typename Derived>
ykuroda 0:13a5d365ba16 829 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitX()
ykuroda 0:13a5d365ba16 830 { return Derived::Unit(0); }
ykuroda 0:13a5d365ba16 831
ykuroda 0:13a5d365ba16 832 /** \returns an expression of the Y axis unit vector (0,1{,0}^*)
ykuroda 0:13a5d365ba16 833 *
ykuroda 0:13a5d365ba16 834 * \only_for_vectors
ykuroda 0:13a5d365ba16 835 *
ykuroda 0:13a5d365ba16 836 * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 837 */
ykuroda 0:13a5d365ba16 838 template<typename Derived>
ykuroda 0:13a5d365ba16 839 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitY()
ykuroda 0:13a5d365ba16 840 { return Derived::Unit(1); }
ykuroda 0:13a5d365ba16 841
ykuroda 0:13a5d365ba16 842 /** \returns an expression of the Z axis unit vector (0,0,1{,0}^*)
ykuroda 0:13a5d365ba16 843 *
ykuroda 0:13a5d365ba16 844 * \only_for_vectors
ykuroda 0:13a5d365ba16 845 *
ykuroda 0:13a5d365ba16 846 * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 847 */
ykuroda 0:13a5d365ba16 848 template<typename Derived>
ykuroda 0:13a5d365ba16 849 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitZ()
ykuroda 0:13a5d365ba16 850 { return Derived::Unit(2); }
ykuroda 0:13a5d365ba16 851
ykuroda 0:13a5d365ba16 852 /** \returns an expression of the W axis unit vector (0,0,0,1)
ykuroda 0:13a5d365ba16 853 *
ykuroda 0:13a5d365ba16 854 * \only_for_vectors
ykuroda 0:13a5d365ba16 855 *
ykuroda 0:13a5d365ba16 856 * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW()
ykuroda 0:13a5d365ba16 857 */
ykuroda 0:13a5d365ba16 858 template<typename Derived>
ykuroda 0:13a5d365ba16 859 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::BasisReturnType MatrixBase<Derived>::UnitW()
ykuroda 0:13a5d365ba16 860 { return Derived::Unit(3); }
ykuroda 0:13a5d365ba16 861
ykuroda 0:13a5d365ba16 862 } // end namespace Eigen
ykuroda 0:13a5d365ba16 863
ykuroda 0:13a5d365ba16 864 #endif // EIGEN_CWISE_NULLARY_OP_H