| 219 | // element and call f(ptr, len). |
| 220 | template <typename F> |
| 221 | Status PyBytesArrayMap(PyArrayObject* array, F f) { |
| 222 | Safe_PyObjectPtr iter = tensorflow::make_safe( |
| 223 | PyArray_IterNew(reinterpret_cast<PyObject*>(array))); |
| 224 | while (PyArray_ITER_NOTDONE(iter.get())) { |
| 225 | auto item = tensorflow::make_safe(PyArray_GETITEM( |
| 226 | array, static_cast<char*>(PyArray_ITER_DATA(iter.get())))); |
| 227 | if (!item) { |
| 228 | return errors::Internal("Unable to get element from the feed - no item."); |
| 229 | } |
| 230 | Py_ssize_t len; |
| 231 | const char* ptr; |
| 232 | PyObject* ptr_owner = nullptr; |
| 233 | TF_RETURN_IF_ERROR(PyObjectToString(item.get(), &ptr, &len, &ptr_owner)); |
| 234 | f(ptr, len); |
| 235 | Py_XDECREF(ptr_owner); |
| 236 | PyArray_ITER_NEXT(iter.get()); |
| 237 | } |
| 238 | return Status::OK(); |
| 239 | } |
| 240 | |
| 241 | // Encode the strings in 'array' into a contiguous buffer and return the base of |
| 242 | // the buffer. The caller takes ownership of the buffer. |
no test coverage detected