Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
81030125
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
81030125
编写于
1月 03, 2020
作者:
M
mapingshuo
提交者:
GitHub
1月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
convert input vars' dtype for range op (#22028)
* convert dtype of vars for range op, test=develop
上级
95d79b6d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
2 deletion
+21
-2
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+15
-1
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+6
-1
未找到文件。
python/paddle/fluid/layers/tensor.py
浏览文件 @
81030125
...
@@ -1158,7 +1158,7 @@ def range(start, end, step, dtype):
...
@@ -1158,7 +1158,7 @@ def range(start, end, step, dtype):
it is a 1-D Tensor with shape [1].
it is a 1-D Tensor with shape [1].
step(float32 | float64 | int32 | int64 | Variable): Spacing between values. For any output out, this is the
step(float32 | float64 | int32 | int64 | Variable): Spacing between values. For any output out, this is the
distance between two adjacent values, out[i+1] - out[i].
distance between two adjacent values, out[i+1] - out[i].
dtype(str): the data type of the output tensor, can be float32, float64, int32, int64.
dtype(str
|core.VarDesc.VarType
): the data type of the output tensor, can be float32, float64, int32, int64.
Returns: a 1-D Tensor which is evenly spaced values within a given interval. Its data type is set by dtype.
Returns: a 1-D Tensor which is evenly spaced values within a given interval. Its data type is set by dtype.
...
@@ -1174,12 +1174,26 @@ def range(start, end, step, dtype):
...
@@ -1174,12 +1174,26 @@ def range(start, end, step, dtype):
"""
"""
helper
=
LayerHelper
(
"range"
,
**
locals
())
helper
=
LayerHelper
(
"range"
,
**
locals
())
check_dtype
(
dtype
,
'create data type'
,
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'range'
)
dtype
=
convert_dtype
(
dtype
)
if
not
isinstance
(
start
,
Variable
):
if
not
isinstance
(
start
,
Variable
):
start
=
fill_constant
([
1
],
dtype
,
start
)
start
=
fill_constant
([
1
],
dtype
,
start
)
elif
convert_dtype
(
start
.
dtype
)
!=
dtype
:
# make sure that start, end, step has the same dtype as
# `dtype`
start
=
cast
(
x
=
start
,
dtype
=
dtype
)
if
not
isinstance
(
end
,
Variable
):
if
not
isinstance
(
end
,
Variable
):
end
=
fill_constant
([
1
],
dtype
,
end
)
end
=
fill_constant
([
1
],
dtype
,
end
)
elif
convert_dtype
(
end
.
dtype
)
!=
dtype
:
end
=
cast
(
x
=
end
,
dtype
=
dtype
)
if
not
isinstance
(
step
,
Variable
):
if
not
isinstance
(
step
,
Variable
):
step
=
fill_constant
([
1
],
dtype
,
step
)
step
=
fill_constant
([
1
],
dtype
,
step
)
elif
convert_dtype
(
step
.
dtype
)
!=
dtype
:
step
=
cast
(
x
=
step
,
dtype
=
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
start
.
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
start
.
dtype
)
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
81030125
...
@@ -2561,7 +2561,12 @@ class TestBook(LayerTest):
...
@@ -2561,7 +2561,12 @@ class TestBook(LayerTest):
with
program_guard
(
fluid
.
default_main_program
(),
with
program_guard
(
fluid
.
default_main_program
(),
fluid
.
default_startup_program
()):
fluid
.
default_startup_program
()):
layers
.
range
(
0
,
10
,
2
,
'int32'
)
layers
.
range
(
0
,
10
,
2
,
'int32'
)
y
=
layers
.
range
(
0.1
,
10.0
,
0.2
,
'float32'
)
layers
.
range
(
0.1
,
10.0
,
0.2
,
'float32'
)
layers
.
range
(
0.1
,
10.0
,
0.2
,
'float64'
)
start
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.1
,
dtype
=
"float32"
)
end
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
10.0
,
dtype
=
"float32"
)
step
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0.2
,
dtype
=
"float32"
)
y
=
layers
.
range
(
start
,
end
,
step
,
'float64'
)
return
y
return
y
def
make_spectral_norm
(
self
):
def
make_spectral_norm
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录