From 921b0418d66aa742129b21ba5380e65eacaabda1 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Mon, 28 Jun 2021 15:44:17 +0800 Subject: [PATCH] PyNumber_Long only for numpy, test=develop (#33778) * PyNumber_Long only for numpy, test=develop --- paddle/fluid/pybind/op_function.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/pybind/op_function.h b/paddle/fluid/pybind/op_function.h index e0886ac144a..eaa70adcc89 100644 --- a/paddle/fluid/pybind/op_function.h +++ b/paddle/fluid/pybind/op_function.h @@ -209,11 +209,16 @@ inline bool PyObject_CheckLongOrToLong(PyObject** obj) { PyObject_IsInstance(*obj, (PyObject*)g_varbase_pytype)) { // NOLINT return true; } - auto to = PyNumber_Long(*obj); - if (to) { - *obj = to; - return true; + + if (std::string(((PyTypeObject*)(*obj)->ob_type)->tp_name) // NOLINT + .find("numpy") != std::string::npos) { + auto to = PyNumber_Long(*obj); + if (to) { + *obj = to; + return true; + } } + return false; } @@ -223,10 +228,13 @@ inline bool PyObject_CheckFloatOrToFloat(PyObject** obj) { PyObject_IsInstance(*obj, (PyObject*)g_varbase_pytype)) { // NOLINT return true; } - auto to = PyNumber_Float(*obj); - if (to) { - *obj = to; - return true; + if (std::string(((PyTypeObject*)(*obj)->ob_type)->tp_name) // NOLINT + .find("numpy") != std::string::npos) { + auto to = PyNumber_Float(*obj); + if (to) { + *obj = to; + return true; + } } return false; } -- GitLab