Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test_gammaincc_op fail #61122

Merged
merged 6 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from paddle import _C_ops
from paddle.base.libpaddle import DataType
from paddle.common_ops_import import VarDesc, dygraph_utils
from paddle.pir import Value
from paddle.utils.inplace_utils import inplace_apis_in_dygraph_only

from ..base.data_feeder import (
Expand Down Expand Up @@ -5126,11 +5127,15 @@ def gammaincc(x, y, name=None):
Tensor(shape=[5], dtype=float32, place=Place(cpu), stop_gradient=True,
[1. , 0.15729916, 0.00000774, 0. , 0. ])
"""
if not paddle.all(paddle.greater_equal(x, paddle.zeros_like(x))):
if not isinstance(x, Value) and not paddle.all(
paddle.greater_equal(x, paddle.zeros_like(x))
):
raise ValueError(
"The input argument x must be greater than or equal to 0."
)
if not paddle.all(paddle.greater_equal(y, paddle.zeros_like(y))):
if not isinstance(x, Value) and not paddle.all(
paddle.greater_equal(y, paddle.zeros_like(y))
):
raise ValueError(
"The input argument y must be greater than or equal to 0."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import numpy as np
from op_test import OpTest
from scipy import special
from utils import static_guard

import paddle
from paddle.base import core
Expand Down Expand Up @@ -69,54 +70,50 @@ def init_dtype_type(self):
self.dtype = "float64"

def test_static_api(self):
paddle.enable_static()
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.static.data('x', self.x_np.shape, self.x_np.dtype)
y = paddle.static.data('y', self.y_np.shape, self.y_np.dtype)
out = paddle.gammaincc(x, y)
exe = paddle.static.Executor(self.place)
(res,) = exe.run(
feed={'x': self.x_np, 'y': self.y_np}, fetch_list=[out]
)
out_ref = ref_gammaincc(self.x_np, self.y_np)
np.testing.assert_allclose(out_ref, res, rtol=1e-6, atol=1e-6)
with static_guard():
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.static.data('x', self.x_np.shape, self.x_np.dtype)
y = paddle.static.data('y', self.y_np.shape, self.y_np.dtype)
out = paddle.gammaincc(x, y)
exe = paddle.static.Executor(self.place)
(res,) = exe.run(
feed={'x': self.x_np, 'y': self.y_np}, fetch_list=[out]
)
out_ref = ref_gammaincc(self.x_np, self.y_np)
np.testing.assert_allclose(out_ref, res, rtol=1e-6, atol=1e-6)

def test_dygraph_api(self):
paddle.disable_static()
x = paddle.to_tensor(self.x_np)
y = paddle.to_tensor(self.y_np)
out = paddle.gammaincc(x, y)
out_ref = ref_gammaincc(self.x_np, self.y_np)
np.testing.assert_allclose(out_ref, out.numpy(), rtol=1e-6, atol=1e-6)

def test_x_le_zero_error(self):
paddle.disable_static()
x = paddle.to_tensor(self.x_np)
y = paddle.to_tensor(self.y_np)
x[0] = -1
self.assertRaises(ValueError, paddle.gammaincc, x, y)

def test_a_le_zero_error(self):
paddle.disable_static()
x = paddle.to_tensor(self.x_np)
y = paddle.to_tensor(self.y_np)
y[0] = -1
self.assertRaises(ValueError, paddle.gammaincc, x, y)

def test_dtype_error(self):
paddle.enable_static()
# in static graph mode
with self.assertRaises(TypeError):
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.static.data(
name="x", shape=self.shape, dtype="int32"
)
y = paddle.static.data(
name="y", shape=self.shape, dtype="int32"
)
out = paddle.gammaincc(x, y)
with static_guard():
# in static graph mode
with self.assertRaises(TypeError):
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.static.data(
name="x", shape=self.shape, dtype="int32"
)
y = paddle.static.data(
name="y", shape=self.shape, dtype="int32"
)
out = paddle.gammaincc(x, y)

paddle.disable_static()
# in dynamic mode
with self.assertRaises(RuntimeError):
with paddle.base.dygraph.guard():
Expand Down