| 136 | explicit HSVToRGBOp(OpKernelConstruction* context) : XlaOpKernel(context) {} |
| 137 | |
| 138 | void Compile(XlaOpKernelContext* context) override { |
| 139 | const TensorShape input_shape = context->InputShape(0); |
| 140 | OP_REQUIRES(context, input_shape.dims() >= 1, |
| 141 | errors::InvalidArgument("input must be at least 1D", |
| 142 | input_shape.DebugString())); |
| 143 | int channel_dim = input_shape.dims() - 1; |
| 144 | int64 channels = input_shape.dim_size(channel_dim); |
| 145 | OP_REQUIRES( |
| 146 | context, channels == 3, |
| 147 | errors::FailedPrecondition("input must have 3 channels but input has ", |
| 148 | channels, " channels.")); |
| 149 | |
| 150 | xla::XlaBuilder* b = context->builder(); |
| 151 | xla::XlaOp input = context->Input(0); |
| 152 | xla::XlaOp hue = xla::SliceInDim(input, /*start_index=*/0, |
| 153 | /*limit_index=*/1, /*stride=*/1, |
| 154 | /*dimno=*/channel_dim); |
| 155 | xla::XlaOp saturation = xla::SliceInDim(input, /*start_index=*/1, |
| 156 | /*limit_index=*/2, /*stride=*/1, |
| 157 | /*dimno=*/channel_dim); |
| 158 | xla::XlaOp value = xla::SliceInDim(input, /*start_index=*/2, |
| 159 | /*limit_index=*/3, /*stride=*/1, |
| 160 | /*dimno=*/channel_dim); |
| 161 | |
| 162 | auto rgb = HSVToRGB(context->builder(), {hue, saturation, value}, |
| 163 | context->input_type(0)); |
| 164 | |
| 165 | context->SetOutput(0, xla::ConcatInDim(b, rgb, channel_dim)); |
| 166 | } |
| 167 | }; |
| 168 | REGISTER_XLA_OP(Name("HSVToRGB"), HSVToRGBOp); |
| 169 |
nothing calls this directly
no test coverage detected