| 65 | } |
| 66 | |
| 67 | void Compute(OpKernelContext* ctx) override { |
| 68 | const Tensor* pattern_tensor; |
| 69 | OP_REQUIRES_OK(ctx, ctx->input("pattern", &pattern_tensor)); |
| 70 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(pattern_tensor->shape()), |
| 71 | errors::InvalidArgument("Pattern must be scalar, but received ", |
| 72 | pattern_tensor->shape().DebugString())); |
| 73 | const string& pattern = pattern_tensor->scalar<tstring>()(); |
| 74 | const RE2 match(pattern); |
| 75 | OP_REQUIRES(ctx, match.ok(), |
| 76 | errors::InvalidArgument("Invalid pattern: ", pattern, |
| 77 | ", error: ", match.error())); |
| 78 | |
| 79 | const Tensor* rewrite_tensor; |
| 80 | OP_REQUIRES_OK(ctx, ctx->input("rewrite", &rewrite_tensor)); |
| 81 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(rewrite_tensor->shape()), |
| 82 | errors::InvalidArgument("Rewrite must be scalar, but received ", |
| 83 | rewrite_tensor->shape().DebugString())); |
| 84 | const string& rewrite = rewrite_tensor->scalar<tstring>()(); |
| 85 | OP_REQUIRES_OK(ctx, InternalCompute(match, rewrite, replace_global_, ctx)); |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | bool replace_global_; |
nothing calls this directly
no test coverage detected