mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Optimize visitor traversal in case of RowMajor.
This commit is contained in:
@@ -23,8 +23,10 @@ template<typename Visitor, typename Derived, int UnrollCount>
|
||||
struct visitor_impl<Visitor, Derived, UnrollCount, false>
|
||||
{
|
||||
enum {
|
||||
col = (UnrollCount-1) / Derived::RowsAtCompileTime,
|
||||
row = (UnrollCount-1) % Derived::RowsAtCompileTime
|
||||
col = Derived::IsRowMajor ? (UnrollCount-1) % Derived::ColsAtCompileTime
|
||||
: (UnrollCount-1) / Derived::RowsAtCompileTime,
|
||||
row = Derived::IsRowMajor ? (UnrollCount-1) / Derived::ColsAtCompileTime
|
||||
: (UnrollCount-1) % Derived::RowsAtCompileTime
|
||||
};
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
@@ -60,11 +62,25 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/false>
|
||||
static inline void run(const Derived& mat, Visitor& visitor)
|
||||
{
|
||||
visitor.init(mat.coeff(0,0), 0, 0);
|
||||
for(Index i = 1; i < mat.rows(); ++i)
|
||||
visitor(mat.coeff(i, 0), i, 0);
|
||||
for(Index j = 1; j < mat.cols(); ++j)
|
||||
for(Index i = 0; i < mat.rows(); ++i)
|
||||
visitor(mat.coeff(i, j), i, j);
|
||||
if (Derived::IsRowMajor) {
|
||||
for(Index i = 1; i < mat.cols(); ++i) {
|
||||
visitor(mat.coeff(0, i), 0, i);
|
||||
}
|
||||
for(Index j = 1; j < mat.rows(); ++j) {
|
||||
for(Index i = 0; i < mat.cols(); ++i) {
|
||||
visitor(mat.coeff(j, i), j, i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Index i = 1; i < mat.rows(); ++i) {
|
||||
visitor(mat.coeff(i, 0), i, 0);
|
||||
}
|
||||
for(Index j = 1; j < mat.cols(); ++j) {
|
||||
for(Index i = 0; i < mat.rows(); ++i) {
|
||||
visitor(mat.coeff(i, j), i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,6 +130,7 @@ public:
|
||||
PacketAccess = Evaluator::Flags & PacketAccessBit,
|
||||
IsRowMajor = XprType::IsRowMajor,
|
||||
RowsAtCompileTime = XprType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = XprType::ColsAtCompileTime,
|
||||
CoeffReadCost = Evaluator::CoeffReadCost
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user