| 502 | } |
| 503 | |
| 504 | void Compute(OpKernelContext* ctx) override { |
| 505 | OP_REQUIRES_OK(ctx, SetupFlowControlInputs(ctx, false)); |
| 506 | |
| 507 | const Tensor* tensor_index; |
| 508 | OP_REQUIRES_OK(ctx, ctx->input("index", &tensor_index)); |
| 509 | |
| 510 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(tensor_index->shape()), |
| 511 | errors::InvalidArgument( |
| 512 | "TensorArray index must be scalar, but had shape: ", |
| 513 | tensor_index->shape().DebugString())); |
| 514 | |
| 515 | TensorArray* tensor_array = nullptr; |
| 516 | OP_REQUIRES_OK(ctx, GetTensorArray(ctx, &tensor_array)); |
| 517 | core::ScopedUnref unref(tensor_array); |
| 518 | |
| 519 | const int32 index = tensor_index->scalar<int32>()(); |
| 520 | OP_REQUIRES( |
| 521 | ctx, dtype_ == tensor_array->ElemType(), |
| 522 | errors::InvalidArgument( |
| 523 | "TensorArray dtype is ", DataTypeString(tensor_array->ElemType()), |
| 524 | " but Op requested dtype ", DataTypeString(dtype_), ".")); |
| 525 | PersistentTensor value; |
| 526 | Status s = tensor_array->Read<Device, T>(ctx, index, &value); |
| 527 | OP_REQUIRES_OK(ctx, s); |
| 528 | ctx->set_output(0, *value.AccessTensor(ctx)); |
| 529 | } |
| 530 | |
| 531 | private: |
| 532 | DataType dtype_; |
nothing calls this directly
no test coverage detected