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;
27 EIGEN_DEVICE_FUNC
virtual Scalar& coeffRef(DenseIndex index) = 0;
29 void incrRefCount() { ++m_refcount; }
30 void decrRefCount() { --m_refcount; }
31 int refCount()
const {
return m_refcount; }
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 {
63 EIGEN_DEVICE_FUNC
virtual const Scalar coeff(DenseIndex index)
const {
64 return m_impl.coeff(index);
66 EIGEN_DEVICE_FUNC
virtual Scalar& coeffRef(DenseIndex ) {
67 eigen_assert(
false &&
"can't reference the coefficient of a rvalue");
77 template <
typename Dimensions,
typename Expr,
typename Device>
81 typedef typename Base::Scalar Scalar;
88 EIGEN_DEVICE_FUNC
virtual Scalar& coeffRef(DenseIndex index) {
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 {
101 typedef typename Base::Scalar Scalar;
119 template<
typename PlainObjectType>
class TensorRef :
public TensorBase<TensorRef<PlainObjectType> >
123 typedef typename PlainObjectType::Base
Base;
129 typedef typename Base::CoeffReturnType CoeffReturnType;
130 typedef Scalar* PointerType;
131 typedef PointerType PointerArgType;
133 static const Index NumIndices = PlainObjectType::NumIndices;
134 typedef typename PlainObjectType::Dimensions Dimensions;
138 PacketAccess =
false,
139 Layout = PlainObjectType::Layout,
144 EIGEN_STRONG_INLINE
TensorRef() : m_evaluator(NULL) {
147 template <
typename Expression>
149 m_evaluator->incrRefCount();
152 template <
typename Expression>
153 EIGEN_STRONG_INLINE TensorRef& operator = (
const Expression& expr) {
156 m_evaluator->incrRefCount();
164 TensorRef(
const TensorRef& other) : m_evaluator(other.m_evaluator) {
165 eigen_assert(m_evaluator->refCount() > 0);
166 m_evaluator->incrRefCount();
169 TensorRef& operator = (
const TensorRef& other) {
170 if (
this != &other) {
172 m_evaluator = other.m_evaluator;
173 eigen_assert(m_evaluator->refCount() > 0);
174 m_evaluator->incrRefCount();
180 EIGEN_STRONG_INLINE Index rank()
const {
return m_evaluator->dimensions().size(); }
182 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_evaluator->dimensions()[n]; }
184 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_evaluator->dimensions(); }
186 EIGEN_STRONG_INLINE Index size()
const {
return m_evaluator->dimensions().TotalSize(); }
188 EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_evaluator->data(); }
191 EIGEN_STRONG_INLINE
const Scalar operator()(Index index)
const 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
205 EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
207 const std::size_t num_indices = (
sizeof...(otherIndices) + 1);
209 return coeffRef(indices);
214 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1)
const 219 return coeff(indices);
222 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2)
const 228 return coeff(indices);
231 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3)
const 238 return coeff(indices);
241 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const 249 return coeff(indices);
252 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1)
257 return coeffRef(indices);
260 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2)
266 return coeffRef(indices);
269 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
276 return coeffRef(indices);
279 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2, Index i3, Index i4)
287 return coeffRef(indices);
291 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
294 const Dimensions& dims = this->dimensions();
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
312 const Dimensions& dims = this->dimensions();
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);
329 EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const 331 return m_evaluator->coeff(index);
335 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
337 return m_evaluator->coeffRef(index);
341 EIGEN_STRONG_INLINE
void unrefEvaluator() {
343 m_evaluator->decrRefCount();
344 if (m_evaluator->refCount() == 0) {
355 template<
typename Derived,
typename Device>
358 typedef typename Derived::Index
Index;
359 typedef typename Derived::Scalar Scalar;
360 typedef typename Derived::Scalar CoeffReturnType;
362 typedef typename Derived::Dimensions Dimensions;
366 PacketAccess =
false,
376 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_ref.dimensions(); }
378 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar*) {
382 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() { }
384 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
385 return m_ref.coeff(index);
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
389 return m_ref.coeffRef(index);
392 EIGEN_DEVICE_FUNC Scalar* data()
const {
return m_ref.data(); }
400 template<
typename Derived,
typename Device>
403 typedef typename Derived::Index
Index;
404 typedef typename Derived::Scalar Scalar;
405 typedef typename Derived::Scalar CoeffReturnType;
407 typedef typename Derived::Dimensions Dimensions;
413 PacketAccess =
false,
420 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) {
421 return this->m_ref.coeffRef(index);
429 #endif // EIGEN_CXX11_TENSOR_TENSOR_REF_H Definition: TensorRef.h:94
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
Definition: TensorRef.h:18
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: TensorDeviceDefault.h:17
The tensor base class.
Definition: TensorBase.h:827
Definition: EmulateArray.h:21
Definition: BandTriangularSolver.h:13
Definition: TensorRef.h:356
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:322
Definition: TensorRef.h:43
A reference to a tensor expression The expression will be evaluated lazily (as much as possible)...
Definition: TensorForwardDeclarations.h:28
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17
Definition: TensorRef.h:78