MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CastPyArg2VectorOfSize_t

Function CastPyArg2VectorOfSize_t

paddle/fluid/pybind/eager_utils.cc:617–663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615}
616
617std::vector<size_t> CastPyArg2VectorOfSize_t(PyObject* obj, size_t arg_pos) {
618 std::vector<size_t> result;
619 if (PyList_Check(obj)) {
620 Py_ssize_t len = PyList_Size(obj);
621 PyObject* item = nullptr;
622 for (Py_ssize_t i = 0; i < len; i++) {
623 item = PyList_GetItem(obj, i);
624 if (PyObject_CheckLong(item)) {
625 result.emplace_back(PyObject_ToSize_t(item));
626 } else {
627 PADDLE_THROW(common::errors::InvalidType(
628 "argument (position %d) must be "
629 "list of int, but got %s at pos %d",
630 arg_pos + 1,
631 reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,
632 i));
633 }
634 }
635 } else if (PyTuple_Check(obj)) {
636 Py_ssize_t len = PyTuple_Size(obj);
637 PyObject* item = nullptr;
638 for (Py_ssize_t i = 0; i < len; i++) {
639 item = PyTuple_GET_ITEM(obj, i);
640 if (PyObject_CheckLong(item)) {
641 result.emplace_back(PyObject_ToSize_t(item));
642 } else {
643 PADDLE_THROW(common::errors::InvalidType(
644 "argument (position %d) must be "
645 "list of size_t, but got %s at pos %d",
646 arg_pos + 1,
647 reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,
648 i));
649 }
650 }
651 } else if (obj == Py_None) {
652 return {};
653 } else if (PyObject_CheckLong(obj)) {
654 return {PyObject_ToSize_t(obj)}; // NOLINT
655 } else {
656 PADDLE_THROW(common::errors::InvalidType(
657 "argument (position %d) must be "
658 "list of size_t, but got %s",
659 arg_pos + 1,
660 reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name));
661 }
662 return result;
663}
664
665std::vector<float> CastPyArg2VectorOfFloat(PyObject* obj, size_t arg_pos) {
666 std::vector<float> result;

Callers 1

Calls 3

PyObject_CheckLongFunction · 0.85
PyObject_ToSize_tFunction · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected