10#ifndef EIGEN_INDEXED_VIEW_H
11#define EIGEN_INDEXED_VIEW_H
14#include "./InternalHeaderCheck.h"
20template <
typename XprType,
typename RowIndices,
typename ColIndices>
21struct traits<IndexedView<XprType, RowIndices, ColIndices>> : traits<XprType> {
23 RowsAtCompileTime = int(IndexedViewHelper<RowIndices>::SizeAtCompileTime),
24 ColsAtCompileTime = int(IndexedViewHelper<ColIndices>::SizeAtCompileTime),
25 MaxRowsAtCompileTime = RowsAtCompileTime,
26 MaxColsAtCompileTime = ColsAtCompileTime,
28 XprTypeIsRowMajor = (int(traits<XprType>::Flags) &
RowMajorBit) != 0,
29 IsRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1
30 : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0
33 RowIncr = int(IndexedViewHelper<RowIndices>::IncrAtCompileTime),
34 ColIncr = int(IndexedViewHelper<ColIndices>::IncrAtCompileTime),
35 InnerIncr = IsRowMajor ? ColIncr : RowIncr,
36 OuterIncr = IsRowMajor ? RowIncr : ColIncr,
38 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
39 XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret)
40 : int(outer_stride_at_compile_time<XprType>::ret),
41 XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret)
42 : int(inner_stride_at_compile_time<XprType>::ret),
44 InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
45 IsBlockAlike = InnerIncr == 1 && OuterIncr == 1,
46 IsInnerPannel = HasSameStorageOrderAsXprType &&
47 is_same<AllRange<InnerSize>, std::conditional_t<XprTypeIsRowMajor, ColIndices, RowIndices>>::value,
49 InnerStrideAtCompileTime =
52 : XprInnerStride * InnerIncr,
53 OuterStrideAtCompileTime =
56 : XprOuterstride * OuterIncr,
58 ReturnAsScalar = is_single_range<RowIndices>::value && is_single_range<ColIndices>::value,
59 ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
60 ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
64 DirectAccessMask = (int(InnerIncr) !=
Undefined && int(OuterIncr) !=
Undefined && InnerIncr >= 0 && OuterIncr >= 0)
68 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
69 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
70 Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask)) | FlagsLvalueBit | FlagsRowMajorBit |
74 typedef Block<XprType, RowsAtCompileTime, ColsAtCompileTime, IsInnerPannel> BlockType;
77template <
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind,
bool DirectAccess>
120template <
typename XprType,
typename RowIndices,
typename ColIndices>
122 :
public internal::IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind,
123 (internal::traits<IndexedView<XprType, RowIndices, ColIndices>>::Flags &
124 DirectAccessBit) != 0> {
126 typedef typename internal::IndexedViewImpl<
127 XprType, RowIndices, ColIndices,
typename internal::traits<XprType>::StorageKind,
128 (internal::traits<IndexedView<XprType, RowIndices, ColIndices>>::Flags &
DirectAccessBit) != 0>
130 EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView)
131 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView)
133 template <
typename T0,
typename T1>
134 IndexedView(XprType& xpr,
const T0& rowIndices,
const T1& colIndices) : Base(xpr, rowIndices, colIndices) {}
140template <
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind,
bool DirectAccess>
141class IndexedViewImpl :
public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices>>::type {
143 typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices>>::type Base;
144 typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
145 typedef internal::remove_all_t<XprType> NestedExpression;
146 typedef typename XprType::Scalar Scalar;
148 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedViewImpl)
150 template <
typename T0,
typename T1>
151 IndexedViewImpl(XprType& xpr,
const T0& rowIndices,
const T1& colIndices)
152 : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices) {}
155 Index rows()
const {
return IndexedViewHelper<RowIndices>::size(m_rowIndices); }
158 Index cols()
const {
return IndexedViewHelper<ColIndices>::size(m_colIndices); }
161 const internal::remove_all_t<XprType>& nestedExpression()
const {
return m_xpr; }
164 std::remove_reference_t<XprType>& nestedExpression() {
return m_xpr; }
167 const RowIndices& rowIndices()
const {
return m_rowIndices; }
170 const ColIndices& colIndices()
const {
return m_colIndices; }
172 constexpr Scalar& coeffRef(Index rowId, Index colId) {
173 return nestedExpression().coeffRef(m_rowIndices[rowId], m_colIndices[colId]);
176 constexpr const Scalar& coeffRef(Index rowId, Index colId)
const {
177 return nestedExpression().coeffRef(m_rowIndices[rowId], m_colIndices[colId]);
181 MatrixTypeNested m_xpr;
182 RowIndices m_rowIndices;
183 ColIndices m_colIndices;
186template <
typename XprType,
typename RowIndices,
typename ColIndices,
typename StorageKind>
187class IndexedViewImpl<XprType, RowIndices, ColIndices, StorageKind, true>
188 :
public IndexedViewImpl<XprType, RowIndices, ColIndices, StorageKind, false> {
190 using Base = internal::IndexedViewImpl<XprType, RowIndices, ColIndices,
191 typename internal::traits<XprType>::StorageKind,
false>;
192 using Derived = IndexedView<XprType, RowIndices, ColIndices>;
194 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedViewImpl)
196 template <
typename T0,
typename T1>
197 IndexedViewImpl(XprType& xpr,
const T0& rowIndices,
const T1& colIndices) : Base(xpr, rowIndices, colIndices) {}
199 Index rowIncrement()
const {
200 if (traits<Derived>::RowIncr != DynamicIndex && traits<Derived>::RowIncr != Undefined) {
201 return traits<Derived>::RowIncr;
203 return IndexedViewHelper<RowIndices>::incr(this->rowIndices());
205 Index colIncrement()
const {
206 if (traits<Derived>::ColIncr != DynamicIndex && traits<Derived>::ColIncr != Undefined) {
207 return traits<Derived>::ColIncr;
209 return IndexedViewHelper<ColIndices>::incr(this->colIndices());
212 Index innerIncrement()
const {
return traits<Derived>::IsRowMajor ? colIncrement() : rowIncrement(); }
214 Index outerIncrement()
const {
return traits<Derived>::IsRowMajor ? rowIncrement() : colIncrement(); }
216 std::decay_t<typename XprType::Scalar>* data() {
217 Index row_offset = this->rowIndices()[0] * this->nestedExpression().rowStride();
218 Index col_offset = this->colIndices()[0] * this->nestedExpression().colStride();
219 return this->nestedExpression().data() + row_offset + col_offset;
222 const std::decay_t<typename XprType::Scalar>* data()
const {
223 Index row_offset = this->rowIndices()[0] * this->nestedExpression().rowStride();
224 Index col_offset = this->colIndices()[0] * this->nestedExpression().colStride();
225 return this->nestedExpression().data() + row_offset + col_offset;
228 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index innerStride() const EIGEN_NOEXCEPT {
229 if (traits<Derived>::InnerStrideAtCompileTime != Dynamic) {
230 return traits<Derived>::InnerStrideAtCompileTime;
232 return innerIncrement() * this->nestedExpression().innerStride();
235 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
inline Index outerStride() const EIGEN_NOEXCEPT {
236 if (traits<Derived>::OuterStrideAtCompileTime != Dynamic) {
237 return traits<Derived>::OuterStrideAtCompileTime;
239 return outerIncrement() * this->nestedExpression().outerStride();
243template <
typename ArgType,
typename RowIndices,
typename ColIndices>
244struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
245 : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices>> {
246 typedef IndexedView<ArgType, RowIndices, ColIndices> XprType;
249 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
251 FlagsLinearAccessBit =
252 (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ? LinearAccessBit : 0,
254 FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
256 Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~
RowMajorBit )) |
257 FlagsLinearAccessBit | FlagsRowMajorBit,
262 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) {
263 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
266 typedef typename XprType::Scalar Scalar;
267 typedef typename XprType::CoeffReturnType CoeffReturnType;
269 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col)
const {
270 eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() &&
271 m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
272 return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
275 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) {
276 eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() &&
277 m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
278 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
281 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
282 EIGEN_STATIC_ASSERT_LVALUE(XprType)
283 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
284 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
285 eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() &&
286 m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
287 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
290 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar& coeffRef(Index index)
const {
291 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
292 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
293 eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() &&
294 m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
295 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
298 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const CoeffReturnType coeff(Index index)
const {
299 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
300 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
301 eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() &&
302 m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols());
303 return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
307 evaluator<ArgType> m_argImpl;
308 const XprType& m_xpr;
const unsigned int LinearAccessBit
Definition Constants.h:133
const unsigned int DirectAccessBit
Definition Constants.h:159
const unsigned int LvalueBit
Definition Constants.h:148
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const int Undefined
Definition Constants.h:34
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int DynamicIndex
Definition Constants.h:30
const int Dynamic
Definition Constants.h:25