1 | /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. |
---|---|
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | // An example Op. |
17 | |
18 | #include "tensorflow/core/framework/common_shape_fns.h" |
19 | #include "tensorflow/core/framework/op.h" |
20 | #include "tensorflow/core/framework/op_kernel.h" |
21 | |
22 | REGISTER_OP("Fact") |
23 | .Output("fact: string") |
24 | .SetShapeFn(tensorflow::shape_inference::UnknownShape); |
25 | |
26 | class FactOp : public tensorflow::OpKernel { |
27 | public: |
28 | explicit FactOp(tensorflow::OpKernelConstruction* context) |
29 | : OpKernel(context) {} |
30 | |
31 | void Compute(tensorflow::OpKernelContext* context) override { |
32 | // Output a scalar string. |
33 | tensorflow::Tensor* output_tensor = nullptr; |
34 | OP_REQUIRES_OK(context, context->allocate_output( |
35 | 0, tensorflow::TensorShape(), &output_tensor)); |
36 | using tensorflow::string; |
37 | auto output = output_tensor->template scalar<tensorflow::tstring>(); |
38 | |
39 | output() = "0! == 1"; |
40 | } |
41 | }; |
42 | |
43 | REGISTER_KERNEL_BUILDER(Name("Fact").Device(tensorflow::DEVICE_CPU), FactOp); |
44 |