Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1e6e5ac6
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1e6e5ac6
编写于
1月 15, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test
上级
f5cd9619
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
214 addition
and
0 deletion
+214
-0
python/paddle/v2/fluid/tests/test_elementwise_max_op.py
python/paddle/v2/fluid/tests/test_elementwise_max_op.py
+107
-0
python/paddle/v2/fluid/tests/test_elementwise_min_op.py
python/paddle/v2/fluid/tests/test_elementwise_min_op.py
+107
-0
未找到文件。
python/paddle/v2/fluid/tests/test_elementwise_max_op.py
0 → 100644
浏览文件 @
1e6e5ac6
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
class
TestElementwiseOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
# If x and y have the same value, the max() is not differentiable.
# So we generate test data by the following method
# to avoid them being too close to each other.
x
=
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
[
13
,
17
]).
astype
(
"float32"
)
y
=
x
+
sgn
*
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad_normal
(
self
):
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
,
max_relative_error
=
0.005
)
def
test_check_grad_ingore_x
(
self
):
self
.
check_grad
(
[
'Y'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
"X"
))
def
test_check_grad_ingore_y
(
self
):
self
.
check_grad
(
[
'X'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
'Y'
))
class
TestElementwiseMaxOp_Vector
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
x
=
np
.
random
.
random
((
32
,
)).
astype
(
"float32"
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
32
,
)).
astype
(
"float32"
)
y
=
x
+
sgn
*
np
.
random
.
uniform
(
0.1
,
1
,
(
32
,
)).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
class
TestElementwiseMaxOp_broadcast_0
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
2
,
)).
astype
(
np
.
float32
)
y
=
x
[:,
0
,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
2
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
0
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
2
,
1
,
1
))
}
class
TestElementwiseMaxOp_broadcast_1
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
3
,
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
:,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
3
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
3
,
1
))
}
class
TestElementwiseMaxOp_broadcast_2
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
4
,
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
0
,
:]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
4
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
1
,
4
))
}
class
TestElementwiseMaxOp_broadcast_3
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_max"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
,
5
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
3
,
4
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
:,
:,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
3
,
4
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
3
,
4
,
1
))
}
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/v2/fluid/tests/test_elementwise_min_op.py
0 → 100644
浏览文件 @
1e6e5ac6
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
class
TestElementwiseOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
# If x and y have the same value, the max() is not differentiable.
# So we generate test data by the following method
# to avoid them being too close to each other.
x
=
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
[
13
,
17
]).
astype
(
"float32"
)
y
=
x
+
sgn
*
np
.
random
.
uniform
(
0.1
,
1
,
[
13
,
17
]).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad_normal
(
self
):
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
,
max_relative_error
=
0.005
)
def
test_check_grad_ingore_x
(
self
):
self
.
check_grad
(
[
'Y'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
"X"
))
def
test_check_grad_ingore_y
(
self
):
self
.
check_grad
(
[
'X'
],
'Out'
,
max_relative_error
=
0.005
,
no_grad_set
=
set
(
'Y'
))
class
TestElementwiseMaxOp_Vector
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
x
=
np
.
random
.
random
((
32
,
)).
astype
(
"float32"
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
32
,
)).
astype
(
"float32"
)
y
=
x
+
sgn
*
np
.
random
.
uniform
(
0.1
,
1
,
(
32
,
)).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
class
TestElementwiseMaxOp_broadcast_0
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
2
,
)).
astype
(
np
.
float32
)
y
=
x
[:,
0
,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
2
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
0
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
2
,
1
,
1
))
}
class
TestElementwiseMaxOp_broadcast_1
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
3
,
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
:,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
3
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
3
,
1
))
}
class
TestElementwiseMaxOp_broadcast_2
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
4
,
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
0
,
:]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
4
,
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
1
,
4
))
}
class
TestElementwiseMaxOp_broadcast_3
(
TestElementwiseOp
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_min"
x
=
np
.
random
.
uniform
(
0.5
,
1
,
(
2
,
3
,
4
,
5
)).
astype
(
np
.
float32
)
sgn
=
np
.
random
.
choice
([
-
1
,
1
],
(
3
,
4
)).
astype
(
np
.
float32
)
y
=
x
[
0
,
:,
:,
0
]
+
sgn
*
\
np
.
random
.
uniform
(
1
,
2
,
(
3
,
4
)).
astype
(
np
.
float32
)
self
.
inputs
=
{
'X'
:
x
,
'Y'
:
y
}
self
.
attrs
=
{
'axis'
:
1
}
self
.
outputs
=
{
'Out'
:
np
.
minimum
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
].
reshape
(
1
,
3
,
4
,
1
))
}
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录