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

Method Compute

tensorflow/core/kernels/whole_file_read_ops.cc:125–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123 public:
124 using OpKernel::OpKernel;
125 void Compute(OpKernelContext* context) override {
126 const Tensor* filename_input;
127 const Tensor* contents_input;
128 OP_REQUIRES_OK(context, context->input("filename", &filename_input));
129 OP_REQUIRES_OK(context, context->input("contents", &contents_input));
130 OP_REQUIRES(context, TensorShapeUtils::IsScalar(filename_input->shape()),
131 errors::InvalidArgument(
132 "Input filename tensor must be scalar, but had shape: ",
133 filename_input->shape().DebugString()));
134 OP_REQUIRES(context, TensorShapeUtils::IsScalar(contents_input->shape()),
135 errors::InvalidArgument(
136 "Contents tensor must be scalar, but had shape: ",
137 contents_input->shape().DebugString()));
138 const string& filename = filename_input->scalar<tstring>()();
139 const string dir(io::Dirname(filename));
140 if (!context->env()->FileExists(dir).ok()) {
141 OP_REQUIRES_OK(context, context->env()->RecursivelyCreateDir(dir));
142 }
143 OP_REQUIRES_OK(context,
144 WriteStringToFile(context->env(), filename,
145 contents_input->scalar<tstring>()()));
146 }
147};
148
149REGISTER_KERNEL_BUILDER(Name("WriteFile").Device(DEVICE_CPU), WriteFileOp);

Callers

nothing calls this directly

Calls 11

InvalidArgumentFunction · 0.85
DirnameFunction · 0.85
WriteStringToFileFunction · 0.85
IsScalarFunction · 0.50
inputMethod · 0.45
shapeMethod · 0.45
DebugStringMethod · 0.45
okMethod · 0.45
FileExistsMethod · 0.45
envMethod · 0.45
RecursivelyCreateDirMethod · 0.45

Tested by

no test coverage detected