diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h b/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h index c1499852cd634fe4ad75e9feb553516f75cce53e..5357a482d077c0d688d2d18ecc60c39b6f559e42 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h @@ -27,6 +27,10 @@ struct traits > : public traits { typedef std::remove_reference_t Nested_; static constexpr int NumDimensions = XprTraits::NumDimensions - array_size::value; static constexpr int Layout = XprTraits::Layout; + enum { + // Trace is read-only. + Flags = traits::Flags & ~LvalueBit + }; }; template @@ -203,6 +207,8 @@ struct TensorEvaluator, Device> { return true; } + EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return nullptr; } + EIGEN_STRONG_INLINE void cleanup() { m_impl.cleanup(); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { diff --git a/unsupported/test/cxx11_tensor_ref.cpp b/unsupported/test/cxx11_tensor_ref.cpp index cf097499da655276c99a6e171de3163a58d77f7c..5e796b47b47f2e3208d94730f398a60bc82ae87a 100644 --- a/unsupported/test/cxx11_tensor_ref.cpp +++ b/unsupported/test/cxx11_tensor_ref.cpp @@ -41,6 +41,9 @@ static void test_simple_lvalue_ref() { for (int i = 0; i < 6; ++i) { VERIFY_IS_EQUAL(input(i), -i * 2); } + + TensorRef> ref5(input.trace()); + VERIFY_IS_EQUAL(ref5[0], input[0]); } static void test_simple_rvalue_ref() {