| 32 | } |
| 33 | |
| 34 | void Compute(OpKernelContext* ctx) override { |
| 35 | const Tensor& serialized = ctx->input(0); |
| 36 | |
| 37 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(serialized.shape()), |
| 38 | errors::InvalidArgument( |
| 39 | "Expected `serialized` to be a scalar, got shape: ", |
| 40 | serialized.shape().DebugString())); |
| 41 | |
| 42 | auto serialized_t = serialized.scalar<tstring>(); |
| 43 | |
| 44 | TensorProto proto; |
| 45 | OP_REQUIRES(ctx, ParseProtoUnlimited(&proto, serialized_t()), |
| 46 | errors::InvalidArgument( |
| 47 | "Could not parse `serialized` as TensorProto: '", |
| 48 | serialized_t(), "'")); |
| 49 | |
| 50 | Tensor output; |
| 51 | OP_REQUIRES_OK(ctx, ctx->device()->MakeTensorFromProto( |
| 52 | proto, ctx->output_alloc_attr(0), &output)); |
| 53 | |
| 54 | OP_REQUIRES( |
| 55 | ctx, out_type_ == output.dtype(), |
| 56 | errors::InvalidArgument("Type mismatch between parsed tensor (", |
| 57 | DataTypeString(output.dtype()), ") and dtype (", |
| 58 | DataTypeString(out_type_), ")")); |
| 59 | |
| 60 | ctx->set_output(0, output); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | DataType out_type_; |
nothing calls this directly
no test coverage detected