Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
de470ff9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
de470ff9
编写于
10月 14, 2019
作者:
Z
Zhaolong Xing
提交者:
Tao Luo
10月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine sqrt api check (#20257)
test=release/1.6
上级
ee0eeded
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
0 deletion
+29
-0
python/paddle/fluid/layers/layer_function_generator.py
python/paddle/fluid/layers/layer_function_generator.py
+13
-0
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+16
-0
未找到文件。
python/paddle/fluid/layers/layer_function_generator.py
浏览文件 @
de470ff9
...
...
@@ -22,6 +22,7 @@ from six.moves import cStringIO
from
..proto
import
framework_pb2
from
..framework
import
OpProtoHolder
,
Variable
,
core
,
convert_np_dtype_to_dtype_
from
..layer_helper
import
LayerHelper
from
..data_feeder
import
convert_dtype
__all__
=
[
'deprecated'
,
'generate_layer_fn'
,
'generate_activation_fn'
,
'autodoc'
,
...
...
@@ -250,6 +251,18 @@ def generate_activation_fn(op_type):
def
func
(
x
,
name
=
None
):
helper
=
LayerHelper
(
op_type
,
**
locals
())
if
not
isinstance
(
x
,
Variable
):
raise
TypeError
(
"The type of 'x' in %s must be Variable, but received %s"
%
(
op_type
,
type
(
x
)))
if
convert_dtype
(
x
.
dtype
)
in
[
'float16'
]:
warnings
.
warn
(
"The data type of 'x' in %s only support float16 in GPU now."
%
(
op_type
))
if
convert_dtype
(
x
.
dtype
)
not
in
[
'float16'
,
'float32'
,
'float64'
]:
raise
TypeError
(
"The data type of 'x' in %s must be float16 (only support on GPU), float32 or float64, but received %s."
%
(
op_type
,
convert_dtype
(
x
.
dtype
)))
output
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
op_type
,
inputs
=
{
"X"
:
x
},
outputs
=
{
"Out"
:
output
})
return
output
...
...
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
de470ff9
...
...
@@ -23,6 +23,22 @@ import paddle.fluid as fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
class
TestSqrtOpError
(
OpTest
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
# The input type of sqrt_op must be Variable or numpy.ndarray.
in1
=
1
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
sqrt
,
in1
)
# The input dtype of sqrt_op must be float16, float32, float64.
in2
=
fluid
.
layers
.
data
(
name
=
'input2'
,
shape
=
[
12
,
10
],
dtype
=
"int32"
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
sqrt
,
in2
)
in3
=
fluid
.
layers
.
data
(
name
=
'input3'
,
shape
=
[
12
,
10
],
dtype
=
"float16"
)
fluid
.
layers
.
sqrt
(
x
=
in3
)
class
TestActivation
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"exp"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录