Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType > Class Template Reference

#include <TensorBlock.h>

Classes

struct  BlockIteratorState
 
struct  InnerDimAssign
 
struct  InnerDimAssign< true, Evaluator >
 
struct  Target
 

Static Public Member Functions

static Target target (const Dimensions &target_dims, const Dimensions &target_strides, Scalar *target_data, IndexType target_offset=0)
 
template<typename TargetDimsIndexType , typename TargetStridesIndexType >
static Target target (const DSizes< TargetDimsIndexType, NumDims > &target_dims, const DSizes< TargetStridesIndexType, NumDims > &target_strides, Scalar *target_data, IndexType target_offset=0)
 
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run (const Target &target, const TensorBlockExpr &expr)
 

Private Types

enum  { Vectorizable = packet_traits<Scalar>::Vectorizable , PacketSize = packet_traits<Scalar>::size }
 
typedef TensorEvaluator< const TensorBlockExpr, DefaultDeviceTensorBlockEvaluator
 
typedef DSizes< IndexType, NumDims > Dimensions
 

Member Typedef Documentation

◆ Dimensions

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
typedef DSizes<IndexType, NumDims> Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Dimensions
private

◆ TensorBlockEvaluator

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
typedef TensorEvaluator<const TensorBlockExpr, DefaultDevice> Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::TensorBlockEvaluator
private

Member Enumeration Documentation

◆ anonymous enum

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
anonymous enum
private
Enumerator
Vectorizable 
PacketSize 
@ PacketSize
Definition: TensorBlock.h:1320
@ Vectorizable
Definition: TensorBlock.h:1320
@ size
Definition: GenericPacketMath.h:113
@ Vectorizable
Definition: GenericPacketMath.h:112

Member Function Documentation

◆ Run()

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Run ( const Target target,
const TensorBlockExpr &  expr 
)
inlinestatic
1384  {
1385  // Prepare evaluator for block expression.
1386  DefaultDevice default_device;
1387  TensorBlockEvaluator eval(expr, default_device);
1388 
1389  // Tensor block expression dimension should match destination dimensions.
1390  eigen_assert(dimensions_match(target.dims, eval.dimensions()));
1391 
1392  static const int Layout = TensorBlockEvaluator::Layout;
1393  static const bool is_col_major = Layout == ColMajor;
1394 
1395  // Initialize output inner dimension size based on a layout.
1396  const IndexType output_size = NumDims == 0 ? 1 : target.dims.TotalSize();
1397  const int inner_dim_idx = is_col_major ? 0 : NumDims - 1;
1398  IndexType output_inner_dim_size = target.dims[inner_dim_idx];
1399 
1400  // Target inner dimension stride must be '1'.
1401  eigen_assert(target.strides[inner_dim_idx] == 1);
1402 
1403  // Squeeze multiple inner dims into one if they are contiguous in `target`.
1404  IndexType num_squeezed_dims = 0;
1405  for (Index i = 1; i < NumDims; ++i) {
1406  const Index dim = is_col_major ? i : NumDims - i - 1;
1407  const IndexType target_stride = target.strides[dim];
1408 
1409  if (output_inner_dim_size == target_stride) {
1410  output_inner_dim_size *= target.dims[dim];
1411  num_squeezed_dims++;
1412  } else {
1413  break;
1414  }
1415  }
1416 
1417  // Initialize output block iterator state. Dimension in this array are
1418  // always in inner_most -> outer_most order (col major layout).
1419  array<BlockIteratorState, NumDims> it;
1420 
1421  int idx = 0; // currently initialized iterator state index
1422  for (Index i = num_squeezed_dims; i < NumDims - 1; ++i) {
1423  const Index dim = is_col_major ? i + 1 : NumDims - i - 2;
1424 
1425  it[idx].count = 0;
1426  it[idx].size = target.dims[dim];
1427  it[idx].output_stride = target.strides[dim];
1428  it[idx].output_span = it[idx].output_stride * (it[idx].size - 1);
1429  idx++;
1430  }
1431 
1432  // We read block expression from the beginning, and start writing data to
1433  // `target` at given offset.
1434  IndexType input_offset = 0;
1435  IndexType output_offset = target.offset;
1436 
1437  // Iterate copying data from `eval` to `target`.
1438  for (IndexType i = 0; i < output_size; i += output_inner_dim_size) {
1439  // Assign to `target` at current offset.
1441  target.data + output_offset, output_inner_dim_size, eval, input_offset);
1442 
1443  // Move input offset forward by the number of assigned coefficients.
1444  input_offset += output_inner_dim_size;
1445 
1446  // Update index.
1447  for (int j = 0; j < idx; ++j) {
1448  if (++it[j].count < it[j].size) {
1449  output_offset += it[j].output_stride;
1450  break;
1451  }
1452  it[j].count = 0;
1453  output_offset -= it[j].output_span;
1454  }
1455  }
1456  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
static Target target(const Dimensions &target_dims, const Dimensions &target_strides, Scalar *target_data, IndexType target_offset=0)
Definition: TensorBlock.h:1371
TensorEvaluator< const TensorBlockExpr, DefaultDevice > TensorBlockEvaluator
Definition: TensorBlock.h:1316
@ ColMajor
Definition: Constants.h:318
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2)
Definition: TensorDimensions.h:322
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
Definition: TensorDimensions.h:167
static constexpr int Layout
Definition: TensorEvaluator.h:46
static EIGEN_ALWAYS_INLINE void Run(Scalar *target, IndexType count, const Evaluator &eval, IndexType eval_offset)
Definition: TensorBlock.h:1324
Dimensions strides
Definition: TensorBlock.h:1366
Dimensions dims
Definition: TensorBlock.h:1365
Scalar * data
Definition: TensorBlock.h:1367
IndexType offset
Definition: TensorBlock.h:1368
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::ColMajor, Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Target::data, Eigen::dimensions_match(), Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Target::dims, eigen_assert, eval(), i, j, Eigen::TensorEvaluator< Derived, Device >::Layout, Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Target::offset, Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::InnerDimAssign< Vectorizable, Evaluator >::Run(), size, Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Target::strides, Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::target(), and Eigen::DSizes< DenseIndex, NumDims >::TotalSize().

◆ target() [1/2]

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
static Target Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::target ( const Dimensions target_dims,
const Dimensions target_strides,
Scalar target_data,
IndexType  target_offset = 0 
)
inlinestatic

◆ target() [2/2]

template<typename Scalar , int NumDims, typename TensorBlockExpr , typename IndexType = Eigen::Index>
template<typename TargetDimsIndexType , typename TargetStridesIndexType >
static Target Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::target ( const DSizes< TargetDimsIndexType, NumDims > &  target_dims,
const DSizes< TargetStridesIndexType, NumDims > &  target_strides,
Scalar target_data,
IndexType  target_offset = 0 
)
inlinestatic
1379  {
1380  // DSizes constructor will do index type promotion if it's safe.
1381  return Target(Dimensions(target_dims), Dimensions(target_strides), target_data, target_offset);
1382  }
DSizes< IndexType, NumDims > Dimensions
Definition: TensorBlock.h:1318

References Eigen::Architecture::Target.


The documentation for this class was generated from the following file: