10 #ifndef EIGEN_INDEXED_VIEW_H
11 #define EIGEN_INDEXED_VIEW_H
19 template<
typename XprType,
typename RowIndices,
typename ColIndices>
20 struct 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>,
std::conditional_t<XprTypeIsRowMajor,ColIndices,RowIndices>>::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;
68 template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
69 class IndexedViewImpl;
109 template<
typename XprType,
typename RowIndices,
typename ColIndices>
120 template<typename T0, typename T1>
121 IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
122 : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
136 std::remove_reference_t<XprType>&
140 const RowIndices&
rowIndices()
const {
return m_rowIndices; }
143 const ColIndices&
colIndices()
const {
return m_colIndices; }
153 template<
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
155 :
public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
158 typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
Base;
164 template<
typename ArgType,
typename RowIndices,
typename ColIndices>
165 struct unary_evaluator<
IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
166 : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
171 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
173 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
175 FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
182 EIGEN_DEVICE_FUNC explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
187 typedef typename XprType::Scalar Scalar;
188 typedef typename XprType::CoeffReturnType CoeffReturnType;
193 eigen_assert(m_xpr.rowIndices()[
row] >= 0 && m_xpr.rowIndices()[
row] < m_xpr.nestedExpression().rows()
194 && m_xpr.colIndices()[
col] >= 0 && m_xpr.colIndices()[
col] < m_xpr.nestedExpression().cols());
195 return m_argImpl.coeff(m_xpr.rowIndices()[
row], m_xpr.colIndices()[
col]);
201 eigen_assert(m_xpr.rowIndices()[
row] >= 0 && m_xpr.rowIndices()[
row] < m_xpr.nestedExpression().rows()
202 && m_xpr.colIndices()[
col] >= 0 && m_xpr.colIndices()[
col] < m_xpr.nestedExpression().cols());
203 return m_argImpl.coeffRef(m_xpr.rowIndices()[
row], m_xpr.colIndices()[
col]);
207 Scalar& coeffRef(
Index index)
210 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
211 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
212 eigen_assert(m_xpr.rowIndices()[
row] >= 0 && m_xpr.rowIndices()[
row] < m_xpr.nestedExpression().rows()
213 && m_xpr.colIndices()[
col] >= 0 && m_xpr.colIndices()[
col] < m_xpr.nestedExpression().cols());
214 return m_argImpl.coeffRef( m_xpr.rowIndices()[
row], m_xpr.colIndices()[
col]);
218 const Scalar& coeffRef(
Index index)
const
220 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
221 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
222 eigen_assert(m_xpr.rowIndices()[
row] >= 0 && m_xpr.rowIndices()[
row] < m_xpr.nestedExpression().rows()
223 && m_xpr.colIndices()[
col] >= 0 && m_xpr.colIndices()[
col] < m_xpr.nestedExpression().cols());
224 return m_argImpl.coeffRef( m_xpr.rowIndices()[
row], m_xpr.colIndices()[
col]);
228 const CoeffReturnType coeff(
Index index)
const
230 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
231 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
232 eigen_assert(m_xpr.rowIndices()[
row] >= 0 && m_xpr.rowIndices()[
row] < m_xpr.nestedExpression().rows()
233 && m_xpr.colIndices()[
col] >= 0 && m_xpr.colIndices()[
col] < m_xpr.nestedExpression().cols());
234 return m_argImpl.coeff( m_xpr.rowIndices()[
row], m_xpr.colIndices()[
col]);
239 evaluator<ArgType> m_argImpl;
240 const XprType& m_xpr;
RowXpr row(Index i)
This is the const version of row(). */.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
#define EIGEN_DEVICE_FUNC
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
internal::generic_xpr_base< IndexedView< XprType, RowIndices, ColIndices > >::type Base
Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices.
internal::ref_selector< XprType >::non_const_type MatrixTypeNested
internal::remove_all_t< XprType > NestedExpression
const internal::remove_all_t< XprType > & nestedExpression() const
IndexedViewImpl< XprType, RowIndices, ColIndices, typename internal::traits< XprType >::StorageKind >::Base Base
std::remove_reference_t< XprType > & nestedExpression()
const ColIndices & colIndices() const
const RowIndices & rowIndices() const
const unsigned int LinearAccessBit
const unsigned int DirectAccessBit
const unsigned int LvalueBit
const unsigned int RowMajorBit
typename remove_all< T >::type remove_all_t
EIGEN_CONSTEXPR auto index_list_size(const T &x)
const unsigned int HereditaryBits
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.