| 39 | } |
| 40 | |
| 41 | void Compile(XlaOpKernelContext* ctx) override { |
| 42 | const TensorShape input_shape = ctx->InputShape(0); |
| 43 | std::vector<xla::XlaOp> operands; |
| 44 | const int rank = input_shape.dims(); |
| 45 | if (rank != 0) { |
| 46 | for (int64 i = 0; i < rank; ++i) { |
| 47 | operands.push_back(xla::Broadcast( |
| 48 | xla::ConvertElementType(xla::GetDimensionSize(ctx->Input(0), i), |
| 49 | ctx->output_xla_type(0)), |
| 50 | {1})); |
| 51 | } |
| 52 | |
| 53 | ctx->SetOutput(0, xla::ConcatInDim(ctx->builder(), operands, 0)); |
| 54 | } else { |
| 55 | // Rank 0 won't have dynamic size dimension, use constant output. |
| 56 | Tensor shape_constant(out_dtype_, TensorShape({input_shape.dims()})); |
| 57 | OP_REQUIRES_OK(ctx, TensorShapeToConstant(input_shape, &shape_constant)); |
| 58 | ctx->SetConstantOutput(0, shape_constant); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | DataType out_dtype_; |
nothing calls this directly
no test coverage detected