10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H 27 template <
typename Tensor,
bool HasRawAccess,
template <
class>
class MakePointer_ =
MakePointer>
31 typename nocontract_t,
typename contract_t,
int packet_size,
32 bool inner_dim_contiguous,
bool inner_dim_reordered,
int Alignment,
36 template <
typename Tensor,
bool HasRawAccess,
template <
class>
class MakePointer_>
59 return m_tensor.template packet<LoadMode>(index);
73 template <
typename Tensor,
template <
class>
class MakePointer_>
95 return internal::ploadt_ro<typename Tensor::PacketReturnType, LoadMode>(m_data + index);
110 template<
typename Scalar,
typename Index,
int side,
112 typename nocontract_t,
typename contract_t,
113 int packet_size,
bool inner_dim_contiguous,
int Alignment,
template <
class>
class MakePointer_ =
MakePointer>
118 const nocontract_t& nocontract_strides,
119 const nocontract_t& ij_strides,
120 const contract_t& contract_strides,
121 const contract_t& k_strides) :
123 m_nocontract_strides(nocontract_strides),
124 m_ij_strides(ij_strides),
125 m_contract_strides(contract_strides),
126 m_k_strides(k_strides) { }
152 const bool left = (side ==
Lhs);
154 Index nocontract_val = left ?
row :
col;
158 const Index idx = nocontract_val / m_ij_strides[
i];
159 linidx += idx * m_nocontract_strides[
i];
160 nocontract_val -= idx * m_ij_strides[
i];
163 if (side ==
Lhs && inner_dim_contiguous) {
165 linidx += nocontract_val;
167 linidx += nocontract_val * m_nocontract_strides[0];
171 Index contract_val = left ?
col :
row;
175 const Index idx = contract_val / m_k_strides[
i];
176 linidx += idx * m_contract_strides[
i];
177 contract_val -= idx * m_k_strides[
i];
180 if (side ==
Rhs && inner_dim_contiguous) {
182 linidx += contract_val;
184 linidx += contract_val * m_contract_strides[0];
193 const bool left = (side ==
Lhs);
195 Index nocontract_val[2] = {left ?
row :
col, left ? row +
distance : col};
196 Index linidx[2] = {0, 0};
200 const Index idx0 = nocontract_val[0] / m_ij_strides[
i];
201 const Index idx1 = nocontract_val[1] / m_ij_strides[
i];
202 linidx[0] += idx0 * m_nocontract_strides[
i];
203 linidx[1] += idx1 * m_nocontract_strides[
i];
204 nocontract_val[0] -= idx0 * m_ij_strides[
i];
205 nocontract_val[1] -= idx1 * m_ij_strides[
i];
207 if (side ==
Lhs && inner_dim_contiguous) {
209 linidx[0] += nocontract_val[0];
210 linidx[1] += nocontract_val[1];
212 linidx[0] += nocontract_val[0] * m_nocontract_strides[0];
213 linidx[1] += nocontract_val[1] * m_nocontract_strides[0];
217 Index contract_val[2] = {left ?
col :
row, left ?
col : row + distance};
221 const Index idx0 = contract_val[0] / m_k_strides[
i];
222 const Index idx1 = contract_val[1] / m_k_strides[
i];
223 linidx[0] += idx0 * m_contract_strides[
i];
224 linidx[1] += idx1 * m_contract_strides[
i];
225 contract_val[0] -= idx0 * m_k_strides[
i];
226 contract_val[1] -= idx1 * m_k_strides[
i];
229 if (side ==
Rhs && inner_dim_contiguous) {
231 linidx[0] += contract_val[0];
232 linidx[1] += contract_val[1];
234 linidx[0] += contract_val[0] * m_contract_strides[0];
235 linidx[1] += contract_val[1] * m_contract_strides[0];
245 return (Alignment ==
Aligned) && (side ==
Lhs) && inner_dim_contiguous ? 0 : size;
251 #ifdef EIGEN_USE_SYCL 263 return m_nocontract_strides;
265 const nocontract_t&
ij_strides()
const {
return m_ij_strides; }
267 const contract_t&
k_strides()
const {
return m_k_strides; }
277 template<
typename Scalar,
typename Index,
int side,
279 typename nocontract_t,
typename contract_t,
280 int packet_size,
bool inner_dim_contiguous,
281 bool inner_dim_reordered,
int Alignment,
template <
class>
class MakePointer_>
289 const nocontract_t& nocontract_strides,
290 const nocontract_t& ij_strides,
291 const contract_t& contract_strides,
292 const contract_t& k_strides) :
293 ParentMapper(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { }
295 template <
typename PacketT,
int AlignmentType>
306 if (Tensor::PacketAccess && inner_dim_contiguous && !inner_dim_reordered) {
307 const Index index = this->computeIndex(i, j);
308 eigen_assert(this->computeIndex(i+packet_size-1, j) == index + packet_size-1);
309 return this->
m_tensor.template packet<AlignmentType>(index);
312 const IndexPair<Index> indexPair = this->computeIndexPair(i, j, packet_size - 1);
313 const Index
first = indexPair.first;
314 const Index lastIdx = indexPair.second;
320 if (Tensor::PacketAccess &&
322 (lastIdx - first) == (packet_size - 1)) {
331 for (Index k = 1; k < packet_size - 1; k += 2) {
338 return pload<PacketT>(
data);
341 template <
typename PacketT,
int AlignmentType>
343 typename internal::enable_if<internal::unpacket_traits<PacketT>::size!=packet_size,PacketT>
::type 349 const IndexPair<Index> indexPair = this->computeIndexPair(i, j, requested_packet_size - 1);
351 const Index lastIdx = indexPair.
second;
354 for (Index k = 1; k < requested_packet_size - 1; k += 2) {
359 data[requested_packet_size - 1] = this->
m_tensor.
coeff(lastIdx);
361 return pload<PacketT>(
data);
364 template <
typename PacketT,
int AlignmentType>
367 return this->load<PacketT,AlignmentType>(
i,
j);
372 template<
typename Scalar,
typename Index,
int side,
374 typename nocontract_t,
typename contract_t,
375 bool inner_dim_contiguous,
376 bool inner_dim_reordered,
int Alignment,
template <
class>
class MakePointer_>
377 class BaseTensorContractionMapper<
Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_>
378 :
public SimpleTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, Alignment, MakePointer_>
385 const nocontract_t& nocontract_strides,
386 const nocontract_t& ij_strides,
387 const contract_t& contract_strides,
388 const contract_t& k_strides) :
389 ParentMapper(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { }
395 return pload<PacketT>(
data);
401 return pload<PacketT>(
data);
406 template<
typename Scalar,
typename Index,
int side,
408 typename nocontract_t,
typename contract_t,
410 bool inner_dim_contiguous,
bool inner_dim_reordered,
int Alignment,
template <
class>
class MakePointer_=
MakePointer>
414 typedef BaseTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> ParentMapper;
415 typedef TensorContractionSubMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> Self;
425 : m_base_mapper(base_mapper), m_vert_offset(vert_offset), m_horiz_offset(horiz_offset) {
428 if (UseDirectOffsets) {
429 Index stride = m_base_mapper.stride();
430 m_base_mapper.offsetBuffer(vert_offset + horiz_offset * stride);
435 if (UseDirectOffsets) {
436 return m_base_mapper(i, 0);
438 return m_base_mapper(i + m_vert_offset, m_horiz_offset);
441 if (UseDirectOffsets) {
442 return m_base_mapper(i, j);
444 return m_base_mapper(i + m_vert_offset, j + m_horiz_offset);
447 template <
typename PacketT>
449 if (UseDirectOffsets) {
450 return m_base_mapper.template loadPacket<PacketT,Alignment>(
i, 0);
452 return m_base_mapper.template loadPacket<PacketT,Alignment>(i + m_vert_offset, m_horiz_offset);
455 template <
typename PacketT>
457 if (UseDirectOffsets) {
458 return m_base_mapper.template loadPacket<PacketT,Alignment>(
i,
j);
460 return m_base_mapper.template loadPacket<PacketT,Alignment>(i + m_vert_offset, j + m_horiz_offset);
463 template <
typename PacketT,
int AlignmentType>
465 if (UseDirectOffsets) {
466 return m_base_mapper.template load<PacketT,AlignmentType>(
i,
j);
468 return m_base_mapper.template loadPacket<PacketT,AlignmentType>(i + m_vert_offset, j + m_horiz_offset);
471 template <
typename PacketT>
473 if (UseDirectOffsets) {
474 m_base_mapper.storePacket(i, 0, p);
476 m_base_mapper.storePacket(i + m_vert_offset, m_horiz_offset, p);
480 if (UseDirectOffsets) {
481 return LinearMapper(m_base_mapper, i, j);
483 return LinearMapper(m_base_mapper, i + m_vert_offset, j + m_horiz_offset);
486 template <
typename PacketT,
int AlignmentType>
490 if (UseDirectOffsets) {
491 return m_base_mapper.template loadPacket<PacketT,ActualAlignment>(
i, 0);
493 return m_base_mapper.template loadPacket<PacketT,ActualAlignment>(i + m_vert_offset, m_horiz_offset);
496 template <
typename PacketT>
501 #ifdef EIGEN_USE_SYCL 504 m_base_mapper.bind(cgh);
519 template<
typename Scalar_,
typename Index,
int side,
521 typename nocontract_t,
typename contract_t,
523 bool inner_dim_contiguous,
bool inner_dim_reordered,
int Alignment,
template <
class>
class MakePointer_=
MakePointer>
525 :
public BaseTensorContractionMapper<Scalar_, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> {
529 typedef BaseTensorContractionMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> Base;
530 typedef TensorContractionSubMapper<Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_> SubMapper;
534 const nocontract_t& nocontract_strides,
535 const nocontract_t& ij_strides,
536 const contract_t& contract_strides,
537 const contract_t& k_strides)
538 : Base(tensor, nocontract_strides, ij_strides, contract_strides, k_strides) { }
542 return SubMapper(*
this, i, j);
546 return VectorMapper(*
this, i, j);
550 return Base::m_tensor;
557 template<
typename Scalar_,
typename Index_,
int side_,
559 typename nocontract_t_,
typename contract_t_,
561 bool inner_dim_contiguous_,
bool inner_dim_reordered_,
int Alignment_,
template <
class>
class MakePointer_>
563 nocontract_t_, contract_t_, packet_size_, inner_dim_contiguous_,
564 inner_dim_reordered_, Alignment_, MakePointer_> > {
567 static const bool inner_dim_contiguous = inner_dim_contiguous_;
568 static const bool inner_dim_reordered = inner_dim_reordered_;
575 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_MAPPER_H EIGEN_DEVICE_FUNC TensorContractionSubMapper(const ParentMapper &base_mapper, Index vert_offset, Index horiz_offset)
const CoeffLoader< Tensor, Tensor::RawAccess, MakePointer_ > & tensor() const
#define EIGEN_ALWAYS_INLINE
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(const array< Index, NumIndices > &indices) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const MakePointer_< const typename Tensor::Scalar >::Type data() const
#define EIGEN_STRONG_INLINE
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LinearMapper getLinearMapper(Index i, Index j) const
const nocontract_t & ij_strides() const
MakePointer_< const Scalar >::Type m_data
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index stride() const
const nocontract_t m_nocontract_strides
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void storePacket(Index i, const PacketT &p) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT load(Index i) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor::PacketReturnType packet(typename Tensor::Index index) const
CoeffLoader< Tensor, Tensor::RawAccess, MakePointer_ > m_tensor
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(Index row) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index)
Index vert_offset() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
Namespace containing all symbols from the Eigen library.
Double_ distance(const OrientedPlane3_ &p)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool aligned(Index) const
SimpleTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, Alignment, MakePointer_ > ParentMapper
EIGEN_DEVICE_FUNC BaseTensorContractionMapper(const Tensor &tensor, const nocontract_t &nocontract_strides, const nocontract_t &ij_strides, const contract_t &contract_strides, const contract_t &k_strides)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffLoader(const Tensor &tensor)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Eigen::internal::BaseTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ >::loadPacket EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketT loadPacket(Index i, Index j) const
const nocontract_t m_ij_strides
const ParentMapper & base_mapper() const
const contract_t & k_strides() const
Eigen::internal::BaseTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ >::BaseTensorContractionMapper EIGEN_DEVICE_FUNC BaseTensorContractionMapper(const Tensor &tensor, const nocontract_t &nocontract_strides, const nocontract_t &ij_strides, const contract_t &contract_strides, const contract_t &k_strides)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index computeIndex(Index row, Index col) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::enable_if< internal::unpacket_traits< PacketT >::size==packet_size, PacketT >::type load(Index i, Index j) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::enable_if< internal::unpacket_traits< PacketT >::size!=packet_size, PacketT >::type load(Index i, Index j) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const MakePointer_< const typename Tensor::Scalar >::Type data() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(Index row, Index col) const
internal::traits< Self >::Index Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const contract_t & contract_strides() const
const nocontract_t & nocontract_strides() const
EIGEN_DEVICE_FUNC SimpleTensorContractionMapper(const Tensor &tensor, const nocontract_t &nocontract_strides, const nocontract_t &ij_strides, const contract_t &contract_strides, const contract_t &k_strides)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i, Index j) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexPair< Index > computeIndexPair(Index row, Index col, const Index distance) const
Eigen::internal::BaseTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ >::ParentMapper SimpleTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, Alignment, MakePointer_ > ParentMapper
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Tensor::Scalar coeff(typename Tensor::Index index) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index offset)
TensorContractionSubMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ > Self
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i, Index j) const
BaseTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, packet_size, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ > ParentMapper
EIGEN_CONSTEXPR Index size(const T &x)
#define EIGEN_DEVICE_FUNC
Index horiz_offset() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE PacketT loadPacket(Index i, Index j) const
const contract_t m_contract_strides
const Index m_horiz_offset
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE CoeffLoader(const Tensor &tensor)
Eigen::internal::BaseTensorContractionMapper< Scalar, Index, side, Tensor, nocontract_t, contract_t, 1, inner_dim_contiguous, inner_dim_reordered, Alignment, MakePointer_ >::load EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketT load(Index i, Index j) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index firstAligned(Index size) const
ParentMapper m_base_mapper
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Tensor::Scalar coeff(typename Tensor::Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void prefetch(Index)
const Index m_vert_offset
const contract_t m_k_strides
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar operator()(Index i) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor::PacketReturnType packet(typename Tensor::Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketT loadPacket(Index i, Index j) const
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
#define EIGEN_UNUSED_VARIABLE(var)
#define EIGEN_UNROLL_LOOP
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void offsetBuffer(typename Tensor::Index offset)