Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:37:03

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 #if !defined(EIGEN_PARSED_BY_DOXYGEN)
0011 
0012 // This file is automatically included twice to generate const and non-const versions
0013 
0014 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
0015 #define EIGEN_INDEXED_VIEW_METHOD_CONST const
0016 #define EIGEN_INDEXED_VIEW_METHOD_TYPE  ConstIndexedViewType
0017 #else
0018 #define EIGEN_INDEXED_VIEW_METHOD_CONST
0019 #define EIGEN_INDEXED_VIEW_METHOD_TYPE IndexedViewType
0020 #endif
0021 
0022 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
0023 protected:
0024 
0025 // define some aliases to ease readability
0026 
0027 template<typename Indices>
0028 struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {};
0029 
0030 template<typename Indices>
0031 struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {};
0032 
0033 template<typename Indices>
0034 struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {};
0035 
0036 typedef typename internal::IndexedViewCompatibleType<Index,1>::type IvcIndex;
0037 
0038 template<typename Indices>
0039 typename IvcRowType<Indices>::type
0040 ivcRow(const Indices& indices) const {
0041   return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized);
0042 }
0043 
0044 template<typename Indices>
0045 typename IvcColType<Indices>::type
0046 ivcCol(const Indices& indices) const {
0047   return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized);
0048 }
0049 
0050 template<typename Indices>
0051 typename IvcColType<Indices>::type
0052 ivcSize(const Indices& indices) const {
0053   return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized);
0054 }
0055 
0056 public:
0057 
0058 #endif
0059 
0060 template<typename RowIndices, typename ColIndices>
0061 struct EIGEN_INDEXED_VIEW_METHOD_TYPE {
0062   typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,
0063                       typename IvcRowType<RowIndices>::type,
0064                       typename IvcColType<ColIndices>::type> type;
0065 };
0066 
0067 // This is the generic version
0068 
0069 template<typename RowIndices, typename ColIndices>
0070 typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
0071   && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsIndexedView,
0072   typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type >::type
0073 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
0074 {
0075   return typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type
0076             (derived(), ivcRow(rowIndices), ivcCol(colIndices));
0077 }
0078 
0079 // The following overload returns a Block<> object
0080 
0081 template<typename RowIndices, typename ColIndices>
0082 typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
0083   && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsBlock,
0084   typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>::type
0085 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
0086 {
0087   typedef typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType BlockType;
0088   typename IvcRowType<RowIndices>::type actualRowIndices = ivcRow(rowIndices);
0089   typename IvcColType<ColIndices>::type actualColIndices = ivcCol(colIndices);
0090   return BlockType(derived(),
0091                    internal::first(actualRowIndices),
0092                    internal::first(actualColIndices),
0093                    internal::size(actualRowIndices),
0094                    internal::size(actualColIndices));
0095 }
0096 
0097 // The following overload returns a Scalar
0098 
0099 template<typename RowIndices, typename ColIndices>
0100 typename internal::enable_if<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
0101   && internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsScalar,
0102   CoeffReturnType >::type
0103 operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
0104 {
0105   return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols()));
0106 }
0107 
0108 #if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
0109 
0110 // The following three overloads are needed to handle raw Index[N] arrays.
0111 
0112 template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
0113 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
0114 operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
0115 {
0116   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
0117                     (derived(), rowIndices, ivcCol(colIndices));
0118 }
0119 
0120 template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
0121 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]>
0122 operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
0123 {
0124   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>
0125                     (derived(), ivcRow(rowIndices), colIndices);
0126 }
0127 
0128 template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
0129 IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
0130 operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
0131 {
0132   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>
0133                     (derived(), rowIndices, colIndices);
0134 }
0135 
0136 #endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
0137 
0138 // Overloads for 1D vectors/arrays
0139 
0140 template<typename Indices>
0141 typename internal::enable_if<
0142   IsRowMajor && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
0143   IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type> >::type
0144 operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
0145 {
0146   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
0147   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type>
0148             (derived(), IvcIndex(0), ivcCol(indices));
0149 }
0150 
0151 template<typename Indices>
0152 typename internal::enable_if<
0153   (!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
0154   IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex> >::type
0155 operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
0156 {
0157   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
0158   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex>
0159             (derived(), ivcRow(indices), IvcIndex(0));
0160 }
0161 
0162 template<typename Indices>
0163 typename internal::enable_if<
0164   (internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1) && (!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
0165   VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> >::type
0166 operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
0167 {
0168   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
0169   typename IvcType<Indices>::type actualIndices = ivcSize(indices);
0170   return VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value>
0171             (derived(), internal::first(actualIndices), internal::size(actualIndices));
0172 }
0173 
0174 template<typename IndexType>
0175 typename internal::enable_if<symbolic::is_symbolic<IndexType>::value, CoeffReturnType >::type
0176 operator()(const IndexType& id) EIGEN_INDEXED_VIEW_METHOD_CONST
0177 {
0178   return Base::operator()(internal::eval_expr_given_size(id,size()));
0179 }
0180 
0181 #if EIGEN_HAS_STATIC_ARRAY_TEMPLATE
0182 
0183 template<typename IndicesT, std::size_t IndicesN>
0184 typename internal::enable_if<IsRowMajor,
0185   IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >::type
0186 operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
0187 {
0188   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
0189   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]>
0190             (derived(), IvcIndex(0), indices);
0191 }
0192 
0193 template<typename IndicesT, std::size_t IndicesN>
0194 typename internal::enable_if<!IsRowMajor,
0195   IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >::type
0196 operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
0197 {
0198   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
0199   return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex>
0200             (derived(), indices, IvcIndex(0));
0201 }
0202 
0203 #endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE
0204 
0205 #undef EIGEN_INDEXED_VIEW_METHOD_CONST
0206 #undef EIGEN_INDEXED_VIEW_METHOD_TYPE
0207 
0208 #ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
0209 #define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
0210 #include "IndexedViewMethods.h"
0211 #undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
0212 #endif
0213 
0214 #else // EIGEN_PARSED_BY_DOXYGEN
0215 
0216 /**
0217   * \returns a generic submatrix view defined by the rows and columns indexed \a rowIndices and \a colIndices respectively.
0218   *
0219   * Each parameter must either be:
0220   *  - An integer indexing a single row or column
0221   *  - Eigen::all indexing the full set of respective rows or columns in increasing order
0222   *  - An ArithmeticSequence as returned by the Eigen::seq and Eigen::seqN functions
0223   *  - Any %Eigen's vector/array of integers or expressions
0224   *  - Plain C arrays: \c int[N]
0225   *  - And more generally any type exposing the following two member functions:
0226   * \code
0227   * <integral type> operator[](<integral type>) const;
0228   * <integral type> size() const;
0229   * \endcode
0230   * where \c <integral \c type>  stands for any integer type compatible with Eigen::Index (i.e. \c std::ptrdiff_t).
0231   *
0232   * The last statement implies compatibility with \c std::vector, \c std::valarray, \c std::array, many of the Range-v3's ranges, etc.
0233   *
0234   * If the submatrix can be represented using a starting position \c (i,j) and positive sizes \c (rows,columns), then this
0235   * method will returns a Block object after extraction of the relevant information from the passed arguments. This is the case
0236   * when all arguments are either:
0237   *  - An integer
0238   *  - Eigen::all
0239   *  - An ArithmeticSequence with compile-time increment strictly equal to 1, as returned by Eigen::seq(a,b), and Eigen::seqN(a,N).
0240   *
0241   * Otherwise a more general IndexedView<Derived,RowIndices',ColIndices'> object will be returned, after conversion of the inputs
0242   * to more suitable types \c RowIndices' and \c ColIndices'.
0243   *
0244   * For 1D vectors and arrays, you better use the operator()(const Indices&) overload, which behave the same way but taking a single parameter.
0245   *
0246   * See also this <a href="https://stackoverflow.com/questions/46110917/eigen-replicate-items-along-one-dimension-without-useless-allocations">question</a> and its answer for an example of how to duplicate coefficients.
0247   *
0248   * \sa operator()(const Indices&), class Block, class IndexedView, DenseBase::block(Index,Index,Index,Index)
0249   */
0250 template<typename RowIndices, typename ColIndices>
0251 IndexedView_or_Block
0252 operator()(const RowIndices& rowIndices, const ColIndices& colIndices);
0253 
0254 /** This is an overload of operator()(const RowIndices&, const ColIndices&) for 1D vectors or arrays
0255   *
0256   * \only_for_vectors
0257   */
0258 template<typename Indices>
0259 IndexedView_or_VectorBlock
0260 operator()(const Indices& indices);
0261 
0262 #endif  // EIGEN_PARSED_BY_DOXYGEN