@@ -587,6 +587,75 @@ TEST_F(OpConvCorrectnessTest, TransposedNonDefaultParams) {
587
587
EXPECT_TENSOR_CLOSE (out, expected);
588
588
}
589
589
590
+ TEST_F (OpConvCorrectnessTest, TransposedNonDefaultParamsChannelsLast) {
591
+ TensorFactory<ScalarType::Float> tf;
592
+
593
+ Tensor input = tf.full_channels_last ({2 , 6 , 4 , 5 }, 2.0 );
594
+ Tensor weight = tf.full_channels_last ({6 , 1 , 2 , 2 }, 0.5 );
595
+ Tensor bias = tf.make ({3 }, {1 , 2 , 3 });
596
+ Tensor out = tf.full_channels_last ({2 , 3 , 3 , 6 }, 0.7 );
597
+ Tensor expected = tf.make (
598
+ {2 , 3 , 3 , 6 },
599
+ {1 , 1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 1 , 3 , 3 , 1 , 3 , 3 , 1 , 3 , 3 , 2 , 2 , 2 , 2 ,
600
+ 2 , 2 , 2 , 4 , 4 , 2 , 4 , 4 , 2 , 4 , 4 , 2 , 4 , 4 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 5 ,
601
+ 5 , 3 , 5 , 5 , 3 , 5 , 5 , 3 , 5 , 5 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 1 , 3 , 3 ,
602
+ 1 , 3 , 3 , 1 , 3 , 3 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 4 , 4 , 2 , 4 , 4 , 2 , 4 , 4 , 2 ,
603
+ 4 , 4 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 5 , 5 , 3 , 5 , 5 , 3 , 5 , 5 , 3 , 5 , 5 });
604
+
605
+ const std::vector<int32_t > sizes (
606
+ expected.sizes ().begin (), expected.sizes ().end ());
607
+
608
+ int32_t N = sizes[0 ];
609
+ int32_t C = sizes[1 ];
610
+ int32_t H = sizes[2 ];
611
+ int32_t W = sizes[3 ];
612
+
613
+ std::vector<float > contiguous_data (
614
+ expected.const_data_ptr <float >(),
615
+ expected.const_data_ptr <float >() + expected.numel ());
616
+ std::vector<float > channels_last_data (
617
+ N * C * H * W); // Create a new blob with the same total size to contain
618
+ // channels_last data
619
+ for (int32_t n = 0 ; n < N; ++n) {
620
+ for (int32_t c = 0 ; c < C; ++c) {
621
+ for (int32_t h = 0 ; h < H; ++h) {
622
+ for (int32_t w = 0 ; w < W; ++w) {
623
+ // Calculate the index in the original blob
624
+ int32_t old_index = ((n * C + c) * H + h) * W + w;
625
+ // Calculate the index in the new blob
626
+ int32_t new_index = ((n * H + h) * W + w) * C + c;
627
+ // Copy the data
628
+ channels_last_data[new_index] = contiguous_data[old_index];
629
+ }
630
+ }
631
+ }
632
+ }
633
+
634
+ Tensor expected_channels_last =
635
+ tf.make_channels_last (sizes, channels_last_data);
636
+
637
+ int64_t stride[1 ] = {3 };
638
+ int64_t padding[1 ] = {7 };
639
+ int64_t dilation[1 ] = {5 };
640
+ bool transposed = true ;
641
+ int64_t output_padding[1 ] = {2 };
642
+ int64_t groups = 3 ;
643
+
644
+ op_convolution_out (
645
+ input,
646
+ weight,
647
+ exec_aten::optional<Tensor>(bias),
648
+ exec_aten::ArrayRef<int64_t >{stride, 1 },
649
+ exec_aten::ArrayRef<int64_t >{padding, 1 },
650
+ exec_aten::ArrayRef<int64_t >{dilation, 1 },
651
+ transposed,
652
+ exec_aten::ArrayRef<int64_t >{output_padding, 1 },
653
+ groups,
654
+ out);
655
+
656
+ EXPECT_TENSOR_CLOSE (out, expected_channels_last);
657
+ }
658
+
590
659
TEST_F (OpConvCorrectnessTest, InvalidOutputPadding) {
591
660
TensorFactory<ScalarType::Float> tf;
592
661
0 commit comments