10#ifndef EIGEN_PARTIALREDUX_H
11#define EIGEN_PARTIALREDUX_H
42template<
typename Func,
typename Evaluator>
43struct 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
55template<
typename PacketType,
typename Func>
57PacketType packetwise_redux_empty_value(
const Func& ) {
58 const typename unpacket_traits<PacketType>::type zero(0);
59 return pset1<PacketType>(zero);
63template<
typename PacketType,
typename Scalar>
65PacketType packetwise_redux_empty_value(
const scalar_product_op<Scalar,Scalar>& ) {
66 return pset1<PacketType>(Scalar(1));
70template<
typename Func,
typename Evaluator,
71 int Unrolling = packetwise_redux_traits<Func, Evaluator>::Unrolling
73struct packetwise_redux_impl;
76template<
typename Func,
typename Evaluator>
77struct packetwise_redux_impl<Func, Evaluator, CompleteUnrolling>
79 typedef redux_novec_unroller<Func,Evaluator, 0, Evaluator::SizeAtCompileTime> Base;
80 typedef typename Evaluator::Scalar Scalar;
82 template<
typename PacketType>
83 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
84 PacketType run(
const Evaluator &eval,
const Func& func, Index )
86 return redux_vec_unroller<Func, Evaluator, 0, packetwise_redux_traits<Func, Evaluator>::OuterSize>::template run<PacketType>(eval,func);
94template<
typename Func,
typename Evaluator,
int Start>
95struct redux_vec_unroller<Func, Evaluator, Start, 0>
97 template<
typename PacketType>
99 static EIGEN_STRONG_INLINE PacketType run(
const Evaluator &,
const Func& f)
101 return packetwise_redux_empty_value<PacketType>(f);
106template<
typename Func,
typename Evaluator>
107struct packetwise_redux_impl<Func, Evaluator, NoUnrolling>
109 typedef typename Evaluator::Scalar Scalar;
110 typedef typename redux_traits<Func, Evaluator>::PacketType PacketScalar;
112 template<
typename PacketType>
114 static PacketType run(
const Evaluator &eval,
const Func& func, Index size)
117 return packetwise_redux_empty_value<PacketType>(func);
119 const Index size4 = (size-1)&(~3);
120 PacketType p = eval.template packetByOuterInner<Unaligned,PacketType>(0,0);
128 func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+0,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+1,0)),
129 func.packetOp(eval.template packetByOuterInner<Unaligned,PacketType>(i+2,0),eval.template packetByOuterInner<Unaligned,PacketType>(i+3,0))));
131 p = func.packetOp(p, eval.template packetByOuterInner<Unaligned,PacketType>(i,0));
136template<
typename ArgType,
typename MemberOp,
int Direction>
137struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
138 : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
140 typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
141 typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested;
142 typedef typename internal::add_const_on_value_type<ArgTypeNested>::type ConstArgTypeNested;
143 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
144 typedef typename ArgType::Scalar InputScalar;
145 typedef typename XprType::Scalar Scalar;
147 TraversalSize = Direction==int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
149 typedef typename MemberOp::template Cost<int(TraversalSize)> CostOpType;
152 : TraversalSize==0 ? 1
153 : int(TraversalSize) * int(evaluator<ArgType>::CoeffReadCost) + int(CostOpType::value),
155 _ArgFlags = evaluator<ArgType>::Flags,
157 _Vectorizable = bool(
int(_ArgFlags)&PacketAccessBit)
158 && bool(MemberOp::Vectorizable)
159 && (Direction==int(Vertical) ? bool(_ArgFlags&RowMajorBit) : (_ArgFlags&
RowMajorBit)==0)
160 && (TraversalSize!=0),
163 | (evaluator<ArgType>::Flags&(HereditaryBits&(~
RowMajorBit)))
170 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType xpr)
171 : m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
173 EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==Dynamic ? HugeCost : (TraversalSize==0 ? 1 :
int(CostOpType::value)));
174 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
177 typedef typename XprType::CoeffReturnType CoeffReturnType;
179 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
180 const Scalar coeff(Index i, Index j)
const
182 return coeff(Direction==Vertical ? j : i);
185 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
186 const Scalar coeff(Index index)
const
188 return m_functor(m_arg.template subVector<
DirectionType(Direction)>(index));
191 template<
int LoadMode,
typename PacketType>
192 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
193 PacketType packet(Index i, Index j)
const
195 return packet<LoadMode,PacketType>(Direction==Vertical ? j : i);
198 template<
int LoadMode,
typename PacketType>
199 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
200 PacketType packet(Index idx)
const
202 enum { PacketSize = internal::unpacket_traits<PacketType>::size };
203 typedef Block<
const ArgTypeNestedCleaned,
204 Direction==
Vertical ? int(ArgType::RowsAtCompileTime) : int(PacketSize),
205 Direction==
Vertical ? int(PacketSize) : int(ArgType::ColsAtCompileTime),
208 PanelType panel(m_arg,
209 Direction==Vertical ? 0 : idx,
210 Direction==Vertical ? idx : 0,
211 Direction==Vertical ? m_arg.rows() :
Index(PacketSize),
212 Direction==Vertical ?
Index(PacketSize) : m_arg.cols());
219 return internal::pset1<PacketType>(coeff(idx));
221 typedef typename internal::redux_evaluator<PanelType> PanelEvaluator;
222 PanelEvaluator panel_eval(panel);
223 typedef typename MemberOp::BinaryOp BinaryOp;
224 PacketType p = internal::packetwise_redux_impl<BinaryOp,PanelEvaluator>::template run<PacketType>(panel_eval,m_functor.binaryFunc(),m_arg.outerSize());
229 ConstArgTypeNested m_arg;
230 const MemberOp m_functor;
DirectionType
Definition Constants.h:261
@ Vertical
Definition Constants.h:264
const unsigned int PacketAccessBit
Definition Constants.h:94
const unsigned int LinearAccessBit
Definition Constants.h:130
const unsigned int RowMajorBit
Definition Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const int HugeCost
Definition Constants.h:44
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
Definition Constants.h:22