| File: | home/liujun/Analysis/pyrefcon_ws/Paddle/build/paddle/fluid/pybind/../../../../paddle/fluid/pybind/op_function_common.cc | 
| Warning: | line 494, column 14 PyObject ownership leak with reference count of 1  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | |||
| 2 | // | |||
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| 4 | // you may not use this file except in compliance with the License. | |||
| 5 | // You may obtain a copy of the License at | |||
| 6 | // | |||
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 | |||
| 8 | // | |||
| 9 | // Unless required by applicable law or agreed to in writing, software | |||
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | |||
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| 12 | // See the License for the specific language governing permissions and | |||
| 13 | // limitations under the License. | |||
| 14 | ||||
| 15 | #include "paddle/fluid/pybind/op_function_common.h" | |||
| 16 | ||||
| 17 | #include <pybind11/chrono.h> | |||
| 18 | #include <pybind11/complex.h> | |||
| 19 | #include <pybind11/functional.h> | |||
| 20 | #include <pybind11/stl.h> | |||
| 21 | ||||
| 22 | #include <memory> | |||
| 23 | #include <string> | |||
| 24 | #include <vector> | |||
| 25 | ||||
| 26 | #include "paddle/fluid/framework/attribute.h" | |||
| 27 | #include "paddle/fluid/framework/op_info.h" | |||
| 28 | #include "paddle/fluid/framework/op_registry.h" | |||
| 29 | #include "paddle/fluid/framework/variable.h" | |||
| 30 | #include "paddle/fluid/imperative/tracer.h" | |||
| 31 | #include "paddle/fluid/imperative/type_defs.h" | |||
| 32 | #include "paddle/fluid/operators/ops_extra_info.h" | |||
| 33 | #include "paddle/fluid/pybind/eager.h" | |||
| 34 | #include "paddle/fluid/pybind/eager_utils.h" | |||
| 35 | #include "paddle/fluid/pybind/imperative.h" | |||
| 36 | #include "paddle/phi/common/complex.h" | |||
| 37 | ||||
| 38 | namespace paddle { | |||
| 39 | namespace pybind { | |||
| 40 | ||||
| 41 | class OpAttrTypeMap { | |||
| 42 | public: | |||
| 43 | static OpAttrTypeMap& Instance() { | |||
| 44 | static OpAttrTypeMap g_op_attr_type_map; | |||
| 45 | return g_op_attr_type_map; | |||
| 46 | } | |||
| 47 | ||||
| 48 | std::unordered_map< | |||
| 49 | std::string, | |||
| 50 | std::unordered_map<std::string, paddle::framework::proto::AttrType>>& | |||
| 51 | Map() { | |||
| 52 | return ops_attrtype_map_; | |||
| 53 | } | |||
| 54 | ||||
| 55 | private: | |||
| 56 | OpAttrTypeMap() = default; | |||
| 57 | std::unordered_map< | |||
| 58 | std::string, | |||
| 59 | std::unordered_map<std::string, paddle::framework::proto::AttrType>> | |||
| 60 | ops_attrtype_map_; | |||
| 61 | }; | |||
| 62 | ||||
| 63 | extern PyTypeObject* g_vartype_pytype; | |||
| 64 | extern PyTypeObject* g_blockdesc_pytype; | |||
| 65 | extern PyTypeObject* p_tensor_type; | |||
| 66 | ||||
| 67 | bool PyObject_CheckBool(PyObject** obj) { return PyBool_Check(*obj)((((PyObject*)(*obj))->ob_type) == &PyBool_Type); } | |||
| 68 | ||||
| 69 | bool PyObject_CheckLongOrToLong(PyObject** obj) { | |||
| 70 |   if ((PyLong_Check(*obj)((((((PyObject*)(*obj))->ob_type))->tp_flags & ((1UL << 24))) != 0) && !PyBool_Check(*obj)((((PyObject*)(*obj))->ob_type) == &PyBool_Type)) ||  | |||
| 71 |       PyObject_TypeCheck(*obj, g_vartype_pytype)((((PyObject*)(*obj))->ob_type) == (g_vartype_pytype) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (g_vartype_pytype))) || // NOLINT  | |||
| 72 |       (PyObject_TypeCheck(*obj, p_tensor_type)((((PyObject*)(*obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (p_tensor_type))) && // NOLINT  | |||
| 73 | (((TensorObject*)(*obj))->tensor.numel() == 1))) { // NOLINT | |||
| 74 | return true; | |||
| 75 | } | |||
| 76 | ||||
| 77 | if (std::string(((PyTypeObject*)(*obj)->ob_type)->tp_name) // NOLINT | |||
| 78 | .find("numpy") != std::string::npos) { | |||
| 79 | auto to = PyNumber_Long(*obj); | |||
| 80 | if (to) { | |||
| 81 | *obj = to; | |||
| 82 | return true; | |||
| 83 | } | |||
| 84 | } | |||
| 85 | ||||
| 86 | return false; | |||
| 87 | } | |||
| 88 | ||||
| 89 | bool PyObject_CheckFloatOrToFloat(PyObject** obj) { | |||
| 90 | // sometimes users provide PyLong or numpy.int64 but attr is float | |||
| 91 |   if (PyFloat_Check(*obj)((((PyObject*)(*obj))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (&PyFloat_Type))) || PyLong_Check(*obj)((((((PyObject*)(*obj))->ob_type))->tp_flags & ((1UL << 24))) != 0) ||  | |||
| 92 |       (PyObject_TypeCheck(*obj, p_tensor_type)((((PyObject*)(*obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (p_tensor_type))) && // NOLINT  | |||
| 93 | (((TensorObject*)(*obj))->tensor.numel() == 1))) { // NOLINT | |||
| 94 | return true; | |||
| 95 | } | |||
| 96 | if (std::string(((PyTypeObject*)(*obj)->ob_type)->tp_name) // NOLINT | |||
| 97 | .find("numpy") != std::string::npos) { | |||
| 98 | auto to = PyNumber_Float(*obj); | |||
| 99 | if (to) { | |||
| 100 | *obj = to; | |||
| 101 | return true; | |||
| 102 | } | |||
| 103 | } | |||
| 104 | return false; | |||
| 105 | } | |||
| 106 | ||||
| 107 | bool PyObject_CheckComplexOrToComplex(PyObject** obj) { | |||
| 108 |   if (PyComplex_Check(*obj)((((PyObject*)(*obj))->ob_type) == (&PyComplex_Type) || PyType_IsSubtype((((PyObject*)(*obj))->ob_type), (&PyComplex_Type ))) || PyLong_Check(*obj)((((((PyObject*)(*obj))->ob_type))->tp_flags & ((1UL << 24))) != 0) || PyFloat_Check(*obj)((((PyObject*)(*obj))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (&PyFloat_Type))) ||  | |||
| 109 |       PyObject_TypeCheck(*obj, g_vartype_pytype)((((PyObject*)(*obj))->ob_type) == (g_vartype_pytype) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (g_vartype_pytype))) || // NOLINT  | |||
| 110 |       PyObject_TypeCheck(*obj, p_tensor_type)((((PyObject*)(*obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (p_tensor_type)))) { // NOLINT  | |||
| 111 | return true; | |||
| 112 | } | |||
| 113 | // consider numpy cfloat & numpy cdouble? | |||
| 114 | return false; | |||
| 115 | } | |||
| 116 | ||||
| 117 | bool PyObject_CheckString(PyObject* obj) { return PyUnicode_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 28))) != 0); }  | |||
| 118 | ||||
| 119 | bool CastPyArg2Boolean(PyObject* obj, | |||
| 120 | const std::string& op_type, | |||
| 121 | ssize_t arg_pos) { | |||
| 122 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 123 | return false; // To be compatible with QA integration testing. Some | |||
| 124 | // test case pass in None. | |||
| 125 | } else if (obj == Py_True((PyObject *) &_Py_TrueStruct)) { | |||
| 126 | return true; | |||
| 127 | } else if (obj == Py_False((PyObject *) &_Py_FalseStruct)) { | |||
| 128 | return false; | |||
| 129 | } else { | |||
| 130 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0)  | |||
| 131 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0)  | |||
| 132 |         "bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0)  | |||
| 133 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0)  | |||
| 134 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0)  | |||
| 135 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 135); } while (0); // NOLINT  | |||
| 136 | } | |||
| 137 | ||||
| 138 | return false; | |||
| 139 | } | |||
| 140 | ||||
| 141 | void CastPyArg2AttrBoolean(PyObject* obj, | |||
| 142 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 143 | const std::string& key, | |||
| 144 | const std::string& op_type, | |||
| 145 | ssize_t arg_pos) { | |||
| 146 | attrs[key] = CastPyArg2Boolean(obj, op_type, arg_pos); | |||
| 147 | } | |||
| 148 | ||||
| 149 | int CastPyArg2Int(PyObject* obj, const std::string& op_type, ssize_t arg_pos) { | |||
| 150 | if (PyObject_CheckLongOrToLong(&obj)) { | |||
| 151 | return (int)PyLong_AsLong(obj); // NOLINT | |||
| 152 | } else { | |||
| 153 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0)  | |||
| 154 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0)  | |||
| 155 |         "int, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0)  | |||
| 156 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0)  | |||
| 157 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0)  | |||
| 158 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 158); } while (0); // NOLINT  | |||
| 159 | } | |||
| 160 | ||||
| 161 | return 0; | |||
| 162 | } | |||
| 163 | ||||
| 164 | void CastPyArg2AttrInt(PyObject* obj, | |||
| 165 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 166 | const std::string& key, | |||
| 167 | const std::string& op_type, | |||
| 168 | ssize_t arg_pos) { | |||
| 169 | attrs[key] = CastPyArg2Int(obj, op_type, arg_pos); | |||
| 170 | } | |||
| 171 | ||||
| 172 | int64_t CastPyArg2Long(PyObject* obj, | |||
| 173 | const std::string& op_type, | |||
| 174 | ssize_t arg_pos) { | |||
| 175 | if (PyObject_CheckLongOrToLong(&obj)) { | |||
| 176 | return (int64_t)PyLong_AsLongLong(obj); // NOLINT | |||
| 177 | } else { | |||
| 178 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0)  | |||
| 179 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0)  | |||
| 180 |         "long, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0)  | |||
| 181 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0)  | |||
| 182 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0)  | |||
| 183 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "long, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 183); } while (0); // NOLINT  | |||
| 184 | } | |||
| 185 | ||||
| 186 | return 0; | |||
| 187 | } | |||
| 188 | ||||
| 189 | void CastPyArg2AttrLong(PyObject* obj, | |||
| 190 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 191 | const std::string& key, | |||
| 192 | const std::string& op_type, | |||
| 193 | ssize_t arg_pos) { | |||
| 194 | attrs[key] = CastPyArg2Long(obj, op_type, arg_pos); | |||
| 195 | } | |||
| 196 | ||||
| 197 | void CastPyArg2AttrScalar(PyObject* obj, | |||
| 198 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 199 | const std::string& key, | |||
| 200 | const std::string& op_type, | |||
| 201 | ssize_t arg_pos) { | |||
| 202 | attrs[key] = CastPyArg2Scalar(obj, op_type, arg_pos); | |||
| 203 | } | |||
| 204 | ||||
| 205 | float16 CastPyArg2Float16(PyObject* obj, | |||
| 206 | const std::string& op_type, | |||
| 207 | ssize_t arg_pos) { | |||
| 208 | return static_cast<float16>(CastPyArg2Double(obj, op_type, arg_pos)); | |||
| 209 | } | |||
| 210 | ||||
| 211 | float CastPyArg2Float(PyObject* obj, | |||
| 212 | const std::string& op_type, | |||
| 213 | ssize_t arg_pos) { | |||
| 214 | return static_cast<float>(CastPyArg2Double(obj, op_type, arg_pos)); | |||
| 215 | } | |||
| 216 | ||||
| 217 | void CastPyArg2AttrFloat(PyObject* obj, | |||
| 218 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 219 | const std::string& key, | |||
| 220 | const std::string& op_type, | |||
| 221 | ssize_t arg_pos) { | |||
| 222 | attrs[key] = CastPyArg2Float(obj, op_type, arg_pos); | |||
| 223 | } | |||
| 224 | ||||
| 225 | double CastPyArg2Double(PyObject* obj, | |||
| 226 | const std::string& op_type, | |||
| 227 | ssize_t arg_pos) { | |||
| 228 | if (PyObject_CheckFloatOrToFloat(&obj)) { | |||
| 229 | return PyFloat_AsDouble(obj); // NOLINT | |||
| 230 | } else { | |||
| 231 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0)  | |||
| 232 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0)  | |||
| 233 |         "double, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0)  | |||
| 234 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0)  | |||
| 235 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0)  | |||
| 236 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "double, but got %s", op_type, arg_pos + 1, ((PyTypeObject*) obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 236); } while (0); // NOLINT  | |||
| 237 | } | |||
| 238 | ||||
| 239 | return 0.0; | |||
| 240 | } | |||
| 241 | ||||
| 242 | phi::dtype::complex<float> CastPyArg2Complex(PyObject* obj, | |||
| 243 | const std::string& op_type, | |||
| 244 | ssize_t arg_pos) { | |||
| 245 |   if (PyComplex_Check(obj)((((PyObject*)(obj))->ob_type) == (&PyComplex_Type) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (&PyComplex_Type )))) {  | |||
| 246 | double real = PyComplex_RealAsDouble(obj); | |||
| 247 | double imag = PyComplex_ImagAsDouble(obj); | |||
| 248 | return phi::dtype::complex<float>(real, imag); | |||
| 249 | } else { | |||
| 250 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0)  | |||
| 251 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0)  | |||
| 252 |         "complex, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0)  | |||
| 253 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0)  | |||
| 254 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0)  | |||
| 255 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 255); } while (0); // NOLINT  | |||
| 256 | } | |||
| 257 | ||||
| 258 | return phi::dtype::complex<float>(0, 0); | |||
| 259 | } | |||
| 260 | ||||
| 261 | phi::dtype::complex<double> CastPyArg2Complex128(PyObject* obj, | |||
| 262 | const std::string& op_type, | |||
| 263 | ssize_t arg_pos) { | |||
| 264 |   if (PyComplex_Check(obj)((((PyObject*)(obj))->ob_type) == (&PyComplex_Type) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (&PyComplex_Type )))) {  | |||
| 265 | double real = PyComplex_RealAsDouble(obj); | |||
| 266 | double imag = PyComplex_ImagAsDouble(obj); | |||
| 267 | return phi::dtype::complex<double>(real, imag); | |||
| 268 | } else { | |||
| 269 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0)  | |||
| 270 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0)  | |||
| 271 |         "complex, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0)  | |||
| 272 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0)  | |||
| 273 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0)  | |||
| 274 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "complex, but got %s", op_type, arg_pos + 1, ((PyTypeObject* )obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 274); } while (0); // NOLINT  | |||
| 275 | } | |||
| 276 | ||||
| 277 | return phi::dtype::complex<double>(0, 0); | |||
| 278 | } | |||
| 279 | ||||
| 280 | void CastPyArg2AttrDouble(PyObject* obj, | |||
| 281 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 282 | const std::string& key, | |||
| 283 | const std::string& op_type, | |||
| 284 | ssize_t arg_pos) { | |||
| 285 | attrs[key] = CastPyArg2Double(obj, op_type, arg_pos); | |||
| 286 | } | |||
| 287 | ||||
| 288 | std::string CastPyArg2String(PyObject* obj, | |||
| 289 | const std::string& op_type, | |||
| 290 | ssize_t arg_pos) { | |||
| 291 | if (PyObject_CheckString(obj)) { | |||
| 292 | Py_ssize_t size; | |||
| 293 | const char* data; | |||
| 294 | data = PyUnicode_AsUTF8AndSize(obj, &size); | |||
| 295 | return std::string(data, (size_t)size); // NOLINT | |||
| 296 | } else { | |||
| 297 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0)  | |||
| 298 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0)  | |||
| 299 |         "str, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0)  | |||
| 300 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0)  | |||
| 301 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0)  | |||
| 302 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "str, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj ->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 302); } while (0); // NOLINT  | |||
| 303 | } | |||
| 304 | ||||
| 305 | return ""; | |||
| 306 | } | |||
| 307 | ||||
| 308 | void CastPyArg2AttrString(PyObject* obj, | |||
| 309 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 310 | const std::string& key, | |||
| 311 | const std::string& op_type, | |||
| 312 | ssize_t arg_pos) { | |||
| 313 | attrs[key] = CastPyArg2String(obj, op_type, arg_pos); | |||
| 314 | } | |||
| 315 | ||||
| 316 | std::vector<bool> CastPyArg2Booleans(PyObject* obj, | |||
| 317 | const std::string& op_type, | |||
| 318 | ssize_t arg_pos) { | |||
| 319 | std::vector<bool> value; | |||
| 320 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 321 | Py_ssize_t len = PyList_Size(obj); | |||
| 322 | PyObject* item = nullptr; | |||
| 323 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 324 | item = PyList_GetItem(obj, i); | |||
| 325 | if (PyObject_CheckBool(&item)) { | |||
| 326 | value.emplace_back(PyLong_AsLong(item)); | |||
| 327 | } else { | |||
| 328 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 329 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 330 |             "list of bool, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 331 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 332 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 333 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0)  | |||
| 334 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 334); } while (0);  | |||
| 335 | } | |||
| 336 | } | |||
| 337 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 338 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 339 | PyObject* item = nullptr; | |||
| 340 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 341 | item = PyTuple_GetItem(obj, i); | |||
| 342 | if (PyObject_CheckBool(&item)) { | |||
| 343 | value.emplace_back(PyLong_AsLong(item)); | |||
| 344 | } else { | |||
| 345 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 346 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 347 |             "list of bool, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 348 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 349 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 350 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0)  | |||
| 351 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of bool, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 351); } while (0);  | |||
| 352 | } | |||
| 353 | } | |||
| 354 | } else { | |||
| 355 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0)  | |||
| 356 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0)  | |||
| 357 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0)  | |||
| 358 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0)  | |||
| 359 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0)  | |||
| 360 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 360); } while (0); // NOLINT  | |||
| 361 | } | |||
| 362 | ||||
| 363 | return value; | |||
| 364 | } | |||
| 365 | ||||
| 366 | void CastPyArg2AttrBooleans(PyObject* obj, | |||
| 367 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 368 | const std::string& key, | |||
| 369 | const std::string& op_type, | |||
| 370 | ssize_t arg_pos) { | |||
| 371 | attrs[key] = CastPyArg2Booleans(obj, op_type, arg_pos); | |||
| 372 | } | |||
| 373 | ||||
| 374 | std::vector<int> CastPyArg2Ints(PyObject* obj, | |||
| 375 | const std::string& op_type, | |||
| 376 | ssize_t arg_pos) { | |||
| 377 | std::vector<int> value; | |||
| 378 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 379 | Py_ssize_t len = PyList_Size(obj); | |||
| 380 | value.reserve(len); | |||
| 381 | PyObject* item = nullptr; | |||
| 382 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 383 | item = PyList_GetItem(obj, i); | |||
| 384 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 385 | value.emplace_back(PyLong_AsLong(item)); | |||
| 386 | } else { | |||
| 387 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 388 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 389 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 390 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 391 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 392 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0)  | |||
| 393 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 393); } while (0);  | |||
| 394 | } | |||
| 395 | } | |||
| 396 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 397 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 398 | value.reserve(len); | |||
| 399 | PyObject* item = nullptr; | |||
| 400 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 401 | item = PyTuple_GetItem(obj, i); | |||
| 402 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 403 | value.emplace_back(PyLong_AsLong(item)); | |||
| 404 | } else { | |||
| 405 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 406 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 407 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 408 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 409 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 410 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0)  | |||
| 411 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 411); } while (0);  | |||
| 412 | } | |||
| 413 | } | |||
| 414 |   } else if (PySequence_Check(obj) && !PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 415 | Py_ssize_t len = PySequence_Size(obj); | |||
| 416 | value.reserve(len); | |||
| 417 | PyObject* item = nullptr; | |||
| 418 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 419 | item = PySequence_GetItem(obj, i); | |||
| 420 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 421 | value.emplace_back(PyLong_AsLong(item)); | |||
| 422 | } else { | |||
| 423 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 424 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 425 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 426 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 427 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 428 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0)  | |||
| 429 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 429); } while (0);  | |||
| 430 | } | |||
| 431 | } | |||
| 432 | } else { | |||
| 433 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0)  | |||
| 434 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0)  | |||
| 435 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0)  | |||
| 436 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0)  | |||
| 437 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0)  | |||
| 438 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 438); } while (0); // NOLINT  | |||
| 439 | } | |||
| 440 | ||||
| 441 | return value; | |||
| 442 | } | |||
| 443 | ||||
| 444 | void CastPyArg2AttrInts(PyObject* obj, | |||
| 445 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 446 | const std::string& key, | |||
| 447 | const std::string& op_type, | |||
| 448 | ssize_t arg_pos) { | |||
| 449 | attrs[key] = CastPyArg2Ints(obj, op_type, arg_pos); | |||
| 450 | } | |||
| 451 | ||||
| 452 | std::vector<int64_t> CastPyArg2Longs(PyObject* obj, | |||
| 453 | const std::string& op_type, | |||
| 454 | ssize_t arg_pos) { | |||
| 455 | std::vector<int64_t> value; | |||
| 456 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 457 | Py_ssize_t len = PyList_Size(obj); | |||
| 458 | PyObject* item = nullptr; | |||
| 459 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 460 | item = PyList_GetItem(obj, i); | |||
| 461 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 462 | value.emplace_back((int64_t)PyLong_AsLongLong(item)); | |||
| 463 | } else { | |||
| 464 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 465 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 466 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 467 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 468 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 469 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0)  | |||
| 470 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 470); } while (0);  | |||
| 471 | } | |||
| 472 | } | |||
| 473 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 474 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 475 | PyObject* item = nullptr; | |||
| 476 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 477 | item = PyTuple_GetItem(obj, i); | |||
| 478 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 479 | value.emplace_back((int64_t)PyLong_AsLongLong(item)); | |||
| 480 | } else { | |||
| 481 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 482 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 483 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 484 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 485 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 486 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0)  | |||
| 487 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 487); } while (0);  | |||
| 488 | } | |||
| 489 | } | |||
| 490 |   } else if (PySequence_Check(obj) && !PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 491 | Py_ssize_t len = PySequence_Size(obj); | |||
| 492 | PyObject* item = nullptr; | |||
| 493 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 494 | item = PySequence_GetItem(obj, i); | |||
  | ||||
| 495 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 496 | value.emplace_back((int64_t)PyLong_AsLongLong(item)); | |||
| 497 | } else { | |||
| 498 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 499 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 500 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 501 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 502 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 503 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0)  | |||
| 504 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of int, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 504); } while (0);  | |||
| 505 | } | |||
| 506 | } | |||
| 507 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 508 | return {}; | |||
| 509 | } else if (PyObject_CheckLongOrToLong(&obj)) { | |||
| 510 | return {(int64_t)PyLong_AsLongLong(obj)}; | |||
| 511 | } else { | |||
| 512 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0)  | |||
| 513 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0)  | |||
| 514 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0)  | |||
| 515 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0)  | |||
| 516 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0)  | |||
| 517 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 517); } while (0); // NOLINT  | |||
| 518 | } | |||
| 519 | ||||
| 520 | return value; | |||
| 521 | } | |||
| 522 | ||||
| 523 | void CastPyArg2AttrLongs(PyObject* obj, | |||
| 524 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 525 | const std::string& key, | |||
| 526 | const std::string& op_type, | |||
| 527 | ssize_t arg_pos) { | |||
| 528 | attrs[key] = CastPyArg2Longs(obj, op_type, arg_pos); | |||
| 529 | } | |||
| 530 | ||||
| 531 | std::vector<float> CastPyArg2Floats(PyObject* obj, | |||
| 532 | const std::string& op_type, | |||
| 533 | ssize_t arg_pos) { | |||
| 534 | std::vector<float> value; | |||
| 535 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 536 | Py_ssize_t len = PyList_Size(obj); | |||
| 537 | PyObject* item = nullptr; | |||
| 538 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 539 | item = PyList_GetItem(obj, i); | |||
| 540 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 541 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 542 | } else { | |||
| 543 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 544 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 545 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 546 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 547 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 548 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0)  | |||
| 549 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 549); } while (0);  | |||
| 550 | } | |||
| 551 | } | |||
| 552 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 553 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 554 | PyObject* item = nullptr; | |||
| 555 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 556 | item = PyTuple_GetItem(obj, i); | |||
| 557 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 558 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 559 | } else { | |||
| 560 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 561 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 562 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 563 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 564 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 565 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0)  | |||
| 566 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 566); } while (0);  | |||
| 567 | } | |||
| 568 | } | |||
| 569 |   } else if (PySequence_Check(obj) && !PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 570 | Py_ssize_t len = PySequence_Size(obj); | |||
| 571 | PyObject* item = nullptr; | |||
| 572 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 573 | item = PySequence_GetItem(obj, i); | |||
| 574 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 575 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 576 | } else { | |||
| 577 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 578 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 579 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 580 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 581 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 582 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0)  | |||
| 583 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 583); } while (0);  | |||
| 584 | } | |||
| 585 | } | |||
| 586 | } else { | |||
| 587 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0)  | |||
| 588 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0)  | |||
| 589 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0)  | |||
| 590 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0)  | |||
| 591 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0)  | |||
| 592 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 592); } while (0); // NOLINT  | |||
| 593 | } | |||
| 594 | ||||
| 595 | return value; | |||
| 596 | } | |||
| 597 | ||||
| 598 | void CastPyArg2AttrFloats(PyObject* obj, | |||
| 599 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 600 | const std::string& key, | |||
| 601 | const std::string& op_type, | |||
| 602 | ssize_t arg_pos) { | |||
| 603 | attrs[key] = CastPyArg2Floats(obj, op_type, arg_pos); | |||
| 604 | } | |||
| 605 | ||||
| 606 | std::vector<double> CastPyArg2Float64s(PyObject* obj, | |||
| 607 | const std::string& op_type, | |||
| 608 | ssize_t arg_pos) { | |||
| 609 | std::vector<double> value; | |||
| 610 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 611 | Py_ssize_t len = PyList_Size(obj); | |||
| 612 | PyObject* item = nullptr; | |||
| 613 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 614 | item = PyList_GetItem(obj, i); | |||
| 615 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 616 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 617 | } else { | |||
| 618 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 619 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 620 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 621 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 622 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 623 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0)  | |||
| 624 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 624); } while (0);  | |||
| 625 | } | |||
| 626 | } | |||
| 627 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 628 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 629 | PyObject* item = nullptr; | |||
| 630 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 631 | item = PyTuple_GetItem(obj, i); | |||
| 632 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 633 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 634 | } else { | |||
| 635 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 636 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 637 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 638 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 639 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 640 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0)  | |||
| 641 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 641); } while (0);  | |||
| 642 | } | |||
| 643 | } | |||
| 644 |   } else if (PySequence_Check(obj) && !PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 645 | Py_ssize_t len = PySequence_Size(obj); | |||
| 646 | PyObject* item = nullptr; | |||
| 647 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 648 | item = PySequence_GetItem(obj, i); | |||
| 649 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 650 | value.emplace_back(PyFloat_AsDouble(item)); | |||
| 651 | } else { | |||
| 652 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 653 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 654 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 655 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 656 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 657 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0)  | |||
| 658 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of float, but got %s at pos %d", op_type, arg_pos + 1, ((PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 658); } while (0);  | |||
| 659 | } | |||
| 660 | } | |||
| 661 | } else { | |||
| 662 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0)  | |||
| 663 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0)  | |||
| 664 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0)  | |||
| 665 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0)  | |||
| 666 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0)  | |||
| 667 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 667); } while (0); // NOLINT  | |||
| 668 | } | |||
| 669 | ||||
| 670 | return value; | |||
| 671 | } | |||
| 672 | ||||
| 673 | void CastPyArg2AttrFloat64s(PyObject* obj, | |||
| 674 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 675 | const std::string& key, | |||
| 676 | const std::string& op_type, | |||
| 677 | ssize_t arg_pos) { | |||
| 678 | attrs[key] = CastPyArg2Float64s(obj, op_type, arg_pos); | |||
| 679 | } | |||
| 680 | ||||
| 681 | void CastPyArg2AttrScalars(PyObject* obj, | |||
| 682 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 683 | const std::string& key, | |||
| 684 | const std::string& op_type, | |||
| 685 | ssize_t arg_pos) { | |||
| 686 | attrs[key] = CastPyArg2Scalars(obj, op_type, arg_pos); | |||
| 687 | } | |||
| 688 | ||||
| 689 | std::vector<std::string> CastPyArg2Strings(PyObject* obj, | |||
| 690 | const std::string& op_type, | |||
| 691 | ssize_t arg_pos) { | |||
| 692 | std::vector<std::string> value; | |||
| 693 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 694 | Py_ssize_t len = PyList_Size(obj); | |||
| 695 | PyObject* item = nullptr; | |||
| 696 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 697 | item = PyList_GetItem(obj, i); | |||
| 698 | if (PyObject_CheckString(item)) { | |||
| 699 | Py_ssize_t size; | |||
| 700 | const char* data; | |||
| 701 | data = PyUnicode_AsUTF8AndSize(item, &size); | |||
| 702 | value.emplace_back(std::string(data, (size_t)size)); // NOLINT | |||
| 703 | } else { | |||
| 704 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 705 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 706 |             "list of str, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 707 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 708 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 709 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0)  | |||
| 710 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 710); } while (0);  | |||
| 711 | } | |||
| 712 | } | |||
| 713 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 714 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 715 | PyObject* item = nullptr; | |||
| 716 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 717 | item = PyTuple_GetItem(obj, i); | |||
| 718 | if (PyObject_CheckString(item)) { | |||
| 719 | Py_ssize_t size; | |||
| 720 | const char* data; | |||
| 721 | data = PyUnicode_AsUTF8AndSize(item, &size); | |||
| 722 | value.emplace_back(std::string(data, (size_t)size)); // NOLINT | |||
| 723 | } else { | |||
| 724 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 725 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 726 |             "list of str, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 727 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 728 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 729 |             ((PyTypeObject*)item->ob_type)->tp_name,  // NOLINTdo { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0)  | |||
| 730 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list of str, but got %s at pos %d", op_type, arg_pos + 1, ( (PyTypeObject*)item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 730); } while (0);  | |||
| 731 | } | |||
| 732 | } | |||
| 733 | } else { | |||
| 734 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0)  | |||
| 735 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0)  | |||
| 736 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0)  | |||
| 737 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0)  | |||
| 738 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0)  | |||
| 739 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or tuple, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 739); } while (0); // NOLINT  | |||
| 740 | } | |||
| 741 | ||||
| 742 | return value; | |||
| 743 | } | |||
| 744 | ||||
| 745 | void CastPyArg2AttrStrings(PyObject* obj, | |||
| 746 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 747 | const std::string& key, | |||
| 748 | const std::string& op_type, | |||
| 749 | ssize_t arg_pos) { | |||
| 750 | attrs[key] = CastPyArg2Strings(obj, op_type, arg_pos); | |||
| 751 | } | |||
| 752 | ||||
| 753 | std::vector<paddle::experimental::Scalar> CastPyArg2Scalars( | |||
| 754 | PyObject* obj, const std::string& op_type, ssize_t arg_pos) { | |||
| 755 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 756 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0)  | |||
| 757 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0)  | |||
| 758 |         "a list of int, float, or bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0)  | |||
| 759 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0)  | |||
| 760 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0)  | |||
| 761 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 761); } while (0); // NOLINT  | |||
| 762 | } | |||
| 763 | ||||
| 764 | PyTypeObject* type = obj->ob_type; | |||
| 765 | auto type_name = std::string(type->tp_name); | |||
| 766 |   VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/op_function_common.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/op_function_common.cc" , 766).stream() << "type_name: " << type_name;  | |||
| 767 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 768 | Py_ssize_t len = PyList_Size(obj); | |||
| 769 | PyObject* item = nullptr; | |||
| 770 | item = PyList_GetItem(obj, 0); | |||
| 771 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 772 | std::vector<paddle::experimental::Scalar> value; | |||
| 773 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 774 | item = PyList_GetItem(obj, i); | |||
| 775 | value.emplace_back( | |||
| 776 | paddle::experimental::Scalar{PyFloat_AsDouble(item)}); | |||
| 777 | } | |||
| 778 | return value; | |||
| 779 | } else if (PyObject_CheckLongOrToLong(&item)) { | |||
| 780 | std::vector<paddle::experimental::Scalar> value; | |||
| 781 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 782 | item = PyList_GetItem(obj, i); | |||
| 783 | value.emplace_back(paddle::experimental::Scalar{ | |||
| 784 | static_cast<int64_t>(PyLong_AsLong(item))}); | |||
| 785 | } | |||
| 786 | return value; | |||
| 787 | } else if (PyObject_CheckComplexOrToComplex(&item)) { | |||
| 788 | std::vector<paddle::experimental::Scalar> value; | |||
| 789 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 790 | item = PyList_GetItem(obj, i); | |||
| 791 | Py_complex v = PyComplex_AsCComplex(item); | |||
| 792 | value.emplace_back( | |||
| 793 | paddle::experimental::Scalar{std::complex<double>(v.real, v.imag)}); | |||
| 794 | } | |||
| 795 | return value; | |||
| 796 | } | |||
| 797 | } else { | |||
| 798 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0)  | |||
| 799 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0)  | |||
| 800 |         "a list of int, float, complex, or bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0)  | |||
| 801 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0)  | |||
| 802 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0)  | |||
| 803 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/op_function_common.cc", 803 ); } while (0); // NOLINT  | |||
| 804 | } | |||
| 805 | ||||
| 806 | // Fake a ScalarArray | |||
| 807 | return std::vector<paddle::experimental::Scalar>( | |||
| 808 | {paddle::experimental::Scalar(1.0)}); | |||
| 809 | } | |||
| 810 | ||||
| 811 | void CastPyArg2AttrBlock(PyObject* obj, | |||
| 812 | paddle::framework::AttributeMap& attrs, // NOLINT | |||
| 813 | const std::string& key, | |||
| 814 | const std::string& op_type, | |||
| 815 | ssize_t arg_pos) { | |||
| 816 | ::pybind11::detail::instance* inst = | |||
| 817 | (::pybind11::detail::instance*)obj; // NOLINT | |||
| 818 | ||||
| 819 |   if (!PyObject_TypeCheck((PyObject*)inst, g_blockdesc_pytype)((((PyObject*)((PyObject*)inst))->ob_type) == (g_blockdesc_pytype ) || PyType_IsSubtype((((PyObject*)((PyObject*)inst))->ob_type ), (g_blockdesc_pytype)))) { // NOLINT  | |||
| 820 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0)  | |||
| 821 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0)  | |||
| 822 |         "BlockDesc, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0)  | |||
| 823 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0)  | |||
| 824 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0)  | |||
| 825 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "BlockDesc, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 825); } while (0); // NOLINT  | |||
| 826 | } | |||
| 827 | void** vh = inst->simple_layout ? inst->simple_value_holder | |||
| 828 | : &inst->nonsimple.values_and_holders[0]; | |||
| 829 | attrs[key] = reinterpret_cast<paddle::framework::BlockDesc*&>(vh[0]); | |||
| 830 | } | |||
| 831 | ||||
| 832 | void ConstructAttrMapFromPyArgs( | |||
| 833 | const std::string& op_type, | |||
| 834 | PyObject* args, | |||
| 835 | ssize_t attr_start, | |||
| 836 | ssize_t attr_end, | |||
| 837 | paddle::framework::AttributeMap& attrs) { // NOLINT | |||
| 838 |   PADDLE_ENFORCE_EQ((attr_end - attr_start) % 2,do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
  | ||||
| 839 |                     0,do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
| 840 |                     platform::errors::InvalidArgument(do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
| 841 |                         "The number of arguments for attributes should be even "do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
| 842 |                         "but attr_start = %d, attr_end = %d.",do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
| 843 |                         attr_start,do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0)  | |||
| 844 |                         attr_end))do { auto __val1 = ((attr_end - attr_start) % 2); auto __val2 = (0); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details::CommonType1 <__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi:: details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))==( static_cast <__COMMON_TYPE2__>(__val2)); if (__builtin_expect(static_cast <bool>(!__is_not_error), 0)) { auto __summary__ = phi:: ErrorSummary(platform::errors::InvalidArgument( "The number of arguments for attributes should be even " "but attr_start = %d, attr_end = %d.", attr_start, attr_end) ); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "(attr_end - attr_start) % 2" , "0", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("(attr_end - attr_start) % 2", __val1), ::phi:: details::BinaryCompareMessageConverter< __kCanToString__> ::Convert("0", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/op_function_common.cc", 844 ); } while (0); } } while (0);  | |||
| 845 | ||||
| 846 | auto attr_type_map = &(OpAttrTypeMap::Instance().Map()[op_type]); | |||
| 847 | ||||
| 848 | PyObject* obj = nullptr; | |||
| 849 | for (ssize_t arg_pos = attr_start; arg_pos < attr_end; arg_pos += 2) { | |||
| 850 | Py_ssize_t key_len; | |||
| 851 | const char* key_ptr; | |||
| 852 | obj = PyTuple_GET_ITEM(args, arg_pos)(((PyTupleObject *)(args))->ob_item[arg_pos]); | |||
| 853 | if (PyObject_CheckString(obj)) { | |||
| 854 | key_ptr = PyUnicode_AsUTF8AndSize(obj, &key_len); | |||
| 855 | } else { | |||
| 856 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0)  | |||
| 857 |           "%s(): argument (position %d) must be str, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0)  | |||
| 858 |           "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0)  | |||
| 859 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0)  | |||
| 860 |           arg_pos,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0)  | |||
| 861 |           ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be str, but got " "%s", op_type, arg_pos, ((PyTypeObject*)obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 861); } while (0); // NOLINT  | |||
| 862 | } | |||
| 863 | ||||
| 864 | std::string key(key_ptr, (size_t)key_len); // NOLINT | |||
| 865 | auto iter = attr_type_map->find(key); | |||
| 866 | if (iter == attr_type_map->end()) { | |||
| 867 | continue; | |||
| 868 | } | |||
| 869 | ||||
| 870 | obj = PyTuple_GET_ITEM(args, arg_pos + 1)(((PyTupleObject *)(args))->ob_item[arg_pos + 1]); | |||
| 871 | ||||
| 872 | switch (iter->second) { | |||
| 873 | case paddle::framework::proto::AttrType::INT: | |||
| 874 | CastPyArg2AttrInt(obj, attrs, key, op_type, arg_pos); | |||
| 875 | break; | |||
| 876 | case paddle::framework::proto::AttrType::FLOAT: | |||
| 877 | CastPyArg2AttrFloat(obj, attrs, key, op_type, arg_pos); | |||
| 878 | break; | |||
| 879 | case paddle::framework::proto::AttrType::FLOAT64: | |||
| 880 | CastPyArg2AttrDouble(obj, attrs, key, op_type, arg_pos); | |||
| 881 | break; | |||
| 882 | case paddle::framework::proto::AttrType::STRING: | |||
| 883 | CastPyArg2AttrString(obj, attrs, key, op_type, arg_pos); | |||
| 884 | break; | |||
| 885 | case paddle::framework::proto::AttrType::INTS: | |||
| 886 | CastPyArg2AttrInts(obj, attrs, key, op_type, arg_pos); | |||
| 887 | break; | |||
| 888 | case paddle::framework::proto::AttrType::FLOATS: | |||
| 889 | CastPyArg2AttrFloats(obj, attrs, key, op_type, arg_pos); | |||
| 890 | break; | |||
| 891 | case paddle::framework::proto::AttrType::STRINGS: | |||
| 892 | CastPyArg2AttrStrings(obj, attrs, key, op_type, arg_pos); | |||
| 893 | break; | |||
| 894 | case paddle::framework::proto::AttrType::BOOLEAN: | |||
| 895 | CastPyArg2AttrBoolean(obj, attrs, key, op_type, arg_pos); | |||
| 896 | break; | |||
| 897 | case paddle::framework::proto::AttrType::BOOLEANS: | |||
| 898 | CastPyArg2AttrBooleans(obj, attrs, key, op_type, arg_pos); | |||
| 899 | break; | |||
| 900 | case paddle::framework::proto::AttrType::LONG: | |||
| 901 | CastPyArg2AttrLong(obj, attrs, key, op_type, arg_pos); | |||
| 902 | break; | |||
| 903 | case paddle::framework::proto::AttrType::LONGS: | |||
| 904 | CastPyArg2AttrLongs(obj, attrs, key, op_type, arg_pos); | |||
| 905 | break; | |||
| 906 | case paddle::framework::proto::AttrType::FLOAT64S: | |||
| 907 | CastPyArg2AttrFloat64s(obj, attrs, key, op_type, arg_pos); | |||
| 908 | break; | |||
| 909 | case paddle::framework::proto::AttrType::BLOCK: | |||
| 910 | CastPyArg2AttrBlock(obj, attrs, key, op_type, arg_pos); | |||
| 911 | break; | |||
| 912 | case paddle::framework::proto::AttrType::SCALAR: | |||
| 913 | CastPyArg2AttrScalar(obj, attrs, key, op_type, arg_pos); | |||
| 914 | break; | |||
| 915 | case paddle::framework::proto::AttrType::SCALARS: | |||
| 916 | CastPyArg2AttrScalars(obj, attrs, key, op_type, arg_pos); | |||
| 917 | break; | |||
| 918 | default: | |||
| 919 | break; | |||
| 920 | } | |||
| 921 | } | |||
| 922 | } | |||
| 923 | ||||
| 924 | unsigned long GetUnsignedLongFromArgs( // NOLINT | |||
| 925 | const std::string& op_type, | |||
| 926 | const std::string& arg_name, | |||
| 927 | PyObject* args, | |||
| 928 | ssize_t arg_idx, | |||
| 929 | bool dispensable) { | |||
| 930 | PyObject* item = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 931 | ||||
| 932 | if (item == nullptr) { | |||
| 933 | if (!dispensable) { | |||
| 934 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be long, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 938); } while (0)  | |||
| 935 |           "%s(): argument '%s' (position %d) must be long, but got None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be long, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 938); } while (0)  | |||
| 936 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be long, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 938); } while (0)  | |||
| 937 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be long, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 938); } while (0)  | |||
| 938 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be long, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 938); } while (0);  | |||
| 939 | } | |||
| 940 | return 0; | |||
| 941 | } | |||
| 942 | ||||
| 943 | if (PyObject_CheckLongOrToLong(&item)) { | |||
| 944 | return PyLong_AsUnsignedLong(item); | |||
| 945 | } else { | |||
| 946 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 947 |         "%s(): argument '%s' (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 948 |         "long, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 949 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 950 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 951 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0)  | |||
| 952 |         ((PyTypeObject*)item->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be " "long, but got %s", op_type, arg_name, arg_idx, ((PyTypeObject *)item->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 952); } while (0); // NOLINT  | |||
| 953 | } | |||
| 954 | } | |||
| 955 | ||||
| 956 | void InitOpsAttrTypeMap() { | |||
| 957 | auto op_info_map = paddle::framework::OpInfoMap::Instance().map(); | |||
| 958 | for (auto& item : op_info_map) { | |||
| 959 | auto op_proto = item.second.proto_; | |||
| 960 | if (op_proto == nullptr) { | |||
| 961 | continue; | |||
| 962 | } | |||
| 963 | auto attrs_proto = op_proto->attrs(); | |||
| 964 | for (auto& attr : attrs_proto) { | |||
| 965 | OpAttrTypeMap::Instance().Map()[item.first][attr.name()] = attr.type(); | |||
| 966 | } | |||
| 967 | } | |||
| 968 | const auto& extra_attr_maps = | |||
| 969 | operators::ExtraInfoUtils::Instance().GetAllExtraAttrsMap(); | |||
| 970 | for (const auto& extra_attrs : extra_attr_maps) { | |||
| 971 | for (auto& attr : extra_attrs.second) { | |||
| 972 | OpAttrTypeMap::Instance().Map()[extra_attrs.first][attr.first] = | |||
| 973 | static_cast<paddle::framework::proto::AttrType>(attr.second.index() - | |||
| 974 | 1); | |||
| 975 | } | |||
| 976 | } | |||
| 977 | } | |||
| 978 | ||||
| 979 | ssize_t GetIdxFromCoreOpsInfoMap( | |||
| 980 | const std::unordered_map<std::string, std::vector<std::string>>& | |||
| 981 | core_ops_info_map, | |||
| 982 | const std::string& op_type, | |||
| 983 | const std::string& name) { | |||
| 984 | // `core_ops_info_map` can be `core_ops_args_info` or `core_ops_returns_info`. | |||
| 985 | // `core_ops_args_info`: get index from core_ops_args_info[op_type] according | |||
| 986 | // to input name. | |||
| 987 | // `core_ops_returns_info`: get index from core_ops_returns_info[op_type] | |||
| 988 | // according to return name. | |||
| 989 | if (!core_ops_info_map.count(op_type)) { | |||
| 990 |     PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Op %s is not found in core_ops_*_info map." , op_type)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 991); } while (0)  | |||
| 991 |         "Op %s is not found in core_ops_*_info map.", op_type))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Op %s is not found in core_ops_*_info map." , op_type)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 991); } while (0);  | |||
| 992 | } else { | |||
| 993 | auto args_list = core_ops_info_map.at(op_type); | |||
| 994 | auto it = std::find(args_list.begin(), args_list.end(), name); | |||
| 995 | if (it == args_list.end()) { | |||
| 996 |       PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "%s is not found in op %s's args.", name, op_type)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 997); } while (0)  | |||
| 997 |           "%s is not found in op %s's args.", name, op_type))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "%s is not found in op %s's args.", name, op_type)), "../../../../paddle/fluid/pybind/op_function_common.cc" , 997); } while (0);  | |||
| 998 | } else { | |||
| 999 | return std::distance(args_list.begin(), it); | |||
| 1000 | } | |||
| 1001 | } | |||
| 1002 | return -1; | |||
| 1003 | } | |||
| 1004 | ||||
| 1005 | } // namespace pybind | |||
| 1006 | } // namespace paddle | 
| 1 | #ifndef PySequence_GetItem | 
| 2 | struct _object; | 
| 3 | typedef struct _object PyObject; | 
| 4 | PyObject* clang_analyzer_PyObject_New_Reference(); | 
| 5 | PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i) { | 
| 6 | return clang_analyzer_PyObject_New_Reference(); | 
| 7 | } | 
| 8 | #else | 
| 9 | #warning "API PySequence_GetItem is defined as a macro." | 
| 10 | #endif |