未验证 提交 ae256454 编写于 作者: C ccrrong 提交者: GitHub

remove isfinite and has_nan (#48046)

上级 d389ddb5
......@@ -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.
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册