Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9872da00
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看板
未验证
提交
9872da00
编写于
4月 09, 2022
作者:
W
Weilong Wu
提交者:
GitHub
4月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Eager] Support allclose and linalg_cond to eager mode (#41545)
上级
b3b8d345
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
5 deletion
+27
-5
python/paddle/fluid/tests/unittests/test_allclose_layer.py
python/paddle/fluid/tests/unittests/test_allclose_layer.py
+8
-2
python/paddle/fluid/tests/unittests/test_linalg_cond.py
python/paddle/fluid/tests/unittests/test_linalg_cond.py
+19
-3
未找到文件。
python/paddle/fluid/tests/unittests/test_allclose_layer.py
浏览文件 @
9872da00
...
...
@@ -16,6 +16,7 @@ import paddle
import
paddle.fluid
as
fluid
import
unittest
import
numpy
as
np
from
paddle.fluid.framework
import
_test_eager_guard
class
TestAllcloseLayer
(
unittest
.
TestCase
):
...
...
@@ -95,7 +96,7 @@ class TestAllcloseLayer(unittest.TestCase):
with
fluid
.
program_guard
(
main
,
startup
):
self
.
allclose_check
(
use_cuda
=
True
,
dtype
=
'float64'
)
def
test
_dygraph_mode
(
self
):
def
func
_dygraph_mode
(
self
):
x_1
=
np
.
array
([
10000.
,
1e-07
]).
astype
(
"float32"
)
y_1
=
np
.
array
([
10000.1
,
1e-08
]).
astype
(
"float32"
)
x_2
=
np
.
array
([
10000.
,
1e-08
]).
astype
(
"float32"
)
...
...
@@ -171,9 +172,14 @@ class TestAllcloseLayer(unittest.TestCase):
x_v_5
=
paddle
.
to_tensor
(
x_5
)
y_v_5
=
paddle
.
to_tensor
(
y_5
)
ret_5
=
paddle
.
allclose
(
x_v_5
,
y_v_5
,
rtol
=
0.01
,
atol
=
0.0
,
name
=
'test_8'
)
x_v_5
,
y_v_5
,
rtol
=
0.01
5
,
atol
=
0.0
,
name
=
'test_8'
)
self
.
assertEqual
(
ret_5
.
numpy
()[
0
],
True
)
def
test_dygraph_mode
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_mode
()
self
.
func_dygraph_mode
()
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_linalg_cond.py
浏览文件 @
9872da00
...
...
@@ -18,6 +18,7 @@ import unittest
import
numpy
as
np
import
paddle
import
paddle.static
as
static
from
paddle.fluid.framework
import
_test_eager_guard
p_list_n_n
=
(
"fro"
,
"nuc"
,
1
,
-
1
,
np
.
inf
,
-
np
.
inf
)
p_list_m_n
=
(
None
,
2
,
-
2
)
...
...
@@ -89,16 +90,21 @@ class API_TestStaticCond(unittest.TestCase):
class
API_TestDygraphCond
(
unittest
.
TestCase
):
def
test
_out
(
self
):
def
func
_out
(
self
):
paddle
.
disable_static
()
# test calling results of 'cond' in dynamic mode
x_list_n_n
,
x_list_m_n
=
gen_input
()
test_dygraph_assert_true
(
self
,
x_list_n_n
,
p_list_n_n
+
p_list_m_n
)
test_dygraph_assert_true
(
self
,
x_list_m_n
,
p_list_m_n
)
def
test_out
(
self
):
with
_test_eager_guard
():
self
.
func_out
()
self
.
func_out
()
class
TestCondAPIError
(
unittest
.
TestCase
):
def
test
_dygraph_api_error
(
self
):
def
func
_dygraph_api_error
(
self
):
paddle
.
disable_static
()
# test raising errors when 'cond' is called in dygraph mode
p_list_error
=
(
'fro_'
,
'_nuc'
,
-
0.7
,
0
,
1.5
,
3
)
...
...
@@ -113,6 +119,11 @@ class TestCondAPIError(unittest.TestCase):
x_tensor
=
paddle
.
to_tensor
(
x
)
self
.
assertRaises
(
ValueError
,
paddle
.
linalg
.
cond
,
x_tensor
,
p
)
def
test_dygraph_api_error
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_api_error
()
self
.
func_dygraph_api_error
()
def
test_static_api_error
(
self
):
paddle
.
enable_static
()
# test raising errors when 'cond' is called in static mode
...
...
@@ -149,13 +160,18 @@ class TestCondAPIError(unittest.TestCase):
class
TestCondEmptyTensorInput
(
unittest
.
TestCase
):
def
test
_dygraph_empty_tensor_input
(
self
):
def
func
_dygraph_empty_tensor_input
(
self
):
paddle
.
disable_static
()
# test calling results of 'cond' when input is an empty tensor in dynamic mode
x_list_n_n
,
x_list_m_n
=
gen_empty_input
()
test_dygraph_assert_true
(
self
,
x_list_n_n
,
p_list_n_n
+
p_list_m_n
)
test_dygraph_assert_true
(
self
,
x_list_m_n
,
p_list_m_n
)
def
test_dygraph_empty_tensor_input
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_empty_tensor_input
()
self
.
func_dygraph_empty_tensor_input
()
if
__name__
==
"__main__"
:
paddle
.
enable_static
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录