|
| 1 | +// Copyright 2026 ihb2032 <hebome@foxmail.com> |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +#include "testutil.h" |
| 5 | + |
| 6 | +static int test_log(const ncnn::Mat& a, float base, float scale, float shift) |
| 7 | +{ |
| 8 | + ncnn::ParamDict pd; |
| 9 | + pd.set(0, base); |
| 10 | + pd.set(1, scale); |
| 11 | + pd.set(2, shift); |
| 12 | + |
| 13 | + std::vector<ncnn::Mat> weights(0); |
| 14 | + |
| 15 | + int ret = test_layer("Log", pd, weights, a); |
| 16 | + if (ret != 0) |
| 17 | + { |
| 18 | + fprintf(stderr, "test_log failed a.dims=%d a=(%d %d %d %d) base=%f scale=%f shift=%f\n", a.dims, a.w, a.h, a.d, a.c, base, scale, shift); |
| 19 | + } |
| 20 | + |
| 21 | + return ret; |
| 22 | +} |
| 23 | + |
| 24 | +static int test_log_0() |
| 25 | +{ |
| 26 | + return 0 |
| 27 | + || test_log(RandomMat(5, 7, 24, 0.001f, 2.f), -1.f, 1.f, 0.f) |
| 28 | + || test_log(RandomMat(7, 9, 12, 0.001f, 2.f), -1.f, 0.75f, 0.25f) |
| 29 | + || test_log(RandomMat(3, 5, 13, 0.001f, 2.f), 2.f, 0.5f, 0.125f); |
| 30 | +} |
| 31 | + |
| 32 | +static int test_log_1() |
| 33 | +{ |
| 34 | + return 0 |
| 35 | + || test_log(RandomMat(15, 24, 0.001f, 2.f), -1.f, 1.f, 0.f) |
| 36 | + || test_log(RandomMat(17, 12, 0.001f, 2.f), -1.f, 1.25f, 0.5f) |
| 37 | + || test_log(RandomMat(19, 15, 0.001f, 2.f), 2.f, 0.75f, 0.25f); |
| 38 | +} |
| 39 | + |
| 40 | +static int test_log_2() |
| 41 | +{ |
| 42 | + return 0 |
| 43 | + || test_log(RandomMat(128, 0.001f, 2.f), -1.f, 1.f, 0.f) |
| 44 | + || test_log(RandomMat(124, 0.001f, 2.f), -1.f, 0.5f, 0.25f) |
| 45 | + || test_log(RandomMat(127, 0.001f, 2.f), 2.f, 1.5f, 0.125f); |
| 46 | +} |
| 47 | + |
| 48 | +int main() |
| 49 | +{ |
| 50 | + SRAND(7767517); |
| 51 | + |
| 52 | + return 0 |
| 53 | + || test_log_0() |
| 54 | + || test_log_1() |
| 55 | + || test_log_2(); |
| 56 | +} |
0 commit comments