Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Rivet/Math/eigen3/src/Core/util/IndexedViewHelper.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2017 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 
0011 #ifndef EIGEN_INDEXED_VIEW_HELPER_H
0012 #define EIGEN_INDEXED_VIEW_HELPER_H
0013 
0014 namespace RivetEigen {
0015 
0016 namespace internal {
0017 struct symbolic_last_tag {};
0018 }
0019 
0020 /** \var last
0021   * \ingroup Core_Module
0022   *
0023   * Can be used as a parameter to RivetEigen::seq and RivetEigen::seqN functions to symbolically reference the last element/row/columns
0024   * of the underlying vector or matrix once passed to DenseBase::operator()(const RowIndices&, const ColIndices&).
0025   *
0026   * This symbolic placeholder supports standard arithmetic operations.
0027   *
0028   * A typical usage example would be:
0029   * \code
0030   * using namespace RivetEigen;
0031   * using RivetEigen::last;
0032   * VectorXd v(n);
0033   * v(seq(2,last-2)).setOnes();
0034   * \endcode
0035   *
0036   * \sa end
0037   */
0038 static const symbolic::SymbolExpr<internal::symbolic_last_tag> last; // PLEASE use RivetEigen::last   instead of RivetEigen::placeholders::last
0039 
0040 /** \var lastp1
0041   * \ingroup Core_Module
0042   *
0043   * Can be used as a parameter to RivetEigen::seq and RivetEigen::seqN functions to symbolically
0044   * reference the last+1 element/row/columns of the underlying vector or matrix once
0045   * passed to DenseBase::operator()(const RowIndices&, const ColIndices&).
0046   *
0047   * This symbolic placeholder supports standard arithmetic operations.
0048   * It is essentially an alias to last+fix<1>.
0049   *
0050   * \sa last
0051   */
0052 #ifdef EIGEN_PARSED_BY_DOXYGEN
0053 static const auto lastp1 = last+fix<1>;
0054 #else
0055 // Using a FixedExpr<1> expression is important here to make sure the compiler
0056 // can fully optimize the computation starting indices with zero overhead.
0057 static const symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<RivetEigen::internal::FixedInt<1> > > lastp1(last+fix<1>());
0058 #endif
0059 
0060 namespace internal {
0061 
0062  // Replace symbolic last/end "keywords" by their true runtime value
0063 inline Index eval_expr_given_size(Index x, Index /* size */)   { return x; }
0064 
0065 template<int N>
0066 FixedInt<N> eval_expr_given_size(FixedInt<N> x, Index /*size*/)   { return x; }
0067 
0068 template<typename Derived>
0069 Index eval_expr_given_size(const symbolic::BaseExpr<Derived> &x, Index size)
0070 {
0071   return x.derived().eval(last=size-1);
0072 }
0073 
0074 // Extract increment/step at compile time
0075 template<typename T, typename EnableIf = void> struct get_compile_time_incr {
0076   enum { value = UndefinedIncr };
0077 };
0078 
0079 // Analogue of std::get<0>(x), but tailored for our needs.
0080 template<typename T>
0081 EIGEN_CONSTEXPR Index first(const T& x) EIGEN_NOEXCEPT { return x.first(); }
0082 
0083 // IndexedViewCompatibleType/makeIndexedViewCompatible turn an arbitrary object of type T into something usable by MatrixSlice
0084 // The generic implementation is a no-op
0085 template<typename T,int XprSize,typename EnableIf=void>
0086 struct IndexedViewCompatibleType {
0087   typedef T type;
0088 };
0089 
0090 template<typename T,typename Q>
0091 const T& makeIndexedViewCompatible(const T& x, Index /*size*/, Q) { return x; }
0092 
0093 //--------------------------------------------------------------------------------
0094 // Handling of a single Index
0095 //--------------------------------------------------------------------------------
0096 
0097 struct SingleRange {
0098   enum {
0099     SizeAtCompileTime = 1
0100   };
0101   SingleRange(Index val) : m_value(val) {}
0102   Index operator[](Index) const { return m_value; }
0103   static EIGEN_CONSTEXPR Index size() EIGEN_NOEXCEPT { return 1; }
0104   Index first() const EIGEN_NOEXCEPT { return m_value; }
0105   Index m_value;
0106 };
0107 
0108 template<> struct get_compile_time_incr<SingleRange> {
0109   enum { value = 1 }; // 1 or 0 ??
0110 };
0111 
0112 // Turn a single index into something that looks like an array (i.e., that exposes a .size(), and operator[](int) methods)
0113 template<typename T, int XprSize>
0114 struct IndexedViewCompatibleType<T,XprSize,typename internal::enable_if<internal::is_integral<T>::value>::type> {
0115   // Here we could simply use Array, but maybe it's less work for the compiler to use
0116   // a simpler wrapper as SingleRange
0117   //typedef RivetEigen::Array<Index,1,1> type;
0118   typedef SingleRange type;
0119 };
0120 
0121 template<typename T, int XprSize>
0122 struct IndexedViewCompatibleType<T, XprSize, typename enable_if<symbolic::is_symbolic<T>::value>::type> {
0123   typedef SingleRange type;
0124 };
0125 
0126 
0127 template<typename T>
0128 typename enable_if<symbolic::is_symbolic<T>::value,SingleRange>::type
0129 makeIndexedViewCompatible(const T& id, Index size, SpecializedType) {
0130   return eval_expr_given_size(id,size);
0131 }
0132 
0133 //--------------------------------------------------------------------------------
0134 // Handling of all
0135 //--------------------------------------------------------------------------------
0136 
0137 struct all_t { all_t() {} };
0138 
0139 // Convert a symbolic 'all' into a usable range type
0140 template<int XprSize>
0141 struct AllRange {
0142   enum { SizeAtCompileTime = XprSize };
0143   AllRange(Index size = XprSize) : m_size(size) {}
0144   EIGEN_CONSTEXPR Index operator[](Index i) const EIGEN_NOEXCEPT { return i; }
0145   EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_size.value(); }
0146   EIGEN_CONSTEXPR Index first() const EIGEN_NOEXCEPT { return 0; }
0147   variable_if_dynamic<Index,XprSize> m_size;
0148 };
0149 
0150 template<int XprSize>
0151 struct IndexedViewCompatibleType<all_t,XprSize> {
0152   typedef AllRange<XprSize> type;
0153 };
0154 
0155 template<typename XprSizeType>
0156 inline AllRange<get_fixed_value<XprSizeType>::value> makeIndexedViewCompatible(all_t , XprSizeType size, SpecializedType) {
0157   return AllRange<get_fixed_value<XprSizeType>::value>(size);
0158 }
0159 
0160 template<int Size> struct get_compile_time_incr<AllRange<Size> > {
0161   enum { value = 1 };
0162 };
0163 
0164 } // end namespace internal
0165 
0166 
0167 /** \var all
0168   * \ingroup Core_Module
0169   * Can be used as a parameter to DenseBase::operator()(const RowIndices&, const ColIndices&) to index all rows or columns
0170   */
0171 static const RivetEigen::internal::all_t all; // PLEASE use RivetEigen::all instead of RivetEigen::placeholders::all
0172 
0173 
0174 namespace placeholders {
0175   typedef symbolic::SymbolExpr<internal::symbolic_last_tag> last_t;
0176   typedef symbolic::AddExpr<symbolic::SymbolExpr<internal::symbolic_last_tag>,symbolic::ValueExpr<RivetEigen::internal::FixedInt<1> > > end_t;
0177   typedef RivetEigen::internal::all_t all_t;
0178 
0179   EIGEN_DEPRECATED static const all_t  all  = RivetEigen::all;    // PLEASE use RivetEigen::all    instead of RivetEigen::placeholders::all
0180   EIGEN_DEPRECATED static const last_t last = RivetEigen::last;   // PLEASE use RivetEigen::last   instead of RivetEigen::placeholders::last
0181   EIGEN_DEPRECATED static const end_t  end  = RivetEigen::lastp1; // PLEASE use RivetEigen::lastp1 instead of RivetEigen::placeholders::end
0182 }
0183 
0184 } // end namespace RivetEigen
0185 
0186 #endif // EIGEN_INDEXED_VIEW_HELPER_H