10#ifndef EIGEN_PARTIALREDUX_H
11#define EIGEN_PARTIALREDUX_H
14#include "./InternalHeaderCheck.h"
43template <
typename Func,
typename Evaluator>
44struct packetwise_redux_traits {
46 OuterSize = int(Evaluator::IsRowMajor) ? Evaluator::RowsAtCompileTime : Evaluator::ColsAtCompileTime,
48 : OuterSize * Evaluator::CoeffReadCost + (OuterSize - 1) * functor_traits<Func>::Cost,
49 Unrolling = Cost <= EIGEN_UNROLLING_LIMIT ? CompleteUnrolling : NoUnrolling
54template <
typename PacketType,
typename Func>
55EIGEN_DEVICE_FUNC PacketType packetwise_redux_empty_value(
const Func&) {
56 const typename unpacket_traits<PacketType>::type zero(0);
57 return pset1<PacketType>(zero);
61template <
typename PacketType,
typename Scalar>
62EIGEN_DEVICE_FUNC PacketType packetwise_redux_empty_value(
const scalar_product_op<Scalar, Scalar>&) {
63 return pset1<PacketType>(Scalar(1));
67template <typename Func, typename Evaluator, int Unrolling = packetwise_redux_traits<Func, Evaluator>::Unrolling>
68struct packetwise_redux_impl;
71template <
typename Func,
typename Evaluator>
72struct packetwise_redux_impl<Func, Evaluator, CompleteUnrolling> {
73 typedef redux_novec_unroller<Func, Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
74 typedef typename Evaluator::Scalar Scalar;
76 template <
typename PacketType>
77 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE PacketType run(
const Evaluator& eval,
const Func& func, Index ) {
78 return redux_vec_unroller<Func, Evaluator, 0,
79 packetwise_redux_traits<Func, Evaluator>::OuterSize>::template run<PacketType>(eval,
88template <
typename Func,
typename Evaluator, Index Start>
89struct redux_vec_unroller<Func, Evaluator, Start, 0> {
90 template <
typename PacketType>
91 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE PacketType run(
const Evaluator&,
const Func& f) {
92 return packetwise_redux_empty_value<PacketType>(f);
97template <
typename Func,
typename Evaluator>
98struct packetwise_redux_impl<Func, Evaluator, NoUnrolling> {
99 typedef typename Evaluator::Scalar Scalar;
100 typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
102 template <
typename PacketType>
103 EIGEN_DEVICE_FUNC
static PacketType run(
const Evaluator& eval,
const Func& func, Index size) {
104 if (size == 0)
return packetwise_redux_empty_value<PacketType>(func);
106 const Index size4 = (size - 1) & (~3);
107 PacketType p = eval.template packetByOuterInner<Unaligned, PacketType>(0, 0);
112 for (; i < size4; i += 4)
114 p, func.packetOp(func.packetOp(eval.template packetByOuterInner<Unaligned, PacketType>(i + 0, 0),
115 eval.template packetByOuterInner<Unaligned, PacketType>(i + 1, 0)),
116 func.packetOp(eval.template packetByOuterInner<Unaligned, PacketType>(i + 2, 0),
117 eval.template packetByOuterInner<Unaligned, PacketType>(i + 3, 0))));
118 for (; i < size; ++i) p = func.packetOp(p, eval.template packetByOuterInner<Unaligned, PacketType>(i, 0));
123template <
typename ArgType,
typename MemberOp,
int Direction>
124struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
125 : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> > {
126 typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
127 typedef typename internal::nested_eval<ArgType, 1>::type ArgTypeNested;
128 typedef add_const_on_value_type_t<ArgTypeNested> ConstArgTypeNested;
129 typedef internal::remove_all_t<ArgTypeNested> ArgTypeNestedCleaned;
130 typedef typename ArgType::Scalar InputScalar;
131 typedef typename XprType::Scalar Scalar;
133 TraversalSize = Direction == int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
135 typedef typename MemberOp::template Cost<int(TraversalSize)> CostOpType;
140 : int(TraversalSize) * int(evaluator<ArgType>::CoeffReadCost) + int(CostOpType::value),
142 ArgFlags_ = evaluator<ArgType>::Flags,
144 Vectorizable_ = bool(
int(ArgFlags_) & PacketAccessBit) && bool(MemberOp::Vectorizable) &&
145 (Direction == int(Vertical) ? bool(ArgFlags_ & RowMajorBit) : (ArgFlags_ &
RowMajorBit) == 0) &&
146 (TraversalSize != 0),
148 Flags = (traits<XprType>::Flags &
RowMajorBit) | (evaluator<ArgType>::Flags & (HereditaryBits & (~
RowMajorBit))) |
154 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType xpr) : m_arg(xpr.nestedExpression()), m_functor(xpr.functor()) {
155 EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize == Dynamic ? HugeCost
156 : (TraversalSize == 0 ? 1 :
int(CostOpType::value)));
157 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
160 typedef typename XprType::CoeffReturnType CoeffReturnType;
162 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index i, Index j)
const {
163 return coeff(Direction == Vertical ? j : i);
166 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const {
167 return m_functor(m_arg.template subVector<
DirectionType(Direction)>(index));
170 template <
int LoadMode,
typename PacketType>
171 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index i, Index j)
const {
172 return packet<LoadMode, PacketType>(Direction == Vertical ? j : i);
175 template <
int LoadMode,
typename PacketType>
176 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC PacketType packet(Index idx)
const {
177 enum { PacketSize = internal::unpacket_traits<PacketType>::size };
178 typedef Block<
const ArgTypeNestedCleaned, Direction ==
Vertical ? int(ArgType::RowsAtCompileTime) : int(PacketSize),
179 Direction ==
Vertical ? int(PacketSize) : int(ArgType::ColsAtCompileTime), true >
182 PanelType panel(m_arg, Direction == Vertical ? 0 : idx, Direction == Vertical ? idx : 0,
183 Direction == Vertical ? m_arg.rows() :
Index(PacketSize),
184 Direction == Vertical ?
Index(PacketSize) : m_arg.cols());
190 if (PacketSize == 1)
return internal::pset1<PacketType>(coeff(idx));
192 typedef typename internal::redux_evaluator<PanelType> PanelEvaluator;
193 PanelEvaluator panel_eval(panel);
194 typedef typename MemberOp::BinaryOp BinaryOp;
195 PacketType p = internal::packetwise_redux_impl<BinaryOp, PanelEvaluator>::template run<PacketType>(
196 panel_eval, m_functor.binaryFunc(), m_arg.outerSize());
201 ConstArgTypeNested m_arg;
202 const MemberOp m_functor;
DirectionType
Definition Constants.h:263
@ Vertical
Definition Constants.h:266
const unsigned int PacketAccessBit
Definition Constants.h:97
const unsigned int LinearAccessBit
Definition Constants.h:133
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const int HugeCost
Definition Constants.h:48
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Dynamic
Definition Constants.h:25