| 93 | } |
| 94 | |
| 95 | void CastOpBase::Compute(OpKernelContext* ctx) { |
| 96 | const Tensor& inp = ctx->input(0); |
| 97 | if (work_ == nullptr) { |
| 98 | ctx->set_output(0, inp); |
| 99 | } else { |
| 100 | Tensor in; |
| 101 | if (external_src_dtype_ != src_dtype_) { |
| 102 | // If the type is a quantized type we need to do a bitcast since the |
| 103 | // src_dtype_ is different from external_src_type_. |
| 104 | OP_REQUIRES_OK(ctx, in.BitcastFrom(inp, src_dtype_, inp.shape())); |
| 105 | } else { |
| 106 | in = inp; |
| 107 | } |
| 108 | Tensor* out = nullptr; |
| 109 | OP_REQUIRES_OK(ctx, ctx->allocate_output(0, in.shape(), &out)); |
| 110 | out->set_dtype(dst_dtype_); |
| 111 | work_(ctx, in, out, use_truncation_); |
| 112 | out->set_dtype(external_dst_dtype_); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | Status CastOpBase::Unimplemented() { |
| 117 | return errors::Unimplemented("Cast ", DataTypeString(external_src_dtype_), |
nothing calls this directly
no test coverage detected