12 #include <Eigen/CXX11/Tensor> 17 template <
int DataLayout>
30 typedef TensorEvaluator<decltype(input.convolve(kernel, dims3)),
DefaultDevice> Evaluator;
31 Evaluator eval(input.convolve(kernel, dims3),
DefaultDevice());
32 eval.evalTo(result.
data());
34 VERIFY_IS_EQUAL(eval.dimensions()[0], 2);
35 VERIFY_IS_EQUAL(eval.dimensions()[1], 3);
37 VERIFY_IS_APPROX(result(0,0), input(0,0)*kernel(0) + input(1,0)*kernel(1));
38 VERIFY_IS_APPROX(result(0,1), input(0,1)*kernel(0) + input(1,1)*kernel(1));
39 VERIFY_IS_APPROX(result(0,2), input(0,2)*kernel(0) + input(1,2)*kernel(1));
40 VERIFY_IS_APPROX(result(1,0), input(1,0)*kernel(0) + input(2,0)*kernel(1));
41 VERIFY_IS_APPROX(result(1,1), input(1,1)*kernel(0) + input(2,1)*kernel(1));
42 VERIFY_IS_APPROX(result(1,2), input(1,2)*kernel(0) + input(2,2)*kernel(1));
45 template <
int DataLayout>
57 result = input.convolve(kernel, dims);
59 VERIFY_IS_APPROX(result(0,0), input(0,0)*kernel(0,0) + input(0,1)*kernel(0,1) +
60 input(1,0)*kernel(1,0) + input(1,1)*kernel(1,1));
61 VERIFY_IS_APPROX(result(0,1), input(0,1)*kernel(0,0) + input(0,2)*kernel(0,1) +
62 input(1,1)*kernel(1,0) + input(1,2)*kernel(1,1));
63 VERIFY_IS_APPROX(result(1,0), input(1,0)*kernel(0,0) + input(1,1)*kernel(0,1) +
64 input(2,0)*kernel(1,0) + input(2,1)*kernel(1,1));
65 VERIFY_IS_APPROX(result(1,1), input(1,1)*kernel(0,0) + input(1,2)*kernel(0,1) +
66 input(2,1)*kernel(1,0) + input(2,2)*kernel(1,1));
69 template <
int DataLayout>
86 padding[0] = std::make_pair(0, 0);
88 valid = input.pad(padding).convolve(kernel, dims);
90 VERIFY_IS_APPROX(valid(0), 2.5
f);
94 padding[0] = std::make_pair(1, 1);
96 same = input.pad(padding).convolve(kernel, dims);
98 VERIFY_IS_APPROX(same(0), 1.0
f);
99 VERIFY_IS_APPROX(same(1), 2.5
f);
100 VERIFY_IS_APPROX(same(2), 4.0
f);
104 padding[0] = std::make_pair(2, 2);
106 full = input.pad(padding).convolve(kernel, dims);
108 VERIFY_IS_APPROX(full(0), 0.0
f);
109 VERIFY_IS_APPROX(full(1), 1.0
f);
110 VERIFY_IS_APPROX(full(2), 2.5
f);
111 VERIFY_IS_APPROX(full(3), 4.0
f);
112 VERIFY_IS_APPROX(full(4), 1.5
f);
115 template <
int DataLayout>
130 result = input.
stride(stride_of_3).convolve(kernel, dims).stride(stride_of_2);
133 VERIFY_IS_APPROX(result(0), (input(0)*kernel(0) + input(3)*kernel(1) +
134 input(6)*kernel(2)));
135 VERIFY_IS_APPROX(result(1), (input(6)*kernel(0) + input(9)*kernel(1) +
136 input(12)*kernel(2)));
141 CALL_SUBTEST(test_evals<ColMajor>());
142 CALL_SUBTEST(test_evals<RowMajor>());
143 CALL_SUBTEST(test_expr<ColMajor>());
144 CALL_SUBTEST(test_expr<RowMajor>());
145 CALL_SUBTEST(test_modes<ColMajor>());
146 CALL_SUBTEST(test_modes<RowMajor>());
147 CALL_SUBTEST(test_strides<ColMajor>());
148 CALL_SUBTEST(test_strides<RowMajor>());
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
void test_cxx11_tensor_convolution()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
static void test_strides()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorStridingOp< const Strides, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > stride(const Strides &strides) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setZero()