FFmpeg
dnn-layer-mathunary-test.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <math.h>
25 #include "libavutil/avassert.h"
26 
27 #define EPS 0.00001
28 
29 static float get_expected(float f, DNNMathUnaryOperation op)
30 {
31  switch (op)
32  {
33  case DMUO_ABS:
34  return (f >= 0) ? f : -f;
35  default:
36  av_assert0(!"not supported yet");
37  return 0.f;
38  }
39 }
40 
42 {
44  DnnOperand operands[2];
45  int32_t input_indexes[1];
46  float input[1*1*2*3] = {
47  -3, 2.5, 2, -2.1, 7.8, 100};
48  float *output;
49 
50  params.un_op = op;
51 
52  operands[0].data = input;
53  operands[0].dims[0] = 1;
54  operands[0].dims[1] = 1;
55  operands[0].dims[2] = 2;
56  operands[0].dims[3] = 3;
57  operands[1].data = NULL;
58 
59  input_indexes[0] = 0;
60  dnn_execute_layer_math_unary(operands, input_indexes, 1, &params);
61 
62  output = operands[1].data;
63  for (int i = 0; i < sizeof(input) / sizeof(float); ++i) {
64  float expected_output = get_expected(input[i], op);
65  if(fabs(output[i] - expected_output) > EPS) {
66  printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
67  av_freep(&output);
68  return 1;
69  }
70  }
71 
72  av_freep(&output);
73  return 0;
74 }
75 
76 int main(int agrc, char **argv)
77 {
78  if (test(DMUO_ABS))
79  return 1;
80  return 0;
81 }
dnn_backend_native_layer_mathunary.h
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
DnnLayerMathUnaryParams::un_op
DNNMathUnaryOperation un_op
Definition: dnn_backend_native_layer_mathunary.h:38
avassert.h
op
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:75
DnnOperand::data
void * data
data pointer with data length in bytes.
Definition: dnn_backend_native.h:98
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
f
#define f(width, name)
Definition: cbs_vp9.c:255
int32_t
int32_t
Definition: audio_convert.c:194
NULL
#define NULL
Definition: coverity.c:32
test
static int test(DNNMathUnaryOperation op)
Definition: dnn-layer-mathunary-test.c:41
DnnOperand::dims
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
Definition: dnn_backend_native.h:68
printf
printf("static const uint8_t my_array[100] = {\n")
EPS
#define EPS
Definition: dnn-layer-mathunary-test.c:27
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
DnnLayerMathUnaryParams
Definition: dnn_backend_native_layer_mathunary.h:37
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
get_expected
static float get_expected(float f, DNNMathUnaryOperation op)
Definition: dnn-layer-mathunary-test.c:29
DNNMathUnaryOperation
DNNMathUnaryOperation
Definition: dnn_backend_native_layer_mathunary.h:32
DnnOperand
Definition: dnn_backend_native.h:63
main
int main(int agrc, char **argv)
Definition: dnn-layer-mathunary-test.c:76
DMUO_ABS
@ DMUO_ABS
Definition: dnn_backend_native_layer_mathunary.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
dnn_execute_layer_math_unary
int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters)
Definition: dnn_backend_native_layer_mathunary.c:53