10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_REF_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_REF_H 17 template <
typename Dimensions,
typename Scalar>
23 EIGEN_DEVICE_FUNC
virtual const Dimensions&
dimensions()
const = 0;
24 EIGEN_DEVICE_FUNC
virtual const Scalar*
data()
const = 0;
26 EIGEN_DEVICE_FUNC
virtual const Scalar
coeff(
DenseIndex index)
const = 0;
42 template <
typename Dimensions,
typename Expr,
typename Device>
49 m_dims = m_impl.dimensions();
50 m_impl.evalSubExprsIfNeeded(NULL);
56 EIGEN_DEVICE_FUNC
virtual const Dimensions&
dimensions()
const {
59 EIGEN_DEVICE_FUNC
virtual const Scalar*
data()
const {
64 return m_impl.coeff(index);
67 eigen_assert(
false &&
"can't reference the coefficient of a rvalue");
77 template <
typename Dimensions,
typename Expr,
typename Device>
89 return this->m_impl.coeffRef(index);
93 template <
typename Dimensions,
typename Expr,
typename Device>
95 TensorLazyEvaluatorWritable<Dimensions, Expr, Device>,
96 TensorLazyEvaluatorReadOnly<Dimensions, const Expr, Device> >::type {
119 template<
typename PlainObjectType>
class TensorRef :
public TensorBase<TensorRef<PlainObjectType> >
123 typedef typename PlainObjectType::Base
Base;
133 static const Index NumIndices = PlainObjectType::NumIndices;
138 PacketAccess =
false,
139 Layout = PlainObjectType::Layout,
147 template <
typename Expression>
149 m_evaluator->incrRefCount();
152 template <
typename Expression>
166 m_evaluator->incrRefCount();
170 if (
this != &other) {
174 m_evaluator->incrRefCount();
193 return m_evaluator->coeff(index);
196 #if EIGEN_HAS_VARIADIC_TEMPLATES 197 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
198 EIGEN_STRONG_INLINE const Scalar operator()(Index firstIndex, IndexTypes... otherIndices)
const 200 const std::size_t num_indices = (
sizeof...(otherIndices) + 1);
202 return coeff(indices);
204 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
207 const std::size_t num_indices = (
sizeof...(otherIndices) + 1);
219 return coeff(indices);
228 return coeff(indices);
238 return coeff(indices);
249 return coeff(indices);
291 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
296 if (PlainObjectType::Options &
RowMajor) {
298 for (
size_t i = 1; i < NumIndices; ++i) {
299 index = index * dims[i] + indices[i];
302 index += indices[NumIndices-1];
303 for (
int i = NumIndices-2; i >= 0; --i) {
304 index = index * dims[i] + indices[i];
307 return m_evaluator->coeff(index);
309 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
314 if (PlainObjectType::Options &
RowMajor) {
316 for (
size_t i = 1; i < NumIndices; ++i) {
317 index = index * dims[i] + indices[i];
320 index += indices[NumIndices-1];
321 for (
int i = NumIndices-2; i >= 0; --i) {
322 index = index * dims[i] + indices[i];
325 return m_evaluator->coeffRef(index);
331 return m_evaluator->coeff(index);
337 return m_evaluator->coeffRef(index);
343 m_evaluator->decrRefCount();
344 if (m_evaluator->refCount() == 0) {
355 template<
typename Derived,
typename Device>
366 PacketAccess =
false,
385 return m_ref.coeff(index);
389 return m_ref.coeffRef(index);
392 EIGEN_DEVICE_FUNC Scalar*
data()
const {
return m_ref.data(); }
400 template<
typename Derived,
typename Device>
413 PacketAccess =
false,
421 return this->m_ref.coeffRef(index);
429 #endif // EIGEN_CXX11_TENSOR_TENSOR_REF_H EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
TensorLazyBaseEvaluator & operator=(const TensorLazyBaseEvaluator &other)
PacketType< CoeffReturnType, Device >::type PacketReturnType
Derived::Scalar CoeffReturnType
TensorRef< PlainObjectType > Self
#define EIGEN_STRONG_INLINE
virtual ~TensorLazyBaseEvaluator()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
virtual EIGEN_DEVICE_FUNC Scalar & coeffRef(DenseIndex index)
virtual EIGEN_DEVICE_FUNC const Dimensions & dimensions() const
virtual EIGEN_DEVICE_FUNC const Dimensions & dimensions() const =0
TensorRef(const TensorRef &other)
virtual EIGEN_DEVICE_FUNC Scalar & coeffRef(DenseIndex)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index i0, Index i1, Index i2, Index i3, Index i4)
Derived::Dimensions Dimensions
A cost model used to limit the number of threads used for evaluating tensor expression.
EIGEN_DEVICE_FUNC Scalar * data() const
internal::traits< PlainObjectType >::Index Index
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
internal::traits< PlainObjectType >::StorageKind StorageKind
TensorLazyEvaluator(const Expr &expr, const Device &device)
internal::traits< PlainObjectType >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2, Index i3, Index i4) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(Scalar *)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(TensorRef< Derived > &m, const Device &d)
virtual EIGEN_DEVICE_FUNC const Scalar coeff(DenseIndex index) const
PlainObjectType::Base Base
PacketType< CoeffReturnType, Device >::type PacketReturnType
TensorEvaluator< Expr, Device > m_impl
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(Index n) const
TensorLazyEvaluatorReadOnly< Dimensions, Expr, Device > Base
Eigen::internal::nested< Self >::type Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index index) const
PointerType PointerArgType
PlainObjectType::Dimensions Dimensions
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const TensorRef< Derived > &m, const Device &)
internal::TensorLazyBaseEvaluator< Dimensions, Scalar > * m_evaluator
EIGEN_STRONG_INLINE TensorRef(const Expression &expr)
TensorLazyBaseEvaluator()
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_STRONG_INLINE void unrefEvaluator()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(const array< Index, NumIndices > &indices)
TensorLazyEvaluatorWritable(const Expr &expr, const Device &device)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
virtual EIGEN_DEVICE_FUNC const Scalar * data() const =0
virtual EIGEN_DEVICE_FUNC const Scalar coeff(DenseIndex index) const =0
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
TensorEvaluator< const TensorRef< Derived >, Device > Base
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index i0, Index i1)
virtual EIGEN_DEVICE_FUNC Scalar & coeffRef(DenseIndex index)=0
TensorLazyEvaluatorReadOnly(const Expr &expr, const Device &device)
Derived::Dimensions Dimensions
TensorRef< Derived > m_ref
virtual ~TensorLazyEvaluatorWritable()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(const array< Index, NumIndices > &indices) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2, Index i3) const
EIGEN_STRONG_INLINE TensorRef()
A reference to a tensor expression The expression will be evaluated lazily (as much as possible)...
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index index)
virtual ~TensorLazyEvaluatorReadOnly()
Base::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1, Index i2) const
TensorEvaluator< Expr, Device >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & operator()(Index i0, Index i1, Index i2, Index i3)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index i0, Index i1, Index i2)
virtual EIGEN_DEVICE_FUNC const Scalar * data() const
Derived::Scalar CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
internal::packet_traits< Scalar >::type type
virtual ~TensorLazyEvaluator()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(Index i0, Index i1) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const