12 #include <Eigen/CXX11/Tensor> 16 template<
int DataLayout>
21 array<ptrdiff_t, 4> patch_dims;
29 no_patch = tensor.extract_patches(patch_dims);
32 VERIFY_IS_EQUAL(no_patch.
dimension(0), 1);
33 VERIFY_IS_EQUAL(no_patch.
dimension(1), 1);
34 VERIFY_IS_EQUAL(no_patch.
dimension(2), 1);
35 VERIFY_IS_EQUAL(no_patch.
dimension(3), 1);
39 VERIFY_IS_EQUAL(no_patch.
dimension(1), 1);
40 VERIFY_IS_EQUAL(no_patch.
dimension(2), 1);
41 VERIFY_IS_EQUAL(no_patch.
dimension(3), 1);
42 VERIFY_IS_EQUAL(no_patch.
dimension(4), 1);
45 for (
int i = 0; i < tensor.
size(); ++i) {
46 VERIFY_IS_EQUAL(tensor.
data()[i], no_patch.
data()[i]);
54 single_patch = tensor.extract_patches(patch_dims);
57 VERIFY_IS_EQUAL(single_patch.
dimension(0), 2);
58 VERIFY_IS_EQUAL(single_patch.
dimension(1), 3);
59 VERIFY_IS_EQUAL(single_patch.
dimension(2), 5);
60 VERIFY_IS_EQUAL(single_patch.
dimension(3), 7);
61 VERIFY_IS_EQUAL(single_patch.
dimension(4), 1);
63 VERIFY_IS_EQUAL(single_patch.
dimension(0), 1);
64 VERIFY_IS_EQUAL(single_patch.
dimension(1), 2);
65 VERIFY_IS_EQUAL(single_patch.
dimension(2), 3);
66 VERIFY_IS_EQUAL(single_patch.
dimension(3), 5);
67 VERIFY_IS_EQUAL(single_patch.
dimension(4), 7);
70 for (
int i = 0; i < tensor.
size(); ++i) {
71 VERIFY_IS_EQUAL(tensor.
data()[i], single_patch.
data()[i]);
79 twod_patch = tensor.extract_patches(patch_dims);
82 VERIFY_IS_EQUAL(twod_patch.
dimension(0), 1);
83 VERIFY_IS_EQUAL(twod_patch.
dimension(1), 2);
84 VERIFY_IS_EQUAL(twod_patch.
dimension(2), 2);
85 VERIFY_IS_EQUAL(twod_patch.
dimension(3), 1);
86 VERIFY_IS_EQUAL(twod_patch.
dimension(4), 2*2*4*7);
88 VERIFY_IS_EQUAL(twod_patch.
dimension(0), 2*2*4*7);
89 VERIFY_IS_EQUAL(twod_patch.
dimension(1), 1);
90 VERIFY_IS_EQUAL(twod_patch.
dimension(2), 2);
91 VERIFY_IS_EQUAL(twod_patch.
dimension(3), 2);
92 VERIFY_IS_EQUAL(twod_patch.
dimension(4), 1);
95 for (
int i = 0; i < 2; ++i) {
96 for (
int j = 0; j < 2; ++j) {
97 for (
int k = 0; k < 4; ++k) {
98 for (
int l = 0; l < 7; ++l) {
101 patch_loc = i + 2 * (j + 2 * (k + 4 * l));
103 patch_loc = l + 7 * (k + 4 * (j + 2 * i));
105 for (
int x = 0; x < 2; ++x) {
106 for (
int y = 0; y < 2; ++y) {
108 VERIFY_IS_EQUAL(tensor(i,j+x,k+y,l), twod_patch(0,x,y,0,patch_loc));
110 VERIFY_IS_EQUAL(tensor(i,j+x,k+y,l), twod_patch(patch_loc,0,x,y,0));
124 threed_patch = tensor.extract_patches(patch_dims);
127 VERIFY_IS_EQUAL(threed_patch.
dimension(0), 1);
128 VERIFY_IS_EQUAL(threed_patch.
dimension(1), 2);
129 VERIFY_IS_EQUAL(threed_patch.
dimension(2), 3);
130 VERIFY_IS_EQUAL(threed_patch.
dimension(3), 5);
131 VERIFY_IS_EQUAL(threed_patch.
dimension(4), 2*2*3*3);
133 VERIFY_IS_EQUAL(threed_patch.
dimension(0), 2*2*3*3);
134 VERIFY_IS_EQUAL(threed_patch.
dimension(1), 1);
135 VERIFY_IS_EQUAL(threed_patch.
dimension(2), 2);
136 VERIFY_IS_EQUAL(threed_patch.
dimension(3), 3);
137 VERIFY_IS_EQUAL(threed_patch.
dimension(4), 5);
140 for (
int i = 0; i < 2; ++i) {
141 for (
int j = 0; j < 2; ++j) {
142 for (
int k = 0; k < 3; ++k) {
143 for (
int l = 0; l < 3; ++l) {
146 patch_loc = i + 2 * (j + 2 * (k + 3 * l));
148 patch_loc = l + 3 * (k + 3 * (j + 2 * i));
150 for (
int x = 0; x < 2; ++x) {
151 for (
int y = 0; y < 3; ++y) {
152 for (
int z = 0;
z < 5; ++
z) {
154 VERIFY_IS_EQUAL(tensor(i,j+x,k+y,l+
z), threed_patch(0,x,y,
z,patch_loc));
156 VERIFY_IS_EQUAL(tensor(i,j+x,k+y,l+
z), threed_patch(patch_loc,0,x,y,
z));
169 CALL_SUBTEST(test_simple_patch<ColMajor>());
170 CALL_SUBTEST(test_simple_patch<RowMajor>());
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_simple_patch()
void test_cxx11_tensor_patch()
TFSIMD_FORCE_INLINE const tfScalar & z() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const