Elffuss BraidHub

kikocis/ncnn public

master · 2.6 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2023 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
15#include "testutil.h"
16
17static int test_celu(const ncnn::Mat& a, float alpha)
18{
19 ncnn::ParamDict pd;
20 pd.set(0, alpha);
21
22 std::vector<ncnn::Mat> weights(0);
23
24 int ret = test_layer("CELU", pd, weights, a);
25 if (ret != 0)
26 {
27 fprintf(stderr, "test_celu failed a.dims=%d a=(%d %d %d %d) alpha=%f\n", a.dims, a.w, a.h, a.d, a.c, alpha);
28 }
29
30 return ret;
31}
32
33static int test_celu_0()
34{
35 return 0
36 || test_celu(RandomMat(3, 8, 12, 18), 1.f)
37 || test_celu(RandomMat(4, 7, 9, 16), 0.1f)
38 || test_celu(RandomMat(3, 5, 12, 16), 1.f)
39 || test_celu(RandomMat(9, 6, 7, 14), 0.1f)
40 || test_celu(RandomMat(5, 6, 9, 10), 1.f)
41 || test_celu(RandomMat(6, 8, 2, 15), 0.1f);
42}
43
44static int test_celu_1()
45{
46 return 0
47 || test_celu(RandomMat(7, 6, 18), 1.f)
48 || test_celu(RandomMat(9, 6, 15), 0.1f)
49 || test_celu(RandomMat(9, 7, 16), 1.f)
50 || test_celu(RandomMat(6, 10, 15), 0.1f)
51 || test_celu(RandomMat(2, 7, 11), 1.f)
52 || test_celu(RandomMat(6, 10, 7), 0.1f);
53}
54
55static int test_celu_2()
56{
57 return 0
58 || test_celu(RandomMat(12, 18), 1.f)
59 || test_celu(RandomMat(18, 12), 0.1f)
60 || test_celu(RandomMat(23, 27), 1.f)
61 || test_celu(RandomMat(18, 16), 0.1f)
62 || test_celu(RandomMat(18, 16), 1.f)
63 || test_celu(RandomMat(20, 16), 0.1f);
64}
65
66static int test_celu_3()
67{
68 return 0
69 || test_celu(RandomMat(256), 1.f)
70 || test_celu(RandomMat(64), 0.1f)
71 || test_celu(RandomMat(128), 1.f)
72 || test_celu(RandomMat(96), 0.1f)
73 || test_celu(RandomMat(128), 1.f)
74 || test_celu(RandomMat(128), 0.1f);
75}
76
77int main()
78{
79 SRAND(7767517);
80
81 return 0
82 || test_celu_0()
83 || test_celu_1()
84 || test_celu_2()
85 || test_celu_3();
86}