You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

padding.cpp 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * \file dnn/test/naive/padding.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "test/common/padding.h"
  12. #include "megdnn/dtype.h"
  13. #include "megdnn/oprs.h"
  14. #include "test/common/checker.h"
  15. #include "test/naive/fixture.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(NAIVE, PADDING) {
  19. std::vector<padding::TestArg> args = padding::get_args();
  20. Checker<Padding> checker(handle());
  21. for (auto&& arg : args) {
  22. checker.set_param(arg.param)
  23. .set_dtype(0, dtype::Float32())
  24. .set_dtype(1, dtype::Float32())
  25. .execs({arg.src, arg.dst});
  26. }
  27. }
  28. TEST_F(NAIVE, PADDING_CONSTANT) {
  29. Checker<Padding> checker(handle(), false);
  30. param::Padding param;
  31. param.padding_val = 10;
  32. param.padding_mode = param::Padding::PaddingMode::CONSTANT;
  33. param.front_offset_dim0 = 2;
  34. param.front_offset_dim1 = 1;
  35. param.front_offset_dim2 = 0;
  36. param.front_offset_dim3 = 0;
  37. param.front_offset_dim4 = 0;
  38. param.front_offset_dim5 = 0;
  39. param.front_offset_dim6 = 0;
  40. param.back_offset_dim0 = 2;
  41. param.back_offset_dim1 = 3;
  42. param.back_offset_dim2 = 0;
  43. param.back_offset_dim3 = 0;
  44. param.back_offset_dim4 = 0;
  45. param.back_offset_dim5 = 0;
  46. param.back_offset_dim6 = 0;
  47. checker.set_param(param).exect(
  48. Testcase{TensorValue({1, 1}, dtype::Float32(), {1}), {}},
  49. Testcase{{}, TensorValue({5, 5}, dtype::Float32(), {10, 10, 10, 10, 10,
  50. 10, 10, 10, 10, 10,
  51. 10, 1, 10, 10, 10,
  52. 10, 10, 10, 10, 10,
  53. 10, 10, 10, 10, 10})});
  54. }
  55. TEST_F(NAIVE, PADDING_REFLECT) {
  56. Checker<Padding> checker(handle(), false);
  57. param::Padding param;
  58. param.padding_val = 10;
  59. param.padding_mode = param::Padding::PaddingMode::REFLECT;
  60. param.front_offset_dim0 = 2;
  61. param.front_offset_dim1 = 0;
  62. param.front_offset_dim2 = 0;
  63. param.front_offset_dim3 = 0;
  64. param.front_offset_dim4 = 0;
  65. param.front_offset_dim5 = 0;
  66. param.front_offset_dim6 = 0;
  67. param.back_offset_dim0 = 3;
  68. param.back_offset_dim1 = 0;
  69. param.back_offset_dim2 = 0;
  70. param.back_offset_dim3 = 0;
  71. param.back_offset_dim4 = 0;
  72. param.back_offset_dim5 = 0;
  73. param.back_offset_dim6 = 0;
  74. checker.set_param(param).exect(
  75. Testcase{TensorValue({5}, dtype::Float32(), {1, 2, 3, 4, 5}), {}},
  76. Testcase{
  77. {},
  78. TensorValue(
  79. {10}, dtype::Float32(), {3, 2, 1, 2, 3, 4, 5, 4, 3, 2})});
  80. }
  81. TEST_F(NAIVE, PADDING_REPLICATE) {
  82. Checker<Padding> checker(handle(), false);
  83. param::Padding param;
  84. param.padding_val = 10;
  85. param.padding_mode = param::Padding::PaddingMode::REPLICATE;
  86. param.front_offset_dim0 = 1;
  87. param.front_offset_dim1 = 0;
  88. param.front_offset_dim2 = 0;
  89. param.front_offset_dim3 = 0;
  90. param.front_offset_dim4 = 0;
  91. param.front_offset_dim5 = 0;
  92. param.front_offset_dim6 = 0;
  93. param.back_offset_dim0 = 2;
  94. param.back_offset_dim1 = 0;
  95. param.back_offset_dim2 = 0;
  96. param.back_offset_dim3 = 0;
  97. param.back_offset_dim4 = 0;
  98. param.back_offset_dim5 = 0;
  99. param.back_offset_dim6 = 0;
  100. checker.set_param(param).exect(
  101. Testcase{
  102. TensorValue({9}, dtype::Float32(), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
  103. {}},
  104. Testcase{
  105. {},
  106. TensorValue(
  107. {12}, dtype::Float32(),
  108. {1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9})});
  109. }
  110. TEST_F(NAIVE, PADDING_REPLICATE2) {
  111. Checker<Padding> checker(handle(), false);
  112. param::Padding param;
  113. param.padding_val = 10;
  114. param.padding_mode = param::Padding::PaddingMode::REPLICATE;
  115. param.front_offset_dim0 = 2;
  116. param.front_offset_dim1 = 1;
  117. param.front_offset_dim2 = 0;
  118. param.front_offset_dim3 = 0;
  119. param.front_offset_dim4 = 0;
  120. param.front_offset_dim5 = 0;
  121. param.front_offset_dim6 = 0;
  122. param.back_offset_dim0 = 0;
  123. param.back_offset_dim1 = 3;
  124. param.back_offset_dim2 = 0;
  125. param.back_offset_dim3 = 0;
  126. param.back_offset_dim4 = 0;
  127. param.back_offset_dim5 = 0;
  128. param.back_offset_dim6 = 0;
  129. checker.set_param(param).exect(
  130. Testcase{
  131. TensorValue({3, 3}, dtype::Float32(), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
  132. {}},
  133. Testcase{{}, TensorValue({5, 7}, dtype::Float32(), {1, 1, 2, 3, 3, 3, 3,
  134. 1, 1, 2, 3, 3, 3, 3,
  135. 1, 1, 2, 3, 3, 3, 3,
  136. 4, 4, 5, 6, 6, 6, 6,
  137. 7, 7, 8, 9, 9, 9, 9})});
  138. }
  139. } // namespace test
  140. } // namespace megdnn