26 template<
typename Func,
typename Derived>
33 ? Derived::MaxColsAtCompileTime
34 : Derived::MaxRowsAtCompileTime
54 || Derived::CoeffReadCost ==
Dynamic 57 : Derived::SizeAtCompileTime * Derived::CoeffReadCost
76 template<
typename Func,
typename Derived,
int Start,
int Length>
83 typedef typename Derived::Scalar
Scalar;
92 template<
typename Func,
typename Derived,
int Start>
96 outer = Start / Derived::InnerSizeAtCompileTime,
97 inner = Start % Derived::InnerSizeAtCompileTime
104 return mat.coeffByOuterInner(outer, inner);
111 template<
typename Func,
typename Derived,
int Start>
120 template<
typename Func,
typename Derived,
int Start,
int Length>
133 return func.packetOp(
139 template<
typename Func,
typename Derived,
int Start>
144 outer = index / int(Derived::InnerSizeAtCompileTime),
145 inner = index % int(Derived::InnerSizeAtCompileTime),
154 return mat.template packetByOuterInner<alignment>(outer, inner);
162 template<
typename Func,
typename Derived,
168 template<
typename Func,
typename Derived>
172 typedef typename Derived::Index
Index;
175 eigen_assert(mat.rows()>0 && mat.cols()>0 &&
"you are using an empty matrix");
177 res = mat.coeffByOuterInner(0, 0);
178 for(Index i = 1; i < mat.innerSize(); ++i)
179 res = func(res, mat.coeffByOuterInner(0, i));
180 for(Index i = 1; i < mat.outerSize(); ++i)
181 for(Index j = 0; j < mat.innerSize(); ++j)
182 res = func(res, mat.coeffByOuterInner(i, j));
187 template<
typename Func,
typename Derived>
192 template<
typename Func,
typename Derived>
197 typedef typename Derived::Index
Index;
199 static Scalar
run(
const Derived& mat,
const Func& func)
201 const Index size = mat.size();
209 const Index alignedSize2 = ((size-alignedStart)/(2*packetSize))*(2*packetSize);
210 const Index alignedSize = ((size-alignedStart)/(packetSize))*(packetSize);
211 const Index alignedEnd2 = alignedStart + alignedSize2;
212 const Index alignedEnd = alignedStart + alignedSize;
216 PacketScalar packet_res0 = mat.template packet<alignment>(alignedStart);
217 if(alignedSize>packetSize)
219 PacketScalar packet_res1 = mat.template packet<alignment>(alignedStart+packetSize);
220 for(Index index = alignedStart + 2*packetSize; index < alignedEnd2; index += 2*packetSize)
222 packet_res0 = func.packetOp(packet_res0, mat.template packet<alignment>(index));
223 packet_res1 = func.packetOp(packet_res1, mat.template packet<alignment>(index+packetSize));
226 packet_res0 = func.packetOp(packet_res0,packet_res1);
227 if(alignedEnd>alignedEnd2)
228 packet_res0 = func.packetOp(packet_res0, mat.template packet<alignment>(alignedEnd2));
230 res = func.predux(packet_res0);
232 for(Index index = 0; index < alignedStart; ++index)
233 res = func(res,mat.coeff(index));
235 for(Index index = alignedEnd; index < size; ++index)
236 res = func(res,mat.coeff(index));
242 for(Index index = 1; index < size; ++index)
243 res = func(res,mat.coeff(index));
250 template<
typename Func,
typename Derived>
255 typedef typename Derived::Index
Index;
257 static Scalar
run(
const Derived& mat,
const Func& func)
259 eigen_assert(mat.rows()>0 && mat.cols()>0 &&
"you are using an empty matrix");
260 const Index innerSize = mat.innerSize();
261 const Index outerSize = mat.outerSize();
265 const Index packetedInnerSize = ((innerSize)/packetSize)*packetSize;
267 if(packetedInnerSize)
269 PacketScalar packet_res = mat.template packet<Unaligned>(0,0);
270 for(Index j=0; j<outerSize; ++j)
271 for(Index i=(j==0?packetSize:0); i<packetedInnerSize; i+=Index(packetSize))
272 packet_res = func.packetOp(packet_res, mat.template packetByOuterInner<Unaligned>(j,i));
274 res = func.predux(packet_res);
275 for(Index j=0; j<outerSize; ++j)
276 for(Index i=packetedInnerSize; i<innerSize; ++i)
277 res = func(res, mat.coeffByOuterInner(j,i));
289 template<
typename Func,
typename Derived>
296 Size = Derived::SizeAtCompileTime,
301 eigen_assert(mat.rows()>0 && mat.cols()>0 &&
"you are using an empty matrix");
303 if (VectorizedSize != Size)
323 template<
typename Derived>
324 template<
typename Func>
330 ::run(derived(), func);
336 template<
typename Derived>
346 template<
typename Derived>
357 template<
typename Derived>
361 if(SizeAtCompileTime==0 || (SizeAtCompileTime==
Dynamic && size()==0))
370 template<
typename Derived>
384 template<
typename Derived>
388 if(SizeAtCompileTime==0 || (SizeAtCompileTime==
Dynamic && size()==0))
399 template<
typename Derived>
403 return derived().diagonal().sum();
408 #endif // EIGEN_REDUX_H
static EIGEN_STRONG_INLINE PacketScalar run(const Derived &mat, const Func &func)
const unsigned int ActualPacketAccessBit
#define EIGEN_STRONG_INLINE
internal::traits< Derived >::Scalar Scalar
static EIGEN_STRONG_INLINE Scalar run(const Derived &, const Func &)
const unsigned int DirectAccessBit
packet_traits< Scalar >::type PacketScalar
static EIGEN_STRONG_INLINE Scalar run(const Derived &mat, const Func &func)
static Scalar run(const Derived &mat, const Func &func)
Base class for all dense matrices, vectors, and arrays.
const unsigned int AlignedBit
packet_traits< Scalar >::type PacketScalar
packet_traits< Scalar >::type PacketScalar
internal::traits< Derived >::Scalar maxCoeff() const
packet_traits< Scalar >::type PacketScalar
static EIGEN_STRONG_INLINE Scalar run(const Derived &mat, const Func &)
internal::traits< Derived >::Scalar minCoeff() const
packet_traits< Scalar >::type PacketScalar
static EIGEN_STRONG_INLINE PacketScalar run(const Derived &mat, const Func &)
static EIGEN_STRONG_INLINE Scalar run(const Derived &mat, const Func &func)
static EIGEN_STRONG_INLINE Scalar run(const Derived &mat, const Func &func)
static Derived::Index first_aligned(const Derived &m)
static Scalar run(const Derived &mat, const Func &func)
const unsigned int LinearAccessBit
#define EIGEN_UNROLLING_LIMIT