ncnn
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
15#include "testutil.h"16
17#define OP_TYPE_MAX 2018
19static int op_type = 0;20
21static int test_unaryop(const ncnn::Mat& _a)22{
23ncnn::Mat a = _a;24if (op_type == 2 || op_type == 3)25{26// large dynamic range for floor ceil27for (int i = 0; i < a.total(); i++)28{29a[i] *= 1000;30}31}32if (op_type == 5 || op_type == 6 || op_type == 8 || op_type == 17)33{34// value must be positive for sqrt rsqrt log35Randomize(a, 0.001f, 2.f);36}37if (op_type == 11 || op_type == 12 || op_type == 13)38{39// smaller range for tan asin acos40Randomize(a, -1.f, 1.f);41}42
43ncnn::ParamDict pd;44pd.set(0, op_type);45
46std::vector<ncnn::Mat> weights(0);47
48int ret = test_layer("UnaryOp", pd, weights, a);49if (ret != 0)50{51fprintf(stderr, "test_unaryop failed a.dims=%d a=(%d %d %d %d) op_type=%d\n", a.dims, a.w, a.h, a.d, a.c, op_type);52}53
54return ret;55}
56
57static int test_unaryop_0()58{
59return 060|| test_unaryop(RandomMat(11, 3, 2, 16))61|| test_unaryop(RandomMat(10, 2, 2, 12))62|| test_unaryop(RandomMat(6, 1, 5, 13));63}
64
65static int test_unaryop_1()66{
67return 068|| test_unaryop(RandomMat(11, 7, 16))69|| test_unaryop(RandomMat(10, 4, 12))70|| test_unaryop(RandomMat(6, 5, 13));71}
72
73static int test_unaryop_2()74{
75return 076|| test_unaryop(RandomMat(12, 16))77|| test_unaryop(RandomMat(10, 12))78|| test_unaryop(RandomMat(14, 15));79}
80
81static int test_unaryop_3()82{
83return 084|| test_unaryop(RandomMat(128))85|| test_unaryop(RandomMat(12))86|| test_unaryop(RandomMat(15));87}
88
89int main()90{
91SRAND(7767517);92
93for (op_type = 0; op_type < OP_TYPE_MAX; op_type++)94{95int ret = 096|| test_unaryop_0()97|| test_unaryop_1()98|| test_unaryop_2()99|| test_unaryop_3();100
101if (ret != 0)102return ret;103}104
105return 0;106}
107