| 361 | } |
| 362 | |
| 363 | void Compute(OpKernelContext* c) override { |
| 364 | const TensorList* l = nullptr; |
| 365 | OP_REQUIRES_OK(c, GetInputList(c, 0, &l)); |
| 366 | OP_REQUIRES(c, element_dtype_ == l->element_dtype, |
| 367 | errors::InvalidArgument("Invalid data types; op elements ", |
| 368 | DataTypeString(element_dtype_), |
| 369 | " but list elements ", |
| 370 | DataTypeString(l->element_dtype))); |
| 371 | |
| 372 | OP_REQUIRES(c, !l->tensors().empty(), |
| 373 | errors::InvalidArgument("Trying to pop from an empty list.")); |
| 374 | |
| 375 | const Tensor& t = l->tensors().back(); |
| 376 | if (t.dtype() != DT_INVALID) { |
| 377 | c->set_output(1, t); |
| 378 | } else { |
| 379 | PartialTensorShape partial_element_shape; |
| 380 | OP_REQUIRES_OK( |
| 381 | c, GetElementShapeFromInput(c, *l, 1, &partial_element_shape)); |
| 382 | TensorShape element_shape; |
| 383 | OP_REQUIRES( |
| 384 | c, partial_element_shape.AsTensorShape(&element_shape), |
| 385 | errors::InvalidArgument("Trying to read an uninitialized tensor but ", |
| 386 | "element_shape is not fully defined.", |
| 387 | partial_element_shape.DebugString())); |
| 388 | Tensor* result; |
| 389 | AllocatorAttributes attr; |
| 390 | if (element_dtype_ == DT_VARIANT) { |
| 391 | attr.set_on_host(true); |
| 392 | } |
| 393 | OP_REQUIRES_OK(c, c->allocate_output(1, element_shape, &result, attr)); |
| 394 | functor::SetZeroFunctor<Device, T>()(c->eigen_device<Device>(), |
| 395 | result->flat<T>()); |
| 396 | } |
| 397 | |
| 398 | TensorList* output_list = nullptr; |
| 399 | OP_REQUIRES_OK(c, ForwardInputOrCreateNewList(c, 0, 0, *l, &output_list)); |
| 400 | output_list->tensors().pop_back(); |
| 401 | } |
| 402 | |
| 403 | private: |
| 404 | DataType element_dtype_; |
nothing calls this directly
no test coverage detected