13 #include <Eigen/CXX11/Tensor> 18 template <
int DataLayout>
31 reversed_tensor = tensor.
reverse(dim_rev);
33 VERIFY_IS_EQUAL(reversed_tensor.
dimension(0), 2);
34 VERIFY_IS_EQUAL(reversed_tensor.
dimension(1), 3);
35 VERIFY_IS_EQUAL(reversed_tensor.
dimension(2), 5);
36 VERIFY_IS_EQUAL(reversed_tensor.
dimension(3), 7);
38 for (
int i = 0; i < 2; ++i) {
39 for (
int j = 0; j < 3; ++j) {
40 for (
int k = 0; k < 5; ++k) {
41 for (
int l = 0; l < 7; ++l) {
42 VERIFY_IS_EQUAL(tensor(i,j,k,l), reversed_tensor(i,2-j,4-k,l));
53 reversed_tensor = tensor.
reverse(dim_rev);
55 VERIFY_IS_EQUAL(reversed_tensor.
dimension(0), 2);
56 VERIFY_IS_EQUAL(reversed_tensor.
dimension(1), 3);
57 VERIFY_IS_EQUAL(reversed_tensor.
dimension(2), 5);
58 VERIFY_IS_EQUAL(reversed_tensor.
dimension(3), 7);
61 for (
int i = 0; i < 2; ++i) {
62 for (
int j = 0; j < 3; ++j) {
63 for (
int k = 0; k < 5; ++k) {
64 for (
int l = 0; l < 7; ++l) {
65 VERIFY_IS_EQUAL(tensor(i,j,k,l), reversed_tensor(1-i,j,k,l));
76 reversed_tensor = tensor.
reverse(dim_rev);
78 VERIFY_IS_EQUAL(reversed_tensor.
dimension(0), 2);
79 VERIFY_IS_EQUAL(reversed_tensor.
dimension(1), 3);
80 VERIFY_IS_EQUAL(reversed_tensor.
dimension(2), 5);
81 VERIFY_IS_EQUAL(reversed_tensor.
dimension(3), 7);
84 for (
int i = 0; i < 2; ++i) {
85 for (
int j = 0; j < 3; ++j) {
86 for (
int k = 0; k < 5; ++k) {
87 for (
int l = 0; l < 7; ++l) {
88 VERIFY_IS_EQUAL(tensor(i,j,k,l), reversed_tensor(1-i,j,k,6-l));
96 template <
int DataLayout>
110 expected.
reverse(dim_rev) = tensor;
112 expected = tensor.
reverse(dim_rev);
118 src_slice_dim[0] = 2;
119 src_slice_dim[1] = 3;
120 src_slice_dim[2] = 1;
121 src_slice_dim[3] = 7;
123 src_slice_start[0] = 0;
124 src_slice_start[1] = 0;
125 src_slice_start[2] = 0;
126 src_slice_start[3] = 0;
130 for (
int i = 0; i < 5; ++i) {
132 result.
slice(dst_slice_start, dst_slice_dim).reverse(dim_rev) =
133 tensor.
slice(src_slice_start, src_slice_dim);
135 result.
slice(dst_slice_start, dst_slice_dim) =
136 tensor.
slice(src_slice_start, src_slice_dim).reverse(dim_rev);
138 src_slice_start[2] += 1;
139 dst_slice_start[2] += 1;
147 for (
int i = 0; i < expected.
dimension(0); ++i) {
148 for (
int j = 0; j < expected.
dimension(1); ++j) {
149 for (
int k = 0; k < expected.
dimension(2); ++k) {
150 for (
int l = 0; l < expected.
dimension(3); ++l) {
151 VERIFY_IS_EQUAL(result(i,j,k,l), expected(i,j,k,l));
157 dst_slice_start[2] = 0;
159 for (
int i = 0; i < 5; ++i) {
161 result.
slice(dst_slice_start, dst_slice_dim).reverse(dim_rev) =
162 tensor.
slice(dst_slice_start, dst_slice_dim);
164 result.
slice(dst_slice_start, dst_slice_dim) =
165 tensor.
reverse(dim_rev).slice(dst_slice_start, dst_slice_dim);
167 dst_slice_start[2] += 1;
170 for (
int i = 0; i < expected.
dimension(0); ++i) {
171 for (
int j = 0; j < expected.
dimension(1); ++j) {
172 for (
int k = 0; k < expected.
dimension(2); ++k) {
173 for (
int l = 0; l < expected.
dimension(3); ++l) {
174 VERIFY_IS_EQUAL(result(i,j,k,l), expected(i,j,k,l));
184 CALL_SUBTEST(test_simple_reverse<ColMajor>());
185 CALL_SUBTEST(test_simple_reverse<RowMajor>());
186 CALL_SUBTEST(test_expr_reverse<ColMajor>(
true));
187 CALL_SUBTEST(test_expr_reverse<RowMajor>(
true));
188 CALL_SUBTEST(test_expr_reverse<ColMajor>(
false));
189 CALL_SUBTEST(test_expr_reverse<RowMajor>(
false));
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorSlicingOp< const StartIndices, const Sizes, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > slice(const StartIndices &startIndices, const Sizes &sizes) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
static void test_expr_reverse(bool LValue)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorReverseOp< const ReverseDimensions, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > reverse(const ReverseDimensions &rev) const
static void test_simple_reverse()
void test_cxx11_tensor_reverse()