10#ifndef EIGEN_COHERENT_PAD_OP_H
11#define EIGEN_COHERENT_PAD_OP_H
13#include "./InternalHeaderCheck.h"
20template <
typename XprType,
int SizeAtCompileTime_>
23template <
typename XprType,
int SizeAtCompileTime_>
24struct traits<CoherentPadOp<XprType, SizeAtCompileTime_>> :
public traits<XprType> {
25 typedef typename internal::remove_all<XprType>::type PlainXprType;
26 typedef typename internal::ref_selector<XprType>::type XprNested;
27 typedef typename std::remove_reference_t<XprNested> XprNested_;
29 IsRowMajor = traits<PlainXprType>::Flags &
RowMajorBit,
30 SizeAtCompileTime = SizeAtCompileTime_,
31 RowsAtCompileTime = IsRowMajor ? 1 : SizeAtCompileTime,
32 ColsAtCompileTime = IsRowMajor ? SizeAtCompileTime : 1,
33 MaxRowsAtCompileTime = RowsAtCompileTime,
34 MaxColsAtCompileTime = ColsAtCompileTime,
35 Flags = traits<XprType>::Flags & ~NestByRefBit,
40template <
typename XprType,
int SizeAtCompileTime_>
41struct CoherentPadOp :
public dense_xpr_base<CoherentPadOp<XprType, SizeAtCompileTime_>>::type {
42 typedef typename internal::generic_xpr_base<CoherentPadOp<XprType, SizeAtCompileTime_>>::type Base;
43 EIGEN_GENERIC_PUBLIC_INTERFACE(CoherentPadOp)
45 using XprNested =
typename traits<CoherentPadOp>::XprNested;
46 using XprNested_ =
typename traits<CoherentPadOp>::XprNested_;
47 using NestedExpression = XprNested_;
49 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoherentPadOp() =
delete;
50 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoherentPadOp(
const CoherentPadOp&) =
default;
51 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoherentPadOp(CoherentPadOp&& other) =
default;
53 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoherentPadOp(
const XprType& xpr,
Index size) : xpr_(xpr), size_(size) {
54 static_assert(XprNested_::IsVectorAtCompileTime,
"input type must be a vector");
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const XprNested_& nestedExpression()
const {
return xpr_; }
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index size()
const {
return size_.value(); }
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index rows()
const {
62 return traits<CoherentPadOp>::IsRowMajor ?
Index(1) : size();
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index cols()
const {
66 return traits<CoherentPadOp>::IsRowMajor ? size() :
Index(1);
71 const internal::variable_if_dynamic<Index, SizeAtCompileTime> size_;
75template <
typename ArgType,
int SizeAtCompileTime>
76struct unary_evaluator<CoherentPadOp<ArgType, SizeAtCompileTime>>
77 : evaluator_base<CoherentPadOp<ArgType, SizeAtCompileTime>> {
78 typedef CoherentPadOp<ArgType, SizeAtCompileTime> XprType;
79 typedef typename internal::remove_all_t<typename XprType::CoeffReturnType> CoeffReturnType;
80 typedef typename internal::nested_eval<ArgType, 1>::type ArgTypeNested;
81 typedef internal::remove_all_t<ArgTypeNested> ArgTypeNestedCleaned;
84 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
85 LinearAccessMask = XprType::IsVectorAtCompileTime ?
LinearAccessBit : 0,
86 Flags = evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits | LinearAccessMask |
RowMajorBit),
87 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit unary_evaluator(
const XprType& pad)
91 : m_arg(pad.nestedExpression()), m_argImpl(m_arg), m_size(pad.nestedExpression().size()) {}
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col)
const {
94 EIGEN_IF_CONSTEXPR(XprType::IsRowMajor) {
95 if (col < m_size.value()) {
96 return m_argImpl.coeff(1, col);
100 if (row < m_size.value()) {
101 return m_argImpl.coeff(row, 1);
104 return CoeffReturnType(0);
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
108 if (index < m_size.value()) {
109 return m_argImpl.coeff(index);
111 return CoeffReturnType(0);
114 template <
int LoadMode,
typename PacketType>
115 EIGEN_STRONG_INLINE PacketType packet(Index row, Index col)
const {
118 EIGEN_IF_CONSTEXPR(XprType::IsRowMajor) {
return packet(col); }
122 template <
int LoadMode,
typename PacketType>
123 EIGEN_STRONG_INLINE PacketType packet(Index index)
const {
124 constexpr int kPacketSize = unpacket_traits<PacketType>::size;
125 if (index + kPacketSize <= m_size.value()) {
126 return m_argImpl.template packet<LoadMode, PacketType>(index);
127 }
else if (index < m_size.value()) {
129 EIGEN_ALIGN_MAX std::remove_const_t<CoeffReturnType> values[kPacketSize];
130 const int partial = m_size.value() - index;
131 for (
int i = 0; i < partial && i < kPacketSize; ++i) {
132 values[i] = m_argImpl.coeff(index + i);
134 for (
int i = partial; i < kPacketSize; ++i) {
135 values[i] = CoeffReturnType(0);
137 return pload<PacketType>(values);
139 return pset1<PacketType>(CoeffReturnType(0));
143 const ArgTypeNested m_arg;
144 evaluator<ArgTypeNestedCleaned> m_argImpl;
145 const variable_if_dynamic<Index, ArgTypeNestedCleaned::SizeAtCompileTime> m_size;
const unsigned int LinearAccessBit
const unsigned int RowMajorBit
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index