File indexing completed on 2025-04-19 09:06:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_INDEXED_VIEW_H
0011 #define EIGEN_INDEXED_VIEW_H
0012
0013 namespace RivetEigen {
0014
0015 namespace internal {
0016
0017 template<typename XprType, typename RowIndices, typename ColIndices>
0018 struct traits<IndexedView<XprType, RowIndices, ColIndices> >
0019 : traits<XprType>
0020 {
0021 enum {
0022 RowsAtCompileTime = int(array_size<RowIndices>::value),
0023 ColsAtCompileTime = int(array_size<ColIndices>::value),
0024 MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : Dynamic,
0025 MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : Dynamic,
0026
0027 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&RowMajorBit) != 0,
0028 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
0029 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
0030 : XprTypeIsRowMajor,
0031
0032 RowIncr = int(get_compile_time_incr<RowIndices>::value),
0033 ColIncr = int(get_compile_time_incr<ColIndices>::value),
0034 InnerIncr = IsRowMajor ? ColIncr : RowIncr,
0035 OuterIncr = IsRowMajor ? RowIncr : ColIncr,
0036
0037 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
0038 XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType>::ret) : int(outer_stride_at_compile_time<XprType>::ret),
0039 XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType>::ret) : int(inner_stride_at_compile_time<XprType>::ret),
0040
0041 InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime,
0042 IsBlockAlike = InnerIncr==1 && OuterIncr==1,
0043 IsInnerPannel = HasSameStorageOrderAsXprType && is_same<AllRange<InnerSize>,typename conditional<XprTypeIsRowMajor,ColIndices,RowIndices>::type>::value,
0044
0045 InnerStrideAtCompileTime = InnerIncr<0 || InnerIncr==DynamicIndex || XprInnerStride==Dynamic ? Dynamic : XprInnerStride * InnerIncr,
0046 OuterStrideAtCompileTime = OuterIncr<0 || OuterIncr==DynamicIndex || XprOuterstride==Dynamic ? Dynamic : XprOuterstride * OuterIncr,
0047
0048 ReturnAsScalar = is_same<RowIndices,SingleRange>::value && is_same<ColIndices,SingleRange>::value,
0049 ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike,
0050 ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock),
0051
0052
0053
0054 DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0,
0055 FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0,
0056 FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
0057 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
0058 Flags = (traits<XprType>::Flags & (HereditaryBits | DirectAccessMask )) | FlagsLvalueBit | FlagsRowMajorBit | FlagsLinearAccessBit
0059 };
0060
0061 typedef Block<XprType,RowsAtCompileTime,ColsAtCompileTime,IsInnerPannel> BlockType;
0062 };
0063
0064 }
0065
0066 template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
0067 class IndexedViewImpl;
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 template<typename XprType, typename RowIndices, typename ColIndices>
0109 class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>
0110 {
0111 public:
0112 typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
0113 EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView)
0114 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView)
0115
0116 typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
0117 typedef typename internal::remove_all<XprType>::type NestedExpression;
0118
0119 template<typename T0, typename T1>
0120 IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices)
0121 : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices)
0122 {}
0123
0124
0125 Index rows() const { return internal::size(m_rowIndices); }
0126
0127
0128 Index cols() const { return internal::size(m_colIndices); }
0129
0130
0131 const typename internal::remove_all<XprType>::type&
0132 nestedExpression() const { return m_xpr; }
0133
0134
0135 typename internal::remove_reference<XprType>::type&
0136 nestedExpression() { return m_xpr; }
0137
0138
0139 const RowIndices& rowIndices() const { return m_rowIndices; }
0140
0141
0142 const ColIndices& colIndices() const { return m_colIndices; }
0143
0144 protected:
0145 MatrixTypeNested m_xpr;
0146 RowIndices m_rowIndices;
0147 ColIndices m_colIndices;
0148 };
0149
0150
0151
0152 template<typename XprType, typename RowIndices, typename ColIndices, typename StorageKind>
0153 class IndexedViewImpl
0154 : public internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type
0155 {
0156 public:
0157 typedef typename internal::generic_xpr_base<IndexedView<XprType, RowIndices, ColIndices> >::type Base;
0158 };
0159
0160 namespace internal {
0161
0162
0163 template<typename ArgType, typename RowIndices, typename ColIndices>
0164 struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
0165 : evaluator_base<IndexedView<ArgType, RowIndices, ColIndices> >
0166 {
0167 typedef IndexedView<ArgType, RowIndices, ColIndices> XprType;
0168
0169 enum {
0170 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
0171
0172 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1) ? LinearAccessBit : 0,
0173
0174 FlagsRowMajorBit = traits<XprType>::FlagsRowMajorBit,
0175
0176 Flags = (evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit )) | FlagsLinearAccessBit | FlagsRowMajorBit,
0177
0178 Alignment = 0
0179 };
0180
0181 EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
0182 {
0183 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
0184 }
0185
0186 typedef typename XprType::Scalar Scalar;
0187 typedef typename XprType::CoeffReturnType CoeffReturnType;
0188
0189 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0190 CoeffReturnType coeff(Index row, Index col) const
0191 {
0192 return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
0193 }
0194
0195 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0196 Scalar& coeffRef(Index row, Index col)
0197 {
0198 return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
0199 }
0200
0201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0202 Scalar& coeffRef(Index index)
0203 {
0204 EIGEN_STATIC_ASSERT_LVALUE(XprType)
0205 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
0206 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
0207 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
0208 }
0209
0210 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0211 const Scalar& coeffRef(Index index) const
0212 {
0213 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
0214 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
0215 return m_argImpl.coeffRef( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
0216 }
0217
0218 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0219 const CoeffReturnType coeff(Index index) const
0220 {
0221 Index row = XprType::RowsAtCompileTime == 1 ? 0 : index;
0222 Index col = XprType::RowsAtCompileTime == 1 ? index : 0;
0223 return m_argImpl.coeff( m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
0224 }
0225
0226 protected:
0227
0228 evaluator<ArgType> m_argImpl;
0229 const XprType& m_xpr;
0230
0231 };
0232
0233 }
0234
0235 }
0236
0237 #endif