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_cumulativesum.cpp 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2023 Xiaomi Corp. (author: Fangjun Kuang)
  2. //
  3. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  4. // in compliance with the License. You may obtain a copy of the License at
  5. //
  6. // https://opensource.org/licenses/BSD-3-Clause
  7. //
  8. // Unless required by applicable law or agreed to in writing, software distributed
  9. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  10. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. // specific language governing permissions and limitations under the License.
  12. #include "testutil.h"
  13. static int test_cumulativesum(const ncnn::Mat& a, int axis)
  14. {
  15. ncnn::ParamDict pd;
  16. pd.set(0, axis);
  17. std::vector<ncnn::Mat> weights(0);
  18. int ret = test_layer("CumulativeSum", pd, weights, a);
  19. if (ret != 0)
  20. {
  21. fprintf(stderr, "test_cumulativesum failed a.dims=%d a=(%d %d %d) axis=%d\n", a.dims, a.w, a.h, a.c, axis);
  22. }
  23. return ret;
  24. }
  25. static int test_cumulativesum_1d()
  26. {
  27. return 0
  28. || test_cumulativesum(RandomMat(6), 0)
  29. || test_cumulativesum(RandomMat(10), 0)
  30. || test_cumulativesum(RandomMat(10), -1)
  31. || test_cumulativesum(RandomMat(10), -2)
  32. || test_cumulativesum(RandomMat(101), 0);
  33. }
  34. static int test_cumulativesum_2d()
  35. {
  36. return 0
  37. || test_cumulativesum(RandomMat(6, 8), 0)
  38. || test_cumulativesum(RandomMat(20, 103), 1)
  39. || test_cumulativesum(RandomMat(106, 50), -1)
  40. || test_cumulativesum(RandomMat(106, 50), -2);
  41. }
  42. static int test_cumulativesum_3d()
  43. {
  44. return 0
  45. || test_cumulativesum(RandomMat(10, 6, 8), 0)
  46. || test_cumulativesum(RandomMat(303, 20, 103), 1)
  47. || test_cumulativesum(RandomMat(106, 50, 99), 2)
  48. || test_cumulativesum(RandomMat(303, 200, 103), -1)
  49. || test_cumulativesum(RandomMat(303, 200, 103), -2)
  50. || test_cumulativesum(RandomMat(303, 200, 103), -2);
  51. }
  52. int main()
  53. {
  54. SRAND(7767517);
  55. return 0
  56. || test_cumulativesum_1d()
  57. || test_cumulativesum_2d()
  58. || test_cumulativesum_3d();
  59. }