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) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
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_DENSECOEFFSBASE_H
ykuroda 0:13a5d365ba16 11 #define EIGEN_DENSECOEFFSBASE_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 template<typename T> struct add_const_on_value_type_if_arithmetic
ykuroda 0:13a5d365ba16 17 {
ykuroda 0:13a5d365ba16 18 typedef typename conditional<is_arithmetic<T>::value, T, typename add_const_on_value_type<T>::type>::type type;
ykuroda 0:13a5d365ba16 19 };
ykuroda 0:13a5d365ba16 20 }
ykuroda 0:13a5d365ba16 21
ykuroda 0:13a5d365ba16 22 /** \brief Base class providing read-only coefficient access to matrices and arrays.
ykuroda 0:13a5d365ba16 23 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 24 * \tparam Derived Type of the derived class
ykuroda 0:13a5d365ba16 25 * \tparam #ReadOnlyAccessors Constant indicating read-only access
ykuroda 0:13a5d365ba16 26 *
ykuroda 0:13a5d365ba16 27 * This class defines the \c operator() \c const function and friends, which can be used to read specific
ykuroda 0:13a5d365ba16 28 * entries of a matrix or array.
ykuroda 0:13a5d365ba16 29 *
ykuroda 0:13a5d365ba16 30 * \sa DenseCoeffsBase<Derived, WriteAccessors>, DenseCoeffsBase<Derived, DirectAccessors>,
ykuroda 0:13a5d365ba16 31 * \ref TopicClassHierarchy
ykuroda 0:13a5d365ba16 32 */
ykuroda 0:13a5d365ba16 33 template<typename Derived>
ykuroda 0:13a5d365ba16 34 class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived>
ykuroda 0:13a5d365ba16 35 {
ykuroda 0:13a5d365ba16 36 public:
ykuroda 0:13a5d365ba16 37 typedef typename internal::traits<Derived>::StorageKind StorageKind;
ykuroda 0:13a5d365ba16 38 typedef typename internal::traits<Derived>::Index Index;
ykuroda 0:13a5d365ba16 39 typedef typename internal::traits<Derived>::Scalar Scalar;
ykuroda 0:13a5d365ba16 40 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
ykuroda 0:13a5d365ba16 41
ykuroda 0:13a5d365ba16 42 // Explanation for this CoeffReturnType typedef.
ykuroda 0:13a5d365ba16 43 // - This is the return type of the coeff() method.
ykuroda 0:13a5d365ba16 44 // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references
ykuroda 0:13a5d365ba16 45 // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value).
ykuroda 0:13a5d365ba16 46 // - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems
ykuroda 0:13a5d365ba16 47 // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is
ykuroda 0:13a5d365ba16 48 // not possible, since the underlying expressions might not offer a valid address the reference could be referring to.
ykuroda 0:13a5d365ba16 49 typedef typename internal::conditional<bool(internal::traits<Derived>::Flags&LvalueBit),
ykuroda 0:13a5d365ba16 50 const Scalar&,
ykuroda 0:13a5d365ba16 51 typename internal::conditional<internal::is_arithmetic<Scalar>::value, Scalar, const Scalar>::type
ykuroda 0:13a5d365ba16 52 >::type CoeffReturnType;
ykuroda 0:13a5d365ba16 53
ykuroda 0:13a5d365ba16 54 typedef typename internal::add_const_on_value_type_if_arithmetic<
ykuroda 0:13a5d365ba16 55 typename internal::packet_traits<Scalar>::type
ykuroda 0:13a5d365ba16 56 >::type PacketReturnType;
ykuroda 0:13a5d365ba16 57
ykuroda 0:13a5d365ba16 58 typedef EigenBase<Derived> Base;
ykuroda 0:13a5d365ba16 59 using Base::rows;
ykuroda 0:13a5d365ba16 60 using Base::cols;
ykuroda 0:13a5d365ba16 61 using Base::size;
ykuroda 0:13a5d365ba16 62 using Base::derived;
ykuroda 0:13a5d365ba16 63
ykuroda 0:13a5d365ba16 64 EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const
ykuroda 0:13a5d365ba16 65 {
ykuroda 0:13a5d365ba16 66 return int(Derived::RowsAtCompileTime) == 1 ? 0
ykuroda 0:13a5d365ba16 67 : int(Derived::ColsAtCompileTime) == 1 ? inner
ykuroda 0:13a5d365ba16 68 : int(Derived::Flags)&RowMajorBit ? outer
ykuroda 0:13a5d365ba16 69 : inner;
ykuroda 0:13a5d365ba16 70 }
ykuroda 0:13a5d365ba16 71
ykuroda 0:13a5d365ba16 72 EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const
ykuroda 0:13a5d365ba16 73 {
ykuroda 0:13a5d365ba16 74 return int(Derived::ColsAtCompileTime) == 1 ? 0
ykuroda 0:13a5d365ba16 75 : int(Derived::RowsAtCompileTime) == 1 ? inner
ykuroda 0:13a5d365ba16 76 : int(Derived::Flags)&RowMajorBit ? inner
ykuroda 0:13a5d365ba16 77 : outer;
ykuroda 0:13a5d365ba16 78 }
ykuroda 0:13a5d365ba16 79
ykuroda 0:13a5d365ba16 80 /** Short version: don't use this function, use
ykuroda 0:13a5d365ba16 81 * \link operator()(Index,Index) const \endlink instead.
ykuroda 0:13a5d365ba16 82 *
ykuroda 0:13a5d365ba16 83 * Long version: this function is similar to
ykuroda 0:13a5d365ba16 84 * \link operator()(Index,Index) const \endlink, but without the assertion.
ykuroda 0:13a5d365ba16 85 * Use this for limiting the performance cost of debugging code when doing
ykuroda 0:13a5d365ba16 86 * repeated coefficient access. Only use this when it is guaranteed that the
ykuroda 0:13a5d365ba16 87 * parameters \a row and \a col are in range.
ykuroda 0:13a5d365ba16 88 *
ykuroda 0:13a5d365ba16 89 * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
ykuroda 0:13a5d365ba16 90 * function equivalent to \link operator()(Index,Index) const \endlink.
ykuroda 0:13a5d365ba16 91 *
ykuroda 0:13a5d365ba16 92 * \sa operator()(Index,Index) const, coeffRef(Index,Index), coeff(Index) const
ykuroda 0:13a5d365ba16 93 */
ykuroda 0:13a5d365ba16 94 EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const
ykuroda 0:13a5d365ba16 95 {
ykuroda 0:13a5d365ba16 96 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 97 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 98 return derived().coeff(row, col);
ykuroda 0:13a5d365ba16 99 }
ykuroda 0:13a5d365ba16 100
ykuroda 0:13a5d365ba16 101 EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const
ykuroda 0:13a5d365ba16 102 {
ykuroda 0:13a5d365ba16 103 return coeff(rowIndexByOuterInner(outer, inner),
ykuroda 0:13a5d365ba16 104 colIndexByOuterInner(outer, inner));
ykuroda 0:13a5d365ba16 105 }
ykuroda 0:13a5d365ba16 106
ykuroda 0:13a5d365ba16 107 /** \returns the coefficient at given the given row and column.
ykuroda 0:13a5d365ba16 108 *
ykuroda 0:13a5d365ba16 109 * \sa operator()(Index,Index), operator[](Index)
ykuroda 0:13a5d365ba16 110 */
ykuroda 0:13a5d365ba16 111 EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const
ykuroda 0:13a5d365ba16 112 {
ykuroda 0:13a5d365ba16 113 eigen_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 114 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 115 return derived().coeff(row, col);
ykuroda 0:13a5d365ba16 116 }
ykuroda 0:13a5d365ba16 117
ykuroda 0:13a5d365ba16 118 /** Short version: don't use this function, use
ykuroda 0:13a5d365ba16 119 * \link operator[](Index) const \endlink instead.
ykuroda 0:13a5d365ba16 120 *
ykuroda 0:13a5d365ba16 121 * Long version: this function is similar to
ykuroda 0:13a5d365ba16 122 * \link operator[](Index) const \endlink, but without the assertion.
ykuroda 0:13a5d365ba16 123 * Use this for limiting the performance cost of debugging code when doing
ykuroda 0:13a5d365ba16 124 * repeated coefficient access. Only use this when it is guaranteed that the
ykuroda 0:13a5d365ba16 125 * parameter \a index is in range.
ykuroda 0:13a5d365ba16 126 *
ykuroda 0:13a5d365ba16 127 * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
ykuroda 0:13a5d365ba16 128 * function equivalent to \link operator[](Index) const \endlink.
ykuroda 0:13a5d365ba16 129 *
ykuroda 0:13a5d365ba16 130 * \sa operator[](Index) const, coeffRef(Index), coeff(Index,Index) const
ykuroda 0:13a5d365ba16 131 */
ykuroda 0:13a5d365ba16 132
ykuroda 0:13a5d365ba16 133 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 134 coeff(Index index) const
ykuroda 0:13a5d365ba16 135 {
ykuroda 0:13a5d365ba16 136 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 137 return derived().coeff(index);
ykuroda 0:13a5d365ba16 138 }
ykuroda 0:13a5d365ba16 139
ykuroda 0:13a5d365ba16 140
ykuroda 0:13a5d365ba16 141 /** \returns the coefficient at given index.
ykuroda 0:13a5d365ba16 142 *
ykuroda 0:13a5d365ba16 143 * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
ykuroda 0:13a5d365ba16 144 *
ykuroda 0:13a5d365ba16 145 * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const,
ykuroda 0:13a5d365ba16 146 * z() const, w() const
ykuroda 0:13a5d365ba16 147 */
ykuroda 0:13a5d365ba16 148
ykuroda 0:13a5d365ba16 149 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 150 operator[](Index index) const
ykuroda 0:13a5d365ba16 151 {
ykuroda 0:13a5d365ba16 152 #ifndef EIGEN2_SUPPORT
ykuroda 0:13a5d365ba16 153 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
ykuroda 0:13a5d365ba16 154 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
ykuroda 0:13a5d365ba16 155 #endif
ykuroda 0:13a5d365ba16 156 eigen_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 157 return derived().coeff(index);
ykuroda 0:13a5d365ba16 158 }
ykuroda 0:13a5d365ba16 159
ykuroda 0:13a5d365ba16 160 /** \returns the coefficient at given index.
ykuroda 0:13a5d365ba16 161 *
ykuroda 0:13a5d365ba16 162 * This is synonymous to operator[](Index) const.
ykuroda 0:13a5d365ba16 163 *
ykuroda 0:13a5d365ba16 164 * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
ykuroda 0:13a5d365ba16 165 *
ykuroda 0:13a5d365ba16 166 * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const,
ykuroda 0:13a5d365ba16 167 * z() const, w() const
ykuroda 0:13a5d365ba16 168 */
ykuroda 0:13a5d365ba16 169
ykuroda 0:13a5d365ba16 170 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 171 operator()(Index index) const
ykuroda 0:13a5d365ba16 172 {
ykuroda 0:13a5d365ba16 173 eigen_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 174 return derived().coeff(index);
ykuroda 0:13a5d365ba16 175 }
ykuroda 0:13a5d365ba16 176
ykuroda 0:13a5d365ba16 177 /** equivalent to operator[](0). */
ykuroda 0:13a5d365ba16 178
ykuroda 0:13a5d365ba16 179 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 180 x() const { return (*this)[0]; }
ykuroda 0:13a5d365ba16 181
ykuroda 0:13a5d365ba16 182 /** equivalent to operator[](1). */
ykuroda 0:13a5d365ba16 183
ykuroda 0:13a5d365ba16 184 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 185 y() const { return (*this)[1]; }
ykuroda 0:13a5d365ba16 186
ykuroda 0:13a5d365ba16 187 /** equivalent to operator[](2). */
ykuroda 0:13a5d365ba16 188
ykuroda 0:13a5d365ba16 189 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 190 z() const { return (*this)[2]; }
ykuroda 0:13a5d365ba16 191
ykuroda 0:13a5d365ba16 192 /** equivalent to operator[](3). */
ykuroda 0:13a5d365ba16 193
ykuroda 0:13a5d365ba16 194 EIGEN_STRONG_INLINE CoeffReturnType
ykuroda 0:13a5d365ba16 195 w() const { return (*this)[3]; }
ykuroda 0:13a5d365ba16 196
ykuroda 0:13a5d365ba16 197 /** \internal
ykuroda 0:13a5d365ba16 198 * \returns the packet of coefficients starting at the given row and column. It is your responsibility
ykuroda 0:13a5d365ba16 199 * to ensure that a packet really starts there. This method is only available on expressions having the
ykuroda 0:13a5d365ba16 200 * PacketAccessBit.
ykuroda 0:13a5d365ba16 201 *
ykuroda 0:13a5d365ba16 202 * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select
ykuroda 0:13a5d365ba16 203 * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
ykuroda 0:13a5d365ba16 204 * starting at an address which is a multiple of the packet size.
ykuroda 0:13a5d365ba16 205 */
ykuroda 0:13a5d365ba16 206
ykuroda 0:13a5d365ba16 207 template<int LoadMode>
ykuroda 0:13a5d365ba16 208 EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const
ykuroda 0:13a5d365ba16 209 {
ykuroda 0:13a5d365ba16 210 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 211 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 212 return derived().template packet<LoadMode>(row,col);
ykuroda 0:13a5d365ba16 213 }
ykuroda 0:13a5d365ba16 214
ykuroda 0:13a5d365ba16 215
ykuroda 0:13a5d365ba16 216 /** \internal */
ykuroda 0:13a5d365ba16 217 template<int LoadMode>
ykuroda 0:13a5d365ba16 218 EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const
ykuroda 0:13a5d365ba16 219 {
ykuroda 0:13a5d365ba16 220 return packet<LoadMode>(rowIndexByOuterInner(outer, inner),
ykuroda 0:13a5d365ba16 221 colIndexByOuterInner(outer, inner));
ykuroda 0:13a5d365ba16 222 }
ykuroda 0:13a5d365ba16 223
ykuroda 0:13a5d365ba16 224 /** \internal
ykuroda 0:13a5d365ba16 225 * \returns the packet of coefficients starting at the given index. It is your responsibility
ykuroda 0:13a5d365ba16 226 * to ensure that a packet really starts there. This method is only available on expressions having the
ykuroda 0:13a5d365ba16 227 * PacketAccessBit and the LinearAccessBit.
ykuroda 0:13a5d365ba16 228 *
ykuroda 0:13a5d365ba16 229 * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select
ykuroda 0:13a5d365ba16 230 * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
ykuroda 0:13a5d365ba16 231 * starting at an address which is a multiple of the packet size.
ykuroda 0:13a5d365ba16 232 */
ykuroda 0:13a5d365ba16 233
ykuroda 0:13a5d365ba16 234 template<int LoadMode>
ykuroda 0:13a5d365ba16 235 EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
ykuroda 0:13a5d365ba16 236 {
ykuroda 0:13a5d365ba16 237 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 238 return derived().template packet<LoadMode>(index);
ykuroda 0:13a5d365ba16 239 }
ykuroda 0:13a5d365ba16 240
ykuroda 0:13a5d365ba16 241 protected:
ykuroda 0:13a5d365ba16 242 // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase.
ykuroda 0:13a5d365ba16 243 // But some methods are only available in the DirectAccess case.
ykuroda 0:13a5d365ba16 244 // So we add dummy methods here with these names, so that "using... " doesn't fail.
ykuroda 0:13a5d365ba16 245 // It's not private so that the child class DenseBase can access them, and it's not public
ykuroda 0:13a5d365ba16 246 // either since it's an implementation detail, so has to be protected.
ykuroda 0:13a5d365ba16 247 void coeffRef();
ykuroda 0:13a5d365ba16 248 void coeffRefByOuterInner();
ykuroda 0:13a5d365ba16 249 void writePacket();
ykuroda 0:13a5d365ba16 250 void writePacketByOuterInner();
ykuroda 0:13a5d365ba16 251 void copyCoeff();
ykuroda 0:13a5d365ba16 252 void copyCoeffByOuterInner();
ykuroda 0:13a5d365ba16 253 void copyPacket();
ykuroda 0:13a5d365ba16 254 void copyPacketByOuterInner();
ykuroda 0:13a5d365ba16 255 void stride();
ykuroda 0:13a5d365ba16 256 void innerStride();
ykuroda 0:13a5d365ba16 257 void outerStride();
ykuroda 0:13a5d365ba16 258 void rowStride();
ykuroda 0:13a5d365ba16 259 void colStride();
ykuroda 0:13a5d365ba16 260 };
ykuroda 0:13a5d365ba16 261
ykuroda 0:13a5d365ba16 262 /** \brief Base class providing read/write coefficient access to matrices and arrays.
ykuroda 0:13a5d365ba16 263 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 264 * \tparam Derived Type of the derived class
ykuroda 0:13a5d365ba16 265 * \tparam #WriteAccessors Constant indicating read/write access
ykuroda 0:13a5d365ba16 266 *
ykuroda 0:13a5d365ba16 267 * This class defines the non-const \c operator() function and friends, which can be used to write specific
ykuroda 0:13a5d365ba16 268 * entries of a matrix or array. This class inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which
ykuroda 0:13a5d365ba16 269 * defines the const variant for reading specific entries.
ykuroda 0:13a5d365ba16 270 *
ykuroda 0:13a5d365ba16 271 * \sa DenseCoeffsBase<Derived, DirectAccessors>, \ref TopicClassHierarchy
ykuroda 0:13a5d365ba16 272 */
ykuroda 0:13a5d365ba16 273 template<typename Derived>
ykuroda 0:13a5d365ba16 274 class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
ykuroda 0:13a5d365ba16 275 {
ykuroda 0:13a5d365ba16 276 public:
ykuroda 0:13a5d365ba16 277
ykuroda 0:13a5d365ba16 278 typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
ykuroda 0:13a5d365ba16 279
ykuroda 0:13a5d365ba16 280 typedef typename internal::traits<Derived>::StorageKind StorageKind;
ykuroda 0:13a5d365ba16 281 typedef typename internal::traits<Derived>::Index Index;
ykuroda 0:13a5d365ba16 282 typedef typename internal::traits<Derived>::Scalar Scalar;
ykuroda 0:13a5d365ba16 283 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
ykuroda 0:13a5d365ba16 284 typedef typename NumTraits<Scalar>::Real RealScalar;
ykuroda 0:13a5d365ba16 285
ykuroda 0:13a5d365ba16 286 using Base::coeff;
ykuroda 0:13a5d365ba16 287 using Base::rows;
ykuroda 0:13a5d365ba16 288 using Base::cols;
ykuroda 0:13a5d365ba16 289 using Base::size;
ykuroda 0:13a5d365ba16 290 using Base::derived;
ykuroda 0:13a5d365ba16 291 using Base::rowIndexByOuterInner;
ykuroda 0:13a5d365ba16 292 using Base::colIndexByOuterInner;
ykuroda 0:13a5d365ba16 293 using Base::operator[];
ykuroda 0:13a5d365ba16 294 using Base::operator();
ykuroda 0:13a5d365ba16 295 using Base::x;
ykuroda 0:13a5d365ba16 296 using Base::y;
ykuroda 0:13a5d365ba16 297 using Base::z;
ykuroda 0:13a5d365ba16 298 using Base::w;
ykuroda 0:13a5d365ba16 299
ykuroda 0:13a5d365ba16 300 /** Short version: don't use this function, use
ykuroda 0:13a5d365ba16 301 * \link operator()(Index,Index) \endlink instead.
ykuroda 0:13a5d365ba16 302 *
ykuroda 0:13a5d365ba16 303 * Long version: this function is similar to
ykuroda 0:13a5d365ba16 304 * \link operator()(Index,Index) \endlink, but without the assertion.
ykuroda 0:13a5d365ba16 305 * Use this for limiting the performance cost of debugging code when doing
ykuroda 0:13a5d365ba16 306 * repeated coefficient access. Only use this when it is guaranteed that the
ykuroda 0:13a5d365ba16 307 * parameters \a row and \a col are in range.
ykuroda 0:13a5d365ba16 308 *
ykuroda 0:13a5d365ba16 309 * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
ykuroda 0:13a5d365ba16 310 * function equivalent to \link operator()(Index,Index) \endlink.
ykuroda 0:13a5d365ba16 311 *
ykuroda 0:13a5d365ba16 312 * \sa operator()(Index,Index), coeff(Index, Index) const, coeffRef(Index)
ykuroda 0:13a5d365ba16 313 */
ykuroda 0:13a5d365ba16 314 EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col)
ykuroda 0:13a5d365ba16 315 {
ykuroda 0:13a5d365ba16 316 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 317 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 318 return derived().coeffRef(row, col);
ykuroda 0:13a5d365ba16 319 }
ykuroda 0:13a5d365ba16 320
ykuroda 0:13a5d365ba16 321 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 322 coeffRefByOuterInner(Index outer, Index inner)
ykuroda 0:13a5d365ba16 323 {
ykuroda 0:13a5d365ba16 324 return coeffRef(rowIndexByOuterInner(outer, inner),
ykuroda 0:13a5d365ba16 325 colIndexByOuterInner(outer, inner));
ykuroda 0:13a5d365ba16 326 }
ykuroda 0:13a5d365ba16 327
ykuroda 0:13a5d365ba16 328 /** \returns a reference to the coefficient at given the given row and column.
ykuroda 0:13a5d365ba16 329 *
ykuroda 0:13a5d365ba16 330 * \sa operator[](Index)
ykuroda 0:13a5d365ba16 331 */
ykuroda 0:13a5d365ba16 332
ykuroda 0:13a5d365ba16 333 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 334 operator()(Index row, Index col)
ykuroda 0:13a5d365ba16 335 {
ykuroda 0:13a5d365ba16 336 eigen_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 337 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 338 return derived().coeffRef(row, col);
ykuroda 0:13a5d365ba16 339 }
ykuroda 0:13a5d365ba16 340
ykuroda 0:13a5d365ba16 341
ykuroda 0:13a5d365ba16 342 /** Short version: don't use this function, use
ykuroda 0:13a5d365ba16 343 * \link operator[](Index) \endlink instead.
ykuroda 0:13a5d365ba16 344 *
ykuroda 0:13a5d365ba16 345 * Long version: this function is similar to
ykuroda 0:13a5d365ba16 346 * \link operator[](Index) \endlink, but without the assertion.
ykuroda 0:13a5d365ba16 347 * Use this for limiting the performance cost of debugging code when doing
ykuroda 0:13a5d365ba16 348 * repeated coefficient access. Only use this when it is guaranteed that the
ykuroda 0:13a5d365ba16 349 * parameters \a row and \a col are in range.
ykuroda 0:13a5d365ba16 350 *
ykuroda 0:13a5d365ba16 351 * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this
ykuroda 0:13a5d365ba16 352 * function equivalent to \link operator[](Index) \endlink.
ykuroda 0:13a5d365ba16 353 *
ykuroda 0:13a5d365ba16 354 * \sa operator[](Index), coeff(Index) const, coeffRef(Index,Index)
ykuroda 0:13a5d365ba16 355 */
ykuroda 0:13a5d365ba16 356
ykuroda 0:13a5d365ba16 357 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 358 coeffRef(Index index)
ykuroda 0:13a5d365ba16 359 {
ykuroda 0:13a5d365ba16 360 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 361 return derived().coeffRef(index);
ykuroda 0:13a5d365ba16 362 }
ykuroda 0:13a5d365ba16 363
ykuroda 0:13a5d365ba16 364 /** \returns a reference to the coefficient at given index.
ykuroda 0:13a5d365ba16 365 *
ykuroda 0:13a5d365ba16 366 * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
ykuroda 0:13a5d365ba16 367 *
ykuroda 0:13a5d365ba16 368 * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w()
ykuroda 0:13a5d365ba16 369 */
ykuroda 0:13a5d365ba16 370
ykuroda 0:13a5d365ba16 371 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 372 operator[](Index index)
ykuroda 0:13a5d365ba16 373 {
ykuroda 0:13a5d365ba16 374 #ifndef EIGEN2_SUPPORT
ykuroda 0:13a5d365ba16 375 EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
ykuroda 0:13a5d365ba16 376 THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
ykuroda 0:13a5d365ba16 377 #endif
ykuroda 0:13a5d365ba16 378 eigen_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 379 return derived().coeffRef(index);
ykuroda 0:13a5d365ba16 380 }
ykuroda 0:13a5d365ba16 381
ykuroda 0:13a5d365ba16 382 /** \returns a reference to the coefficient at given index.
ykuroda 0:13a5d365ba16 383 *
ykuroda 0:13a5d365ba16 384 * This is synonymous to operator[](Index).
ykuroda 0:13a5d365ba16 385 *
ykuroda 0:13a5d365ba16 386 * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
ykuroda 0:13a5d365ba16 387 *
ykuroda 0:13a5d365ba16 388 * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w()
ykuroda 0:13a5d365ba16 389 */
ykuroda 0:13a5d365ba16 390
ykuroda 0:13a5d365ba16 391 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 392 operator()(Index index)
ykuroda 0:13a5d365ba16 393 {
ykuroda 0:13a5d365ba16 394 eigen_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 395 return derived().coeffRef(index);
ykuroda 0:13a5d365ba16 396 }
ykuroda 0:13a5d365ba16 397
ykuroda 0:13a5d365ba16 398 /** equivalent to operator[](0). */
ykuroda 0:13a5d365ba16 399
ykuroda 0:13a5d365ba16 400 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 401 x() { return (*this)[0]; }
ykuroda 0:13a5d365ba16 402
ykuroda 0:13a5d365ba16 403 /** equivalent to operator[](1). */
ykuroda 0:13a5d365ba16 404
ykuroda 0:13a5d365ba16 405 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 406 y() { return (*this)[1]; }
ykuroda 0:13a5d365ba16 407
ykuroda 0:13a5d365ba16 408 /** equivalent to operator[](2). */
ykuroda 0:13a5d365ba16 409
ykuroda 0:13a5d365ba16 410 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 411 z() { return (*this)[2]; }
ykuroda 0:13a5d365ba16 412
ykuroda 0:13a5d365ba16 413 /** equivalent to operator[](3). */
ykuroda 0:13a5d365ba16 414
ykuroda 0:13a5d365ba16 415 EIGEN_STRONG_INLINE Scalar&
ykuroda 0:13a5d365ba16 416 w() { return (*this)[3]; }
ykuroda 0:13a5d365ba16 417
ykuroda 0:13a5d365ba16 418 /** \internal
ykuroda 0:13a5d365ba16 419 * Stores the given packet of coefficients, at the given row and column of this expression. It is your responsibility
ykuroda 0:13a5d365ba16 420 * to ensure that a packet really starts there. This method is only available on expressions having the
ykuroda 0:13a5d365ba16 421 * PacketAccessBit.
ykuroda 0:13a5d365ba16 422 *
ykuroda 0:13a5d365ba16 423 * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select
ykuroda 0:13a5d365ba16 424 * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
ykuroda 0:13a5d365ba16 425 * starting at an address which is a multiple of the packet size.
ykuroda 0:13a5d365ba16 426 */
ykuroda 0:13a5d365ba16 427
ykuroda 0:13a5d365ba16 428 template<int StoreMode>
ykuroda 0:13a5d365ba16 429 EIGEN_STRONG_INLINE void writePacket
ykuroda 0:13a5d365ba16 430 (Index row, Index col, const typename internal::packet_traits<Scalar>::type& val)
ykuroda 0:13a5d365ba16 431 {
ykuroda 0:13a5d365ba16 432 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 433 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 434 derived().template writePacket<StoreMode>(row,col,val);
ykuroda 0:13a5d365ba16 435 }
ykuroda 0:13a5d365ba16 436
ykuroda 0:13a5d365ba16 437
ykuroda 0:13a5d365ba16 438 /** \internal */
ykuroda 0:13a5d365ba16 439 template<int StoreMode>
ykuroda 0:13a5d365ba16 440 EIGEN_STRONG_INLINE void writePacketByOuterInner
ykuroda 0:13a5d365ba16 441 (Index outer, Index inner, const typename internal::packet_traits<Scalar>::type& val)
ykuroda 0:13a5d365ba16 442 {
ykuroda 0:13a5d365ba16 443 writePacket<StoreMode>(rowIndexByOuterInner(outer, inner),
ykuroda 0:13a5d365ba16 444 colIndexByOuterInner(outer, inner),
ykuroda 0:13a5d365ba16 445 val);
ykuroda 0:13a5d365ba16 446 }
ykuroda 0:13a5d365ba16 447
ykuroda 0:13a5d365ba16 448 /** \internal
ykuroda 0:13a5d365ba16 449 * Stores the given packet of coefficients, at the given index in this expression. It is your responsibility
ykuroda 0:13a5d365ba16 450 * to ensure that a packet really starts there. This method is only available on expressions having the
ykuroda 0:13a5d365ba16 451 * PacketAccessBit and the LinearAccessBit.
ykuroda 0:13a5d365ba16 452 *
ykuroda 0:13a5d365ba16 453 * The \a LoadMode parameter may have the value \a Aligned or \a Unaligned. Its effect is to select
ykuroda 0:13a5d365ba16 454 * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets
ykuroda 0:13a5d365ba16 455 * starting at an address which is a multiple of the packet size.
ykuroda 0:13a5d365ba16 456 */
ykuroda 0:13a5d365ba16 457 template<int StoreMode>
ykuroda 0:13a5d365ba16 458 EIGEN_STRONG_INLINE void writePacket
ykuroda 0:13a5d365ba16 459 (Index index, const typename internal::packet_traits<Scalar>::type& val)
ykuroda 0:13a5d365ba16 460 {
ykuroda 0:13a5d365ba16 461 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 462 derived().template writePacket<StoreMode>(index,val);
ykuroda 0:13a5d365ba16 463 }
ykuroda 0:13a5d365ba16 464
ykuroda 0:13a5d365ba16 465 #ifndef EIGEN_PARSED_BY_DOXYGEN
ykuroda 0:13a5d365ba16 466
ykuroda 0:13a5d365ba16 467 /** \internal Copies the coefficient at position (row,col) of other into *this.
ykuroda 0:13a5d365ba16 468 *
ykuroda 0:13a5d365ba16 469 * This method is overridden in SwapWrapper, allowing swap() assignments to share 99% of their code
ykuroda 0:13a5d365ba16 470 * with usual assignments.
ykuroda 0:13a5d365ba16 471 *
ykuroda 0:13a5d365ba16 472 * Outside of this internal usage, this method has probably no usefulness. It is hidden in the public API dox.
ykuroda 0:13a5d365ba16 473 */
ykuroda 0:13a5d365ba16 474
ykuroda 0:13a5d365ba16 475 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 476 EIGEN_STRONG_INLINE void copyCoeff(Index row, Index col, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 477 {
ykuroda 0:13a5d365ba16 478 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 479 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 480 derived().coeffRef(row, col) = other.derived().coeff(row, col);
ykuroda 0:13a5d365ba16 481 }
ykuroda 0:13a5d365ba16 482
ykuroda 0:13a5d365ba16 483 /** \internal Copies the coefficient at the given index of other into *this.
ykuroda 0:13a5d365ba16 484 *
ykuroda 0:13a5d365ba16 485 * This method is overridden in SwapWrapper, allowing swap() assignments to share 99% of their code
ykuroda 0:13a5d365ba16 486 * with usual assignments.
ykuroda 0:13a5d365ba16 487 *
ykuroda 0:13a5d365ba16 488 * Outside of this internal usage, this method has probably no usefulness. It is hidden in the public API dox.
ykuroda 0:13a5d365ba16 489 */
ykuroda 0:13a5d365ba16 490
ykuroda 0:13a5d365ba16 491 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 492 EIGEN_STRONG_INLINE void copyCoeff(Index index, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 493 {
ykuroda 0:13a5d365ba16 494 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 495 derived().coeffRef(index) = other.derived().coeff(index);
ykuroda 0:13a5d365ba16 496 }
ykuroda 0:13a5d365ba16 497
ykuroda 0:13a5d365ba16 498
ykuroda 0:13a5d365ba16 499 template<typename OtherDerived>
ykuroda 0:13a5d365ba16 500 EIGEN_STRONG_INLINE void copyCoeffByOuterInner(Index outer, Index inner, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 501 {
ykuroda 0:13a5d365ba16 502 const Index row = rowIndexByOuterInner(outer,inner);
ykuroda 0:13a5d365ba16 503 const Index col = colIndexByOuterInner(outer,inner);
ykuroda 0:13a5d365ba16 504 // derived() is important here: copyCoeff() may be reimplemented in Derived!
ykuroda 0:13a5d365ba16 505 derived().copyCoeff(row, col, other);
ykuroda 0:13a5d365ba16 506 }
ykuroda 0:13a5d365ba16 507
ykuroda 0:13a5d365ba16 508 /** \internal Copies the packet at position (row,col) of other into *this.
ykuroda 0:13a5d365ba16 509 *
ykuroda 0:13a5d365ba16 510 * This method is overridden in SwapWrapper, allowing swap() assignments to share 99% of their code
ykuroda 0:13a5d365ba16 511 * with usual assignments.
ykuroda 0:13a5d365ba16 512 *
ykuroda 0:13a5d365ba16 513 * Outside of this internal usage, this method has probably no usefulness. It is hidden in the public API dox.
ykuroda 0:13a5d365ba16 514 */
ykuroda 0:13a5d365ba16 515
ykuroda 0:13a5d365ba16 516 template<typename OtherDerived, int StoreMode, int LoadMode>
ykuroda 0:13a5d365ba16 517 EIGEN_STRONG_INLINE void copyPacket(Index row, Index col, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 518 {
ykuroda 0:13a5d365ba16 519 eigen_internal_assert(row >= 0 && row < rows()
ykuroda 0:13a5d365ba16 520 && col >= 0 && col < cols());
ykuroda 0:13a5d365ba16 521 derived().template writePacket<StoreMode>(row, col,
ykuroda 0:13a5d365ba16 522 other.derived().template packet<LoadMode>(row, col));
ykuroda 0:13a5d365ba16 523 }
ykuroda 0:13a5d365ba16 524
ykuroda 0:13a5d365ba16 525 /** \internal Copies the packet at the given index of other into *this.
ykuroda 0:13a5d365ba16 526 *
ykuroda 0:13a5d365ba16 527 * This method is overridden in SwapWrapper, allowing swap() assignments to share 99% of their code
ykuroda 0:13a5d365ba16 528 * with usual assignments.
ykuroda 0:13a5d365ba16 529 *
ykuroda 0:13a5d365ba16 530 * Outside of this internal usage, this method has probably no usefulness. It is hidden in the public API dox.
ykuroda 0:13a5d365ba16 531 */
ykuroda 0:13a5d365ba16 532
ykuroda 0:13a5d365ba16 533 template<typename OtherDerived, int StoreMode, int LoadMode>
ykuroda 0:13a5d365ba16 534 EIGEN_STRONG_INLINE void copyPacket(Index index, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 535 {
ykuroda 0:13a5d365ba16 536 eigen_internal_assert(index >= 0 && index < size());
ykuroda 0:13a5d365ba16 537 derived().template writePacket<StoreMode>(index,
ykuroda 0:13a5d365ba16 538 other.derived().template packet<LoadMode>(index));
ykuroda 0:13a5d365ba16 539 }
ykuroda 0:13a5d365ba16 540
ykuroda 0:13a5d365ba16 541 /** \internal */
ykuroda 0:13a5d365ba16 542 template<typename OtherDerived, int StoreMode, int LoadMode>
ykuroda 0:13a5d365ba16 543 EIGEN_STRONG_INLINE void copyPacketByOuterInner(Index outer, Index inner, const DenseBase<OtherDerived>& other)
ykuroda 0:13a5d365ba16 544 {
ykuroda 0:13a5d365ba16 545 const Index row = rowIndexByOuterInner(outer,inner);
ykuroda 0:13a5d365ba16 546 const Index col = colIndexByOuterInner(outer,inner);
ykuroda 0:13a5d365ba16 547 // derived() is important here: copyCoeff() may be reimplemented in Derived!
ykuroda 0:13a5d365ba16 548 derived().template copyPacket< OtherDerived, StoreMode, LoadMode>(row, col, other);
ykuroda 0:13a5d365ba16 549 }
ykuroda 0:13a5d365ba16 550 #endif
ykuroda 0:13a5d365ba16 551
ykuroda 0:13a5d365ba16 552 };
ykuroda 0:13a5d365ba16 553
ykuroda 0:13a5d365ba16 554 /** \brief Base class providing direct read-only coefficient access to matrices and arrays.
ykuroda 0:13a5d365ba16 555 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 556 * \tparam Derived Type of the derived class
ykuroda 0:13a5d365ba16 557 * \tparam #DirectAccessors Constant indicating direct access
ykuroda 0:13a5d365ba16 558 *
ykuroda 0:13a5d365ba16 559 * This class defines functions to work with strides which can be used to access entries directly. This class
ykuroda 0:13a5d365ba16 560 * inherits DenseCoeffsBase<Derived, ReadOnlyAccessors> which defines functions to access entries read-only using
ykuroda 0:13a5d365ba16 561 * \c operator() .
ykuroda 0:13a5d365ba16 562 *
ykuroda 0:13a5d365ba16 563 * \sa \ref TopicClassHierarchy
ykuroda 0:13a5d365ba16 564 */
ykuroda 0:13a5d365ba16 565 template<typename Derived>
ykuroda 0:13a5d365ba16 566 class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
ykuroda 0:13a5d365ba16 567 {
ykuroda 0:13a5d365ba16 568 public:
ykuroda 0:13a5d365ba16 569
ykuroda 0:13a5d365ba16 570 typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
ykuroda 0:13a5d365ba16 571 typedef typename internal::traits<Derived>::Index Index;
ykuroda 0:13a5d365ba16 572 typedef typename internal::traits<Derived>::Scalar Scalar;
ykuroda 0:13a5d365ba16 573 typedef typename NumTraits<Scalar>::Real RealScalar;
ykuroda 0:13a5d365ba16 574
ykuroda 0:13a5d365ba16 575 using Base::rows;
ykuroda 0:13a5d365ba16 576 using Base::cols;
ykuroda 0:13a5d365ba16 577 using Base::size;
ykuroda 0:13a5d365ba16 578 using Base::derived;
ykuroda 0:13a5d365ba16 579
ykuroda 0:13a5d365ba16 580 /** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
ykuroda 0:13a5d365ba16 581 *
ykuroda 0:13a5d365ba16 582 * \sa outerStride(), rowStride(), colStride()
ykuroda 0:13a5d365ba16 583 */
ykuroda 0:13a5d365ba16 584 inline Index innerStride() const
ykuroda 0:13a5d365ba16 585 {
ykuroda 0:13a5d365ba16 586 return derived().innerStride();
ykuroda 0:13a5d365ba16 587 }
ykuroda 0:13a5d365ba16 588
ykuroda 0:13a5d365ba16 589 /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
ykuroda 0:13a5d365ba16 590 * in a column-major matrix).
ykuroda 0:13a5d365ba16 591 *
ykuroda 0:13a5d365ba16 592 * \sa innerStride(), rowStride(), colStride()
ykuroda 0:13a5d365ba16 593 */
ykuroda 0:13a5d365ba16 594 inline Index outerStride() const
ykuroda 0:13a5d365ba16 595 {
ykuroda 0:13a5d365ba16 596 return derived().outerStride();
ykuroda 0:13a5d365ba16 597 }
ykuroda 0:13a5d365ba16 598
ykuroda 0:13a5d365ba16 599 // FIXME shall we remove it ?
ykuroda 0:13a5d365ba16 600 inline Index stride() const
ykuroda 0:13a5d365ba16 601 {
ykuroda 0:13a5d365ba16 602 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
ykuroda 0:13a5d365ba16 603 }
ykuroda 0:13a5d365ba16 604
ykuroda 0:13a5d365ba16 605 /** \returns the pointer increment between two consecutive rows.
ykuroda 0:13a5d365ba16 606 *
ykuroda 0:13a5d365ba16 607 * \sa innerStride(), outerStride(), colStride()
ykuroda 0:13a5d365ba16 608 */
ykuroda 0:13a5d365ba16 609 inline Index rowStride() const
ykuroda 0:13a5d365ba16 610 {
ykuroda 0:13a5d365ba16 611 return Derived::IsRowMajor ? outerStride() : innerStride();
ykuroda 0:13a5d365ba16 612 }
ykuroda 0:13a5d365ba16 613
ykuroda 0:13a5d365ba16 614 /** \returns the pointer increment between two consecutive columns.
ykuroda 0:13a5d365ba16 615 *
ykuroda 0:13a5d365ba16 616 * \sa innerStride(), outerStride(), rowStride()
ykuroda 0:13a5d365ba16 617 */
ykuroda 0:13a5d365ba16 618 inline Index colStride() const
ykuroda 0:13a5d365ba16 619 {
ykuroda 0:13a5d365ba16 620 return Derived::IsRowMajor ? innerStride() : outerStride();
ykuroda 0:13a5d365ba16 621 }
ykuroda 0:13a5d365ba16 622 };
ykuroda 0:13a5d365ba16 623
ykuroda 0:13a5d365ba16 624 /** \brief Base class providing direct read/write coefficient access to matrices and arrays.
ykuroda 0:13a5d365ba16 625 * \ingroup Core_Module
ykuroda 0:13a5d365ba16 626 * \tparam Derived Type of the derived class
ykuroda 0:13a5d365ba16 627 * \tparam #DirectWriteAccessors Constant indicating direct access
ykuroda 0:13a5d365ba16 628 *
ykuroda 0:13a5d365ba16 629 * This class defines functions to work with strides which can be used to access entries directly. This class
ykuroda 0:13a5d365ba16 630 * inherits DenseCoeffsBase<Derived, WriteAccessors> which defines functions to access entries read/write using
ykuroda 0:13a5d365ba16 631 * \c operator().
ykuroda 0:13a5d365ba16 632 *
ykuroda 0:13a5d365ba16 633 * \sa \ref TopicClassHierarchy
ykuroda 0:13a5d365ba16 634 */
ykuroda 0:13a5d365ba16 635 template<typename Derived>
ykuroda 0:13a5d365ba16 636 class DenseCoeffsBase<Derived, DirectWriteAccessors>
ykuroda 0:13a5d365ba16 637 : public DenseCoeffsBase<Derived, WriteAccessors>
ykuroda 0:13a5d365ba16 638 {
ykuroda 0:13a5d365ba16 639 public:
ykuroda 0:13a5d365ba16 640
ykuroda 0:13a5d365ba16 641 typedef DenseCoeffsBase<Derived, WriteAccessors> Base;
ykuroda 0:13a5d365ba16 642 typedef typename internal::traits<Derived>::Index Index;
ykuroda 0:13a5d365ba16 643 typedef typename internal::traits<Derived>::Scalar Scalar;
ykuroda 0:13a5d365ba16 644 typedef typename NumTraits<Scalar>::Real RealScalar;
ykuroda 0:13a5d365ba16 645
ykuroda 0:13a5d365ba16 646 using Base::rows;
ykuroda 0:13a5d365ba16 647 using Base::cols;
ykuroda 0:13a5d365ba16 648 using Base::size;
ykuroda 0:13a5d365ba16 649 using Base::derived;
ykuroda 0:13a5d365ba16 650
ykuroda 0:13a5d365ba16 651 /** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
ykuroda 0:13a5d365ba16 652 *
ykuroda 0:13a5d365ba16 653 * \sa outerStride(), rowStride(), colStride()
ykuroda 0:13a5d365ba16 654 */
ykuroda 0:13a5d365ba16 655 inline Index innerStride() const
ykuroda 0:13a5d365ba16 656 {
ykuroda 0:13a5d365ba16 657 return derived().innerStride();
ykuroda 0:13a5d365ba16 658 }
ykuroda 0:13a5d365ba16 659
ykuroda 0:13a5d365ba16 660 /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
ykuroda 0:13a5d365ba16 661 * in a column-major matrix).
ykuroda 0:13a5d365ba16 662 *
ykuroda 0:13a5d365ba16 663 * \sa innerStride(), rowStride(), colStride()
ykuroda 0:13a5d365ba16 664 */
ykuroda 0:13a5d365ba16 665 inline Index outerStride() const
ykuroda 0:13a5d365ba16 666 {
ykuroda 0:13a5d365ba16 667 return derived().outerStride();
ykuroda 0:13a5d365ba16 668 }
ykuroda 0:13a5d365ba16 669
ykuroda 0:13a5d365ba16 670 // FIXME shall we remove it ?
ykuroda 0:13a5d365ba16 671 inline Index stride() const
ykuroda 0:13a5d365ba16 672 {
ykuroda 0:13a5d365ba16 673 return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
ykuroda 0:13a5d365ba16 674 }
ykuroda 0:13a5d365ba16 675
ykuroda 0:13a5d365ba16 676 /** \returns the pointer increment between two consecutive rows.
ykuroda 0:13a5d365ba16 677 *
ykuroda 0:13a5d365ba16 678 * \sa innerStride(), outerStride(), colStride()
ykuroda 0:13a5d365ba16 679 */
ykuroda 0:13a5d365ba16 680 inline Index rowStride() const
ykuroda 0:13a5d365ba16 681 {
ykuroda 0:13a5d365ba16 682 return Derived::IsRowMajor ? outerStride() : innerStride();
ykuroda 0:13a5d365ba16 683 }
ykuroda 0:13a5d365ba16 684
ykuroda 0:13a5d365ba16 685 /** \returns the pointer increment between two consecutive columns.
ykuroda 0:13a5d365ba16 686 *
ykuroda 0:13a5d365ba16 687 * \sa innerStride(), outerStride(), rowStride()
ykuroda 0:13a5d365ba16 688 */
ykuroda 0:13a5d365ba16 689 inline Index colStride() const
ykuroda 0:13a5d365ba16 690 {
ykuroda 0:13a5d365ba16 691 return Derived::IsRowMajor ? innerStride() : outerStride();
ykuroda 0:13a5d365ba16 692 }
ykuroda 0:13a5d365ba16 693 };
ykuroda 0:13a5d365ba16 694
ykuroda 0:13a5d365ba16 695 namespace internal {
ykuroda 0:13a5d365ba16 696
ykuroda 0:13a5d365ba16 697 template<typename Derived, bool JustReturnZero>
ykuroda 0:13a5d365ba16 698 struct first_aligned_impl
ykuroda 0:13a5d365ba16 699 {
ykuroda 0:13a5d365ba16 700 static inline typename Derived::Index run(const Derived&)
ykuroda 0:13a5d365ba16 701 { return 0; }
ykuroda 0:13a5d365ba16 702 };
ykuroda 0:13a5d365ba16 703
ykuroda 0:13a5d365ba16 704 template<typename Derived>
ykuroda 0:13a5d365ba16 705 struct first_aligned_impl<Derived, false>
ykuroda 0:13a5d365ba16 706 {
ykuroda 0:13a5d365ba16 707 static inline typename Derived::Index run(const Derived& m)
ykuroda 0:13a5d365ba16 708 {
ykuroda 0:13a5d365ba16 709 return internal::first_aligned(&m.const_cast_derived().coeffRef(0,0), m.size());
ykuroda 0:13a5d365ba16 710 }
ykuroda 0:13a5d365ba16 711 };
ykuroda 0:13a5d365ba16 712
ykuroda 0:13a5d365ba16 713 /** \internal \returns the index of the first element of the array that is well aligned for vectorization.
ykuroda 0:13a5d365ba16 714 *
ykuroda 0:13a5d365ba16 715 * There is also the variant first_aligned(const Scalar*, Integer) defined in Memory.h. See it for more
ykuroda 0:13a5d365ba16 716 * documentation.
ykuroda 0:13a5d365ba16 717 */
ykuroda 0:13a5d365ba16 718 template<typename Derived>
ykuroda 0:13a5d365ba16 719 static inline typename Derived::Index first_aligned(const Derived& m)
ykuroda 0:13a5d365ba16 720 {
ykuroda 0:13a5d365ba16 721 return first_aligned_impl
ykuroda 0:13a5d365ba16 722 <Derived, (Derived::Flags & AlignedBit) || !(Derived::Flags & DirectAccessBit)>
ykuroda 0:13a5d365ba16 723 ::run(m);
ykuroda 0:13a5d365ba16 724 }
ykuroda 0:13a5d365ba16 725
ykuroda 0:13a5d365ba16 726 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
ykuroda 0:13a5d365ba16 727 struct inner_stride_at_compile_time
ykuroda 0:13a5d365ba16 728 {
ykuroda 0:13a5d365ba16 729 enum { ret = traits<Derived>::InnerStrideAtCompileTime };
ykuroda 0:13a5d365ba16 730 };
ykuroda 0:13a5d365ba16 731
ykuroda 0:13a5d365ba16 732 template<typename Derived>
ykuroda 0:13a5d365ba16 733 struct inner_stride_at_compile_time<Derived, false>
ykuroda 0:13a5d365ba16 734 {
ykuroda 0:13a5d365ba16 735 enum { ret = 0 };
ykuroda 0:13a5d365ba16 736 };
ykuroda 0:13a5d365ba16 737
ykuroda 0:13a5d365ba16 738 template<typename Derived, bool HasDirectAccess = has_direct_access<Derived>::ret>
ykuroda 0:13a5d365ba16 739 struct outer_stride_at_compile_time
ykuroda 0:13a5d365ba16 740 {
ykuroda 0:13a5d365ba16 741 enum { ret = traits<Derived>::OuterStrideAtCompileTime };
ykuroda 0:13a5d365ba16 742 };
ykuroda 0:13a5d365ba16 743
ykuroda 0:13a5d365ba16 744 template<typename Derived>
ykuroda 0:13a5d365ba16 745 struct outer_stride_at_compile_time<Derived, false>
ykuroda 0:13a5d365ba16 746 {
ykuroda 0:13a5d365ba16 747 enum { ret = 0 };
ykuroda 0:13a5d365ba16 748 };
ykuroda 0:13a5d365ba16 749
ykuroda 0:13a5d365ba16 750 } // end namespace internal
ykuroda 0:13a5d365ba16 751
ykuroda 0:13a5d365ba16 752 } // end namespace Eigen
ykuroda 0:13a5d365ba16 753
ykuroda 0:13a5d365ba16 754 #endif // EIGEN_DENSECOEFFSBASE_H