Elffuss BraidHub

kikocis/ncnn public

master · 2.1 KiBRawPermalink
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
13#include "testutil.h"
14
15static int test_cumulativesum(const ncnn::Mat& a, int axis)
16{
17 ncnn::ParamDict pd;
18 pd.set(0, axis);
19
20 std::vector<ncnn::Mat> weights(0);
21
22 int ret = test_layer("CumulativeSum", pd, weights, a);
23 if (ret != 0)
24 {
25 fprintf(stderr, "test_cumulativesum failed a.dims=%d a=(%d %d %d) axis=%d\n", a.dims, a.w, a.h, a.c, axis);
26 }
27
28 return ret;
29}
30
31static int test_cumulativesum_1d()
32{
33 return 0
34 || test_cumulativesum(RandomMat(6), 0)
35 || test_cumulativesum(RandomMat(10), 0)
36 || test_cumulativesum(RandomMat(10), -1)
37 || test_cumulativesum(RandomMat(10), -2)
38 || test_cumulativesum(RandomMat(101), 0);
39}
40
41static int test_cumulativesum_2d()
42{
43 return 0
44 || test_cumulativesum(RandomMat(6, 8), 0)
45 || test_cumulativesum(RandomMat(20, 103), 1)
46 || test_cumulativesum(RandomMat(106, 50), -1)
47 || test_cumulativesum(RandomMat(106, 50), -2);
48}
49
50static int test_cumulativesum_3d()
51{
52 return 0
53 || test_cumulativesum(RandomMat(10, 6, 8), 0)
54 || test_cumulativesum(RandomMat(303, 20, 103), 1)
55 || test_cumulativesum(RandomMat(106, 50, 99), 2)
56 || test_cumulativesum(RandomMat(303, 200, 103), -1)
57 || test_cumulativesum(RandomMat(303, 200, 103), -2)
58 || test_cumulativesum(RandomMat(303, 200, 103), -2);
59}
60
61int main()
62{
63 SRAND(7767517);
64
65 return 0
66 || test_cumulativesum_1d()
67 || test_cumulativesum_2d()
68 || test_cumulativesum_3d();
69}