cxx11_tensor_padding.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Functions

template<int DataLayout>
static void test_simple_padding ()
 
template<int DataLayout>
static void test_padded_expr ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_padding)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_padding  )
85  {
86  CALL_SUBTEST(test_simple_padding<ColMajor>());
87  CALL_SUBTEST(test_simple_padding<RowMajor>());
88  CALL_SUBTEST(test_padded_expr<ColMajor>());
89  CALL_SUBTEST(test_padded_expr<RowMajor>());
90 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ test_padded_expr()

template<int DataLayout>
static void test_padded_expr ( )
static
51  {
52  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
53  tensor.setRandom();
54 
56  paddings[0] = std::make_pair(0, 0);
57  paddings[1] = std::make_pair(2, 1);
58  paddings[2] = std::make_pair(3, 4);
59  paddings[3] = std::make_pair(0, 0);
60 
61  Eigen::DSizes<ptrdiff_t, 2> reshape_dims;
62  reshape_dims[0] = 12;
63  reshape_dims[1] = 84;
64 
66  result = tensor.pad(paddings).reshape(reshape_dims);
67 
68  for (int i = 0; i < 2; ++i) {
69  for (int j = 0; j < 6; ++j) {
70  for (int k = 0; k < 12; ++k) {
71  for (int l = 0; l < 7; ++l) {
72  const float result_value =
73  DataLayout == ColMajor ? result(i + 2 * j, k + 12 * l) : result(j + 6 * i, l + 7 * k);
74  if (j >= 2 && j < 5 && k >= 3 && k < 8) {
75  VERIFY_IS_EQUAL(result_value, tensor(i, j - 2, k - 3, l));
76  } else {
77  VERIFY_IS_EQUAL(result_value, 0.0f);
78  }
79  }
80  }
81  }
82  }
83 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorReshapingOp< const NewDimensions, const Derived > reshape(const NewDimensions &newDimensions) const
Definition: TensorBase.h:1106
The tensor class.
Definition: Tensor.h:68
static const int DataLayout
Definition: cxx11_tensor_image_patch_sycl.cpp:24
@ ColMajor
Definition: Constants.h:318
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
std::array< T, N > array
Definition: EmulateArray.h:231
Definition: TensorDimensions.h:161
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::ColMajor, DataLayout, i, j, k, Eigen::TensorBase< Derived, AccessLevel >::reshape(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

◆ test_simple_padding()

template<int DataLayout>
static void test_simple_padding ( )
static
17  {
18  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
19  tensor.setRandom();
20 
22  paddings[0] = std::make_pair(0, 0);
23  paddings[1] = std::make_pair(2, 1);
24  paddings[2] = std::make_pair(3, 4);
25  paddings[3] = std::make_pair(0, 0);
26 
28  padded = tensor.pad(paddings);
29 
30  VERIFY_IS_EQUAL(padded.dimension(0), 2 + 0);
31  VERIFY_IS_EQUAL(padded.dimension(1), 3 + 3);
32  VERIFY_IS_EQUAL(padded.dimension(2), 5 + 7);
33  VERIFY_IS_EQUAL(padded.dimension(3), 7 + 0);
34 
35  for (int i = 0; i < 2; ++i) {
36  for (int j = 0; j < 6; ++j) {
37  for (int k = 0; k < 12; ++k) {
38  for (int l = 0; l < 7; ++l) {
39  if (j >= 2 && j < 5 && k >= 3 && k < 8) {
40  VERIFY_IS_EQUAL(padded(i, j, k, l), tensor(i, j - 2, k - 3, l));
41  } else {
42  VERIFY_IS_EQUAL(padded(i, j, k, l), 0.0f);
43  }
44  }
45  }
46  }
47  }
48 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition: Tensor.h:99

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, k, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.