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.

test_eltwise.cpp 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "layer/eltwise.h"
  15. #include "testutil.h"
  16. static void print_float_array(const ncnn::Mat& a)
  17. {
  18. fprintf(stderr, "[");
  19. for (int i = 0; i < a.w; i++)
  20. {
  21. fprintf(stderr, " %f", a[i]);
  22. }
  23. fprintf(stderr, " ]");
  24. }
  25. static int test_eltwise(const std::vector<ncnn::Mat>& a, int op_type, const ncnn::Mat& coeffs)
  26. {
  27. ncnn::ParamDict pd;
  28. pd.set(0, op_type);
  29. pd.set(1, coeffs);
  30. std::vector<ncnn::Mat> weights(0);
  31. ncnn::Option opt;
  32. opt.num_threads = 1;
  33. opt.use_vulkan_compute = true;
  34. opt.use_int8_inference = false;
  35. int ret = test_layer<ncnn::Eltwise>("Eltwise", pd, weights, opt, a);
  36. if (ret != 0)
  37. {
  38. fprintf(stderr, "test_eltwise failed a[0].dims=%d a[0]=(%d %d %d) op_type=%d", a[0].dims, a[0].w, a[0].h, a[0].c, op_type);
  39. fprintf(stderr, " coeffs=");
  40. print_float_array(coeffs);
  41. fprintf(stderr, "\n");
  42. }
  43. return ret;
  44. }
  45. static int test_eltwise_0()
  46. {
  47. std::vector<ncnn::Mat> a(2);
  48. a[0] = RandomMat(16, 12, 8);
  49. a[1] = RandomMat(16, 12, 8);
  50. return 0
  51. || test_eltwise(a, 0, ncnn::Mat())
  52. || test_eltwise(a, 1, ncnn::Mat())
  53. || test_eltwise(a, 2, ncnn::Mat())
  54. || test_eltwise(a, 0, RandomMat(2))
  55. || test_eltwise(a, 1, RandomMat(2))
  56. || test_eltwise(a, 2, RandomMat(2));
  57. }
  58. static int test_eltwise_1()
  59. {
  60. std::vector<ncnn::Mat> a(4);
  61. a[0] = RandomMat(7, 3, 5);
  62. a[1] = RandomMat(7, 3, 5);
  63. a[2] = RandomMat(7, 3, 5);
  64. a[3] = RandomMat(7, 3, 5);
  65. return 0
  66. || test_eltwise(a, 0, ncnn::Mat())
  67. || test_eltwise(a, 1, ncnn::Mat())
  68. || test_eltwise(a, 2, ncnn::Mat())
  69. || test_eltwise(a, 0, RandomMat(4))
  70. || test_eltwise(a, 1, RandomMat(4))
  71. || test_eltwise(a, 2, RandomMat(4));
  72. }
  73. int main()
  74. {
  75. SRAND(7767517);
  76. return 0
  77. || test_eltwise_0()
  78. || test_eltwise_1();
  79. }