123 typedef typename PlainObjectType::Base Base;
124 typedef typename Eigen::internal::nested<Self>::type Nested;
125 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
126 typedef typename internal::traits<PlainObjectType>::Index Index;
127 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
128 typedef typename NumTraits<Scalar>::Real RealScalar;
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>
148 EIGEN_STRONG_INLINE
TensorRef(
const Expression& expr) : m_evaluator(
new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice())) {
149 m_evaluator->incrRefCount();
152 template <
typename Expression>
153 EIGEN_STRONG_INLINE
TensorRef& operator = (
const Expression& expr) {
155 m_evaluator =
new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice());
156 m_evaluator->incrRefCount();
165 eigen_assert(m_evaluator->refCount() > 0);
166 m_evaluator->incrRefCount();
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);
201 const array<Index, num_indices> indices{{firstIndex, otherIndices...}};
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);
208 const array<Index, num_indices> indices{{firstIndex, otherIndices...}};
209 return coeffRef(indices);
214 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1)
const
216 array<Index, 2> indices;
219 return coeff(indices);
222 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2)
const
224 array<Index, 3> indices;
228 return coeff(indices);
231 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3)
const
233 array<Index, 4> indices;
238 return coeff(indices);
241 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const
243 array<Index, 5> indices;
249 return coeff(indices);
252 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1)
254 array<Index, 2> indices;
257 return coeffRef(indices);
260 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2)
262 array<Index, 3> indices;
266 return coeffRef(indices);
269 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
271 array<Index, 4> indices;
276 return coeffRef(indices);
279 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2, Index i3, Index i4)
281 array<Index, 5> indices;
287 return coeffRef(indices);
291 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
292 EIGEN_STRONG_INLINE
const Scalar coeff(
const array<Index, NumIndices>& indices)
const
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
310 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
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) {
350 internal::TensorLazyBaseEvaluator<Dimensions, Scalar>* m_evaluator;