Enable direct access for NestByValue.

This commit is contained in:
Antonio Sánchez 2022-12-07 18:21:45 +00:00 committed by Rasmus Munk Larsen
parent b59f18b4f7
commit 03c9b4738c
2 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,8 @@ template<typename ExpressionType> class NestByValue
public:
typedef typename internal::dense_xpr_base<NestByValue>::type Base;
static constexpr bool HasDirectAccess = internal::has_direct_access<ExpressionType>::ret;
EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue)
EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
@ -54,6 +56,18 @@ template<typename ExpressionType> class NestByValue
EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; }
EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, const Scalar*>::type data() const {
return m_expression.data();
}
EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, Index>::type innerStride() const {
return m_expression.innerStride();
}
EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, Index>::type outerStride() const {
return m_expression.outerStride();
}
protected:
const ExpressionType m_expression;
};

View File

@ -33,5 +33,7 @@ EIGEN_DECLARE_TEST(nestbyvalue)
MatrixXd b = x;
VERIFY_IS_EQUAL(nb_temporaries,6+1);
VERIFY_IS_APPROX(b, a.rowwise().reverse().eval() + (a+a).eval());
// Block expressions work with dense NestByValue.
VERIFY_IS_APPROX(b, a.nestByValue().rowwise().reverse().eval() + (a.nestByValue()+a.nestByValue()).eval());
}
}