| 264 | explicit InplaceOpBase(OpKernelConstruction* ctx) : OpKernel(ctx) {} |
| 265 | |
| 266 | void Compute(OpKernelContext* ctx) override { |
| 267 | auto x = ctx->input(0); |
| 268 | auto i = ctx->input(1); |
| 269 | auto v = ctx->input(2); |
| 270 | |
| 271 | OP_REQUIRES(ctx, TensorShapeUtils::IsVector(i.shape()), |
| 272 | errors::InvalidArgument("i must be a vector. ", |
| 273 | i.shape().DebugString())); |
| 274 | OP_REQUIRES(ctx, x.dims() == v.dims(), |
| 275 | errors::InvalidArgument( |
| 276 | "x and v shape doesn't match (ranks differ): ", |
| 277 | x.shape().DebugString(), " vs. ", v.shape().DebugString())); |
| 278 | for (int i = 1; i < x.dims(); ++i) { |
| 279 | OP_REQUIRES( |
| 280 | ctx, x.dim_size(i) == v.dim_size(i), |
| 281 | errors::InvalidArgument("x and v shape doesn't match at index ", i, |
| 282 | " : ", x.shape().DebugString(), " vs. ", |
| 283 | v.shape().DebugString())); |
| 284 | } |
| 285 | OP_REQUIRES(ctx, i.dim_size(0) == v.dim_size(0), |
| 286 | errors::InvalidArgument( |
| 287 | "i and x shape doesn't match at index 0: ", |
| 288 | i.shape().DebugString(), " vs. ", v.shape().DebugString())); |
| 289 | |
| 290 | Tensor y = x; // This creates an alias intentionally. |
| 291 | // Skip processing if tensors are empty. |
| 292 | if (x.NumElements() > 0 && v.NumElements() > 0) { |
| 293 | OP_REQUIRES_OK(ctx, DoCompute(ctx, i, v, &y)); |
| 294 | } |
| 295 | ctx->set_output(0, y); |
| 296 | } |
| 297 | |
| 298 | protected: |
| 299 | virtual Status DoCompute(OpKernelContext* ctx, const Tensor& i, |
nothing calls this directly
no test coverage detected