| 458 | |
| 459 | template <class NodeDefOrAttrSlice> |
| 460 | Status AddArgToSig(const NodeDefOrAttrSlice& node_or_attrs, |
| 461 | const OpDef::ArgDef& arg_def, DataTypeVector* sig) { |
| 462 | const int original_size = sig->size(); |
| 463 | if (!arg_def.number_attr().empty()) { |
| 464 | // Same type repeated "repeats" times. |
| 465 | int32 repeats = -1; |
| 466 | TF_RETURN_IF_ERROR( |
| 467 | GetNodeAttr(node_or_attrs, arg_def.number_attr(), &repeats)); |
| 468 | if (repeats < 0) { |
| 469 | return errors::InvalidArgument("Value for number_attr() ", repeats, |
| 470 | " < 0"); |
| 471 | } |
| 472 | |
| 473 | if (!arg_def.type_attr().empty()) { |
| 474 | DataType dtype; |
| 475 | TF_RETURN_IF_ERROR( |
| 476 | GetNodeAttr(node_or_attrs, arg_def.type_attr(), &dtype)); |
| 477 | for (int i = 0; i < repeats; ++i) { |
| 478 | sig->push_back(dtype); |
| 479 | } |
| 480 | } else if (arg_def.type() != DT_INVALID) { |
| 481 | for (int i = 0; i < repeats; ++i) { |
| 482 | sig->push_back(arg_def.type()); |
| 483 | } |
| 484 | } else { |
| 485 | return errors::InvalidArgument("Missing type or type_attr field in ", |
| 486 | ProtoShortDebugString(arg_def)); |
| 487 | } |
| 488 | } else if (!arg_def.type_attr().empty()) { |
| 489 | const AttrValue* attr_value; |
| 490 | TF_RETURN_IF_ERROR( |
| 491 | AttrSlice(node_or_attrs).Find(arg_def.type_attr(), &attr_value)); |
| 492 | sig->push_back(attr_value->type()); |
| 493 | } else if (!arg_def.type_list_attr().empty()) { |
| 494 | const AttrValue* attr_value; |
| 495 | TF_RETURN_IF_ERROR( |
| 496 | AttrSlice(node_or_attrs).Find(arg_def.type_list_attr(), &attr_value)); |
| 497 | for (int dtype : attr_value->list().type()) { |
| 498 | sig->push_back(static_cast<DataType>(dtype)); |
| 499 | } |
| 500 | } else if (arg_def.type() != DT_INVALID) { |
| 501 | sig->push_back(arg_def.type()); |
| 502 | } else { |
| 503 | return errors::InvalidArgument("No type fields in ", |
| 504 | ProtoShortDebugString(arg_def)); |
| 505 | } |
| 506 | if (arg_def.is_ref()) { |
| 507 | // For all types that were added by this function call, make them refs. |
| 508 | for (size_t i = original_size; i < sig->size(); ++i) { |
| 509 | (*sig)[i] = MakeRefType((*sig)[i]); |
| 510 | } |
| 511 | } |
| 512 | return Status::OK(); |
| 513 | } |
| 514 | |
| 515 | } // namespace |
| 516 |
no test coverage detected