Create an empty tensor of type 'dtype'. 'shape' can be arbitrary, but has to result in a zero-sized tensor.
| 259 | // Create an empty tensor of type 'dtype'. 'shape' can be arbitrary, but has to |
| 260 | // result in a zero-sized tensor. |
| 261 | static 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 | |
| 278 | namespace tensorflow { |
| 279 |
no test coverage detected