| 567 | } |
| 568 | |
| 569 | std::vector<int64_t> CastPyArg2VectorOfInt64(PyObject* obj, size_t arg_pos) { |
| 570 | std::vector<int64_t> result; |
| 571 | if (PyList_Check(obj)) { |
| 572 | Py_ssize_t len = PyList_Size(obj); |
| 573 | PyObject* item = nullptr; |
| 574 | for (Py_ssize_t i = 0; i < len; i++) { |
| 575 | item = PyList_GET_ITEM(obj, i); |
| 576 | if (PyObject_CheckLong(item)) { |
| 577 | result.emplace_back(PyObject_ToInt64(item)); |
| 578 | } else { |
| 579 | PADDLE_THROW(common::errors::InvalidType( |
| 580 | "argument (position %d) must be " |
| 581 | "list of int, but got %s at pos %d", |
| 582 | arg_pos + 1, |
| 583 | reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name, |
| 584 | i)); |
| 585 | } |
| 586 | } |
| 587 | } else if (PyTuple_Check(obj)) { |
| 588 | Py_ssize_t len = PyTuple_Size(obj); |
| 589 | PyObject* item = nullptr; |
| 590 | for (Py_ssize_t i = 0; i < len; i++) { |
| 591 | item = PyTuple_GET_ITEM(obj, i); |
| 592 | if (PyObject_CheckLong(item)) { |
| 593 | result.emplace_back(PyObject_ToInt64(item)); |
| 594 | } else { |
| 595 | PADDLE_THROW(common::errors::InvalidType( |
| 596 | "argument (position %d) must be " |
| 597 | "list of int, but got %s at pos %d", |
| 598 | arg_pos + 1, |
| 599 | reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name, |
| 600 | i)); |
| 601 | } |
| 602 | } |
| 603 | } else if (obj == Py_None) { |
| 604 | return {}; |
| 605 | } else if (PyObject_CheckLong(obj)) { |
| 606 | return {PyObject_ToInt64(obj)}; // NOLINT |
| 607 | } else { |
| 608 | PADDLE_THROW(common::errors::InvalidType( |
| 609 | "argument (position %d) must be " |
| 610 | "list or tuple, but got %s", |
| 611 | arg_pos + 1, |
| 612 | reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name)); |
| 613 | } |
| 614 | return result; |
| 615 | } |
| 616 | |
| 617 | std::vector<size_t> CastPyArg2VectorOfSize_t(PyObject* obj, size_t arg_pos) { |
| 618 | std::vector<size_t> result; |
no test coverage detected