| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | // This file is part of Eigen, a lightweight C++ template library
 | 
					
						
							|  |  |  | // for linear algebra.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-07-14 02:42:47 +08:00
										 |  |  | // This Source Code Form is subject to the terms of the Mozilla
 | 
					
						
							|  |  |  | // Public License v. 2.0. If a copy of the MPL was not distributed
 | 
					
						
							|  |  |  | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "main.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename MatrixType> | 
					
						
							|  |  |  | void matrixVisitor(const MatrixType& p) { | 
					
						
							|  |  |  |   typedef typename MatrixType::Scalar Scalar; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   Index rows = p.rows(); | 
					
						
							|  |  |  |   Index cols = p.cols(); | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // construct a random matrix where all coefficients are different
 | 
					
						
							|  |  |  |   MatrixType m; | 
					
						
							|  |  |  |   m = MatrixType::Random(rows, cols); | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   for (Index i = 0; i < m.size(); i++) | 
					
						
							|  |  |  |     for (Index i2 = 0; i2 < i; i2++) | 
					
						
							| 
									
										
										
										
											2022-01-27 02:16:19 +08:00
										 |  |  |       while (numext::equal_strict(m(i), m(i2)))  // yes, strict equality
 | 
					
						
							| 
									
										
										
										
											2010-10-25 22:15:22 +08:00
										 |  |  |         m(i) = internal::random<Scalar>(); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   Scalar minc = Scalar(1000), maxc = Scalar(-1000); | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   Index minrow = 0, mincol = 0, maxrow = 0, maxcol = 0; | 
					
						
							|  |  |  |   for (Index j = 0; j < cols; j++) | 
					
						
							|  |  |  |     for (Index i = 0; i < rows; i++) { | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |       if (m(i, j) < minc) { | 
					
						
							|  |  |  |         minc = m(i, j); | 
					
						
							|  |  |  |         minrow = i; | 
					
						
							|  |  |  |         mincol = j; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (m(i, j) > maxc) { | 
					
						
							|  |  |  |         maxc = m(i, j); | 
					
						
							|  |  |  |         maxrow = i; | 
					
						
							|  |  |  |         maxcol = j; | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   Index eigen_minrow, eigen_mincol, eigen_maxrow, eigen_maxcol; | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   Scalar eigen_minc, eigen_maxc; | 
					
						
							|  |  |  |   eigen_minc = m.minCoeff(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |   eigen_maxc = m.maxCoeff(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |   VERIFY(minrow == eigen_minrow); | 
					
						
							|  |  |  |   VERIFY(maxrow == eigen_maxrow); | 
					
						
							|  |  |  |   VERIFY(mincol == eigen_mincol); | 
					
						
							|  |  |  |   VERIFY(maxcol == eigen_maxcol); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(minc, eigen_minc); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(maxc, eigen_maxc); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(minc, m.minCoeff()); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(maxc, m.maxCoeff()); | 
					
						
							| 
									
										
										
										
											2015-11-19 06:29:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   eigen_maxc = (m.adjoint() * m).maxCoeff(&eigen_maxrow, &eigen_maxcol); | 
					
						
							| 
									
										
										
										
											2021-03-17 01:02:50 +08:00
										 |  |  |   Index maxrow2 = 0, maxcol2 = 0; | 
					
						
							|  |  |  |   eigen_maxc = (m.adjoint() * m).eval().maxCoeff(&maxrow2, &maxcol2); | 
					
						
							|  |  |  |   VERIFY(maxrow2 == eigen_maxrow); | 
					
						
							|  |  |  |   VERIFY(maxcol2 == eigen_maxcol); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!NumTraits<Scalar>::IsInteger && m.size() > 2) { | 
					
						
							|  |  |  |     // Test NaN propagation by replacing an element with NaN.
 | 
					
						
							|  |  |  |     bool stop = false; | 
					
						
							|  |  |  |     for (Index j = 0; j < cols && !stop; ++j) { | 
					
						
							|  |  |  |       for (Index i = 0; i < rows && !stop; ++i) { | 
					
						
							|  |  |  |         if (!(j == mincol && i == minrow) && !(j == maxcol && i == maxrow)) { | 
					
						
							|  |  |  |           m(i, j) = NumTraits<Scalar>::quiet_NaN(); | 
					
						
							|  |  |  |           stop = true; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eigen_minc = m.template minCoeff<PropagateNumbers>(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |     eigen_maxc = m.template maxCoeff<PropagateNumbers>(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY(minrow == eigen_minrow); | 
					
						
							|  |  |  |     VERIFY(maxrow == eigen_maxrow); | 
					
						
							|  |  |  |     VERIFY(mincol == eigen_mincol); | 
					
						
							|  |  |  |     VERIFY(maxcol == eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(minc, eigen_minc); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(maxc, eigen_maxc); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(minc, m.template minCoeff<PropagateNumbers>()); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(maxc, m.template maxCoeff<PropagateNumbers>()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eigen_minc = m.template minCoeff<PropagateNaN>(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |     eigen_maxc = m.template maxCoeff<PropagateNaN>(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY(minrow != eigen_minrow || mincol != eigen_mincol); | 
					
						
							|  |  |  |     VERIFY(maxrow != eigen_maxrow || maxcol != eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_minc)); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_maxc)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-14 02:25:22 +08:00
										 |  |  |     // Test matrix of all NaNs.
 | 
					
						
							|  |  |  |     m.fill(NumTraits<Scalar>::quiet_NaN()); | 
					
						
							|  |  |  |     eigen_minc = m.template minCoeff<PropagateNumbers>(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |     eigen_maxc = m.template maxCoeff<PropagateNumbers>(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY(eigen_minrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_mincol == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxcol == 0); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_minc)); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_maxc)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eigen_minc = m.template minCoeff<PropagateNaN>(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |     eigen_maxc = m.template maxCoeff<PropagateNaN>(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY(eigen_minrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_mincol == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxcol == 0); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_minc)); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_maxc)); | 
					
						
							| 
									
										
										
										
											2023-03-14 04:47:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     eigen_minc = m.template minCoeff<PropagateFast>(&eigen_minrow, &eigen_mincol); | 
					
						
							|  |  |  |     eigen_maxc = m.template maxCoeff<PropagateFast>(&eigen_maxrow, &eigen_maxcol); | 
					
						
							|  |  |  |     VERIFY(eigen_minrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxrow == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_mincol == 0); | 
					
						
							|  |  |  |     VERIFY(eigen_maxcol == 0); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_minc)); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_maxc)); | 
					
						
							| 
									
										
										
										
											2023-03-14 02:25:22 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename VectorType> | 
					
						
							|  |  |  | void vectorVisitor(const VectorType& w) { | 
					
						
							|  |  |  |   typedef typename VectorType::Scalar Scalar; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   Index size = w.size(); | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // construct a random vector where all coefficients are different
 | 
					
						
							|  |  |  |   VectorType v; | 
					
						
							|  |  |  |   v = VectorType::Random(size); | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   for (Index i = 0; i < size; i++) | 
					
						
							|  |  |  |     for (Index i2 = 0; i2 < i; i2++) | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |       while (v(i) == v(i2))  // yes, ==
 | 
					
						
							| 
									
										
										
										
											2010-10-25 22:15:22 +08:00
										 |  |  |         v(i) = internal::random<Scalar>(); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-25 08:12:07 +08:00
										 |  |  |   Scalar minc = v(0), maxc = v(0); | 
					
						
							|  |  |  |   Index minidx = 0, maxidx = 0; | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   for (Index i = 0; i < size; i++) { | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |     if (v(i) < minc) { | 
					
						
							|  |  |  |       minc = v(i); | 
					
						
							|  |  |  |       minidx = i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (v(i) > maxc) { | 
					
						
							|  |  |  |       maxc = v(i); | 
					
						
							|  |  |  |       maxidx = i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-05-31 04:00:58 +08:00
										 |  |  |   Index eigen_minidx, eigen_maxidx; | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   Scalar eigen_minc, eigen_maxc; | 
					
						
							|  |  |  |   eigen_minc = v.minCoeff(&eigen_minidx); | 
					
						
							|  |  |  |   eigen_maxc = v.maxCoeff(&eigen_maxidx); | 
					
						
							|  |  |  |   VERIFY(minidx == eigen_minidx); | 
					
						
							|  |  |  |   VERIFY(maxidx == eigen_maxidx); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(minc, eigen_minc); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(maxc, eigen_maxc); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(minc, v.minCoeff()); | 
					
						
							|  |  |  |   VERIFY_IS_APPROX(maxc, v.maxCoeff()); | 
					
						
							| 
									
										
										
										
											2023-12-06 05:22:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-06 06:49:47 +08:00
										 |  |  |   Index idx0 = internal::random<Index>(0, size - 1); | 
					
						
							|  |  |  |   Index idx1 = eigen_minidx; | 
					
						
							|  |  |  |   Index idx2 = eigen_maxidx; | 
					
						
							|  |  |  |   VectorType v1(v), v2(v); | 
					
						
							|  |  |  |   v1(idx0) = v1(idx1); | 
					
						
							|  |  |  |   v2(idx0) = v2(idx2); | 
					
						
							|  |  |  |   v1.minCoeff(&eigen_minidx); | 
					
						
							|  |  |  |   v2.maxCoeff(&eigen_maxidx); | 
					
						
							|  |  |  |   VERIFY(eigen_minidx == (std::min)(idx0, idx1)); | 
					
						
							|  |  |  |   VERIFY(eigen_maxidx == (std::min)(idx0, idx2)); | 
					
						
							| 
									
										
										
										
											2021-03-17 01:02:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!NumTraits<Scalar>::IsInteger && size > 2) { | 
					
						
							|  |  |  |     // Test NaN propagation by replacing an element with NaN.
 | 
					
						
							|  |  |  |     for (Index i = 0; i < size; ++i) { | 
					
						
							|  |  |  |       if (i != minidx && i != maxidx) { | 
					
						
							|  |  |  |         v(i) = NumTraits<Scalar>::quiet_NaN(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     eigen_minc = v.template minCoeff<PropagateNumbers>(&eigen_minidx); | 
					
						
							|  |  |  |     eigen_maxc = v.template maxCoeff<PropagateNumbers>(&eigen_maxidx); | 
					
						
							|  |  |  |     VERIFY(minidx == eigen_minidx); | 
					
						
							|  |  |  |     VERIFY(maxidx == eigen_maxidx); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(minc, eigen_minc); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(maxc, eigen_maxc); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(minc, v.template minCoeff<PropagateNumbers>()); | 
					
						
							|  |  |  |     VERIFY_IS_APPROX(maxc, v.template maxCoeff<PropagateNumbers>()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eigen_minc = v.template minCoeff<PropagateNaN>(&eigen_minidx); | 
					
						
							|  |  |  |     eigen_maxc = v.template maxCoeff<PropagateNaN>(&eigen_maxidx); | 
					
						
							|  |  |  |     VERIFY(minidx != eigen_minidx); | 
					
						
							|  |  |  |     VERIFY(maxidx != eigen_maxidx); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_minc)); | 
					
						
							|  |  |  |     VERIFY((numext::isnan)(eigen_maxc)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  | template <typename Derived, bool Vectorizable> | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  | struct TrackedVisitor { | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |   using Scalar = typename DenseBase<Derived>::Scalar; | 
					
						
							|  |  |  |   static constexpr int PacketSize = Eigen::internal::packet_traits<Scalar>::size; | 
					
						
							|  |  |  |   static constexpr bool RowMajor = Derived::IsRowMajor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void init(Scalar v, Index i, Index j) { return this->operator()(v, i, j); } | 
					
						
							|  |  |  |   template <typename Packet> | 
					
						
							|  |  |  |   void initpacket(Packet p, Index i, Index j) { | 
					
						
							|  |  |  |     return this->packet(p, i, j); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   void operator()(Scalar v, Index i, Index j) { | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  |     EIGEN_UNUSED_VARIABLE(v) | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |     visited.emplace_back(i, j); | 
					
						
							|  |  |  |     scalarOps++; | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   template <typename Packet> | 
					
						
							| 
									
										
										
										
											2022-05-28 02:51:37 +08:00
										 |  |  |   void packet(Packet p, Index i, Index j) { | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |     EIGEN_UNUSED_VARIABLE(p) | 
					
						
							|  |  |  |     for (int k = 0; k < PacketSize; k++) | 
					
						
							|  |  |  |       if (RowMajor) | 
					
						
							|  |  |  |         visited.emplace_back(i, j + k); | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         visited.emplace_back(i + k, j); | 
					
						
							|  |  |  |     vectorOps++; | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |   std::vector<std::pair<Index, Index>> visited; | 
					
						
							|  |  |  |   Index scalarOps = 0; | 
					
						
							|  |  |  |   Index vectorOps = 0; | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Eigen { | 
					
						
							|  |  |  | namespace internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T, bool Vectorizable> | 
					
						
							|  |  |  | struct functor_traits<TrackedVisitor<T, Vectorizable>> { | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |   enum { PacketAccess = Vectorizable, LinearAccess = false, Cost = 1 }; | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace internal
 | 
					
						
							|  |  |  | }  // namespace Eigen
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  | template <typename Derived, bool Vectorized> | 
					
						
							|  |  |  | void checkOptimalTraversal_impl(const DenseBase<Derived>& mat) { | 
					
						
							|  |  |  |   using Scalar = typename DenseBase<Derived>::Scalar; | 
					
						
							|  |  |  |   static constexpr int PacketSize = Eigen::internal::packet_traits<Scalar>::size; | 
					
						
							|  |  |  |   static constexpr bool RowMajor = Derived::IsRowMajor; | 
					
						
							|  |  |  |   Derived X(mat.rows(), mat.cols()); | 
					
						
							|  |  |  |   X.setRandom(); | 
					
						
							|  |  |  |   TrackedVisitor<Derived, Vectorized> visitor; | 
					
						
							|  |  |  |   visitor.visited.reserve(X.size()); | 
					
						
							|  |  |  |   X.visit(visitor); | 
					
						
							|  |  |  |   Index count = 0; | 
					
						
							|  |  |  |   for (Index j = 0; j < X.outerSize(); ++j) { | 
					
						
							|  |  |  |     for (Index i = 0; i < X.innerSize(); ++i) { | 
					
						
							|  |  |  |       Index r = RowMajor ? j : i; | 
					
						
							|  |  |  |       Index c = RowMajor ? i : j; | 
					
						
							|  |  |  |       VERIFY_IS_EQUAL(visitor.visited[count].first, r); | 
					
						
							|  |  |  |       VERIFY_IS_EQUAL(visitor.visited[count].second, c); | 
					
						
							|  |  |  |       ++count; | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-03-07 07:54:02 +08:00
										 |  |  |   Index vectorOps = Vectorized ? ((X.innerSize() / PacketSize) * X.outerSize()) : 0; | 
					
						
							|  |  |  |   Index scalarOps = X.size() - (vectorOps * PacketSize); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(vectorOps, visitor.vectorOps); | 
					
						
							|  |  |  |   VERIFY_IS_EQUAL(scalarOps, visitor.scalarOps); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void checkOptimalTraversal() { | 
					
						
							|  |  |  |   using Scalar = float; | 
					
						
							|  |  |  |   constexpr int PacketSize = Eigen::internal::packet_traits<Scalar>::size; | 
					
						
							|  |  |  |   // use sizes that mix vector and scalar ops
 | 
					
						
							|  |  |  |   constexpr int Rows = 3 * PacketSize + 1; | 
					
						
							|  |  |  |   constexpr int Cols = 4 * PacketSize + 1; | 
					
						
							|  |  |  |   int rows = internal::random(PacketSize + 1, EIGEN_TEST_MAX_SIZE); | 
					
						
							|  |  |  |   int cols = internal::random(PacketSize + 1, EIGEN_TEST_MAX_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   using UnrollColMajor = Matrix<Scalar, Rows, Cols, ColMajor>; | 
					
						
							|  |  |  |   using UnrollRowMajor = Matrix<Scalar, Rows, Cols, RowMajor>; | 
					
						
							|  |  |  |   using DynamicColMajor = Matrix<Scalar, Dynamic, Dynamic, ColMajor>; | 
					
						
							|  |  |  |   using DynamicRowMajor = Matrix<Scalar, Dynamic, Dynamic, RowMajor>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Scalar-only visitors
 | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<UnrollColMajor, false>(UnrollColMajor(Rows, Cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<UnrollRowMajor, false>(UnrollRowMajor(Rows, Cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<DynamicColMajor, false>(DynamicColMajor(rows, cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<DynamicRowMajor, false>(DynamicRowMajor(rows, cols)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Vectorized visitors
 | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<UnrollColMajor, true>(UnrollColMajor(Rows, Cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<UnrollRowMajor, true>(UnrollRowMajor(Rows, Cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<DynamicColMajor, true>(DynamicColMajor(rows, cols)); | 
					
						
							|  |  |  |   checkOptimalTraversal_impl<DynamicRowMajor, true>(DynamicRowMajor(rows, cols)); | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 20:46:15 +08:00
										 |  |  | EIGEN_DECLARE_TEST(visitor) { | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   for (int i = 0; i < g_repeat; i++) { | 
					
						
							| 
									
										
										
										
											2009-10-29 06:19:29 +08:00
										 |  |  |     CALL_SUBTEST_1(matrixVisitor(Matrix<float, 1, 1>())); | 
					
						
							|  |  |  |     CALL_SUBTEST_2(matrixVisitor(Matrix2f())); | 
					
						
							|  |  |  |     CALL_SUBTEST_3(matrixVisitor(Matrix4d())); | 
					
						
							|  |  |  |     CALL_SUBTEST_4(matrixVisitor(MatrixXd(8, 12))); | 
					
						
							|  |  |  |     CALL_SUBTEST_5(matrixVisitor(Matrix<double, Dynamic, Dynamic, RowMajor>(20, 20))); | 
					
						
							|  |  |  |     CALL_SUBTEST_6(matrixVisitor(MatrixXi(8, 12))); | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   for (int i = 0; i < g_repeat; i++) { | 
					
						
							| 
									
										
										
										
											2009-10-29 06:19:29 +08:00
										 |  |  |     CALL_SUBTEST_7(vectorVisitor(Vector4f())); | 
					
						
							| 
									
										
										
										
											2013-01-06 06:49:47 +08:00
										 |  |  |     CALL_SUBTEST_7(vectorVisitor(Matrix<int, 12, 1>())); | 
					
						
							| 
									
										
										
										
											2009-10-29 06:19:29 +08:00
										 |  |  |     CALL_SUBTEST_8(vectorVisitor(VectorXd(10))); | 
					
						
							|  |  |  |     CALL_SUBTEST_9(vectorVisitor(RowVectorXd(10))); | 
					
						
							|  |  |  |     CALL_SUBTEST_10(vectorVisitor(VectorXf(33))); | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-03-23 23:27:57 +08:00
										 |  |  |   CALL_SUBTEST_11(checkOptimalTraversal()); | 
					
						
							| 
									
										
										
										
											2009-09-17 02:18:30 +08:00
										 |  |  | } |