Eigen  5.0.1
 
Loading...
Searching...
No Matches
Reshaped.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2017 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2014 yoco <peter.xiau@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_RESHAPED_H
13#define EIGEN_RESHAPED_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
48
49namespace internal {
50
51template <typename XprType, int Rows, int Cols, int Order>
52struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType> {
53 using Scalar = typename traits<XprType>::Scalar;
54 using StorageKind = typename traits<XprType>::StorageKind;
55 using XprKind = typename traits<XprType>::XprKind;
56 enum {
57 MatrixRows = traits<XprType>::RowsAtCompileTime,
58 MatrixCols = traits<XprType>::ColsAtCompileTime,
59 RowsAtCompileTime = Rows,
60 ColsAtCompileTime = Cols,
61 MaxRowsAtCompileTime = Rows,
62 MaxColsAtCompileTime = Cols,
63 XprStorageOrder = ((int(traits<XprType>::Flags) & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor,
64 ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? RowMajor
65 : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor
66 : XprStorageOrder,
67 HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XprStorageOrder),
68 InnerSize = (ReshapedStorageOrder == int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
69 // A mismatched ReshapedStorageOrder only happens for vector shapes, where the storage order is
70 // immaterial: the runtime innerStride() is the nested expression's in all cases (see below).
71 InnerStrideAtCompileTime = (HasSameStorageOrderAsXprType || RowsAtCompileTime == 1 || ColsAtCompileTime == 1)
72 ? int(inner_stride_at_compile_time<XprType>::value)
73 : Dynamic,
74 OuterStrideAtCompileTime = Dynamic,
75
76 HasDirectAccess = internal::has_direct_access<XprType>::value && (Order == int(XprStorageOrder)) &&
77 ((evaluator<XprType>::Flags & LinearAccessBit) == LinearAccessBit),
78
79 MaskPacketAccessBit =
80 (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0) && (InnerStrideAtCompileTime == 1)
82 : 0,
83 // MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16)
84 // == 0)) ? AlignedBit : 0,
85 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
86 FlagsLvalueBit = is_lvalue<XprType>::value ? LvalueBit : 0,
87 FlagsRowMajorBit = (ReshapedStorageOrder == int(RowMajor)) ? RowMajorBit : 0,
88 FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0,
89 Flags0 = traits<XprType>::Flags & ((HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit),
90
91 Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit)
92 };
93};
94
95template <typename XprType, int Rows, int Cols, int Order, bool HasDirectAccess>
96class ReshapedImpl_dense;
97
98} // end namespace internal
99
100template <typename XprType, int Rows, int Cols, int Order, typename StorageKind>
101class ReshapedImpl;
102
103template <typename XprType, int Rows, int Cols, int Order>
104class Reshaped : public ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> {
105 using Impl = ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind>;
106
107 public:
108 // typedef typename Impl::Base Base;
109 using Base = Impl;
110 EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped)
111 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped)
112
113
115 EIGEN_DEVICE_FUNC constexpr inline Reshaped(XprType& xpr) : Impl(xpr) {
116 EIGEN_STATIC_ASSERT(RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic,
117 THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
118 eigen_assert(Rows * Cols == xpr.rows() * xpr.cols());
119 }
120
123 EIGEN_DEVICE_FUNC constexpr inline Reshaped(XprType& xpr, Index reshapeRows, Index reshapeCols)
124 : Impl(xpr, reshapeRows, reshapeCols) {
125 eigen_assert((RowsAtCompileTime == Dynamic || RowsAtCompileTime == reshapeRows) &&
126 (ColsAtCompileTime == Dynamic || ColsAtCompileTime == reshapeCols));
127 eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols());
128 }
129};
130
131// The generic default implementation for dense reshape simply forward to the internal::ReshapedImpl_dense
132// that must be specialized for direct and non-direct access...
133template <typename XprType, int Rows, int Cols, int Order>
134class ReshapedImpl<XprType, Rows, Cols, Order, Dense>
135 : public internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,
136 internal::traits<Reshaped<XprType, Rows, Cols, Order> >::HasDirectAccess> {
137 using Impl = internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,
138 internal::traits<Reshaped<XprType, Rows, Cols, Order>>::HasDirectAccess>;
139
140 public:
141 using Base = Impl;
142 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl)
143 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl(XprType& xpr) : Impl(xpr) {}
144 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl(XprType& xpr, Index reshapeRows, Index reshapeCols)
145 : Impl(xpr, reshapeRows, reshapeCols) {}
146};
147
148namespace internal {
149
151template <typename XprType, int Rows, int Cols, int Order>
152class ReshapedImpl_dense<XprType, Rows, Cols, Order, false>
153 : public internal::dense_xpr_base<Reshaped<XprType, Rows, Cols, Order> >::type {
154 using ReshapedType = Reshaped<XprType, Rows, Cols, Order>;
155
156 public:
157 using Base = typename internal::dense_xpr_base<ReshapedType>::type;
158 EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
159 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
160
161 using MatrixTypeNested = typename internal::ref_selector<XprType>::non_const_type;
162 using NestedExpression = internal::remove_all_t<XprType>;
163
164 class InnerIterator;
165
168 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl_dense(XprType& xpr) : m_xpr(xpr), m_rows(Rows), m_cols(Cols) {}
169
172 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols)
173 : m_xpr(xpr), m_rows(nRows), m_cols(nCols) {}
174
175 EIGEN_DEVICE_FUNC constexpr Index rows() const { return m_rows; }
176 EIGEN_DEVICE_FUNC constexpr Index cols() const { return m_cols; }
177
178#ifdef EIGEN_PARSED_BY_DOXYGEN
180 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const;
181 EIGEN_DEVICE_FUNC inline Index innerStride() const;
182 EIGEN_DEVICE_FUNC inline Index outerStride() const;
183#endif
184
186 EIGEN_DEVICE_FUNC constexpr const internal::remove_all_t<XprType>& nestedExpression() const { return m_xpr; }
187
189 EIGEN_DEVICE_FUNC constexpr std::remove_reference_t<XprType>& nestedExpression() { return m_xpr; }
190
191 protected:
192 MatrixTypeNested m_xpr;
193 const internal::variable_if_dynamic<Index, Rows> m_rows;
194 const internal::variable_if_dynamic<Index, Cols> m_cols;
195};
196
198template <typename XprType, int Rows, int Cols, int Order>
199class ReshapedImpl_dense<XprType, Rows, Cols, Order, true> : public MapBase<Reshaped<XprType, Rows, Cols, Order> > {
200 using ReshapedType = Reshaped<XprType, Rows, Cols, Order>;
201 using XprTypeNested = typename internal::ref_selector<XprType>::non_const_type;
202
203 public:
204 using Base = MapBase<ReshapedType>;
205 EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
206 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
207
208
210 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl_dense(XprType& xpr) : Base(xpr.data()), m_xpr(xpr) {}
211
214 EIGEN_DEVICE_FUNC constexpr inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols)
215 : Base(xpr.data(), nRows, nCols), m_xpr(xpr) {}
216
217 EIGEN_DEVICE_FUNC constexpr const internal::remove_all_t<XprTypeNested>& nestedExpression() const { return m_xpr; }
218
219 EIGEN_DEVICE_FUNC constexpr XprType& nestedExpression() { return m_xpr; }
220
222 EIGEN_DEVICE_FUNC constexpr Index innerStride() const { return m_xpr.innerStride(); }
223
225 EIGEN_DEVICE_FUNC constexpr Index outerStride() const {
226 return (((Flags & RowMajorBit) == RowMajorBit) ? this->cols() : this->rows()) * m_xpr.innerStride();
227 }
228
229 protected:
230 XprTypeNested m_xpr;
231};
232
233// Evaluators
234template <typename ArgType, int Rows, int Cols, int Order, bool HasDirectAccess>
235struct reshaped_evaluator;
236
237template <typename ArgType, int Rows, int Cols, int Order>
238struct evaluator<Reshaped<ArgType, Rows, Cols, Order> >
239 : reshaped_evaluator<ArgType, Rows, Cols, Order, traits<Reshaped<ArgType, Rows, Cols, Order> >::HasDirectAccess> {
240 using XprType = Reshaped<ArgType, Rows, Cols, Order>;
241 using Scalar = typename XprType::Scalar;
242 // TODO: should check for smaller packet types
243 using PacketScalar = typename packet_traits<Scalar>::type;
244
245 enum {
246 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
247 HasDirectAccess = traits<XprType>::HasDirectAccess,
248
249 // RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
250 // ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
251 // MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
252 // MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
253 //
254 // InnerStrideAtCompileTime = traits<XprType>::HasSameStorageOrderAsXprType
255 // ? int(inner_stride_at_compile_time<ArgType>::value)
256 // : Dynamic,
257 // OuterStrideAtCompileTime = Dynamic,
258
259 // Whether the coeff-based specialization below serves all accesses by forwarding the nested
260 // evaluator's own linear accesses; always false for the direct-access specialization.
261 ForwardLinearAccess = reshaped_evaluator<ArgType, Rows, Cols, Order, bool(HasDirectAccess)>::ForwardLinearAccess,
262
263 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1 ||
264 HasDirectAccess || ForwardLinearAccess)
265 ? LinearAccessBit
266 : 0,
267 FlagsRowMajorBit = (traits<XprType>::ReshapedStorageOrder == int(RowMajor)) ? RowMajorBit : 0,
268 FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0,
269 // A direct-access reshape with unit inner stride is the nested expression's buffer, contiguous
270 // from data(), so the mapbase_evaluator packet paths apply whenever the nested evaluator's do.
271 // A forwarding coeff-based reshape serves the nested evaluator's own packets directly.
272 MaskPacketAccessBit = (HasDirectAccess && (traits<XprType>::InnerStrideAtCompileTime == 1)) || ForwardLinearAccess
274 : 0,
275 Flags0 = evaluator<ArgType>::Flags & ((HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit),
276 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit,
277
278 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
279 // The view starts at the nested data() with no offset (direct access) or forwards the nested
280 // evaluator's accesses element-for-element, so its alignment carries over.
281 Alignment = evaluator<ArgType>::Alignment
282 };
283 using reshaped_evaluator_type = reshaped_evaluator<ArgType, Rows, Cols, Order, HasDirectAccess>;
284 EIGEN_DEVICE_FUNC constexpr explicit evaluator(const XprType& xpr) : reshaped_evaluator_type(xpr) {
285 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
286 }
287};
288
289template <typename ArgType, int Rows, int Cols, int Order>
290struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ false>
291 : evaluator_base<Reshaped<ArgType, Rows, Cols, Order> > {
292 using XprType = Reshaped<ArgType, Rows, Cols, Order>;
293
294 enum {
295 CoeffReadCost = evaluator<ArgType>::CoeffReadCost /* TODO + cost of index computations */,
296
297 // The reshape enumerates the nested expression's elements in `Order`. When the nested
298 // evaluator and the reshape's storage both enumerate in that order, linear accesses and
299 // packets can forward unchanged. A vector shape makes only its own storage order immaterial.
300 NestedRowMajor = (int(evaluator<ArgType>::Flags) & RowMajorBit) != 0,
301 OrderMatchesNested = (Order == int(ColMajor)) != NestedRowMajor,
302 ForwardLinearAccess = (OrderMatchesNested || ArgType::RowsAtCompileTime == 1 || ArgType::ColsAtCompileTime == 1) &&
303 (Order == int(traits<XprType>::ReshapedStorageOrder) || Rows == 1 || Cols == 1) &&
304 ((int(evaluator<ArgType>::Flags) & LinearAccessBit) != 0)
305
306 // Flags and Alignment are defined by evaluator<Reshaped>, which derives from this evaluator.
307 };
308
309 EIGEN_DEVICE_FUNC constexpr explicit reshaped_evaluator(const XprType& xpr)
310 : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) {
311 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
312 }
313
314 using Scalar = typename XprType::Scalar;
315 using CoeffReturnType = typename XprType::CoeffReturnType;
316
317 using RowCol = std::pair<Index, Index>;
318
319 // The n-th element of the reshape in `Order` enumeration; under ForwardLinearAccess this is also
320 // the nested evaluator's linear index of that element.
321 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Index linear_index(Index rowId, Index colId) const {
322 EIGEN_IF_CONSTEXPR (Order == ColMajor) {
323 return colId * m_xpr.rows() + rowId;
324 } else {
325 return colId + rowId * m_xpr.cols();
326 }
327 }
328
329 EIGEN_DEVICE_FUNC constexpr inline RowCol index_remap(Index rowId, Index colId) const {
330 const Index nth_elem_idx = linear_index(rowId, colId);
331 EIGEN_IF_CONSTEXPR (Order == ColMajor) {
332 return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(), nth_elem_idx / m_xpr.nestedExpression().rows());
333 } else {
334 return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(), nth_elem_idx % m_xpr.nestedExpression().cols());
335 }
336 }
337
338 EIGEN_DEVICE_FUNC constexpr inline Scalar& coeffRef(Index rowId, Index colId) {
339 EIGEN_STATIC_ASSERT_LVALUE(XprType)
340 return coeffRef_impl(rowId, colId, bool_constant<ForwardLinearAccess>());
341 }
342
343 EIGEN_DEVICE_FUNC constexpr inline const Scalar& coeffRef(Index rowId, Index colId) const {
344 return coeffRef_impl(rowId, colId, bool_constant<ForwardLinearAccess>());
345 }
346
347 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const {
348 return coeff_impl(rowId, colId, bool_constant<ForwardLinearAccess>());
349 }
350
351 EIGEN_DEVICE_FUNC constexpr inline Scalar& coeffRef(Index index) {
352 EIGEN_STATIC_ASSERT_LVALUE(XprType)
353 return coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
354 }
355
356 EIGEN_DEVICE_FUNC constexpr inline const Scalar& coeffRef(Index index) const {
357 return coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
358 }
359
360 EIGEN_DEVICE_FUNC constexpr inline const CoeffReturnType coeff(Index index) const {
361 return coeff_impl(index, bool_constant<ForwardLinearAccess>());
362 }
363
364 // The packet paths are advertised only under ForwardLinearAccess (see evaluator<Reshaped>), so
365 // they forward the nested evaluator's linear packets without index remapping.
366 template <int LoadMode, typename PacketType>
367 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index rowId, Index colId) const {
368 return m_argImpl.template packet<LoadMode, PacketType>(linear_index(rowId, colId));
369 }
370
371 template <int LoadMode, typename PacketType>
372 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index index) const {
373 return m_argImpl.template packet<LoadMode, PacketType>(index);
374 }
375
376 template <int StoreMode, typename PacketType>
377 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketType& x) {
378 m_argImpl.template writePacket<StoreMode, PacketType>(linear_index(rowId, colId), x);
379 }
380
381 template <int StoreMode, typename PacketType>
382 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) {
383 m_argImpl.template writePacket<StoreMode, PacketType>(index, x);
384 }
385
386 template <int LoadMode, typename PacketType>
387 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packetSegment(Index rowId, Index colId, Index begin,
388 Index count) const {
389 return m_argImpl.template packetSegment<LoadMode, PacketType>(linear_index(rowId, colId), begin, count);
390 }
391
392 template <int LoadMode, typename PacketType>
393 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packetSegment(Index index, Index begin, Index count) const {
394 return m_argImpl.template packetSegment<LoadMode, PacketType>(index, begin, count);
395 }
396
397 template <int StoreMode, typename PacketType>
398 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacketSegment(Index rowId, Index colId, const PacketType& x,
399 Index begin, Index count) {
400 m_argImpl.template writePacketSegment<StoreMode, PacketType>(linear_index(rowId, colId), x, begin, count);
401 }
402
403 template <int StoreMode, typename PacketType>
404 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacketSegment(Index index, const PacketType& x, Index begin,
405 Index count) {
406 m_argImpl.template writePacketSegment<StoreMode, PacketType>(index, x, begin, count);
407 }
408
409 protected:
410 // Linear-access members map an index onto the vector shape's single row or column.
411 EIGEN_DEVICE_FUNC static constexpr Index vector_row(Index index) { return Rows == 1 ? 0 : index; }
412 EIGEN_DEVICE_FUNC static constexpr Index vector_col(Index index) { return Rows == 1 ? index : 0; }
413
414 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CoeffReturnType
415 coeff_impl(Index index, std::true_type /* ForwardLinearAccess */) const {
416 // The one-dimensional index already follows the nested evaluator's linear enumeration.
417 return m_argImpl.coeff(index);
418 }
419
420 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CoeffReturnType
421 coeff_impl(Index index, std::false_type /* not ForwardLinearAccess */) const {
422 return coeff_impl(vector_row(index), vector_col(index), std::false_type());
423 }
424
425 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CoeffReturnType
426 coeff_impl(Index rowId, Index colId, std::true_type /* ForwardLinearAccess */) const {
427 return m_argImpl.coeff(linear_index(rowId, colId));
428 }
429
430 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CoeffReturnType
431 coeff_impl(Index rowId, Index colId, std::false_type /* not ForwardLinearAccess */) const {
432 const RowCol row_col = index_remap(rowId, colId);
433 return m_argImpl.coeff(row_col.first, row_col.second);
434 }
435
436 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar& coeffRef_impl(Index index,
437 std::true_type /* ForwardLinearAccess */) {
438 return m_argImpl.coeffRef(index);
439 }
440
441 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar& coeffRef_impl(Index index,
442 std::false_type /* not ForwardLinearAccess */) {
443 return coeffRef_impl(vector_row(index), vector_col(index), std::false_type());
444 }
445
446 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar& coeffRef_impl(Index rowId, Index colId,
447 std::true_type /* ForwardLinearAccess */) {
448 return m_argImpl.coeffRef(linear_index(rowId, colId));
449 }
450
451 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar& coeffRef_impl(Index rowId, Index colId,
452 std::false_type /* not ForwardLinearAccess */) {
453 const RowCol row_col = index_remap(rowId, colId);
454 return m_argImpl.coeffRef(row_col.first, row_col.second);
455 }
456
457 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar& coeffRef_impl(
458 Index index, std::true_type /* ForwardLinearAccess */) const {
459 return m_argImpl.coeffRef(index);
460 }
461
462 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar& coeffRef_impl(
463 Index index, std::false_type /* not ForwardLinearAccess */) const {
464 return coeffRef_impl(vector_row(index), vector_col(index), std::false_type());
465 }
466
467 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar& coeffRef_impl(
468 Index rowId, Index colId, std::true_type /* ForwardLinearAccess */) const {
469 return m_argImpl.coeffRef(linear_index(rowId, colId));
470 }
471
472 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar& coeffRef_impl(
473 Index rowId, Index colId, std::false_type /* not ForwardLinearAccess */) const {
474 const RowCol row_col = index_remap(rowId, colId);
475 return m_argImpl.coeffRef(row_col.first, row_col.second);
476 }
477
478 evaluator<ArgType> m_argImpl;
479 const XprType& m_xpr;
480};
481
482template <typename ArgType, int Rows, int Cols, int Order>
483struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ true>
484 : mapbase_evaluator<Reshaped<ArgType, Rows, Cols, Order>,
485 typename Reshaped<ArgType, Rows, Cols, Order>::PlainObject> {
486 using XprType = Reshaped<ArgType, Rows, Cols, Order>;
487 using Scalar = typename XprType::Scalar;
488
489 // Packets come from the mapbase_evaluator machinery, not from linear forwarding.
490 enum { ForwardLinearAccess = false };
491
492 EIGEN_DEVICE_FUNC constexpr explicit reshaped_evaluator(const XprType& xpr)
493 : mapbase_evaluator<XprType, typename XprType::PlainObject>(xpr) {
494 eigen_assert(((std::uintptr_t(xpr.data()) % plain_enum_max(1, evaluator<XprType>::Alignment)) == 0) &&
495 "data is not aligned");
496 }
497};
498
499} // end namespace internal
500
501} // end namespace Eigen
502
503#endif // EIGEN_RESHAPED_H
constexpr Reshaped(XprType &xpr, Index reshapeRows, Index reshapeCols)
Definition Reshaped.h:123
constexpr Reshaped(XprType &xpr)
Definition Reshaped.h:115
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
constexpr unsigned int PacketAccessBit
Definition Constants.h:98
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int LinearAccessBit
Definition Constants.h:134
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71