Eigne Matrix Class Library
Dependents: Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more
Eigen Matrix Class Library for mbed.
Finally, you can use Eigen on your mbed!!!
src/Core/Ref.h@0:13a5d365ba16, 2016-10-13 (annotated)
- Committer:
- ykuroda
- Date:
- Thu Oct 13 04:07:23 2016 +0000
- Revision:
- 0:13a5d365ba16
First commint, Eigne Matrix Class Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 0:13a5d365ba16 | 1 | // This file is part of Eigen, a lightweight C++ template library |
ykuroda | 0:13a5d365ba16 | 2 | // for linear algebra. |
ykuroda | 0:13a5d365ba16 | 3 | // |
ykuroda | 0:13a5d365ba16 | 4 | // Copyright (C) 2012 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_REF_H |
ykuroda | 0:13a5d365ba16 | 11 | #define EIGEN_REF_H |
ykuroda | 0:13a5d365ba16 | 12 | |
ykuroda | 0:13a5d365ba16 | 13 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 14 | |
ykuroda | 0:13a5d365ba16 | 15 | template<typename Derived> class RefBase; |
ykuroda | 0:13a5d365ba16 | 16 | template<typename PlainObjectType, int Options = 0, |
ykuroda | 0:13a5d365ba16 | 17 | typename StrideType = typename internal::conditional<PlainObjectType::IsVectorAtCompileTime,InnerStride<1>,OuterStride<> >::type > class Ref; |
ykuroda | 0:13a5d365ba16 | 18 | |
ykuroda | 0:13a5d365ba16 | 19 | /** \class Ref |
ykuroda | 0:13a5d365ba16 | 20 | * \ingroup Core_Module |
ykuroda | 0:13a5d365ba16 | 21 | * |
ykuroda | 0:13a5d365ba16 | 22 | * \brief A matrix or vector expression mapping an existing expressions |
ykuroda | 0:13a5d365ba16 | 23 | * |
ykuroda | 0:13a5d365ba16 | 24 | * \tparam PlainObjectType the equivalent matrix type of the mapped data |
ykuroda | 0:13a5d365ba16 | 25 | * \tparam Options specifies whether the pointer is \c #Aligned, or \c #Unaligned. |
ykuroda | 0:13a5d365ba16 | 26 | * The default is \c #Unaligned. |
ykuroda | 0:13a5d365ba16 | 27 | * \tparam StrideType optionally specifies strides. By default, Ref implies a contiguous storage along the inner dimension (inner stride==1), |
ykuroda | 0:13a5d365ba16 | 28 | * but accept a variable outer stride (leading dimension). |
ykuroda | 0:13a5d365ba16 | 29 | * This can be overridden by specifying strides. |
ykuroda | 0:13a5d365ba16 | 30 | * The type passed here must be a specialization of the Stride template, see examples below. |
ykuroda | 0:13a5d365ba16 | 31 | * |
ykuroda | 0:13a5d365ba16 | 32 | * This class permits to write non template functions taking Eigen's object as parameters while limiting the number of copies. |
ykuroda | 0:13a5d365ba16 | 33 | * A Ref<> object can represent either a const expression or a l-value: |
ykuroda | 0:13a5d365ba16 | 34 | * \code |
ykuroda | 0:13a5d365ba16 | 35 | * // in-out argument: |
ykuroda | 0:13a5d365ba16 | 36 | * void foo1(Ref<VectorXf> x); |
ykuroda | 0:13a5d365ba16 | 37 | * |
ykuroda | 0:13a5d365ba16 | 38 | * // read-only const argument: |
ykuroda | 0:13a5d365ba16 | 39 | * void foo2(const Ref<const VectorXf>& x); |
ykuroda | 0:13a5d365ba16 | 40 | * \endcode |
ykuroda | 0:13a5d365ba16 | 41 | * |
ykuroda | 0:13a5d365ba16 | 42 | * In the in-out case, the input argument must satisfies the constraints of the actual Ref<> type, otherwise a compilation issue will be triggered. |
ykuroda | 0:13a5d365ba16 | 43 | * By default, a Ref<VectorXf> can reference any dense vector expression of float having a contiguous memory layout. |
ykuroda | 0:13a5d365ba16 | 44 | * Likewise, a Ref<MatrixXf> can reference any column major dense matrix expression of float whose column's elements are contiguously stored with |
ykuroda | 0:13a5d365ba16 | 45 | * the possibility to have a constant space inbetween each column, i.e.: the inner stride mmust be equal to 1, but the outer-stride (or leading dimension), |
ykuroda | 0:13a5d365ba16 | 46 | * can be greater than the number of rows. |
ykuroda | 0:13a5d365ba16 | 47 | * |
ykuroda | 0:13a5d365ba16 | 48 | * In the const case, if the input expression does not match the above requirement, then it is evaluated into a temporary before being passed to the function. |
ykuroda | 0:13a5d365ba16 | 49 | * Here are some examples: |
ykuroda | 0:13a5d365ba16 | 50 | * \code |
ykuroda | 0:13a5d365ba16 | 51 | * MatrixXf A; |
ykuroda | 0:13a5d365ba16 | 52 | * VectorXf a; |
ykuroda | 0:13a5d365ba16 | 53 | * foo1(a.head()); // OK |
ykuroda | 0:13a5d365ba16 | 54 | * foo1(A.col()); // OK |
ykuroda | 0:13a5d365ba16 | 55 | * foo1(A.row()); // compilation error because here innerstride!=1 |
ykuroda | 0:13a5d365ba16 | 56 | * foo2(A.row()); // The row is copied into a contiguous temporary |
ykuroda | 0:13a5d365ba16 | 57 | * foo2(2*a); // The expression is evaluated into a temporary |
ykuroda | 0:13a5d365ba16 | 58 | * foo2(A.col().segment(2,4)); // No temporary |
ykuroda | 0:13a5d365ba16 | 59 | * \endcode |
ykuroda | 0:13a5d365ba16 | 60 | * |
ykuroda | 0:13a5d365ba16 | 61 | * The range of inputs that can be referenced without temporary can be enlarged using the last two template parameter. |
ykuroda | 0:13a5d365ba16 | 62 | * Here is an example accepting an innerstride!=1: |
ykuroda | 0:13a5d365ba16 | 63 | * \code |
ykuroda | 0:13a5d365ba16 | 64 | * // in-out argument: |
ykuroda | 0:13a5d365ba16 | 65 | * void foo3(Ref<VectorXf,0,InnerStride<> > x); |
ykuroda | 0:13a5d365ba16 | 66 | * foo3(A.row()); // OK |
ykuroda | 0:13a5d365ba16 | 67 | * \endcode |
ykuroda | 0:13a5d365ba16 | 68 | * The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to exploit vectorization, and will involved more |
ykuroda | 0:13a5d365ba16 | 69 | * expensive address computations even if the input is contiguously stored in memory. To overcome this issue, one might propose to overloads internally calling a |
ykuroda | 0:13a5d365ba16 | 70 | * template function, e.g.: |
ykuroda | 0:13a5d365ba16 | 71 | * \code |
ykuroda | 0:13a5d365ba16 | 72 | * // in the .h: |
ykuroda | 0:13a5d365ba16 | 73 | * void foo(const Ref<MatrixXf>& A); |
ykuroda | 0:13a5d365ba16 | 74 | * void foo(const Ref<MatrixXf,0,Stride<> >& A); |
ykuroda | 0:13a5d365ba16 | 75 | * |
ykuroda | 0:13a5d365ba16 | 76 | * // in the .cpp: |
ykuroda | 0:13a5d365ba16 | 77 | * template<typename TypeOfA> void foo_impl(const TypeOfA& A) { |
ykuroda | 0:13a5d365ba16 | 78 | * ... // crazy code goes here |
ykuroda | 0:13a5d365ba16 | 79 | * } |
ykuroda | 0:13a5d365ba16 | 80 | * void foo(const Ref<MatrixXf>& A) { foo_impl(A); } |
ykuroda | 0:13a5d365ba16 | 81 | * void foo(const Ref<MatrixXf,0,Stride<> >& A) { foo_impl(A); } |
ykuroda | 0:13a5d365ba16 | 82 | * \endcode |
ykuroda | 0:13a5d365ba16 | 83 | * |
ykuroda | 0:13a5d365ba16 | 84 | * |
ykuroda | 0:13a5d365ba16 | 85 | * \sa PlainObjectBase::Map(), \ref TopicStorageOrders |
ykuroda | 0:13a5d365ba16 | 86 | */ |
ykuroda | 0:13a5d365ba16 | 87 | |
ykuroda | 0:13a5d365ba16 | 88 | namespace internal { |
ykuroda | 0:13a5d365ba16 | 89 | |
ykuroda | 0:13a5d365ba16 | 90 | template<typename _PlainObjectType, int _Options, typename _StrideType> |
ykuroda | 0:13a5d365ba16 | 91 | struct traits<Ref<_PlainObjectType, _Options, _StrideType> > |
ykuroda | 0:13a5d365ba16 | 92 | : public traits<Map<_PlainObjectType, _Options, _StrideType> > |
ykuroda | 0:13a5d365ba16 | 93 | { |
ykuroda | 0:13a5d365ba16 | 94 | typedef _PlainObjectType PlainObjectType; |
ykuroda | 0:13a5d365ba16 | 95 | typedef _StrideType StrideType; |
ykuroda | 0:13a5d365ba16 | 96 | enum { |
ykuroda | 0:13a5d365ba16 | 97 | Options = _Options, |
ykuroda | 0:13a5d365ba16 | 98 | Flags = traits<Map<_PlainObjectType, _Options, _StrideType> >::Flags | NestByRefBit |
ykuroda | 0:13a5d365ba16 | 99 | }; |
ykuroda | 0:13a5d365ba16 | 100 | |
ykuroda | 0:13a5d365ba16 | 101 | template<typename Derived> struct match { |
ykuroda | 0:13a5d365ba16 | 102 | enum { |
ykuroda | 0:13a5d365ba16 | 103 | HasDirectAccess = internal::has_direct_access<Derived>::ret, |
ykuroda | 0:13a5d365ba16 | 104 | StorageOrderMatch = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime || ((PlainObjectType::Flags&RowMajorBit)==(Derived::Flags&RowMajorBit)), |
ykuroda | 0:13a5d365ba16 | 105 | InnerStrideMatch = int(StrideType::InnerStrideAtCompileTime)==int(Dynamic) |
ykuroda | 0:13a5d365ba16 | 106 | || int(StrideType::InnerStrideAtCompileTime)==int(Derived::InnerStrideAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 107 | || (int(StrideType::InnerStrideAtCompileTime)==0 && int(Derived::InnerStrideAtCompileTime)==1), |
ykuroda | 0:13a5d365ba16 | 108 | OuterStrideMatch = Derived::IsVectorAtCompileTime |
ykuroda | 0:13a5d365ba16 | 109 | || int(StrideType::OuterStrideAtCompileTime)==int(Dynamic) || int(StrideType::OuterStrideAtCompileTime)==int(Derived::OuterStrideAtCompileTime), |
ykuroda | 0:13a5d365ba16 | 110 | AlignmentMatch = (_Options!=Aligned) || ((PlainObjectType::Flags&AlignedBit)==0) || ((traits<Derived>::Flags&AlignedBit)==AlignedBit), |
ykuroda | 0:13a5d365ba16 | 111 | ScalarTypeMatch = internal::is_same<typename PlainObjectType::Scalar, typename Derived::Scalar>::value, |
ykuroda | 0:13a5d365ba16 | 112 | MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && AlignmentMatch && ScalarTypeMatch |
ykuroda | 0:13a5d365ba16 | 113 | }; |
ykuroda | 0:13a5d365ba16 | 114 | typedef typename internal::conditional<MatchAtCompileTime,internal::true_type,internal::false_type>::type type; |
ykuroda | 0:13a5d365ba16 | 115 | }; |
ykuroda | 0:13a5d365ba16 | 116 | |
ykuroda | 0:13a5d365ba16 | 117 | }; |
ykuroda | 0:13a5d365ba16 | 118 | |
ykuroda | 0:13a5d365ba16 | 119 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 120 | struct traits<RefBase<Derived> > : public traits<Derived> {}; |
ykuroda | 0:13a5d365ba16 | 121 | |
ykuroda | 0:13a5d365ba16 | 122 | } |
ykuroda | 0:13a5d365ba16 | 123 | |
ykuroda | 0:13a5d365ba16 | 124 | template<typename Derived> class RefBase |
ykuroda | 0:13a5d365ba16 | 125 | : public MapBase<Derived> |
ykuroda | 0:13a5d365ba16 | 126 | { |
ykuroda | 0:13a5d365ba16 | 127 | typedef typename internal::traits<Derived>::PlainObjectType PlainObjectType; |
ykuroda | 0:13a5d365ba16 | 128 | typedef typename internal::traits<Derived>::StrideType StrideType; |
ykuroda | 0:13a5d365ba16 | 129 | |
ykuroda | 0:13a5d365ba16 | 130 | public: |
ykuroda | 0:13a5d365ba16 | 131 | |
ykuroda | 0:13a5d365ba16 | 132 | typedef MapBase<Derived> Base; |
ykuroda | 0:13a5d365ba16 | 133 | EIGEN_DENSE_PUBLIC_INTERFACE(RefBase) |
ykuroda | 0:13a5d365ba16 | 134 | |
ykuroda | 0:13a5d365ba16 | 135 | inline Index innerStride() const |
ykuroda | 0:13a5d365ba16 | 136 | { |
ykuroda | 0:13a5d365ba16 | 137 | return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; |
ykuroda | 0:13a5d365ba16 | 138 | } |
ykuroda | 0:13a5d365ba16 | 139 | |
ykuroda | 0:13a5d365ba16 | 140 | inline Index outerStride() const |
ykuroda | 0:13a5d365ba16 | 141 | { |
ykuroda | 0:13a5d365ba16 | 142 | return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() |
ykuroda | 0:13a5d365ba16 | 143 | : IsVectorAtCompileTime ? this->size() |
ykuroda | 0:13a5d365ba16 | 144 | : int(Flags)&RowMajorBit ? this->cols() |
ykuroda | 0:13a5d365ba16 | 145 | : this->rows(); |
ykuroda | 0:13a5d365ba16 | 146 | } |
ykuroda | 0:13a5d365ba16 | 147 | |
ykuroda | 0:13a5d365ba16 | 148 | RefBase() |
ykuroda | 0:13a5d365ba16 | 149 | : Base(0,RowsAtCompileTime==Dynamic?0:RowsAtCompileTime,ColsAtCompileTime==Dynamic?0:ColsAtCompileTime), |
ykuroda | 0:13a5d365ba16 | 150 | // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values: |
ykuroda | 0:13a5d365ba16 | 151 | m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime, |
ykuroda | 0:13a5d365ba16 | 152 | StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 153 | {} |
ykuroda | 0:13a5d365ba16 | 154 | |
ykuroda | 0:13a5d365ba16 | 155 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase) |
ykuroda | 0:13a5d365ba16 | 156 | |
ykuroda | 0:13a5d365ba16 | 157 | protected: |
ykuroda | 0:13a5d365ba16 | 158 | |
ykuroda | 0:13a5d365ba16 | 159 | typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase; |
ykuroda | 0:13a5d365ba16 | 160 | |
ykuroda | 0:13a5d365ba16 | 161 | template<typename Expression> |
ykuroda | 0:13a5d365ba16 | 162 | void construct(Expression& expr) |
ykuroda | 0:13a5d365ba16 | 163 | { |
ykuroda | 0:13a5d365ba16 | 164 | if(PlainObjectType::RowsAtCompileTime==1) |
ykuroda | 0:13a5d365ba16 | 165 | { |
ykuroda | 0:13a5d365ba16 | 166 | eigen_assert(expr.rows()==1 || expr.cols()==1); |
ykuroda | 0:13a5d365ba16 | 167 | ::new (static_cast<Base*>(this)) Base(expr.data(), 1, expr.size()); |
ykuroda | 0:13a5d365ba16 | 168 | } |
ykuroda | 0:13a5d365ba16 | 169 | else if(PlainObjectType::ColsAtCompileTime==1) |
ykuroda | 0:13a5d365ba16 | 170 | { |
ykuroda | 0:13a5d365ba16 | 171 | eigen_assert(expr.rows()==1 || expr.cols()==1); |
ykuroda | 0:13a5d365ba16 | 172 | ::new (static_cast<Base*>(this)) Base(expr.data(), expr.size(), 1); |
ykuroda | 0:13a5d365ba16 | 173 | } |
ykuroda | 0:13a5d365ba16 | 174 | else |
ykuroda | 0:13a5d365ba16 | 175 | ::new (static_cast<Base*>(this)) Base(expr.data(), expr.rows(), expr.cols()); |
ykuroda | 0:13a5d365ba16 | 176 | |
ykuroda | 0:13a5d365ba16 | 177 | if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit))) |
ykuroda | 0:13a5d365ba16 | 178 | ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1); |
ykuroda | 0:13a5d365ba16 | 179 | else |
ykuroda | 0:13a5d365ba16 | 180 | ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(), |
ykuroda | 0:13a5d365ba16 | 181 | StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride()); |
ykuroda | 0:13a5d365ba16 | 182 | } |
ykuroda | 0:13a5d365ba16 | 183 | |
ykuroda | 0:13a5d365ba16 | 184 | StrideBase m_stride; |
ykuroda | 0:13a5d365ba16 | 185 | }; |
ykuroda | 0:13a5d365ba16 | 186 | |
ykuroda | 0:13a5d365ba16 | 187 | |
ykuroda | 0:13a5d365ba16 | 188 | template<typename PlainObjectType, int Options, typename StrideType> class Ref |
ykuroda | 0:13a5d365ba16 | 189 | : public RefBase<Ref<PlainObjectType, Options, StrideType> > |
ykuroda | 0:13a5d365ba16 | 190 | { |
ykuroda | 0:13a5d365ba16 | 191 | private: |
ykuroda | 0:13a5d365ba16 | 192 | typedef internal::traits<Ref> Traits; |
ykuroda | 0:13a5d365ba16 | 193 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 194 | inline Ref(const PlainObjectBase<Derived>& expr, |
ykuroda | 0:13a5d365ba16 | 195 | typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0); |
ykuroda | 0:13a5d365ba16 | 196 | public: |
ykuroda | 0:13a5d365ba16 | 197 | |
ykuroda | 0:13a5d365ba16 | 198 | typedef RefBase<Ref> Base; |
ykuroda | 0:13a5d365ba16 | 199 | EIGEN_DENSE_PUBLIC_INTERFACE(Ref) |
ykuroda | 0:13a5d365ba16 | 200 | |
ykuroda | 0:13a5d365ba16 | 201 | |
ykuroda | 0:13a5d365ba16 | 202 | #ifndef EIGEN_PARSED_BY_DOXYGEN |
ykuroda | 0:13a5d365ba16 | 203 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 204 | inline Ref(PlainObjectBase<Derived>& expr, |
ykuroda | 0:13a5d365ba16 | 205 | typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0) |
ykuroda | 0:13a5d365ba16 | 206 | { |
ykuroda | 0:13a5d365ba16 | 207 | EIGEN_STATIC_ASSERT(static_cast<bool>(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); |
ykuroda | 0:13a5d365ba16 | 208 | Base::construct(expr.derived()); |
ykuroda | 0:13a5d365ba16 | 209 | } |
ykuroda | 0:13a5d365ba16 | 210 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 211 | inline Ref(const DenseBase<Derived>& expr, |
ykuroda | 0:13a5d365ba16 | 212 | typename internal::enable_if<bool(Traits::template match<Derived>::MatchAtCompileTime),Derived>::type* = 0) |
ykuroda | 0:13a5d365ba16 | 213 | #else |
ykuroda | 0:13a5d365ba16 | 214 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 215 | inline Ref(DenseBase<Derived>& expr) |
ykuroda | 0:13a5d365ba16 | 216 | #endif |
ykuroda | 0:13a5d365ba16 | 217 | { |
ykuroda | 0:13a5d365ba16 | 218 | EIGEN_STATIC_ASSERT(static_cast<bool>(internal::is_lvalue<Derived>::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); |
ykuroda | 0:13a5d365ba16 | 219 | EIGEN_STATIC_ASSERT(static_cast<bool>(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); |
ykuroda | 0:13a5d365ba16 | 220 | enum { THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY = Derived::ThisConstantIsPrivateInPlainObjectBase}; |
ykuroda | 0:13a5d365ba16 | 221 | Base::construct(expr.const_cast_derived()); |
ykuroda | 0:13a5d365ba16 | 222 | } |
ykuroda | 0:13a5d365ba16 | 223 | |
ykuroda | 0:13a5d365ba16 | 224 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref) |
ykuroda | 0:13a5d365ba16 | 225 | |
ykuroda | 0:13a5d365ba16 | 226 | }; |
ykuroda | 0:13a5d365ba16 | 227 | |
ykuroda | 0:13a5d365ba16 | 228 | // this is the const ref version |
ykuroda | 0:13a5d365ba16 | 229 | template<typename TPlainObjectType, int Options, typename StrideType> class Ref<const TPlainObjectType, Options, StrideType> |
ykuroda | 0:13a5d365ba16 | 230 | : public RefBase<Ref<const TPlainObjectType, Options, StrideType> > |
ykuroda | 0:13a5d365ba16 | 231 | { |
ykuroda | 0:13a5d365ba16 | 232 | typedef internal::traits<Ref> Traits; |
ykuroda | 0:13a5d365ba16 | 233 | public: |
ykuroda | 0:13a5d365ba16 | 234 | |
ykuroda | 0:13a5d365ba16 | 235 | typedef RefBase<Ref> Base; |
ykuroda | 0:13a5d365ba16 | 236 | EIGEN_DENSE_PUBLIC_INTERFACE(Ref) |
ykuroda | 0:13a5d365ba16 | 237 | |
ykuroda | 0:13a5d365ba16 | 238 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 239 | inline Ref(const DenseBase<Derived>& expr, |
ykuroda | 0:13a5d365ba16 | 240 | typename internal::enable_if<bool(Traits::template match<Derived>::ScalarTypeMatch),Derived>::type* = 0) |
ykuroda | 0:13a5d365ba16 | 241 | { |
ykuroda | 0:13a5d365ba16 | 242 | // std::cout << match_helper<Derived>::HasDirectAccess << "," << match_helper<Derived>::OuterStrideMatch << "," << match_helper<Derived>::InnerStrideMatch << "\n"; |
ykuroda | 0:13a5d365ba16 | 243 | // std::cout << int(StrideType::OuterStrideAtCompileTime) << " - " << int(Derived::OuterStrideAtCompileTime) << "\n"; |
ykuroda | 0:13a5d365ba16 | 244 | // std::cout << int(StrideType::InnerStrideAtCompileTime) << " - " << int(Derived::InnerStrideAtCompileTime) << "\n"; |
ykuroda | 0:13a5d365ba16 | 245 | construct(expr.derived(), typename Traits::template match<Derived>::type()); |
ykuroda | 0:13a5d365ba16 | 246 | } |
ykuroda | 0:13a5d365ba16 | 247 | |
ykuroda | 0:13a5d365ba16 | 248 | inline Ref(const Ref& other) : Base(other) { |
ykuroda | 0:13a5d365ba16 | 249 | // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy |
ykuroda | 0:13a5d365ba16 | 250 | } |
ykuroda | 0:13a5d365ba16 | 251 | |
ykuroda | 0:13a5d365ba16 | 252 | template<typename OtherRef> |
ykuroda | 0:13a5d365ba16 | 253 | inline Ref(const RefBase<OtherRef>& other) { |
ykuroda | 0:13a5d365ba16 | 254 | construct(other.derived(), typename Traits::template match<OtherRef>::type()); |
ykuroda | 0:13a5d365ba16 | 255 | } |
ykuroda | 0:13a5d365ba16 | 256 | |
ykuroda | 0:13a5d365ba16 | 257 | protected: |
ykuroda | 0:13a5d365ba16 | 258 | |
ykuroda | 0:13a5d365ba16 | 259 | template<typename Expression> |
ykuroda | 0:13a5d365ba16 | 260 | void construct(const Expression& expr,internal::true_type) |
ykuroda | 0:13a5d365ba16 | 261 | { |
ykuroda | 0:13a5d365ba16 | 262 | Base::construct(expr); |
ykuroda | 0:13a5d365ba16 | 263 | } |
ykuroda | 0:13a5d365ba16 | 264 | |
ykuroda | 0:13a5d365ba16 | 265 | template<typename Expression> |
ykuroda | 0:13a5d365ba16 | 266 | void construct(const Expression& expr, internal::false_type) |
ykuroda | 0:13a5d365ba16 | 267 | { |
ykuroda | 0:13a5d365ba16 | 268 | m_object.lazyAssign(expr); |
ykuroda | 0:13a5d365ba16 | 269 | Base::construct(m_object); |
ykuroda | 0:13a5d365ba16 | 270 | } |
ykuroda | 0:13a5d365ba16 | 271 | |
ykuroda | 0:13a5d365ba16 | 272 | protected: |
ykuroda | 0:13a5d365ba16 | 273 | TPlainObjectType m_object; |
ykuroda | 0:13a5d365ba16 | 274 | }; |
ykuroda | 0:13a5d365ba16 | 275 | |
ykuroda | 0:13a5d365ba16 | 276 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 277 | |
ykuroda | 0:13a5d365ba16 | 278 | #endif // EIGEN_REF_H |