aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2014-07-08 16:43:28 -0700
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2014-07-08 16:43:28 -0700
commitea0906dfd877b3be91b5b0a28d2040ec360b1d3a (patch)
treeb76ebd29f66d47191e405349cbc194aae15df753 /unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h
parentcc1bacea5b6b532728a001f8cfcf762e5385dcef (diff)
Improved evaluation of tensor expressions when used as rvalues
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h')
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h46
1 files changed, 45 insertions, 1 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h
index 5c8b079da..ac9829ce9 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h
@@ -23,6 +23,7 @@ namespace Eigen {
* leading to lvalues (slicing, reshaping, etc...)
*/
+// Generic evaluator
template<typename Derived, typename Device>
struct TensorEvaluator
{
@@ -38,7 +39,7 @@ struct TensorEvaluator
PacketAccess = Derived::PacketAccess,
};
- EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(Derived& m, const Device&)
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const Derived& m, const Device&)
: m_data(const_cast<Scalar*>(m.data())), m_dims(m.dimensions())
{ }
@@ -75,6 +76,49 @@ struct TensorEvaluator
};
+// Default evaluator for rvalues
+template<typename Derived, typename Device>
+struct TensorEvaluator<const Derived, Device>
+{
+ typedef typename Derived::Index Index;
+ typedef typename Derived::Scalar Scalar;
+ typedef typename Derived::Packet Packet;
+ typedef typename Derived::Scalar CoeffReturnType;
+ typedef typename Derived::Packet PacketReturnType;
+ typedef typename Derived::Dimensions Dimensions;
+
+ enum {
+ IsAligned = Derived::IsAligned,
+ PacketAccess = Derived::PacketAccess,
+ };
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const Derived& m, const Device&)
+ : m_data(m.data()), m_dims(m.dimensions())
+ { }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dims; }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalSubExprsIfNeeded() { }
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { }
+
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const {
+ eigen_assert(m_data);
+ return m_data[index];
+ }
+
+ template<int LoadMode> EIGEN_STRONG_INLINE
+ PacketReturnType packet(Index index) const
+ {
+ return internal::ploadt<Packet, LoadMode>(m_data + index);
+ }
+
+ protected:
+ const Scalar* m_data;
+ Dimensions m_dims;
+};
+
+
+
// -------------------- CwiseNullaryOp --------------------