MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / InternalCompute

Function InternalCompute

tensorflow/core/kernels/regex_replace_op.cc:32–58  ·  view source on GitHub ↗

Execute the specified regex using the given context. Context requirements: - "input" string Tensor at input_index=0 - "output" string Tensor at output_index=0

Source from the content-addressed store, hash-verified

30// - "input" string Tensor at input_index=0
31// - "output" string Tensor at output_index=0
32Status InternalCompute(const RE2& match, const string& rewrite,
33 const bool replace_global, OpKernelContext* ctx) {
34 const Tensor* input_tensor;
35 TF_RETURN_IF_ERROR(ctx->input("input", &input_tensor));
36 Tensor* output_tensor;
37 std::unique_ptr<Tensor> maybe_forwarded =
38 ctx->forward_input(0 /*input_index*/, 0 /*output_index*/,
39 tensorflow::DT_STRING, input_tensor->shape(),
40 ctx->input_memory_type(0), ctx->input_alloc_attr(0));
41 if (maybe_forwarded) {
42 output_tensor = maybe_forwarded.get();
43 TF_RETURN_IF_ERROR(ctx->set_output("output", *output_tensor));
44 } else {
45 TF_RETURN_IF_ERROR(
46 ctx->allocate_output("output", input_tensor->shape(), &output_tensor));
47 output_tensor->flat<tstring>() = input_tensor->flat<tstring>();
48 }
49 auto output_flat = output_tensor->flat<tstring>();
50 for (size_t i = 0; i < output_flat.size(); ++i) {
51 if (replace_global) {
52 RE2::GlobalReplace(&output_flat(i), match, rewrite);
53 } else {
54 RE2::Replace(&output_flat(i), match, rewrite);
55 }
56 }
57 return Status::OK();
58}
59} // namespace
60
61class RegexReplaceOp : public OpKernel {

Callers 2

ComputeMethod · 0.85
ComputeMethod · 0.85

Calls 9

forward_inputMethod · 0.80
input_memory_typeMethod · 0.80
input_alloc_attrMethod · 0.80
allocate_outputMethod · 0.80
inputMethod · 0.45
shapeMethod · 0.45
getMethod · 0.45
set_outputMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected