12 #include <Eigen/CXX11/Tensor> 17 template <
int DataLayout>
29 no_shuffle = tensor.
shuffle(shuffles);
31 VERIFY_IS_EQUAL(no_shuffle.
dimension(0), 2);
32 VERIFY_IS_EQUAL(no_shuffle.
dimension(1), 3);
33 VERIFY_IS_EQUAL(no_shuffle.
dimension(2), 5);
34 VERIFY_IS_EQUAL(no_shuffle.
dimension(3), 7);
36 for (
int i = 0; i < 2; ++i) {
37 for (
int j = 0; j < 3; ++j) {
38 for (
int k = 0; k < 5; ++k) {
39 for (
int l = 0; l < 7; ++l) {
40 VERIFY_IS_EQUAL(tensor(i,j,k,l), no_shuffle(i,j,k,l));
51 shuffle = tensor.
shuffle(shuffles);
58 for (
int i = 0; i < 2; ++i) {
59 for (
int j = 0; j < 3; ++j) {
60 for (
int k = 0; k < 5; ++k) {
61 for (
int l = 0; l < 7; ++l) {
62 VERIFY_IS_EQUAL(tensor(i,j,k,l), shuffle(k,l,j,i));
70 template <
int DataLayout>
82 expected = tensor.
shuffle(shuffles);
91 for (
int i = 0; i < 5; ++i) {
92 result.
slice(dst_slice_start, dst_slice_dim) =
93 tensor.
slice(src_slice_start, src_slice_dim).shuffle(shuffles);
94 src_slice_start[2] += 1;
95 dst_slice_start[0] += 1;
103 for (
int i = 0; i < expected.
dimension(0); ++i) {
104 for (
int j = 0; j < expected.
dimension(1); ++j) {
105 for (
int k = 0; k < expected.
dimension(2); ++k) {
106 for (
int l = 0; l < expected.
dimension(3); ++l) {
107 VERIFY_IS_EQUAL(result(i,j,k,l), expected(i,j,k,l));
113 dst_slice_start[0] = 0;
115 for (
int i = 0; i < 5; ++i) {
116 result.
slice(dst_slice_start, dst_slice_dim) =
117 tensor.
shuffle(shuffles).slice(dst_slice_start, dst_slice_dim);
118 dst_slice_start[0] += 1;
121 for (
int i = 0; i < expected.
dimension(0); ++i) {
122 for (
int j = 0; j < expected.
dimension(1); ++j) {
123 for (
int k = 0; k < expected.
dimension(2); ++k) {
124 for (
int l = 0; l < expected.
dimension(3); ++l) {
125 VERIFY_IS_EQUAL(result(i,j,k,l), expected(i,j,k,l));
133 template <
int DataLayout>
144 shuffle.
shuffle(shuffles) = tensor;
146 VERIFY_IS_EQUAL(shuffle.
dimension(0), 5);
147 VERIFY_IS_EQUAL(shuffle.
dimension(1), 7);
148 VERIFY_IS_EQUAL(shuffle.
dimension(2), 3);
149 VERIFY_IS_EQUAL(shuffle.
dimension(3), 2);
151 for (
int i = 0; i < 2; ++i) {
152 for (
int j = 0; j < 3; ++j) {
153 for (
int k = 0; k < 5; ++k) {
154 for (
int l = 0; l < 7; ++l) {
155 VERIFY_IS_EQUAL(tensor(i,j,k,l), shuffle(k,l,j,i));
168 for (
int i = 0; i < 5; ++i) {
169 for (
int j = 0; j < 7; ++j) {
170 for (
int k = 0; k < 3; ++k) {
171 for (
int l = 0; l < 2; ++l) {
172 VERIFY_IS_EQUAL(shuffle2(i,j,k,l), shuffle(i,j,k,l));
180 template <
int DataLayout>
188 for (
int i = 0; i < 4; ++i) {
192 for (
int i = 0; i < 4; ++i) {
193 const ptrdiff_t index = internal::random<ptrdiff_t>(i, 3);
194 shuffles_inverse[shuffles[index]] = i;
199 shuffle = tensor.
shuffle(shuffles).shuffle(shuffles_inverse);
201 VERIFY_IS_EQUAL(shuffle.
dimension(0), 2);
202 VERIFY_IS_EQUAL(shuffle.
dimension(1), 3);
203 VERIFY_IS_EQUAL(shuffle.
dimension(2), 5);
204 VERIFY_IS_EQUAL(shuffle.
dimension(3), 7);
206 for (
int i = 0; i < 2; ++i) {
207 for (
int j = 0; j < 3; ++j) {
208 for (
int k = 0; k < 5; ++k) {
209 for (
int l = 0; l < 7; ++l) {
210 VERIFY_IS_EQUAL(tensor(i,j,k,l), shuffle(i,j,k,l));
220 CALL_SUBTEST(test_simple_shuffling<ColMajor>());
221 CALL_SUBTEST(test_simple_shuffling<RowMajor>());
222 CALL_SUBTEST(test_expr_shuffling<ColMajor>());
223 CALL_SUBTEST(test_expr_shuffling<RowMajor>());
224 CALL_SUBTEST(test_shuffling_as_value<ColMajor>());
225 CALL_SUBTEST(test_shuffling_as_value<RowMajor>());
226 CALL_SUBTEST(test_shuffle_unshuffle<ColMajor>());
227 CALL_SUBTEST(test_shuffle_unshuffle<RowMajor>());
static void test_expr_shuffling()
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 const TensorShufflingOp< const Shuffle, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > shuffle(const Shuffle &shuffle) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
void test_cxx11_tensor_shuffling()
static void test_shuffle_unshuffle()
static void test_simple_shuffling()
static void test_shuffling_as_value()
void swap(mpfr::mpreal &x, mpfr::mpreal &y)