Skip to content

Commit eaf0935

Browse files
committed
support __ne__ for unsupported type
1 parent bc8feee commit eaf0935

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

paddle/fluid/pybind/eager_math_op_patch.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,8 +2190,16 @@ static PyObject* tensor__ne__method(TensorObject* self,
21902190
other_tensor = paddle::empty({}, phi::DataType::FLOAT32, place);
21912191
InitTensorWithNumpyValue(numpy_value, place, &other_tensor);
21922192
} else {
2193-
paddle::experimental::Scalar value =
2194-
CastPyArg2Scalar(other_obj, "__ne__", 0);
2193+
paddle::experimental::Scalar value;
2194+
2195+
// return True if other_obj is unsupported type
2196+
try {
2197+
value = CastPyArg2Scalar(other_obj, "__ne__", 0);
2198+
} catch (const ::common::enforce::EnforceNotMet& e) {
2199+
Py_INCREF(Py_True);
2200+
return Py_True;
2201+
}
2202+
21952203
if (PyComplex_Check(other_obj)) {
21962204
eager_gil_scoped_release guard;
21972205
other_tensor =

0 commit comments

Comments
 (0)