26 template<
typename Func,
typename Derived>
32 InnerMaxSize = int(Derived::IsRowMajor)
33 ? Derived::MaxColsAtCompileTime
34 : Derived::MaxRowsAtCompileTime
38 MightVectorize = (int(Derived::Flags)&ActualPacketAccessBit)
40 MayLinearVectorize = MightVectorize && (int(Derived::Flags)&
LinearAccessBit),
41 MaySliceVectorize = MightVectorize &&
int(InnerMaxSize)>=3*PacketSize
46 Traversal = int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
47 : int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
48 : int(DefaultTraversal)
53 Cost = ( Derived::SizeAtCompileTime ==
Dynamic 54 || Derived::CoeffReadCost ==
Dynamic 57 : Derived::SizeAtCompileTime * Derived::CoeffReadCost
59 UnrollingLimit = EIGEN_UNROLLING_LIMIT * (
int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize))
64 Unrolling = Cost !=
Dynamic && Cost <= UnrollingLimit
76 template<
typename Func,
typename Derived,
int Start,
int Length>
85 static EIGEN_STRONG_INLINE Scalar run(
const Derived &mat,
const Func&
func)
92 template<
typename Func,
typename Derived,
int Start>
96 outer = Start / Derived::InnerSizeAtCompileTime,
97 inner = Start % Derived::InnerSizeAtCompileTime
102 static EIGEN_STRONG_INLINE Scalar run(
const Derived &mat,
const Func&)
104 return mat.coeffByOuterInner(outer, inner);
111 template<
typename Func,
typename Derived,
int Start>
115 static EIGEN_STRONG_INLINE Scalar run(
const Derived&,
const Func&) {
return Scalar(); }
120 template<
typename Func,
typename Derived,
int Start,
int Length>
125 HalfLength = Length/2
131 static EIGEN_STRONG_INLINE PacketScalar run(
const Derived &mat,
const Func&
func)
133 return func.packetOp(
139 template<
typename Func,
typename Derived,
int Start>
144 outer = index / int(Derived::InnerSizeAtCompileTime),
145 inner = index % int(Derived::InnerSizeAtCompileTime),
152 static EIGEN_STRONG_INLINE PacketScalar run(
const Derived &mat,
const Func&)
154 return mat.template packetByOuterInner<alignment>(outer, inner);
162 template<
typename Func,
typename Derived,
168 template<
typename Func,
typename Derived>
169 struct redux_impl<Func, Derived, DefaultTraversal, NoUnrolling>
172 typedef typename Derived::Index Index;
173 static EIGEN_STRONG_INLINE Scalar run(
const Derived& mat,
const Func&
func)
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>
188 struct redux_impl<Func,Derived, DefaultTraversal, CompleteUnrolling>
192 template<
typename Func,
typename Derived>
193 struct redux_impl<Func, Derived, LinearVectorizedTraversal, NoUnrolling>
197 typedef typename Derived::Index Index;
199 static Scalar run(
const Derived& mat,
const Func&
func)
201 const Index
size = mat.size();
202 eigen_assert(size &&
"you are using an empty matrix");
204 const Index alignedStart = internal::first_aligned(mat);
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));
251 template<
typename Func,
typename Derived,
int Unrolling>
252 struct redux_impl<Func, Derived, SliceVectorizedTraversal, Unrolling>
256 typedef typename Derived::Index Index;
258 static Scalar run(
const Derived& mat,
const Func&
func)
260 eigen_assert(mat.rows()>0 && mat.cols()>0 &&
"you are using an empty matrix");
261 const Index innerSize = mat.innerSize();
262 const Index outerSize = mat.outerSize();
266 const Index packetedInnerSize = ((innerSize)/packetSize)*packetSize;
268 if(packetedInnerSize)
270 PacketScalar packet_res = mat.template packet<Unaligned>(0,0);
271 for(Index j=0; j<outerSize; ++j)
272 for(Index i=(j==0?packetSize:0); i<packetedInnerSize; i+=Index(packetSize))
273 packet_res = func.packetOp(packet_res, mat.template packetByOuterInner<Unaligned>(j,i));
275 res = func.predux(packet_res);
276 for(Index j=0; j<outerSize; ++j)
277 for(Index i=packetedInnerSize; i<innerSize; ++i)
278 res = func(res, mat.coeffByOuterInner(j,i));
290 template<
typename Func,
typename Derived>
291 struct redux_impl<Func, Derived, LinearVectorizedTraversal, CompleteUnrolling>
297 Size = Derived::SizeAtCompileTime,
298 VectorizedSize = (Size / PacketSize) * PacketSize
300 static EIGEN_STRONG_INLINE Scalar run(
const Derived& mat,
const Func&
func)
302 eigen_assert(mat.rows()>0 && mat.cols()>0 &&
"you are using an empty matrix");
304 if (VectorizedSize != Size)
324 template<
typename Derived>
325 template<
typename Func>
331 ::run(derived(), func);
337 template<
typename Derived>
347 template<
typename Derived>
358 template<
typename Derived>
362 if(SizeAtCompileTime==0 || (SizeAtCompileTime==
Dynamic &&
size()==0))
371 template<
typename Derived>
385 template<
typename Derived>
389 if(SizeAtCompileTime==0 || (SizeAtCompileTime==
Dynamic &&
size()==0))
400 template<
typename Derived>
404 return derived().diagonal().sum();
409 #endif // EIGEN_REDUX_H Object is not correctly aligned for vectorization.
Definition: Constants.h:192
Scalar mean() const
Definition: Redux.h:373
internal::traits< Derived >::Scalar maxCoeff() const
Definition: Redux.h:349
Definition: Functors.h:24
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:142
Scalar trace() const
Definition: Redux.h:402
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Object is aligned for vectorization.
Definition: Constants.h:194
Scalar prod() const
Definition: Redux.h:387
Definition: GenericPacketMath.h:71
const unsigned int AlignedBit
means the first coefficient packet is guaranteed to be aligned
Definition: Constants.h:147
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
Definition: Functors.h:47
internal::traits< Derived >::Scalar minCoeff() const
Definition: Redux.h:339
Scalar sum() const
Definition: Redux.h:360
Definition: benchGeometry.cpp:23
Definition: BandTriangularSolver.h:13
Definition: Functors.h:104
Definition: XprHelper.h:89
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition: Constants.h:117
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Definition: Functors.h:127