diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index d032b8cd20a7cc68108f48dae67760bc597ab430..ee7b764ad7b863eb925c1a180804099808098e69 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -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. diff --git a/python/paddle/fluid/tests/unittests/test_isfinite_op.py b/python/paddle/fluid/tests/unittests/test_isfinite_op.py index e2fa9f67b53312df45aef154a5d11ee61cac017e..cbe12d1cb3f4babb32e13fab0c55273f8efd44bc 100644 --- a/python/paddle/fluid/tests/unittests/test_isfinite_op.py +++ b/python/paddle/fluid/tests/unittests/test_isfinite_op.py @@ -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__':