| 111 | } |
| 112 | |
| 113 | bool IsSingleNone(PyObject* obj) { |
| 114 | if (!PyArray_Check(obj)) { |
| 115 | return false; |
| 116 | } |
| 117 | PyArrayObject* array_obj = reinterpret_cast<PyArrayObject*>(obj); |
| 118 | if (PyArray_NDIM(array_obj) != 0 || PyArray_SIZE(array_obj) != 1) { |
| 119 | return false; |
| 120 | } |
| 121 | std::array<npy_intp, 0> indices; |
| 122 | char* item_ptr = |
| 123 | static_cast<char*>(PyArray_GetPtr(array_obj, indices.data())); |
| 124 | PyObject* item = PyArray_GETITEM(array_obj, item_ptr); |
| 125 | CHECK(item); |
| 126 | return item == Py_None; |
| 127 | } |
| 128 | |
| 129 | // Retrieves a Tensor from `eager_tensor` and stores it in `output_tensor`. |
| 130 | // Validates that `output_tensor` is backed by memory in `expected_device` |