12 #include <Eigen/CXX11/Tensor> 16 template<
int DataLayout>
22 array<std::pair<ptrdiff_t, ptrdiff_t>, 4> paddings;
23 paddings[0] = std::make_pair(0, 0);
24 paddings[1] = std::make_pair(2, 1);
25 paddings[2] = std::make_pair(3, 4);
26 paddings[3] = std::make_pair(0, 0);
29 padded = tensor.pad(paddings);
31 VERIFY_IS_EQUAL(padded.
dimension(0), 2+0);
32 VERIFY_IS_EQUAL(padded.
dimension(1), 3+3);
33 VERIFY_IS_EQUAL(padded.
dimension(2), 5+7);
34 VERIFY_IS_EQUAL(padded.
dimension(3), 7+0);
36 for (
int i = 0; i < 2; ++i) {
37 for (
int j = 0; j < 6; ++j) {
38 for (
int k = 0; k < 12; ++k) {
39 for (
int l = 0; l < 7; ++l) {
40 if (j >= 2 && j < 5 && k >= 3 && k < 8) {
41 VERIFY_IS_EQUAL(padded(i,j,k,l), tensor(i,j-2,k-3,l));
43 VERIFY_IS_EQUAL(padded(i,j,k,l), 0.0
f);
51 template<
int DataLayout>
57 array<std::pair<ptrdiff_t, ptrdiff_t>, 4> paddings;
58 paddings[0] = std::make_pair(0, 0);
59 paddings[1] = std::make_pair(2, 1);
60 paddings[2] = std::make_pair(3, 4);
61 paddings[3] = std::make_pair(0, 0);
68 result = tensor.pad(paddings).
reshape(reshape_dims);
70 for (
int i = 0; i < 2; ++i) {
71 for (
int j = 0; j < 6; ++j) {
72 for (
int k = 0; k < 12; ++k) {
73 for (
int l = 0; l < 7; ++l) {
74 const float result_value = DataLayout ==
ColMajor ?
75 result(i+2*j,k+12*l) : result(j+6*i,l+7*k);
76 if (j >= 2 && j < 5 && k >= 3 && k < 8) {
77 VERIFY_IS_EQUAL(result_value, tensor(i,j-2,k-3,l));
79 VERIFY_IS_EQUAL(result_value, 0.0
f);
89 CALL_SUBTEST(test_simple_padding<ColMajor>());
90 CALL_SUBTEST(test_simple_padding<RowMajor>());
91 CALL_SUBTEST(test_padded_expr<ColMajor>());
92 CALL_SUBTEST(test_padded_expr<RowMajor>());
static void test_padded_expr()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorReshapingOp< const NewDimensions, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > reshape(const NewDimensions &newDimensions) const
static void test_simple_padding()
void test_cxx11_tensor_padding()