Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
17006196
Commit
17006196
authored
Apr 10, 2020
by
Guo, Yejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnn-layer-mathbinary-test: add unit test for add
Signed-off-by:
Guo, Yejun
<
yejun.guo@intel.com
>
parent
6aa7e07e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
17 deletions
+38
-17
dnn-layer-mathbinary-test.c
tests/dnn/dnn-layer-mathbinary-test.c
+38
-17
No files found.
tests/dnn/dnn-layer-mathbinary-test.c
View file @
17006196
...
...
@@ -22,10 +22,25 @@
#include <string.h>
#include <math.h>
#include "libavfilter/dnn/dnn_backend_native_layer_mathbinary.h"
#include "libavutil/avassert.h"
#define EPSON 0.00001
static
int
test_sub_broadcast_input0
(
void
)
static
float
get_expected
(
float
f1
,
float
f2
,
DNNMathBinaryOperation
op
)
{
switch
(
op
)
{
case
DMBO_SUB
:
return
f1
-
f2
;
case
DMBO_ADD
:
return
f1
+
f2
;
default:
av_assert0
(
!
"not supported yet"
);
return
0
.
f
;
}
}
static
int
test_broadcast_input0
(
DNNMathBinaryOperation
op
)
{
DnnLayerMathBinaryParams
params
;
DnnOperand
operands
[
2
];
...
...
@@ -35,7 +50,7 @@ static int test_sub_broadcast_input0(void)
};
float
*
output
;
params
.
bin_op
=
DMBO_SUB
;
params
.
bin_op
=
op
;
params
.
input0_broadcast
=
1
;
params
.
input1_broadcast
=
0
;
params
.
v
=
7
.
28
;
...
...
@@ -52,9 +67,10 @@ static int test_sub_broadcast_input0(void)
output
=
operands
[
1
].
data
;
for
(
int
i
=
0
;
i
<
sizeof
(
input
)
/
sizeof
(
float
);
i
++
)
{
float
expected_output
=
params
.
v
-
input
[
i
]
;
float
expected_output
=
get_expected
(
params
.
v
,
input
[
i
],
op
)
;
if
(
fabs
(
output
[
i
]
-
expected_output
)
>
EPSON
)
{
printf
(
"at index %d, output: %f, expected_output: %f
\n
"
,
i
,
output
[
i
],
expected_output
);
printf
(
"op %d, at index %d, output: %f, expected_output: %f (%s:%d)
\n
"
,
op
,
i
,
output
[
i
],
expected_output
,
__FILE__
,
__LINE__
);
av_freep
(
&
output
);
return
1
;
}
...
...
@@ -64,7 +80,7 @@ static int test_sub_broadcast_input0(void)
return
0
;
}
static
int
test_
sub_broadcast_input1
(
void
)
static
int
test_
broadcast_input1
(
DNNMathBinaryOperation
op
)
{
DnnLayerMathBinaryParams
params
;
DnnOperand
operands
[
2
];
...
...
@@ -74,7 +90,7 @@ static int test_sub_broadcast_input1(void)
};
float
*
output
;
params
.
bin_op
=
DMBO_SUB
;
params
.
bin_op
=
op
;
params
.
input0_broadcast
=
0
;
params
.
input1_broadcast
=
1
;
params
.
v
=
7
.
28
;
...
...
@@ -91,9 +107,10 @@ static int test_sub_broadcast_input1(void)
output
=
operands
[
1
].
data
;
for
(
int
i
=
0
;
i
<
sizeof
(
input
)
/
sizeof
(
float
);
i
++
)
{
float
expected_output
=
input
[
i
]
-
params
.
v
;
float
expected_output
=
get_expected
(
input
[
i
],
params
.
v
,
op
)
;
if
(
fabs
(
output
[
i
]
-
expected_output
)
>
EPSON
)
{
printf
(
"at index %d, output: %f, expected_output: %f
\n
"
,
i
,
output
[
i
],
expected_output
);
printf
(
"op %d, at index %d, output: %f, expected_output: %f (%s:%d)
\n
"
,
op
,
i
,
output
[
i
],
expected_output
,
__FILE__
,
__LINE__
);
av_freep
(
&
output
);
return
1
;
}
...
...
@@ -103,7 +120,7 @@ static int test_sub_broadcast_input1(void)
return
0
;
}
static
int
test_
sub_no_broadcast
(
void
)
static
int
test_
no_broadcast
(
DNNMathBinaryOperation
op
)
{
DnnLayerMathBinaryParams
params
;
DnnOperand
operands
[
3
];
...
...
@@ -116,7 +133,7 @@ static int test_sub_no_broadcast(void)
};
float
*
output
;
params
.
bin_op
=
DMBO_SUB
;
params
.
bin_op
=
op
;
params
.
input0_broadcast
=
0
;
params
.
input1_broadcast
=
0
;
...
...
@@ -138,9 +155,10 @@ static int test_sub_no_broadcast(void)
output
=
operands
[
2
].
data
;
for
(
int
i
=
0
;
i
<
sizeof
(
input0
)
/
sizeof
(
float
);
i
++
)
{
float
expected_output
=
input0
[
i
]
-
input1
[
i
]
;
float
expected_output
=
get_expected
(
input0
[
i
],
input1
[
i
],
op
)
;
if
(
fabs
(
output
[
i
]
-
expected_output
)
>
EPSON
)
{
printf
(
"at index %d, output: %f, expected_output: %f
\n
"
,
i
,
output
[
i
],
expected_output
);
printf
(
"op %d, at index %d, output: %f, expected_output: %f (%s:%d)
\n
"
,
op
,
i
,
output
[
i
],
expected_output
,
__FILE__
,
__LINE__
);
av_freep
(
&
output
);
return
1
;
}
...
...
@@ -150,15 +168,15 @@ static int test_sub_no_broadcast(void)
return
0
;
}
static
int
test
_sub
(
void
)
static
int
test
(
DNNMathBinaryOperation
op
)
{
if
(
test_
sub_broadcast_input0
(
))
if
(
test_
broadcast_input0
(
op
))
return
1
;
if
(
test_
sub_broadcast_input1
(
))
if
(
test_
broadcast_input1
(
op
))
return
1
;
if
(
test_
sub_no_broadcast
(
))
if
(
test_
no_broadcast
(
op
))
return
1
;
return
0
;
...
...
@@ -166,7 +184,10 @@ static int test_sub(void)
int
main
(
int
argc
,
char
**
argv
)
{
if
(
test_sub
())
if
(
test
(
DMBO_SUB
))
return
1
;
if
(
test
(
DMBO_ADD
))
return
1
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment