127 typedef TensorRef<PlainObjectType> Self;
128 typedef typename PlainObjectType::Base Base;
129 typedef typename Eigen::internal::nested<Self>::type Nested;
130 typedef typename internal::traits<PlainObjectType>::StorageKind StorageKind;
131 typedef typename internal::traits<PlainObjectType>::Index Index;
132 typedef typename internal::traits<PlainObjectType>::Scalar Scalar;
134 typedef typename Base::CoeffReturnType CoeffReturnType;
135 typedef Scalar* PointerType;
136 typedef PointerType PointerArgType;
138 static const Index NumIndices = PlainObjectType::NumIndices;
139 typedef typename PlainObjectType::Dimensions Dimensions;
143 PacketAccess =
false,
145 PreferBlockAccess =
false,
146 Layout = PlainObjectType::Layout,
152 typedef internal::TensorBlockNotImplemented TensorBlock;
155 EIGEN_STRONG_INLINE
TensorRef() : m_evaluator(NULL) {
158 template <
typename Expression>
159 EIGEN_STRONG_INLINE
TensorRef(
const Expression& expr) : m_evaluator(
new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice())) {
160 m_evaluator->incrRefCount();
163 template <
typename Expression>
164 EIGEN_STRONG_INLINE
TensorRef& operator = (
const Expression& expr) {
166 m_evaluator =
new internal::TensorLazyEvaluator<Dimensions, Expression, DefaultDevice>(expr, DefaultDevice());
167 m_evaluator->incrRefCount();
176 eigen_assert(m_evaluator->refCount() > 0);
177 m_evaluator->incrRefCount();
181 if (
this != &other) {
183 m_evaluator = other.m_evaluator;
184 eigen_assert(m_evaluator->refCount() > 0);
185 m_evaluator->incrRefCount();
191 EIGEN_STRONG_INLINE Index rank()
const {
return m_evaluator->dimensions().size(); }
193 EIGEN_STRONG_INLINE Index dimension(Index n)
const {
return m_evaluator->dimensions()[n]; }
195 EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_evaluator->dimensions(); }
197 EIGEN_STRONG_INLINE Index size()
const {
return m_evaluator->dimensions().TotalSize(); }
199 EIGEN_STRONG_INLINE
const Scalar* data()
const {
return m_evaluator->data(); }
202 EIGEN_STRONG_INLINE
const Scalar operator()(Index index)
const
204 return m_evaluator->coeff(index);
207#if EIGEN_HAS_VARIADIC_TEMPLATES
208 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
209 EIGEN_STRONG_INLINE
const Scalar operator()(Index firstIndex, IndexTypes... otherIndices)
const
211 const std::size_t num_indices = (
sizeof...(otherIndices) + 1);
212 const array<Index, num_indices> indices{{firstIndex, otherIndices...}};
213 return coeff(indices);
215 template<
typename... IndexTypes> EIGEN_DEVICE_FUNC
216 EIGEN_STRONG_INLINE Scalar& coeffRef(Index firstIndex, IndexTypes... otherIndices)
218 const std::size_t num_indices = (
sizeof...(otherIndices) + 1);
219 const array<Index, num_indices> indices{{firstIndex, otherIndices...}};
220 return coeffRef(indices);
225 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1)
const
227 array<Index, 2> indices;
230 return coeff(indices);
233 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2)
const
235 array<Index, 3> indices;
239 return coeff(indices);
242 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3)
const
244 array<Index, 4> indices;
249 return coeff(indices);
252 EIGEN_STRONG_INLINE
const Scalar operator()(Index i0, Index i1, Index i2, Index i3, Index i4)
const
254 array<Index, 5> indices;
260 return coeff(indices);
263 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1)
265 array<Index, 2> indices;
268 return coeffRef(indices);
271 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2)
273 array<Index, 3> indices;
277 return coeffRef(indices);
280 EIGEN_STRONG_INLINE Scalar& operator()(Index i0, Index i1, Index i2, Index i3)
282 array<Index, 4> indices;
287 return coeffRef(indices);
290 EIGEN_STRONG_INLINE Scalar& coeffRef(Index i0, Index i1, Index i2, Index i3, Index i4)
292 array<Index, 5> indices;
298 return coeffRef(indices);
302 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
303 EIGEN_STRONG_INLINE
const Scalar coeff(
const array<Index, NumIndices>& indices)
const
305 const Dimensions& dims = this->dimensions();
307 if (PlainObjectType::Options &
RowMajor) {
309 for (
size_t i = 1; i < NumIndices; ++i) {
310 index = index * dims[i] + indices[i];
313 index += indices[NumIndices-1];
314 for (
int i = NumIndices-2; i >= 0; --i) {
315 index = index * dims[i] + indices[i];
318 return m_evaluator->coeff(index);
320 template <std::
size_t NumIndices> EIGEN_DEVICE_FUNC
321 EIGEN_STRONG_INLINE Scalar& coeffRef(
const array<Index, NumIndices>& indices)
323 const Dimensions& dims = this->dimensions();
325 if (PlainObjectType::Options &
RowMajor) {
327 for (
size_t i = 1; i < NumIndices; ++i) {
328 index = index * dims[i] + indices[i];
331 index += indices[NumIndices-1];
332 for (
int i = NumIndices-2; i >= 0; --i) {
333 index = index * dims[i] + indices[i];
336 return m_evaluator->coeffRef(index);
340 EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const
342 return m_evaluator->coeff(index);
346 EIGEN_STRONG_INLINE Scalar& coeffRef(Index index)
348 return m_evaluator->coeffRef(index);
352 EIGEN_STRONG_INLINE
void unrefEvaluator() {
354 m_evaluator->decrRefCount();
355 if (m_evaluator->refCount() == 0) {
361 internal::TensorLazyBaseEvaluator<Dimensions, Scalar>* m_evaluator;