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

Function ConvertToEagerTensor

tensorflow/python/eager/pywrap_tensor.cc:394–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394TFE_TensorHandle* ConvertToEagerTensor(TFE_Context* ctx, PyObject* value,
395 DataType dtype,
396 const char* device_name) {
397 // Reduce the overhead of allocation/transfer-to-device for scalars by
398 // caching the corresponding handles. Note that currently only Python
399 // scalars are cached.
400 // TODO(slebedev): also cache singleton NumPy arrays and scalars?
401 if (PyArray_IsPythonNumber(value)) {
402 auto* cache = TFE_TensorHandleCache::Get();
403 TFE_TensorHandle* handle = cache->Lookup(value, dtype, device_name);
404 if (handle != nullptr) return handle;
405 handle = ConvertToEagerTensorUncached(ctx, value, dtype, device_name);
406 if (handle == nullptr) return nullptr;
407 cache->Insert(value, dtype, device_name, handle);
408 return handle;
409 } else {
410 return ConvertToEagerTensorUncached(ctx, value, dtype, device_name);
411 }
412}
413
414} // namespace tensorflow
415

Callers 2

ConvertToTensorFunction · 0.85
EagerTensor_initFunction · 0.85

Calls 4

GetFunction · 0.85
LookupMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected