10 #ifndef EIGEN_INDEXED_VIEW_H 11 #define EIGEN_INDEXED_VIEW_H 17 template<
typename XprType,
typename RowIndices,
typename ColIndices>
18 struct traits<IndexedView<XprType, RowIndices, ColIndices> >
22 RowsAtCompileTime = int(array_size<RowIndices>::value),
23 ColsAtCompileTime = int(array_size<ColIndices>::value),
24 MaxRowsAtCompileTime = RowsAtCompileTime !=
Dynamic ? int(RowsAtCompileTime) :
Dynamic,
25 MaxColsAtCompileTime = ColsAtCompileTime !=
Dynamic ? int(ColsAtCompileTime) :
Dynamic,
27 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0,
28 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
29 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
32 RowIncr = int(get_compile_time_incr<RowIndices>::value),
33 ColIncr = int(get_compile_time_incr<ColIndices>::value),
34 InnerIncr = IsRowMajor ? ColIncr : RowIncr,
35 OuterIncr = IsRowMajor ? RowIncr : ColIncr,
37 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
38 XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
39 XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
41 InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
42 IsBlockAlike = InnerIncr==1 && OuterIncr==1,
43 IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
45 InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==
DynamicIndex || XprInnerStride==
Dynamic ?
Dynamic : XprInnerStride * InnerIncr,
46 OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==
DynamicIndex || XprOuterstride==
Dynamic ?
Dynamic : XprOuterstride * OuterIncr,
48 ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
49 ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
50 ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
56 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
57 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
58 Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
61 typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType;
66 template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
67 class IndexedViewImpl;
108 template<
typename XprType,
typename RowIndices,
typename ColIndices>
109 class IndexedView :
public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
112 typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
116 typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
117 typedef typename internal::remove_all<XprType>::type NestedExpression;
119 template<
typename T0,
typename T1>
120 IndexedView(XprType& xpr,
const T0& rowIndices,
const T1& colIndices)
121 : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
125 Index rows()
const {
return internal::size(m_rowIndices); }
128 Index cols()
const {
return internal::size(m_colIndices); }
131 const typename internal::remove_all<XprType>::type&
135 typename internal::remove_reference<XprType>::type&
139 const RowIndices&
rowIndices()
const {
return m_rowIndices; }
142 const ColIndices&
colIndices()
const {
return m_colIndices; }
145 MatrixTypeNested m_xpr;
146 RowIndices m_rowIndices;
147 ColIndices m_colIndices;
152 template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
153 class IndexedViewImpl
154 :
public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
157 typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base;
163 template<
typename ArgType,
typename RowIndices,
typename ColIndices>
164 struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
165 : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
170 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
172 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
174 FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
176 Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~
RowMajorBit )) | FlagsLinearAccessBit | FlagsRowMajorBit,
181 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
183 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
186 typedef typename XprType::Scalar Scalar;
187 typedef typename XprType::CoeffReturnType CoeffReturnType;
189 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
190 CoeffReturnType coeff(
Index row,
Index col)
const 192 return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
195 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
198 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
202 Scalar& coeffRef(
Index index)
204 EIGEN_STATIC_ASSERT_LVALUE(XprType)
205 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
206 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
207 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
210 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
211 const Scalar& coeffRef(
Index index)
const 213 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
214 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
215 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
218 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
219 const CoeffReturnType coeff(
Index index)
const 221 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
222 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
223 return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
228 evaluator<ArgType> m_argImpl;
229 const XprType& m_xpr;
237 #endif // EIGEN_INDEXED_VIEW_H Index rows() const
Definition: IndexedView.h:125
const ColIndices & colIndices() const
Definition: IndexedView.h:142
const unsigned int DirectAccessBit
Definition: Constants.h:155
const RowIndices & rowIndices() const
Definition: IndexedView.h:139
const unsigned int LvalueBit
Definition: Constants.h:144
Namespace containing all symbols from the Eigen library.
Definition: Core:141
const int DynamicIndex
Definition: Constants.h:27
const unsigned int RowMajorBit
Definition: Constants.h:66
Index cols() const
Definition: IndexedView.h:128
const internal::remove_all< XprType >::type & nestedExpression() const
Definition: IndexedView.h:132
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50
internal::remove_reference< XprType >::type & nestedExpression()
Definition: IndexedView.h:136
Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices...
Definition: IndexedView.h:109
const int UndefinedIncr
Definition: Constants.h:31
const int Dynamic
Definition: Constants.h:22
const unsigned int LinearAccessBit
Definition: Constants.h:130