10#ifndef EIGEN_INDEXED_VIEW_H
11#define EIGEN_INDEXED_VIEW_H
13#include "./InternalHeaderCheck.h"
19template<
typename XprType,
typename RowIndices,
typename ColIndices>
20struct traits<IndexedView<XprType, RowIndices, ColIndices> >
24 RowsAtCompileTime = int(array_size<RowIndices>::value),
25 ColsAtCompileTime = int(array_size<ColIndices>::value),
26 MaxRowsAtCompileTime = RowsAtCompileTime,
27 MaxColsAtCompileTime = ColsAtCompileTime,
29 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0,
30 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
31 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
34 RowIncr =
int(get_compile_time_incr<RowIndices>::value),
35 ColIncr = int(get_compile_time_incr<ColIndices>::value),
36 InnerIncr = IsRowMajor ? ColIncr : RowIncr,
37 OuterIncr = IsRowMajor ? RowIncr : ColIncr,
39 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
40 XprInnerStride = HasSameStorageOrderAsXprType ?
int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
41 XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
43 InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
44 IsBlockAlike = InnerIncr==1 && OuterIncr==1,
45 IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
50 ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
51 ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
52 ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
58 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
59 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
60 Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
63 typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType;
68template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
110template<
typename XprType,
typename RowIndices,
typename ColIndices>
111class IndexedView :
public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
114 typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
118 typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
119 typedef typename internal::remove_all<XprType>::type NestedExpression;
121 template<
typename T0,
typename T1>
122 IndexedView(XprType& xpr,
const T0& rowIndices,
const T1& colIndices)
123 : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
127 Index rows()
const {
return internal::size(m_rowIndices); }
130 Index cols()
const {
return internal::size(m_colIndices); }
133 const typename internal::remove_all<XprType>::type&
137 typename internal::remove_reference<XprType>::type&
141 const RowIndices&
rowIndices()
const {
return m_rowIndices; }
144 const ColIndices&
colIndices()
const {
return m_colIndices; }
147 MatrixTypeNested m_xpr;
148 RowIndices m_rowIndices;
149 ColIndices m_colIndices;
154template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
156 :
public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
159 typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base;
165template<
typename ArgType,
typename RowIndices,
typename ColIndices>
166struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
167 : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
169 typedef IndexedView<ArgType, RowIndices, ColIndices> XprType;
172 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
174 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
176 FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
178 Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~
RowMajorBit )) | FlagsLinearAccessBit | FlagsRowMajorBit,
183 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
185 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
188 typedef typename XprType::Scalar Scalar;
189 typedef typename XprType::CoeffReturnType CoeffReturnType;
191 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
192 CoeffReturnType coeff(
Index row,
Index col)
const
194 return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
197 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
200 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
203 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
204 Scalar& coeffRef(
Index index)
206 EIGEN_STATIC_ASSERT_LVALUE(XprType)
207 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
208 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
209 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
212 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
213 const Scalar& coeffRef(
Index index)
const
215 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
216 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
217 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
220 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
221 const CoeffReturnType coeff(
Index index)
const
223 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
224 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
225 return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
230 evaluator<ArgType> m_argImpl;
231 const XprType& m_xpr;
Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices.
Definition: IndexedView.h:112
const RowIndices & rowIndices() const
Definition: IndexedView.h:141
const ColIndices & colIndices() const
Definition: IndexedView.h:144
Index cols() const
Definition: IndexedView.h:130
internal::remove_reference< XprType >::type & nestedExpression()
Definition: IndexedView.h:138
const internal::remove_all< XprType >::type & nestedExpression() const
Definition: IndexedView.h:134
Index rows() const
Definition: IndexedView.h:127
const unsigned int LinearAccessBit
Definition: Constants.h:132
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const int UndefinedIncr
Definition: Constants.h:33
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int DynamicIndex
Definition: Constants.h:29
const int Dynamic
Definition: Constants.h:24