TensorDevice.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
00011 #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
00012 
00013 namespace Eigen {
00014 
00027 template <typename ExpressionType, typename DeviceType> class TensorDevice {
00028   public:
00029     TensorDevice(const DeviceType& device, ExpressionType& expression) : m_device(device), m_expression(expression) {}
00030 
00031     template<typename OtherDerived>
00032     EIGEN_STRONG_INLINE TensorDevice& operator=(const OtherDerived& other) {
00033       typedef TensorAssignOp<ExpressionType, const OtherDerived> Assign;
00034       Assign assign(m_expression, other);
00035       internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device);
00036       return *this;
00037     }
00038 
00039     template<typename OtherDerived>
00040     EIGEN_STRONG_INLINE TensorDevice& operator+=(const OtherDerived& other) {
00041       typedef typename OtherDerived::Scalar Scalar;
00042       typedef TensorCwiseBinaryOp<internal::scalar_sum_op<Scalar>, const ExpressionType, const OtherDerived> Sum;
00043       Sum sum(m_expression, other);
00044       typedef TensorAssignOp<ExpressionType, const Sum> Assign;
00045       Assign assign(m_expression, sum);
00046       internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device);
00047       return *this;
00048     }
00049 
00050     template<typename OtherDerived>
00051     EIGEN_STRONG_INLINE TensorDevice& operator-=(const OtherDerived& other) {
00052       typedef typename OtherDerived::Scalar Scalar;
00053       typedef TensorCwiseBinaryOp<internal::scalar_difference_op<Scalar>, const ExpressionType, const OtherDerived> Difference;
00054       Difference difference(m_expression, other);
00055       typedef TensorAssignOp<ExpressionType, const Difference> Assign;
00056       Assign assign(m_expression, difference);
00057       internal::TensorExecutor<const Assign, DeviceType>::run(assign, m_device);
00058       return *this;
00059     }
00060 
00061   protected:
00062     const DeviceType& m_device;
00063     ExpressionType& m_expression;
00064 };
00065 
00066 } // end namespace Eigen
00067 
00068 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
 All Classes Functions Variables Typedefs Enumerator