Caffe2 - C++ API
A deep learning, cross platform ML framework
reciprocal_op.cc
1 #include "caffe2/operators/reciprocal_op.h"
2 
3 #include <string>
4 #include <vector>
5 
6 namespace caffe2 {
7 
8 REGISTER_CPU_OPERATOR(
9  Reciprocal,
10  UnaryElementwiseOp<
11  TensorTypes<float>,
12  CPUContext,
13  ReciprocalFunctor<CPUContext>>);
14 
15 // Input: X, output: Y
16 OPERATOR_SCHEMA(Reciprocal)
17  .NumInputs(1)
18  .NumOutputs(1)
19  .AllowInplace({{0, 0}})
20  .IdenticalTypeAndShape()
21  .SetDoc(R"DOC(
22 Performs element-wise reciprocal ($\1/x$) of input tensor $X$.
23 
24 Github Link:
25 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/reciprocal_op.cc
26 
27 <details>
28 
29 <summary> <b>Example</b> </summary>
30 
31 **Code**
32 
33 ```
34 
35 workspace.ResetWorkspace()
36 
37 op = core.CreateOperator(
38  "Reciprocal",
39  ["X"],
40  ["Y"],
41 )
42 
43 workspace.FeedBlob("X", (np.random.randint(10, size=(3,3))).astype(np.float32))
44 print("X:", workspace.FetchBlob("X"))
45 workspace.RunOperatorOnce(op)
46 print("Y:", workspace.FetchBlob("Y"))
47 
48 ```
49 
50 **Result**
51 
52 ```
53 
54 X:
55 [[8. 3. 3.]
56  [4. 0. 0.]
57  [1. 2. 5.]]
58 Y:
59 [[0.125 0.3333333 0.3333333 ]
60  [0.25 inf inf ]
61  [1 0.5 0.2 ]]
62 
63 ```
64 
65 </details>
66 )DOC")
67 .Input(0, "X", "*(type: Tensor`<float>`)* Input data tensor.")
68 .Output(0, "Y", "*(type: Tensor`<float>`)* Output tensor.");
69 
70 OPERATOR_SCHEMA(ReciprocalGradient).NumInputs(2).NumOutputs(1).AllowInplace({{1, 0}});
71 
72 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13