Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bc3e9ba1
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看板
未验证
提交
bc3e9ba1
编写于
9月 14, 2020
作者:
L
lilong12
提交者:
GitHub
9月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check the validation of parameters for expand and tile apis (#26816)
* bug fix, test=develop
上级
a6854359
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
4 deletion
+35
-4
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+35
-4
未找到文件。
python/paddle/tensor/manipulation.py
浏览文件 @
bc3e9ba1
...
@@ -21,6 +21,7 @@ from ..fluid.data_feeder import convert_dtype, check_variable_and_dtype, check_t
...
@@ -21,6 +21,7 @@ from ..fluid.data_feeder import convert_dtype, check_variable_and_dtype, check_t
from
..fluid.layers.tensor
import
fill_constant
from
..fluid.layers.tensor
import
fill_constant
from
..fluid.layers
import
utils
from
..fluid.layers
import
utils
import
numpy
as
np
import
numpy
as
np
import
six
# TODO: define functions to manipulate a tensor
# TODO: define functions to manipulate a tensor
from
..fluid.layers
import
cast
#DEFINE_ALIAS
from
..fluid.layers
import
cast
#DEFINE_ALIAS
from
..fluid.layers
import
slice
#DEFINE_ALIAS
from
..fluid.layers
import
slice
#DEFINE_ALIAS
...
@@ -1056,10 +1057,25 @@ def tile(x, repeat_times, name=None):
...
@@ -1056,10 +1057,25 @@ def tile(x, repeat_times, name=None):
"""
"""
if
in_dygraph_mode
():
if
in_dygraph_mode
():
return
core
.
ops
.
tile
(
x
,
'repeat_times'
,
repeat_times
)
return
core
.
ops
.
tile
(
x
,
'repeat_times'
,
repeat_times
)
check_type
(
repeat_times
,
'repeat_times'
,
(
list
,
tuple
,
Variable
),
'tile'
)
if
isinstance
(
repeat_times
,
Variable
):
assert
len
(
repeat_times
.
shape
)
==
1
,
(
'repeat_times must be an 1-D Tensor.'
)
else
:
for
elem
in
repeat_times
:
if
isinstance
(
elem
,
Variable
):
assert
len
(
elem
.
shape
)
==
1
,
(
'Elements in repeat_times must be 1-D Tensors or integers.'
)
else
:
if
six
.
PY3
:
type_tuple
=
(
int
,
np
.
int32
,
np
.
int64
)
elif
six
.
PY2
:
type_tuple
=
(
int
,
long
,
np
.
int32
,
np
.
int64
)
assert
isinstance
(
elem
,
type_tuple
),
(
'Elements in repeat_times must be 1-D Tensors or integers.'
)
check_variable_and_dtype
(
check_variable_and_dtype
(
x
,
'x'
,
[
'bool'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'tile'
)
x
,
'x'
,
[
'bool'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'tile'
)
check_type
(
repeat_times
,
'repeat_times'
,
(
list
,
tuple
,
Variable
),
'tile'
)
if
convert_dtype
(
x
.
dtype
)
==
'bool'
and
x
.
stop_gradient
==
False
:
if
convert_dtype
(
x
.
dtype
)
==
'bool'
and
x
.
stop_gradient
==
False
:
raise
ValueError
(
raise
ValueError
(
"When the date type is bool for the input 'x' of tile op, you "
"When the date type is bool for the input 'x' of tile op, you "
...
@@ -1181,18 +1197,33 @@ def expand(x, shape, name=None):
...
@@ -1181,18 +1197,33 @@ def expand(x, shape, name=None):
if
in_dygraph_mode
():
if
in_dygraph_mode
():
return
core
.
ops
.
expand_v2
(
x
,
'shape'
,
shape
)
return
core
.
ops
.
expand_v2
(
x
,
'shape'
,
shape
)
if
isinstance
(
shape
,
Variable
):
assert
len
(
shape
.
shape
)
==
1
,
(
'shape must be an 1-D Tensor.'
)
else
:
for
elem
in
shape
:
if
isinstance
(
elem
,
Variable
):
assert
len
(
elem
.
shape
)
==
1
,
(
'Elements in shape must be 1-D Tensors or integers.'
)
else
:
if
six
.
PY3
:
type_tuple
=
(
int
,
np
.
int32
,
np
.
int64
)
elif
six
.
PY2
:
type_tuple
=
(
int
,
long
,
np
.
int32
,
np
.
int64
)
assert
isinstance
(
elem
,
type_tuple
),
(
'Elements in shape must be 1-D Tensors or integers.'
)
check_variable_and_dtype
(
check_variable_and_dtype
(
x
,
'x'
,
[
'bool'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'expand'
)
x
,
'x'
,
[
'bool'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'expand'
)
check_type
(
shape
,
'shape'
,
(
list
,
tuple
,
Variable
),
'expand'
)
check_type
(
shape
,
'shape'
,
(
list
,
tuple
,
Variable
),
'expand'
)
inputs
=
{
"X"
:
[
x
]}
attrs
=
{}
if
convert_dtype
(
x
.
dtype
)
==
'bool'
and
x
.
stop_gradient
==
False
:
if
convert_dtype
(
x
.
dtype
)
==
'bool'
and
x
.
stop_gradient
==
False
:
raise
ValueError
(
"When the data type of input 'x' for expand is bool, "
raise
ValueError
(
"When the data type of input 'x' for expand is bool, "
"you must set its stop_gradient to be False by "
"you must set its stop_gradient to be False by "
"some_var.stop_gradient = True, supporting "
"some_var.stop_gradient = True, supporting "
"some_var as the input."
)
"some_var as the input."
)
inputs
=
{
"X"
:
[
x
]}
attrs
=
{}
helper
=
LayerHelper
(
'expand'
,
**
locals
())
helper
=
LayerHelper
(
'expand'
,
**
locals
())
def
get_attr_expand_shape
(
list_expand_shape
):
def
get_attr_expand_shape
(
list_expand_shape
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录