| 233 | } |
| 234 | |
| 235 | string GenEagerPythonOp::Code() { |
| 236 | if (api_def_.visibility() == ApiDef::SKIP) { |
| 237 | return ""; |
| 238 | } |
| 239 | |
| 240 | for (int i = 0; i < api_def_.arg_order_size(); ++i) { |
| 241 | const auto& arg = *FindInputArg(api_def_.arg_order(i), op_def_); |
| 242 | const auto& api_def_arg = *FindInputArg(api_def_.arg_order(i), api_def_); |
| 243 | params_no_default_.emplace_back(api_def_arg.name(), |
| 244 | api_def_arg.rename_to()); |
| 245 | if (!arg.type_attr().empty()) { |
| 246 | AddAttrForArg(arg.type_attr(), i); |
| 247 | } else if (!arg.type_list_attr().empty()) { |
| 248 | AddAttrForArg(arg.type_list_attr(), i); |
| 249 | } |
| 250 | if (!arg.number_attr().empty()) { |
| 251 | AddAttrForArg(arg.number_attr(), i); |
| 252 | } |
| 253 | } |
| 254 | for (int i = 0; i < op_def_.attr_size(); ++i) { |
| 255 | const auto& attr(op_def_.attr(i)); |
| 256 | const auto& api_def_attr(api_def_.attr(i)); |
| 257 | // Do not add inferred attrs to the Python function signature. |
| 258 | if (inferred_attrs_.find(attr.name()) == inferred_attrs_.end()) { |
| 259 | if (api_def_attr.has_default_value()) { |
| 260 | if (attr.type() == "tensor") { |
| 261 | params_with_default_.emplace_back( |
| 262 | python_op_gen_internal::ParamNames(api_def_attr.name(), |
| 263 | api_def_attr.rename_to()), |
| 264 | strings::StrCat( |
| 265 | "_execute.make_tensor(", |
| 266 | TensorPBString(api_def_attr.default_value().tensor()), ", \"", |
| 267 | api_def_attr.rename_to(), "\")")); |
| 268 | } else if (attr.type() == "list(tensor)") { |
| 269 | std::vector<string> pbtxt; |
| 270 | for (const auto& pb : api_def_attr.default_value().list().tensor()) { |
| 271 | pbtxt.emplace_back(TensorPBString(pb)); |
| 272 | } |
| 273 | params_with_default_.emplace_back( |
| 274 | python_op_gen_internal::ParamNames(api_def_attr.name(), |
| 275 | api_def_attr.rename_to()), |
| 276 | strings::StrCat("[_execute.make_tensor(_pb, \"", |
| 277 | api_def_attr.rename_to(), "\") for _pb in ", |
| 278 | VectorToTuple(pbtxt), "]")); |
| 279 | } else { |
| 280 | params_with_default_.emplace_back( |
| 281 | python_op_gen_internal::ParamNames(api_def_attr.name(), |
| 282 | api_def_attr.rename_to()), |
| 283 | python_op_gen_internal::AttrValueToPython( |
| 284 | attr.type(), api_def_attr.default_value(), "_dtypes.")); |
| 285 | } |
| 286 | } else { |
| 287 | params_no_default_.emplace_back(api_def_attr.name(), |
| 288 | api_def_attr.rename_to()); |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 |
no test coverage detected