Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:56:14

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2014-2019 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_INVERSE_H
0011 #define EIGEN_INVERSE_H
0012 
0013 namespace Eigen {
0014 
0015 template<typename XprType,typename StorageKind> class InverseImpl;
0016 
0017 namespace internal {
0018 
0019 template<typename XprType>
0020 struct traits<Inverse<XprType> >
0021   : traits<typename XprType::PlainObject>
0022 {
0023   typedef typename XprType::PlainObject PlainObject;
0024   typedef traits<PlainObject> BaseTraits;
0025   enum {
0026     Flags = BaseTraits::Flags & RowMajorBit
0027   };
0028 };
0029 
0030 } // end namespace internal
0031 
0032 /** \class Inverse
0033   *
0034   * \brief Expression of the inverse of another expression
0035   *
0036   * \tparam XprType the type of the expression we are taking the inverse
0037   *
0038   * This class represents an abstract expression of A.inverse()
0039   * and most of the time this is the only way it is used.
0040   *
0041   */
0042 template<typename XprType>
0043 class Inverse : public InverseImpl<XprType,typename internal::traits<XprType>::StorageKind>
0044 {
0045 public:
0046   typedef typename XprType::StorageIndex StorageIndex;
0047   typedef typename XprType::Scalar                            Scalar;
0048   typedef typename internal::ref_selector<XprType>::type      XprTypeNested;
0049   typedef typename internal::remove_all<XprTypeNested>::type  XprTypeNestedCleaned;
0050   typedef typename internal::ref_selector<Inverse>::type Nested;
0051   typedef typename internal::remove_all<XprType>::type NestedExpression;
0052 
0053   explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr)
0054     : m_xpr(xpr)
0055   {}
0056 
0057   EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR  Index rows() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
0058   EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR  Index cols() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
0059 
0060   EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; }
0061 
0062 protected:
0063   XprTypeNested m_xpr;
0064 };
0065 
0066 // Generic API dispatcher
0067 template<typename XprType, typename StorageKind>
0068 class InverseImpl
0069   : public internal::generic_xpr_base<Inverse<XprType> >::type
0070 {
0071 public:
0072   typedef typename internal::generic_xpr_base<Inverse<XprType> >::type Base;
0073   typedef typename XprType::Scalar Scalar;
0074 private:
0075 
0076   Scalar coeff(Index row, Index col) const;
0077   Scalar coeff(Index i) const;
0078 };
0079 
0080 namespace internal {
0081 
0082 /** \internal
0083   * \brief Default evaluator for Inverse expression.
0084   *
0085   * This default evaluator for Inverse expression simply evaluate the inverse into a temporary
0086   * by a call to internal::call_assignment_no_alias.
0087   * Therefore, inverse implementers only have to specialize Assignment<Dst,Inverse<...>, ...> for
0088   * there own nested expression.
0089   *
0090   * \sa class Inverse
0091   */
0092 template<typename ArgType>
0093 struct unary_evaluator<Inverse<ArgType> >
0094   : public evaluator<typename Inverse<ArgType>::PlainObject>
0095 {
0096   typedef Inverse<ArgType> InverseType;
0097   typedef typename InverseType::PlainObject PlainObject;
0098   typedef evaluator<PlainObject> Base;
0099 
0100   enum { Flags = Base::Flags | EvalBeforeNestingBit };
0101 
0102   unary_evaluator(const InverseType& inv_xpr)
0103     : m_result(inv_xpr.rows(), inv_xpr.cols())
0104   {
0105     ::new (static_cast<Base*>(this)) Base(m_result);
0106     internal::call_assignment_no_alias(m_result, inv_xpr);
0107   }
0108 
0109 protected:
0110   PlainObject m_result;
0111 };
0112 
0113 } // end namespace internal
0114 
0115 } // end namespace Eigen
0116 
0117 #endif // EIGEN_INVERSE_H