Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ae256454
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看板
未验证
提交
ae256454
编写于
11月 22, 2022
作者:
C
ccrrong
提交者:
GitHub
11月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove isfinite and has_nan (#48046)
上级
d389ddb5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
0 addition
and
86 deletion
+0
-86
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+0
-64
python/paddle/fluid/tests/unittests/test_isfinite_op.py
python/paddle/fluid/tests/unittests/test_isfinite_op.py
+0
-22
未找到文件。
python/paddle/fluid/layers/tensor.py
浏览文件 @
ae256454
...
...
@@ -64,8 +64,6 @@ __all__ = [
'zeros'
,
'reverse'
,
'has_inf'
,
'has_nan'
,
'isfinite'
,
'linspace'
,
'zeros_like'
,
'ones_like'
,
...
...
@@ -1572,68 +1570,6 @@ def has_inf(x):
return
out
def
has_nan
(
x
):
"""
Test if any of x contains a NAN
Args:
x (Tensor): The Tensor to be checked.
Returns:
Tensor: The tensor variable storing the output, only a bool value, indicating that whether there is NAN in x or not.
Examples:
.. code-block:: python
import paddle
data = paddle.randn(shape=[2,3], dtype="float32")
res = paddle.fluid.layers.has_nan(data)
# [False]
"""
if
_non_static_mode
():
return
_legacy_C_ops
.
isnan
(
x
)
check_type
(
x
,
'x'
,
(
Variable
),
'has_nan'
)
helper
=
LayerHelper
(
"isnan"
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
"isnan"
,
inputs
=
{
"X"
:
x
},
outputs
=
{
"Out"
:
out
})
return
out
def
isfinite
(
x
):
"""
Test if any of x contains an infinity/NAN number. If all the elements are finite,
returns true, else false.
Args:
x(Tensor): The Tensor to be checked.
Returns:
Tensor: The tensor storing the output, contains a bool value.
Examples:
.. code-block:: python
import paddle
x = paddle.rand(shape=[4, 6], dtype='float32')
y = paddle.fluid.layers.isfinite(x)
print(y)
"""
check_variable_and_dtype
(
x
,
"x"
,
[
"float32"
,
"float64"
,
"int32"
,
"int64"
],
"isfinite"
)
helper
=
LayerHelper
(
"isfinite"
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
'bool'
)
helper
.
append_op
(
type
=
"isfinite"
,
inputs
=
{
"X"
:
x
},
outputs
=
{
"Out"
:
out
})
return
out
def
linspace
(
start
,
stop
,
num
,
dtype
=
None
,
name
=
None
):
r
"""
This OP return fixed number of evenly spaced values within a given interval.
...
...
python/paddle/fluid/tests/unittests/test_isfinite_op.py
浏览文件 @
ae256454
...
...
@@ -40,20 +40,6 @@ class TestInf(OpTest):
self
.
check_output
()
class
TestRaiseError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_type
():
fluid
.
layers
.
isfinite
([
10
])
self
.
assertRaises
(
TypeError
,
test_type
)
def
test_dtype
():
data
=
fluid
.
data
(
shape
=
[
10
],
dtype
=
"float16"
,
name
=
"input"
)
fluid
.
layers
.
isfinite
(
data
)
self
.
assertRaises
(
TypeError
,
test_dtype
)
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
(),
"core is not compiled with CUDA"
)
...
...
@@ -129,19 +115,11 @@ class BadInputTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
test_has_inf_bad_x
)
def
test_has_nan_bad_x
():
data
=
[
1
,
2
,
3
]
result
=
fluid
.
layers
.
has_nan
(
data
)
self
.
assertRaises
(
TypeError
,
test_has_nan_bad_x
)
with
fluid
.
dygraph
.
guard
():
data
=
paddle
.
zeros
([
2
,
3
])
result
=
paddle
.
fluid
.
layers
.
has_inf
(
data
)
expect_value
=
np
.
array
([
False
])
self
.
assertEqual
((
result
.
numpy
()
==
expect_value
).
all
(),
True
)
result
=
paddle
.
fluid
.
layers
.
has_nan
(
data
)
self
.
assertEqual
((
result
.
numpy
()
==
expect_value
).
all
(),
True
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录