| 31 | } |
| 32 | |
| 33 | void Compile(XlaOpKernelContext* context) override { |
| 34 | int64 k; |
| 35 | OP_REQUIRES_OK(context, context->ConstantInputAsIntScalar(1, &k)); |
| 36 | OP_REQUIRES(context, k >= 0, |
| 37 | errors::InvalidArgument("Need k >= 0, got ", k)); |
| 38 | const TensorShape input_shape = context->InputShape(0); |
| 39 | OP_REQUIRES(context, input_shape.dims() >= 1, |
| 40 | errors::InvalidArgument("input must be >= 1-D, got shape ", |
| 41 | input_shape.DebugString())); |
| 42 | int last_dim = input_shape.dims() - 1; |
| 43 | int last_dim_size = input_shape.dim_size(last_dim); |
| 44 | OP_REQUIRES( |
| 45 | context, last_dim_size >= k, |
| 46 | errors::InvalidArgument("input must have at least k columns. Had ", |
| 47 | last_dim_size, ", needed ", k)); |
| 48 | if (last_dim_size < k) { |
| 49 | k = last_dim_size; |
| 50 | } |
| 51 | xla::XlaOp output_tuple = TopK(context->Input(0), k); |
| 52 | context->SetOutput(0, xla::GetTupleElement(output_tuple, 0)); |
| 53 | context->SetOutput(1, xla::GetTupleElement(output_tuple, 1)); |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | bool sorted_; |
nothing calls this directly
no test coverage detected