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

Function EmptyTensor

tensorflow/c/c_api.cc:392–407  ·  view source on GitHub ↗

Create an empty tensor of type 'dtype'. 'shape' can be arbitrary, but has to result in a zero-sized tensor.

Source from the content-addressed store, hash-verified

390// Create an empty tensor of type 'dtype'. 'shape' can be arbitrary, but has to
391// result in a zero-sized tensor.
392static TF_Tensor* EmptyTensor(TF_DataType dtype,
393 const tensorflow::TensorShape& shape) {
394 static char empty;
395 tensorflow::int64 nelems = 1;
396 std::vector<tensorflow::int64> dims;
397 for (int i = 0; i < shape.dims(); ++i) {
398 dims.push_back(shape.dim_size(i));
399 nelems *= shape.dim_size(i);
400 }
401 CHECK_EQ(nelems, 0);
402 static_assert(sizeof(int64_t) == sizeof(tensorflow::int64),
403 "64-bit int types should match in size");
404 return TF_NewTensor(
405 dtype, reinterpret_cast<const int64_t*>(dims.data()), shape.dims(),
406 reinterpret_cast<void*>(&empty), 0, [](void*, size_t, void*) {}, nullptr);
407}
408
409static void TF_Run_Helper(
410 Session* session, const char* handle, const TF_Buffer* run_options,

Callers 1

TF_Run_HelperFunction · 0.70

Calls 5

TF_NewTensorFunction · 0.85
dimsMethod · 0.45
push_backMethod · 0.45
dim_sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected