start_index is the index at which the Tuple/List attrs will start getting processed.
| 635 | // start_index is the index at which the Tuple/List attrs will start getting |
| 636 | // processed. |
| 637 | void SetOpAttrs(TFE_Context* ctx, TFE_Op* op, PyObject* attrs, int start_index, |
| 638 | TF_Status* out_status) { |
| 639 | if (attrs == Py_None) return; |
| 640 | Py_ssize_t len = PyTuple_GET_SIZE(attrs) - start_index; |
| 641 | if ((len & 1) != 0) { |
| 642 | TF_SetStatus(out_status, TF_INVALID_ARGUMENT, |
| 643 | "Expecting attrs tuple to have even length."); |
| 644 | return; |
| 645 | } |
| 646 | // Parse attrs |
| 647 | for (Py_ssize_t i = 0; i < len; i += 2) { |
| 648 | PyObject* py_key = PyTuple_GET_ITEM(attrs, start_index + i); |
| 649 | PyObject* py_value = PyTuple_GET_ITEM(attrs, start_index + i + 1); |
| 650 | #if PY_MAJOR_VERSION >= 3 |
| 651 | const char* key = PyBytes_Check(py_key) ? PyBytes_AsString(py_key) |
| 652 | : PyUnicode_AsUTF8(py_key); |
| 653 | #else |
| 654 | const char* key = PyBytes_AsString(py_key); |
| 655 | #endif |
| 656 | unsigned char is_list = 0; |
| 657 | const TF_AttrType type = TFE_OpGetAttrType(op, key, &is_list, out_status); |
| 658 | if (TF_GetCode(out_status) != TF_OK) return; |
| 659 | if (is_list != 0) { |
| 660 | if (!SetOpAttrList(ctx, op, key, py_value, type, nullptr, out_status)) |
| 661 | return; |
| 662 | } else { |
| 663 | if (!SetOpAttrScalar(ctx, op, key, py_value, type, nullptr, out_status)) |
| 664 | return; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | // This function will set the op attrs required. If an attr has the value of |
| 670 | // None, then it will read the AttrDef to get the default value and set that |
no test coverage detected