Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
a30e3602
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看板
未验证
提交
a30e3602
编写于
12月 29, 2022
作者:
L
Lin Manhui
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add scale and floor_divide ut cases (#49418)
上级
3c2420a3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
111 addition
and
0 deletion
+111
-0
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
+76
-0
python/paddle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
...dle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
+35
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
浏览文件 @
a30e3602
...
...
@@ -712,6 +712,41 @@ class TestSundryAPI(unittest.TestCase):
self
.
assertEqual
(
out
.
numpy
()[
3
],
2
)
self
.
assertEqual
(
out
.
grad
.
shape
,
[
5
])
def
test_scale
(
self
):
x
=
paddle
.
rand
([])
x
.
stop_gradient
=
False
out
=
paddle
.
scale
(
x
,
scale
=
2.0
,
bias
=
1.0
)
out
.
backward
()
self
.
assertEqual
(
out
.
shape
,
[])
self
.
assertEqual
(
out
.
grad
.
shape
,
[])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
def
test_floor_divide
(
self
):
# 1-d // 0-d
x
=
paddle
.
to_tensor
([
1
,
-
2
,
3
],
dtype
=
"int64"
)
y
=
paddle
.
full
([],
2
,
dtype
=
'int64'
)
out1_1
=
paddle
.
floor_divide
(
x
,
y
)
out1_2
=
paddle
.
Tensor
.
__floordiv__
(
x
,
y
)
np
.
testing
.
assert_array_equal
(
out1_1
.
numpy
(),
out1_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out1_1
.
numpy
(),
np
.
asarray
([
0
,
-
1
,
1
]))
# 0-d // 1-d
out2_1
=
paddle
.
floor_divide
(
y
,
x
)
out2_2
=
paddle
.
Tensor
.
__floordiv__
(
y
,
x
)
np
.
testing
.
assert_array_equal
(
out2_1
.
numpy
(),
out2_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out2_2
.
numpy
(),
np
.
asarray
([
2
,
-
1
,
0
]))
# 0-d // 0-d
x
=
paddle
.
full
([],
3
,
dtype
=
'int64'
)
out3_1
=
paddle
.
floor_divide
(
x
,
y
)
out3_2
=
paddle
.
Tensor
.
__floordiv__
(
x
,
y
)
np
.
testing
.
assert_array_equal
(
out3_1
.
numpy
(),
out3_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out3_2
.
numpy
(),
np
.
asarray
(
1
))
class
TestSundryAPIStatic
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -914,6 +949,47 @@ class TestSundryAPIStatic(unittest.TestCase):
self
.
assertEqual
(
res
[
0
].
shape
,
(
5
,))
self
.
assertEqual
(
res
[
0
][
3
],
2
)
@
prog_scope
()
def
test_scale
(
self
):
x
=
paddle
.
rand
([])
x
.
stop_gradient
=
False
out
=
paddle
.
scale
(
x
,
scale
=
2.0
,
bias
=
1.0
)
paddle
.
static
.
append_backward
(
out
)
prog
=
paddle
.
static
.
default_main_program
()
res
=
self
.
exe
.
run
(
prog
,
fetch_list
=
[
out
])
self
.
assertEqual
(
res
[
0
].
shape
,
())
@
prog_scope
()
def
test_floor_divide
(
self
):
# 1-d // 0-d
x
=
paddle
.
to_tensor
([
1
,
-
2
,
3
],
dtype
=
"int64"
)
y
=
paddle
.
full
([],
2
,
dtype
=
'int64'
)
out1_1
=
paddle
.
floor_divide
(
x
,
y
)
out1_2
=
x
//
y
# 0-d // 1-d
out2_1
=
paddle
.
floor_divide
(
y
,
x
)
out2_2
=
y
//
x
# 0-d // 0-d
x
=
paddle
.
full
([],
3
,
dtype
=
'int64'
)
out3_1
=
paddle
.
floor_divide
(
x
,
y
)
out3_2
=
x
//
y
prog
=
paddle
.
static
.
default_main_program
()
res
=
self
.
exe
.
run
(
prog
,
fetch_list
=
[
out1_1
,
out1_2
,
out2_1
,
out2_2
,
out3_1
,
out3_2
]
)
out1_1
,
out1_2
,
out2_1
,
out2_2
,
out3_1
,
out3_2
=
res
np
.
testing
.
assert_array_equal
(
out1_1
,
out1_2
)
np
.
testing
.
assert_array_equal
(
out1_1
,
np
.
asarray
([
0
,
-
1
,
1
]))
np
.
testing
.
assert_array_equal
(
out2_1
,
out2_2
)
np
.
testing
.
assert_array_equal
(
out2_2
,
np
.
asarray
([
2
,
-
1
,
0
]))
np
.
testing
.
assert_array_equal
(
out3_1
,
out3_2
)
np
.
testing
.
assert_array_equal
(
out3_2
,
np
.
asarray
(
1
))
# Use to test API whose zero-dim input tensors don't have grad and not need to test backward in OpTest.
class
TestNoBackwardAPI
(
unittest
.
TestCase
):
...
...
python/paddle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
浏览文件 @
a30e3602
...
...
@@ -521,6 +521,41 @@ class TestSundryAPI(unittest.TestCase):
for
i
in
range
(
3
):
self
.
assertEqual
(
out
.
numpy
()[
1
][
i
],
updates
.
numpy
()[
i
])
def
test_scale
(
self
):
x
=
paddle
.
rand
([])
x
.
stop_gradient
=
False
out
=
paddle
.
scale
(
x
,
scale
=
2.0
,
bias
=
1.0
)
out
.
backward
()
self
.
assertEqual
(
out
.
shape
,
[])
self
.
assertEqual
(
out
.
grad
.
shape
,
[])
self
.
assertEqual
(
x
.
grad
.
shape
,
[])
def
test_floor_divide
(
self
):
# 1-d // 0-d
x
=
paddle
.
to_tensor
([
1
,
-
2
,
3
],
dtype
=
"int64"
)
y
=
paddle
.
full
([],
2
,
dtype
=
'int64'
)
out1_1
=
paddle
.
floor_divide
(
x
,
y
)
out1_2
=
paddle
.
Tensor
.
__floordiv__
(
x
,
y
)
np
.
testing
.
assert_array_equal
(
out1_1
.
numpy
(),
out1_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out1_1
.
numpy
(),
np
.
asarray
([
0
,
-
1
,
1
]))
# 0-d // 1-d
out2_1
=
paddle
.
floor_divide
(
y
,
x
)
out2_2
=
paddle
.
Tensor
.
__floordiv__
(
y
,
x
)
np
.
testing
.
assert_array_equal
(
out2_1
.
numpy
(),
out2_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out2_2
.
numpy
(),
np
.
asarray
([
2
,
-
1
,
0
]))
# 0-d // 0-d
x
=
paddle
.
full
([],
3
,
dtype
=
'int64'
)
out3_1
=
paddle
.
floor_divide
(
x
,
y
)
out3_2
=
paddle
.
Tensor
.
__floordiv__
(
x
,
y
)
np
.
testing
.
assert_array_equal
(
out3_1
.
numpy
(),
out3_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
out3_2
.
numpy
(),
np
.
asarray
(
1
))
# Use to test API whose zero-dim input tensors don't have grad and not need to test backward in OpTest.
class
TestNoBackwardAPI
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录