Eigen  3.3.3
Inverse.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_INVERSE_H
00011 #define EIGEN_INVERSE_H
00012 
00013 namespace Eigen { 
00014 
00015 template<typename XprType,typename StorageKind> class InverseImpl;
00016 
00017 namespace internal {
00018 
00019 template<typename XprType>
00020 struct traits<Inverse<XprType> >
00021   : traits<typename XprType::PlainObject>
00022 {
00023   typedef typename XprType::PlainObject PlainObject;
00024   typedef traits<PlainObject> BaseTraits;
00025   enum {
00026     Flags = BaseTraits::Flags & RowMajorBit
00027   };
00028 };
00029 
00030 } // end namespace internal
00031 
00042 template<typename XprType>
00043 class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
00044 {
00045 public:
00046   typedef typename XprType::StorageIndex StorageIndex;
00047   typedef typename XprType::PlainObject                       PlainObject;
00048   typedef typename XprType::Scalar                            Scalar;
00049   typedef typename internal::ref_selector<XprType>::type      XprTypeNested;
00050   typedef typename internal::remove_all<XprTypeNested>::type  XprTypeNestedCleaned;
00051   typedef typename internal::ref_selector<Inverse>::type Nested;
00052   typedef typename internal::remove_all<XprType>::type NestedExpression;
00053   
00054   explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr)
00055     : m_xpr(xpr)
00056   {}
00057 
00058   EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); }
00059   EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); }
00060 
00061   EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
00062 
00063 protected:
00064   XprTypeNested m_xpr;
00065 };
00066 
00067 // Generic API dispatcher
00068 template<typename XprType, typename StorageKind>
00069 class InverseImpl
00070   : public internal::generic_xpr_base<Inverse<XprType> >::type
00071 {
00072 public:
00073   typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base;
00074   typedef typename XprType::Scalar Scalar;
00075 private:
00076 
00077   Scalar coeff(Index row, Index col) const;
00078   Scalar coeff(Index i) const;
00079 };
00080 
00081 namespace internal {
00082 
00093 template<typename ArgType>
00094 struct unary_evaluator<Inverse<ArgType> >
00095   : public evaluator<typename Inverse<ArgType>::PlainObject>
00096 {
00097   typedef Inverse<ArgType> InverseType;
00098   typedef typename InverseType::PlainObject PlainObject;
00099   typedef evaluator<PlainObject> Base;
00100   
00101   enum { Flags = Base::Flags | EvalBeforeNestingBit };
00102 
00103   unary_evaluator(const InverseType& inv_xpr)
00104     : m_result(inv_xpr.rows(), inv_xpr.cols())
00105   {
00106     ::new (static_cast<Base*>(this)) Base(m_result);
00107     internal::call_assignment_no_alias(m_result, inv_xpr);
00108   }
00109   
00110 protected:
00111   PlainObject m_result;
00112 };
00113   
00114 } // end namespace internal
00115 
00116 } // end namespace Eigen
00117 
00118 #endif // EIGEN_INVERSE_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends