cxx11_tensor_image_patch.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Functions

void test_simple_patch ()
 
void test_patch_padding_valid ()
 
void test_patch_padding_valid_same_value ()
 
void test_patch_padding_same ()
 
void test_patch_padding_same_negative_padding_clip_to_zero ()
 
void test_patch_no_extra_dim ()
 
void test_imagenet_patches ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_image_patch)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_image_patch  )
803  {
811 }
void test_patch_no_extra_dim()
Definition: cxx11_tensor_image_patch.cpp:458
void test_patch_padding_valid()
Definition: cxx11_tensor_image_patch.cpp:178
void test_patch_padding_same_negative_padding_clip_to_zero()
Definition: cxx11_tensor_image_patch.cpp:411
void test_patch_padding_valid_same_value()
Definition: cxx11_tensor_image_patch.cpp:256
void test_simple_patch()
Definition: cxx11_tensor_image_patch.cpp:16
void test_patch_padding_same()
Definition: cxx11_tensor_image_patch.cpp:331
void test_imagenet_patches()
Definition: cxx11_tensor_image_patch.cpp:607
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, test_imagenet_patches(), test_patch_no_extra_dim(), test_patch_padding_same(), test_patch_padding_same_negative_padding_clip_to_zero(), test_patch_padding_valid(), test_patch_padding_valid_same_value(), and test_simple_patch().

◆ test_imagenet_patches()

void test_imagenet_patches ( )
607  {
608  // Test the code on typical configurations used by the 'imagenet' benchmarks at
609  // https://github.com/soumith/convnet-benchmarks
610  // ColMajor
611  Tensor<float, 4> l_in(3, 128, 128, 16);
612  l_in.setRandom();
613  Tensor<float, 5> l_out = l_in.extract_image_patches(11, 11);
614  VERIFY_IS_EQUAL(l_out.dimension(0), 3);
615  VERIFY_IS_EQUAL(l_out.dimension(1), 11);
616  VERIFY_IS_EQUAL(l_out.dimension(2), 11);
617  VERIFY_IS_EQUAL(l_out.dimension(3), 128 * 128);
618  VERIFY_IS_EQUAL(l_out.dimension(4), 16);
619 
620  // RowMajor
621  Tensor<float, 5, RowMajor> l_out_row_major = l_in.swap_layout().extract_image_patches(11, 11);
622  VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 16);
623  VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 128 * 128);
624  VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 11);
625  VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 11);
626  VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 3);
627 
628  for (int b = 0; b < 16; ++b) {
629  for (int i = 0; i < 128; ++i) {
630  for (int j = 0; j < 128; ++j) {
631  int patchId = i + 128 * j;
632  for (int c = 0; c < 11; ++c) {
633  for (int r = 0; r < 11; ++r) {
634  for (int d = 0; d < 3; ++d) {
635  float expected = 0.0f;
636  if (r - 5 + i >= 0 && c - 5 + j >= 0 && r - 5 + i < 128 && c - 5 + j < 128) {
637  expected = l_in(d, r - 5 + i, c - 5 + j, b);
638  }
639  // ColMajor
640  if (l_out(d, r, c, patchId, b) != expected) {
641  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
642  << " d=" << d << " b=" << b << std::endl;
643  }
644  VERIFY_IS_EQUAL(l_out(d, r, c, patchId, b), expected);
645  // RowMajor
646  if (l_out_row_major(b, patchId, c, r, d) != expected) {
647  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
648  << " d=" << d << " b=" << b << std::endl;
649  }
650  VERIFY_IS_EQUAL(l_out_row_major(b, patchId, c, r, d), expected);
651  }
652  }
653  }
654  }
655  }
656  }
657 
658  // ColMajor
659  l_in.resize(16, 64, 64, 32);
660  l_in.setRandom();
661  l_out = l_in.extract_image_patches(9, 9);
662  VERIFY_IS_EQUAL(l_out.dimension(0), 16);
663  VERIFY_IS_EQUAL(l_out.dimension(1), 9);
664  VERIFY_IS_EQUAL(l_out.dimension(2), 9);
665  VERIFY_IS_EQUAL(l_out.dimension(3), 64 * 64);
666  VERIFY_IS_EQUAL(l_out.dimension(4), 32);
667 
668  // RowMajor
669  l_out_row_major = l_in.swap_layout().extract_image_patches(9, 9);
670  VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
671  VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 64 * 64);
672  VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 9);
673  VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 9);
674  VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 16);
675 
676  for (int b = 0; b < 32; ++b) {
677  for (int i = 0; i < 64; ++i) {
678  for (int j = 0; j < 64; ++j) {
679  int patchId = i + 64 * j;
680  for (int c = 0; c < 9; ++c) {
681  for (int r = 0; r < 9; ++r) {
682  for (int d = 0; d < 16; ++d) {
683  float expected = 0.0f;
684  if (r - 4 + i >= 0 && c - 4 + j >= 0 && r - 4 + i < 64 && c - 4 + j < 64) {
685  expected = l_in(d, r - 4 + i, c - 4 + j, b);
686  }
687  // ColMajor
688  if (l_out(d, r, c, patchId, b) != expected) {
689  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
690  << " d=" << d << " b=" << b << std::endl;
691  }
692  VERIFY_IS_EQUAL(l_out(d, r, c, patchId, b), expected);
693  // RowMajor
694  if (l_out_row_major(b, patchId, c, r, d) != expected) {
695  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
696  << " d=" << d << " b=" << b << std::endl;
697  }
698  VERIFY_IS_EQUAL(l_out_row_major(b, patchId, c, r, d), expected);
699  }
700  }
701  }
702  }
703  }
704  }
705 
706  // ColMajor
707  l_in.resize(32, 16, 16, 32);
708  l_in.setRandom();
709  l_out = l_in.extract_image_patches(7, 7);
710  VERIFY_IS_EQUAL(l_out.dimension(0), 32);
711  VERIFY_IS_EQUAL(l_out.dimension(1), 7);
712  VERIFY_IS_EQUAL(l_out.dimension(2), 7);
713  VERIFY_IS_EQUAL(l_out.dimension(3), 16 * 16);
714  VERIFY_IS_EQUAL(l_out.dimension(4), 32);
715 
716  // RowMajor
717  l_out_row_major = l_in.swap_layout().extract_image_patches(7, 7);
718  VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
719  VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 16 * 16);
720  VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 7);
721  VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 7);
722  VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 32);
723 
724  for (int b = 0; b < 32; ++b) {
725  for (int i = 0; i < 16; ++i) {
726  for (int j = 0; j < 16; ++j) {
727  int patchId = i + 16 * j;
728  for (int c = 0; c < 7; ++c) {
729  for (int r = 0; r < 7; ++r) {
730  for (int d = 0; d < 32; ++d) {
731  float expected = 0.0f;
732  if (r - 3 + i >= 0 && c - 3 + j >= 0 && r - 3 + i < 16 && c - 3 + j < 16) {
733  expected = l_in(d, r - 3 + i, c - 3 + j, b);
734  }
735  // ColMajor
736  if (l_out(d, r, c, patchId, b) != expected) {
737  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
738  << " d=" << d << " b=" << b << std::endl;
739  }
740  VERIFY_IS_EQUAL(l_out(d, r, c, patchId, b), expected);
741  // RowMajor
742  if (l_out_row_major(b, patchId, c, r, d) != expected) {
743  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
744  << " d=" << d << " b=" << b << std::endl;
745  }
746  VERIFY_IS_EQUAL(l_out_row_major(b, patchId, c, r, d), expected);
747  }
748  }
749  }
750  }
751  }
752  }
753 
754  // ColMajor
755  l_in.resize(64, 13, 13, 32);
756  l_in.setRandom();
757  l_out = l_in.extract_image_patches(3, 3);
758  VERIFY_IS_EQUAL(l_out.dimension(0), 64);
759  VERIFY_IS_EQUAL(l_out.dimension(1), 3);
760  VERIFY_IS_EQUAL(l_out.dimension(2), 3);
761  VERIFY_IS_EQUAL(l_out.dimension(3), 13 * 13);
762  VERIFY_IS_EQUAL(l_out.dimension(4), 32);
763 
764  // RowMajor
765  l_out_row_major = l_in.swap_layout().extract_image_patches(3, 3);
766  VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
767  VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 13 * 13);
768  VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 3);
769  VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 3);
770  VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 64);
771 
772  for (int b = 0; b < 32; ++b) {
773  for (int i = 0; i < 13; ++i) {
774  for (int j = 0; j < 13; ++j) {
775  int patchId = i + 13 * j;
776  for (int c = 0; c < 3; ++c) {
777  for (int r = 0; r < 3; ++r) {
778  for (int d = 0; d < 64; ++d) {
779  float expected = 0.0f;
780  if (r - 1 + i >= 0 && c - 1 + j >= 0 && r - 1 + i < 13 && c - 1 + j < 13) {
781  expected = l_in(d, r - 1 + i, c - 1 + j, b);
782  }
783  // ColMajor
784  if (l_out(d, r, c, patchId, b) != expected) {
785  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
786  << " d=" << d << " b=" << b << std::endl;
787  }
788  VERIFY_IS_EQUAL(l_out(d, r, c, patchId, b), expected);
789  // RowMajor
790  if (l_out_row_major(b, patchId, c, r, d) != expected) {
791  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
792  << " d=" << d << " b=" << b << std::endl;
793  }
794  VERIFY_IS_EQUAL(l_out_row_major(b, patchId, c, r, d), expected);
795  }
796  }
797  }
798  }
799  }
800  }
801 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorLayoutSwapOp< const Derived > swap_layout() const
Definition: TensorBase.h:1084
The tensor class.
Definition: Tensor.h:68
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition: Tensor.h:99
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References b, calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, UniformPSDSelfTest::r, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::resize(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_patch_no_extra_dim()

void test_patch_no_extra_dim ( )
458  {
459  Tensor<float, 3> tensor(2, 3, 5);
460  tensor.setRandom();
461  Tensor<float, 3, RowMajor> tensor_row_major = tensor.swap_layout();
462  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(2));
463  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(1));
464  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(0));
465 
466  // Single pixel patch: ColMajor
467  Tensor<float, 4> single_pixel_patch;
468  single_pixel_patch = tensor.extract_image_patches(1, 1);
469  VERIFY_IS_EQUAL(single_pixel_patch.dimension(0), 2);
470  VERIFY_IS_EQUAL(single_pixel_patch.dimension(1), 1);
471  VERIFY_IS_EQUAL(single_pixel_patch.dimension(2), 1);
472  VERIFY_IS_EQUAL(single_pixel_patch.dimension(3), 3 * 5);
473 
474  // Single pixel patch: RowMajor
475  Tensor<float, 4, RowMajor> single_pixel_patch_row_major;
476  single_pixel_patch_row_major = tensor_row_major.extract_image_patches(1, 1);
477  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(0), 3 * 5);
478  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(1), 1);
479  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(2), 1);
480  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(3), 2);
481 
482  for (int i = 0; i < tensor.size(); ++i) {
483  // ColMajor
484  if (tensor.data()[i] != single_pixel_patch.data()[i]) {
485  std::cout << "Mismatch detected at index " << i << " : " << tensor.data()[i] << " vs "
486  << single_pixel_patch.data()[i] << std::endl;
487  }
488  VERIFY_IS_EQUAL(single_pixel_patch.data()[i], tensor.data()[i]);
489  // RowMajor
490  if (tensor_row_major.data()[i] != single_pixel_patch_row_major.data()[i]) {
491  std::cout << "Mismatch detected at index " << i << " : " << tensor.data()[i] << " vs "
492  << single_pixel_patch_row_major.data()[i] << std::endl;
493  }
494  VERIFY_IS_EQUAL(single_pixel_patch_row_major.data()[i], tensor_row_major.data()[i]);
495  VERIFY_IS_EQUAL(tensor.data()[i], tensor_row_major.data()[i]);
496  VERIFY_IS_EQUAL(single_pixel_patch.data()[i], single_pixel_patch_row_major.data()[i]);
497  }
498 
499  // Entire image patch: ColMajor
500  Tensor<float, 4> entire_image_patch;
501  entire_image_patch = tensor.extract_image_patches(3, 5);
502  VERIFY_IS_EQUAL(entire_image_patch.dimension(0), 2);
503  VERIFY_IS_EQUAL(entire_image_patch.dimension(1), 3);
504  VERIFY_IS_EQUAL(entire_image_patch.dimension(2), 5);
505  VERIFY_IS_EQUAL(entire_image_patch.dimension(3), 3 * 5);
506 
507  // Entire image patch: RowMajor
508  Tensor<float, 4, RowMajor> entire_image_patch_row_major;
509  entire_image_patch_row_major = tensor_row_major.extract_image_patches(3, 5);
510  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(0), 3 * 5);
511  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(1), 5);
512  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(2), 3);
513  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(3), 2);
514 
515  for (int i = 0; i < 3; ++i) {
516  for (int j = 0; j < 5; ++j) {
517  int patchId = i + 3 * j;
518  for (int r = 0; r < 3; ++r) {
519  for (int c = 0; c < 5; ++c) {
520  for (int d = 0; d < 2; ++d) {
521  float expected = 0.0f;
522  float expected_row_major = 0.0f;
523  if (r - 1 + i >= 0 && c - 2 + j >= 0 && r - 1 + i < 3 && c - 2 + j < 5) {
524  expected = tensor(d, r - 1 + i, c - 2 + j);
525  expected_row_major = tensor_row_major(c - 2 + j, r - 1 + i, d);
526  }
527  // ColMajor
528  if (entire_image_patch(d, r, c, patchId) != expected) {
529  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c << " d=" << d
530  << std::endl;
531  }
532  VERIFY_IS_EQUAL(entire_image_patch(d, r, c, patchId), expected);
533  // RowMajor
534  if (entire_image_patch_row_major(patchId, c, r, d) != expected_row_major) {
535  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c << " d=" << d
536  << std::endl;
537  }
538  VERIFY_IS_EQUAL(entire_image_patch_row_major(patchId, c, r, d), expected_row_major);
539  // Check that ColMajor and RowMajor agree.
540  VERIFY_IS_EQUAL(expected, expected_row_major);
541  }
542  }
543  }
544  }
545  }
546 
547  // 2D patch: ColMajor
548  Tensor<float, 4> twod_patch;
549  twod_patch = tensor.extract_image_patches(2, 2);
550  VERIFY_IS_EQUAL(twod_patch.dimension(0), 2);
551  VERIFY_IS_EQUAL(twod_patch.dimension(1), 2);
552  VERIFY_IS_EQUAL(twod_patch.dimension(2), 2);
553  VERIFY_IS_EQUAL(twod_patch.dimension(3), 3 * 5);
554 
555  // 2D patch: RowMajor
556  Tensor<float, 4, RowMajor> twod_patch_row_major;
557  twod_patch_row_major = tensor_row_major.extract_image_patches(2, 2);
558  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(0), 3 * 5);
559  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(1), 2);
560  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(2), 2);
561  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(3), 2);
562 
563  // Based on the calculation described in TensorTraits.h, padding happens to be 0.
564  int row_padding = 0;
565  int col_padding = 0;
566  int stride = 1;
567 
568  for (int i = 0; i < 3; ++i) {
569  for (int j = 0; j < 5; ++j) {
570  int patchId = i + 3 * j;
571  for (int r = 0; r < 2; ++r) {
572  for (int c = 0; c < 2; ++c) {
573  for (int d = 0; d < 2; ++d) {
574  float expected = 0.0f;
575  float expected_row_major = 0.0f;
576  int row_offset = r * stride + i - row_padding;
577  int col_offset = c * stride + j - col_padding;
578  // ColMajor
579  if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor.dimension(1) &&
580  col_offset < tensor.dimension(2)) {
581  expected = tensor(d, row_offset, col_offset);
582  }
583  if (twod_patch(d, r, c, patchId) != expected) {
584  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c << " d=" << d
585  << std::endl;
586  }
587  VERIFY_IS_EQUAL(twod_patch(d, r, c, patchId), expected);
588  // RowMajor
589  if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor_row_major.dimension(1) &&
590  col_offset < tensor_row_major.dimension(0)) {
591  expected_row_major = tensor_row_major(col_offset, row_offset, d);
592  }
593  if (twod_patch_row_major(patchId, c, r, d) != expected_row_major) {
594  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c << " d=" << d
595  << std::endl;
596  }
597  VERIFY_IS_EQUAL(twod_patch_row_major(patchId, c, r, d), expected_row_major);
598  // Check that ColMajor and RowMajor agree.
599  VERIFY_IS_EQUAL(expected, expected_row_major);
600  }
601  }
602  }
603  }
604  }
605 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:102

References calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, UniformPSDSelfTest::r, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_patch_padding_same()

void test_patch_padding_same ( )
331  {
332  int input_depth = 3;
333  int input_rows = 4;
334  int input_cols = 2;
335  int input_batches = 1;
336  int ksize = 2; // Corresponds to the Rows and Cols for tensor.extract_image_patches<>.
337  int stride = 2; // Only same stride is supported.
338  // ColMajor
339  Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
340  // Initializes tensor with incrementing numbers.
341  for (int i = 0; i < tensor.size(); ++i) {
342  tensor.data()[i] = i + 1;
343  }
344  Tensor<float, 5> result = tensor.extract_image_patches(ksize, ksize, stride, stride, PADDING_SAME);
345 
346  VERIFY_IS_EQUAL(result.dimension(0), input_depth); // depth
347  VERIFY_IS_EQUAL(result.dimension(1), ksize); // kernel rows
348  VERIFY_IS_EQUAL(result.dimension(2), ksize); // kernel cols
349  VERIFY_IS_EQUAL(result.dimension(3), 2); // number of patches
350  VERIFY_IS_EQUAL(result.dimension(4), input_batches); // number of batches
351 
352  // RowMajor
353  Tensor<float, 4, RowMajor> tensor_row_major = tensor.swap_layout();
354  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(3));
355  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(2));
356  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(1));
357  VERIFY_IS_EQUAL(tensor.dimension(3), tensor_row_major.dimension(0));
358 
359  Tensor<float, 5, RowMajor> result_row_major =
360  tensor_row_major.extract_image_patches(ksize, ksize, stride, stride, PADDING_SAME);
361  VERIFY_IS_EQUAL(result.dimension(0), result_row_major.dimension(4));
362  VERIFY_IS_EQUAL(result.dimension(1), result_row_major.dimension(3));
363  VERIFY_IS_EQUAL(result.dimension(2), result_row_major.dimension(2));
364  VERIFY_IS_EQUAL(result.dimension(3), result_row_major.dimension(1));
365  VERIFY_IS_EQUAL(result.dimension(4), result_row_major.dimension(0));
366 
367  // Based on the calculation described in TensorTraits.h, padding happens to be
368  // 0.
369  int row_padding = 0;
370  int col_padding = 0;
371 
372  for (int i = 0; (i + stride + ksize - 1) <= input_rows; i += stride) { // input rows
373  for (int j = 0; (j + stride + ksize - 1) <= input_cols; j += stride) { // input cols
374  int patchId = i + input_rows * j;
375  for (int r = 0; r < ksize; ++r) { // patch rows
376  for (int c = 0; c < ksize; ++c) { // patch cols
377  for (int d = 0; d < input_depth; ++d) { // depth
378  for (int b = 0; b < input_batches; ++b) { // batch
379  float expected = 0.0f;
380  float expected_row_major = 0.0f;
381  int row_offset = r * stride + i - row_padding;
382  int col_offset = c * stride + j - col_padding;
383  if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
384  expected = tensor(d, row_offset, col_offset, b);
385  expected_row_major = tensor_row_major(b, col_offset, row_offset, d);
386  }
387  // ColMajor
388  if (result(d, r, c, patchId, b) != expected) {
389  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
390  << " d=" << d << " b=" << b << std::endl;
391  }
392  VERIFY_IS_EQUAL(result(d, r, c, patchId, b), expected);
393  // RowMajor
394  if (result_row_major(b, patchId, c, r, d) != expected_row_major) {
395  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
396  << " d=" << d << " b=" << b << std::endl;
397  }
398  VERIFY_IS_EQUAL(result_row_major(b, patchId, c, r, d), expected_row_major);
399  // Check that ColMajor and RowMajor agree.
400  VERIFY_IS_EQUAL(expected, expected_row_major);
401  }
402  }
403  }
404  }
405  }
406  }
407 }
@ PADDING_SAME
Definition: TensorTraits.h:227

References b, calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, Eigen::PADDING_SAME, UniformPSDSelfTest::r, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_patch_padding_same_negative_padding_clip_to_zero()

void test_patch_padding_same_negative_padding_clip_to_zero ( )
411  {
412  int input_depth = 1;
413  int input_rows = 15;
414  int input_cols = 1;
415  int input_batches = 1;
416  int ksize = 1; // Corresponds to the Rows and Cols for
417  // tensor.extract_image_patches<>.
418  int row_stride = 5;
419  int col_stride = 1;
420  // ColMajor
421  Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
422  // Initializes tensor with incrementing numbers.
423  for (int i = 0; i < tensor.size(); ++i) {
424  tensor.data()[i] = i + 1;
425  }
426  Tensor<float, 5> result = tensor.extract_image_patches(ksize, ksize, row_stride, col_stride, 1, 1, PADDING_SAME);
427  // row padding will be computed as -2 originally and then be clipped to 0.
428  VERIFY_IS_EQUAL(result.coeff(0), 1.0f);
429  VERIFY_IS_EQUAL(result.coeff(1), 6.0f);
430  VERIFY_IS_EQUAL(result.coeff(2), 11.0f);
431 
432  VERIFY_IS_EQUAL(result.dimension(0), input_depth); // depth
433  VERIFY_IS_EQUAL(result.dimension(1), ksize); // kernel rows
434  VERIFY_IS_EQUAL(result.dimension(2), ksize); // kernel cols
435  VERIFY_IS_EQUAL(result.dimension(3), 3); // number of patches
436  VERIFY_IS_EQUAL(result.dimension(4), input_batches); // number of batches
437 
438  // RowMajor
439  Tensor<float, 4, RowMajor> tensor_row_major = tensor.swap_layout();
440  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(3));
441  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(2));
442  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(1));
443  VERIFY_IS_EQUAL(tensor.dimension(3), tensor_row_major.dimension(0));
444 
445  Tensor<float, 5, RowMajor> result_row_major =
446  tensor_row_major.extract_image_patches(ksize, ksize, row_stride, col_stride, 1, 1, PADDING_SAME);
447  VERIFY_IS_EQUAL(result_row_major.coeff(0), 1.0f);
448  VERIFY_IS_EQUAL(result_row_major.coeff(1), 6.0f);
449  VERIFY_IS_EQUAL(result_row_major.coeff(2), 11.0f);
450 
451  VERIFY_IS_EQUAL(result.dimension(0), result_row_major.dimension(4));
452  VERIFY_IS_EQUAL(result.dimension(1), result_row_major.dimension(3));
453  VERIFY_IS_EQUAL(result.dimension(2), result_row_major.dimension(2));
454  VERIFY_IS_EQUAL(result.dimension(3), result_row_major.dimension(1));
455  VERIFY_IS_EQUAL(result.dimension(4), result_row_major.dimension(0));
456 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index firstIndex, Index secondIndex, IndexTypes... otherIndices) const
Definition: Tensor.h:112

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeff(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, Eigen::PADDING_SAME, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_patch_padding_valid()

void test_patch_padding_valid ( )
178  {
179  int input_depth = 3;
180  int input_rows = 3;
181  int input_cols = 3;
182  int input_batches = 1;
183  int ksize = 2; // Corresponds to the Rows and Cols for tensor.extract_image_patches<>.
184  int stride = 2; // Only same stride is supported.
185  Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
186  // Initializes tensor with incrementing numbers.
187  for (int i = 0; i < tensor.size(); ++i) {
188  tensor.data()[i] = i + 1;
189  }
190  // ColMajor
191  Tensor<float, 5> result = tensor.extract_image_patches(ksize, ksize, stride, stride, 1, 1, PADDING_VALID);
192 
193  VERIFY_IS_EQUAL(result.dimension(0), input_depth); // depth
194  VERIFY_IS_EQUAL(result.dimension(1), ksize); // kernel rows
195  VERIFY_IS_EQUAL(result.dimension(2), ksize); // kernel cols
196  VERIFY_IS_EQUAL(result.dimension(3), 1); // number of patches
197  VERIFY_IS_EQUAL(result.dimension(4), input_batches); // number of batches
198 
199  // RowMajor
200  Tensor<float, 4, RowMajor> tensor_row_major = tensor.swap_layout();
201  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(3));
202  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(2));
203  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(1));
204  VERIFY_IS_EQUAL(tensor.dimension(3), tensor_row_major.dimension(0));
205 
206  Tensor<float, 5, RowMajor> result_row_major =
207  tensor_row_major.extract_image_patches(ksize, ksize, stride, stride, 1, 1, PADDING_VALID);
208  VERIFY_IS_EQUAL(result.dimension(0), result_row_major.dimension(4));
209  VERIFY_IS_EQUAL(result.dimension(1), result_row_major.dimension(3));
210  VERIFY_IS_EQUAL(result.dimension(2), result_row_major.dimension(2));
211  VERIFY_IS_EQUAL(result.dimension(3), result_row_major.dimension(1));
212  VERIFY_IS_EQUAL(result.dimension(4), result_row_major.dimension(0));
213 
214  // No padding is carried out.
215  int row_padding = 0;
216  int col_padding = 0;
217 
218  for (int i = 0; (i + stride + ksize - 1) < input_rows; i += stride) { // input rows
219  for (int j = 0; (j + stride + ksize - 1) < input_cols; j += stride) { // input cols
220  int patchId = i + input_rows * j;
221  for (int r = 0; r < ksize; ++r) { // patch rows
222  for (int c = 0; c < ksize; ++c) { // patch cols
223  for (int d = 0; d < input_depth; ++d) { // depth
224  for (int b = 0; b < input_batches; ++b) { // batch
225  float expected = 0.0f;
226  float expected_row_major = 0.0f;
227  int row_offset = r + i - row_padding;
228  int col_offset = c + j - col_padding;
229  if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
230  expected = tensor(d, row_offset, col_offset, b);
231  expected_row_major = tensor_row_major(b, col_offset, row_offset, d);
232  }
233  // ColMajor
234  if (result(d, r, c, patchId, b) != expected) {
235  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
236  << " d=" << d << " b=" << b << std::endl;
237  }
238  VERIFY_IS_EQUAL(result(d, r, c, patchId, b), expected);
239  // RowMajor
240  if (result_row_major(b, patchId, c, r, d) != expected_row_major) {
241  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
242  << " d=" << d << " b=" << b << std::endl;
243  }
244  VERIFY_IS_EQUAL(result_row_major(b, patchId, c, r, d), expected_row_major);
245  // Check that ColMajor and RowMajor agree.
246  VERIFY_IS_EQUAL(expected, expected_row_major);
247  }
248  }
249  }
250  }
251  }
252  }
253 }
@ PADDING_VALID
Definition: TensorTraits.h:227

References b, calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, Eigen::PADDING_VALID, UniformPSDSelfTest::r, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_patch_padding_valid_same_value()

void test_patch_padding_valid_same_value ( )
256  {
257  int input_depth = 1;
258  int input_rows = 5;
259  int input_cols = 5;
260  int input_batches = 2;
261  int ksize = 3; // Corresponds to the Rows and Cols for tensor.extract_image_patches<>.
262  int stride = 2; // Only same stride is supported.
263  // ColMajor
264  Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
265  tensor = tensor.constant(11.0f);
266  Tensor<float, 5> result = tensor.extract_image_patches(ksize, ksize, stride, stride, 1, 1, PADDING_VALID);
267 
268  VERIFY_IS_EQUAL(result.dimension(0), input_depth); // depth
269  VERIFY_IS_EQUAL(result.dimension(1), ksize); // kernel rows
270  VERIFY_IS_EQUAL(result.dimension(2), ksize); // kernel cols
271  VERIFY_IS_EQUAL(result.dimension(3), 4); // number of patches
272  VERIFY_IS_EQUAL(result.dimension(4), input_batches); // number of batches
273 
274  // RowMajor
275  Tensor<float, 4, RowMajor> tensor_row_major = tensor.swap_layout();
276  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(3));
277  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(2));
278  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(1));
279  VERIFY_IS_EQUAL(tensor.dimension(3), tensor_row_major.dimension(0));
280 
281  Tensor<float, 5, RowMajor> result_row_major =
282  tensor_row_major.extract_image_patches(ksize, ksize, stride, stride, 1, 1, PADDING_VALID);
283  VERIFY_IS_EQUAL(result.dimension(0), result_row_major.dimension(4));
284  VERIFY_IS_EQUAL(result.dimension(1), result_row_major.dimension(3));
285  VERIFY_IS_EQUAL(result.dimension(2), result_row_major.dimension(2));
286  VERIFY_IS_EQUAL(result.dimension(3), result_row_major.dimension(1));
287  VERIFY_IS_EQUAL(result.dimension(4), result_row_major.dimension(0));
288 
289  // No padding is carried out.
290  int row_padding = 0;
291  int col_padding = 0;
292 
293  for (int i = 0; (i + stride + ksize - 1) <= input_rows; i += stride) { // input rows
294  for (int j = 0; (j + stride + ksize - 1) <= input_cols; j += stride) { // input cols
295  int patchId = i + input_rows * j;
296  for (int r = 0; r < ksize; ++r) { // patch rows
297  for (int c = 0; c < ksize; ++c) { // patch cols
298  for (int d = 0; d < input_depth; ++d) { // depth
299  for (int b = 0; b < input_batches; ++b) { // batch
300  float expected = 0.0f;
301  float expected_row_major = 0.0f;
302  int row_offset = r + i - row_padding;
303  int col_offset = c + j - col_padding;
304  if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
305  expected = tensor(d, row_offset, col_offset, b);
306  expected_row_major = tensor_row_major(b, col_offset, row_offset, d);
307  }
308  // ColMajor
309  if (result(d, r, c, patchId, b) != expected) {
310  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
311  << " d=" << d << " b=" << b << std::endl;
312  }
313  VERIFY_IS_EQUAL(result(d, r, c, patchId, b), expected);
314  // RowMajor
315  if (result_row_major(b, patchId, c, r, d) != expected_row_major) {
316  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
317  << " d=" << d << " b=" << b << std::endl;
318  }
319  VERIFY_IS_EQUAL(result_row_major(b, patchId, c, r, d), expected_row_major);
320  // Check that ColMajor and RowMajor agree.
321  VERIFY_IS_EQUAL(expected, expected_row_major);
322  }
323  }
324  }
325  }
326  }
327  }
328 }

References b, calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, Eigen::PADDING_VALID, UniformPSDSelfTest::r, Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_simple_patch()

void test_simple_patch ( )
16  {
17  Tensor<float, 4> tensor(2, 3, 5, 7);
18  tensor.setRandom();
19  Tensor<float, 4, RowMajor> tensor_row_major = tensor.swap_layout();
20  VERIFY_IS_EQUAL(tensor.dimension(0), tensor_row_major.dimension(3));
21  VERIFY_IS_EQUAL(tensor.dimension(1), tensor_row_major.dimension(2));
22  VERIFY_IS_EQUAL(tensor.dimension(2), tensor_row_major.dimension(1));
23  VERIFY_IS_EQUAL(tensor.dimension(3), tensor_row_major.dimension(0));
24 
25  // Single pixel patch: ColMajor
26  Tensor<float, 5> single_pixel_patch;
27  single_pixel_patch = tensor.extract_image_patches(1, 1);
28  VERIFY_IS_EQUAL(single_pixel_patch.dimension(0), 2);
29  VERIFY_IS_EQUAL(single_pixel_patch.dimension(1), 1);
30  VERIFY_IS_EQUAL(single_pixel_patch.dimension(2), 1);
31  VERIFY_IS_EQUAL(single_pixel_patch.dimension(3), 3 * 5);
32  VERIFY_IS_EQUAL(single_pixel_patch.dimension(4), 7);
33 
34  // Single pixel patch: RowMajor
35  Tensor<float, 5, RowMajor> single_pixel_patch_row_major;
36  single_pixel_patch_row_major = tensor_row_major.extract_image_patches(1, 1);
37  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(0), 7);
38  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(1), 3 * 5);
39  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(2), 1);
40  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(3), 1);
41  VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(4), 2);
42 
43  for (int i = 0; i < tensor.size(); ++i) {
44  // ColMajor
45  if (tensor.data()[i] != single_pixel_patch.data()[i]) {
46  std::cout << "Mismatch detected at index " << i << " : " << tensor.data()[i] << " vs "
47  << single_pixel_patch.data()[i] << std::endl;
48  }
49  VERIFY_IS_EQUAL(single_pixel_patch.data()[i], tensor.data()[i]);
50  // RowMajor
51  if (tensor_row_major.data()[i] != single_pixel_patch_row_major.data()[i]) {
52  std::cout << "Mismatch detected at index " << i << " : " << tensor.data()[i] << " vs "
53  << single_pixel_patch_row_major.data()[i] << std::endl;
54  }
55  VERIFY_IS_EQUAL(single_pixel_patch_row_major.data()[i], tensor_row_major.data()[i]);
56  VERIFY_IS_EQUAL(tensor.data()[i], tensor_row_major.data()[i]);
57  VERIFY_IS_EQUAL(single_pixel_patch.data()[i], single_pixel_patch_row_major.data()[i]);
58  }
59 
60  // Entire image patch: ColMajor
61  Tensor<float, 5> entire_image_patch;
62  entire_image_patch = tensor.extract_image_patches(3, 5);
63  VERIFY_IS_EQUAL(entire_image_patch.dimension(0), 2);
64  VERIFY_IS_EQUAL(entire_image_patch.dimension(1), 3);
65  VERIFY_IS_EQUAL(entire_image_patch.dimension(2), 5);
66  VERIFY_IS_EQUAL(entire_image_patch.dimension(3), 3 * 5);
67  VERIFY_IS_EQUAL(entire_image_patch.dimension(4), 7);
68 
69  // Entire image patch: RowMajor
70  Tensor<float, 5, RowMajor> entire_image_patch_row_major;
71  entire_image_patch_row_major = tensor_row_major.extract_image_patches(3, 5);
72  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(0), 7);
73  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(1), 3 * 5);
74  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(2), 5);
75  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(3), 3);
76  VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(4), 2);
77 
78  for (int i = 0; i < 3; ++i) {
79  for (int j = 0; j < 5; ++j) {
80  int patchId = i + 3 * j;
81  for (int r = 0; r < 3; ++r) {
82  for (int c = 0; c < 5; ++c) {
83  for (int d = 0; d < 2; ++d) {
84  for (int b = 0; b < 7; ++b) {
85  float expected = 0.0f;
86  float expected_row_major = 0.0f;
87  if (r - 1 + i >= 0 && c - 2 + j >= 0 && r - 1 + i < 3 && c - 2 + j < 5) {
88  expected = tensor(d, r - 1 + i, c - 2 + j, b);
89  expected_row_major = tensor_row_major(b, c - 2 + j, r - 1 + i, d);
90  }
91  // ColMajor
92  if (entire_image_patch(d, r, c, patchId, b) != expected) {
93  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
94  << " d=" << d << " b=" << b << std::endl;
95  }
96  VERIFY_IS_EQUAL(entire_image_patch(d, r, c, patchId, b), expected);
97  // RowMajor
98  if (entire_image_patch_row_major(b, patchId, c, r, d) != expected_row_major) {
99  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
100  << " d=" << d << " b=" << b << std::endl;
101  }
102  VERIFY_IS_EQUAL(entire_image_patch_row_major(b, patchId, c, r, d), expected_row_major);
103  // Check that ColMajor and RowMajor agree.
104  VERIFY_IS_EQUAL(expected, expected_row_major);
105  }
106  }
107  }
108  }
109  }
110  }
111 
112  // 2D patch: ColMajor
113  Tensor<float, 5> twod_patch;
114  twod_patch = tensor.extract_image_patches(2, 2);
115  VERIFY_IS_EQUAL(twod_patch.dimension(0), 2);
116  VERIFY_IS_EQUAL(twod_patch.dimension(1), 2);
117  VERIFY_IS_EQUAL(twod_patch.dimension(2), 2);
118  VERIFY_IS_EQUAL(twod_patch.dimension(3), 3 * 5);
119  VERIFY_IS_EQUAL(twod_patch.dimension(4), 7);
120 
121  // 2D patch: RowMajor
122  Tensor<float, 5, RowMajor> twod_patch_row_major;
123  twod_patch_row_major = tensor_row_major.extract_image_patches(2, 2);
124  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(0), 7);
125  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(1), 3 * 5);
126  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(2), 2);
127  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(3), 2);
128  VERIFY_IS_EQUAL(twod_patch_row_major.dimension(4), 2);
129 
130  // Based on the calculation described in TensorTraits.h, padding happens to be 0.
131  int row_padding = 0;
132  int col_padding = 0;
133  int stride = 1;
134 
135  for (int i = 0; i < 3; ++i) {
136  for (int j = 0; j < 5; ++j) {
137  int patchId = i + 3 * j;
138  for (int r = 0; r < 2; ++r) {
139  for (int c = 0; c < 2; ++c) {
140  for (int d = 0; d < 2; ++d) {
141  for (int b = 0; b < 7; ++b) {
142  float expected = 0.0f;
143  float expected_row_major = 0.0f;
144  int row_offset = r * stride + i - row_padding;
145  int col_offset = c * stride + j - col_padding;
146  // ColMajor
147  if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor.dimension(1) &&
148  col_offset < tensor.dimension(2)) {
149  expected = tensor(d, row_offset, col_offset, b);
150  }
151  if (twod_patch(d, r, c, patchId, b) != expected) {
152  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
153  << " d=" << d << " b=" << b << std::endl;
154  }
155  VERIFY_IS_EQUAL(twod_patch(d, r, c, patchId, b), expected);
156 
157  // RowMajor
158  if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor_row_major.dimension(2) &&
159  col_offset < tensor_row_major.dimension(1)) {
160  expected_row_major = tensor_row_major(b, col_offset, row_offset, d);
161  }
162  if (twod_patch_row_major(b, patchId, c, r, d) != expected_row_major) {
163  std::cout << "Mismatch detected at index i=" << i << " j=" << j << " r=" << r << " c=" << c
164  << " d=" << d << " b=" << b << std::endl;
165  }
166  VERIFY_IS_EQUAL(twod_patch_row_major(b, patchId, c, r, d), expected_row_major);
167  // Check that ColMajor and RowMajor agree.
168  VERIFY_IS_EQUAL(expected, expected_row_major);
169  }
170  }
171  }
172  }
173  }
174  }
175 }

References b, calibrate::c, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, UniformPSDSelfTest::r, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().