| 242 | explicit ZerosLikeOp(OpKernelConstruction* ctx) : XlaOpKernel(ctx) {} |
| 243 | |
| 244 | void Compile(XlaOpKernelContext* ctx) override { |
| 245 | if (IsTensorListInput(ctx, 0)) { |
| 246 | // Input is a TensorList. |
| 247 | |
| 248 | // Check the TensorList input is initialized. |
| 249 | xla::XlaOp list = ctx->Input(0); |
| 250 | bool is_initialized; |
| 251 | OP_REQUIRES_OK(ctx, IsTensorListInitialized(list, &is_initialized)); |
| 252 | OP_REQUIRES( |
| 253 | ctx, is_initialized, |
| 254 | errors::InvalidArgument( |
| 255 | "TensorList input for ZerosLike op is an uninitialized list")); |
| 256 | |
| 257 | auto list_shape_or = ctx->builder()->GetShape(list); |
| 258 | OP_REQUIRES_OK(ctx, list_shape_or.status()); |
| 259 | xla::XlaOp new_list; |
| 260 | OP_REQUIRES_OK( |
| 261 | ctx, CreateZerosTensorListWithShape( |
| 262 | ctx->builder(), list_shape_or.ValueOrDie(), &new_list)); |
| 263 | |
| 264 | xla::XlaOp push_index; |
| 265 | OP_REQUIRES_OK(ctx, GetTensorListPushIndex(list, &push_index)); |
| 266 | |
| 267 | xla::XlaOp result; |
| 268 | OP_REQUIRES_OK(ctx, |
| 269 | SetTensorListPushIndex(new_list, push_index, &result)); |
| 270 | ctx->SetTensorListOutput(0, result); |
| 271 | } else { |
| 272 | const TensorShape input_shape = ctx->InputShape(0); |
| 273 | |
| 274 | auto zero = XlaHelpers::Zero(ctx->builder(), input_type(0)); |
| 275 | ctx->SetOutput(0, xla::Broadcast(zero, input_shape.dim_sizes())); |
| 276 | } |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | REGISTER_XLA_OP(Name("ZerosLike").AllowVariantTypes(), ZerosLikeOp); |
nothing calls this directly
no test coverage detected