![]() |
Eigen
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> 00005 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 #ifndef EIGEN_EIGENBASE_H 00012 #define EIGEN_EIGENBASE_H 00013 00014 namespace Eigen { 00015 00028 template<typename Derived> struct EigenBase 00029 { 00030 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject; 00031 00037 typedef Eigen::Index Index; 00038 00039 // FIXME is it needed? 00040 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00041 00043 EIGEN_DEVICE_FUNC 00044 Derived& derived() { return *static_cast<Derived*>(this); } 00046 EIGEN_DEVICE_FUNC 00047 const Derived& derived() const { return *static_cast<const Derived*>(this); } 00048 00049 EIGEN_DEVICE_FUNC 00050 inline Derived& const_cast_derived() const 00051 { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); } 00052 EIGEN_DEVICE_FUNC 00053 inline const Derived& const_derived() const 00054 { return *static_cast<const Derived*>(this); } 00055 00057 EIGEN_DEVICE_FUNC 00058 inline Index rows() const { return derived().rows(); } 00060 EIGEN_DEVICE_FUNC 00061 inline Index cols() const { return derived().cols(); } 00064 EIGEN_DEVICE_FUNC 00065 inline Index size() const { return rows() * cols(); } 00066 00068 template<typename Dest> 00069 EIGEN_DEVICE_FUNC 00070 inline void evalTo(Dest& dst) const 00071 { derived().evalTo(dst); } 00072 00074 template<typename Dest> 00075 EIGEN_DEVICE_FUNC 00076 inline void addTo(Dest& dst) const 00077 { 00078 // This is the default implementation, 00079 // derived class can reimplement it in a more optimized way. 00080 typename Dest::PlainObject res(rows(),cols()); 00081 evalTo(res); 00082 dst += res; 00083 } 00084 00086 template<typename Dest> 00087 EIGEN_DEVICE_FUNC 00088 inline void subTo(Dest& dst) const 00089 { 00090 // This is the default implementation, 00091 // derived class can reimplement it in a more optimized way. 00092 typename Dest::PlainObject res(rows(),cols()); 00093 evalTo(res); 00094 dst -= res; 00095 } 00096 00098 template<typename Dest> 00099 EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const 00100 { 00101 // This is the default implementation, 00102 // derived class can reimplement it in a more optimized way. 00103 dst = dst * this->derived(); 00104 } 00105 00107 template<typename Dest> 00108 EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const 00109 { 00110 // This is the default implementation, 00111 // derived class can reimplement it in a more optimized way. 00112 dst = this->derived() * dst; 00113 } 00114 00115 }; 00116 00117 /*************************************************************************** 00118 * Implementation of matrix base methods 00119 ***************************************************************************/ 00120 00129 template<typename Derived> 00130 template<typename OtherDerived> 00131 Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other) 00132 { 00133 call_assignment(derived(), other.derived()); 00134 return derived(); 00135 } 00136 00137 template<typename Derived> 00138 template<typename OtherDerived> 00139 Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other) 00140 { 00141 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); 00142 return derived(); 00143 } 00144 00145 template<typename Derived> 00146 template<typename OtherDerived> 00147 Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other) 00148 { 00149 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); 00150 return derived(); 00151 } 00152 00153 } // end namespace Eigen 00154 00155 #endif // EIGEN_EIGENBASE_H