MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PyBytesArrayMap

Function PyBytesArrayMap

tensorflow/python/lib/core/ndarray_tensor.cc:221–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219// element and call f(ptr, len).
220template <typename F>
221Status 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.

Callers 1

EncodePyBytesArrayFunction · 0.85

Calls 5

InternalFunction · 0.85
make_safeFunction · 0.70
PyObjectToStringFunction · 0.70
fFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected