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

Function EmptyTensor

tensorflow/c/tf_tensor.cc:261–276  ·  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

259// Create an empty tensor of type 'dtype'. 'shape' can be arbitrary, but has to
260// result in a zero-sized tensor.
261static TF_Tensor* EmptyTensor(TF_DataType dtype,
262 const tensorflow::TensorShape& shape) {
263 static char empty;
264 tensorflow::int64 nelems = 1;
265 std::vector<tensorflow::int64> dims;
266 for (int i = 0; i < shape.dims(); ++i) {
267 dims.push_back(shape.dim_size(i));
268 nelems *= shape.dim_size(i);
269 }
270 CHECK_EQ(nelems, 0);
271 static_assert(sizeof(int64_t) == sizeof(tensorflow::int64),
272 "64-bit int types should match in size");
273 return TF_NewTensor(
274 dtype, reinterpret_cast<const int64_t*>(dims.data()), shape.dims(),
275 reinterpret_cast<void*>(&empty), 0, [](void*, size_t, void*) {}, nullptr);
276}
277
278namespace tensorflow {
279

Callers 1

TF_TensorFromTensorFunction · 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