Caffe2 - C++ API
A deep learning, cross platform ML framework
exp_op.cc
1 #include "caffe2/operators/exp_op.h"
2 
3 #include <string>
4 #include <vector>
5 
6 namespace caffe2 {
7 
8 REGISTER_CPU_OPERATOR(
9  Exp,
10  UnaryElementwiseOp<TensorTypes<float>, CPUContext, ExpFunctor<CPUContext>>);
11 
12 OPERATOR_SCHEMA(Exp)
13  .NumInputs(1)
14  .NumOutputs(1)
15  .AllowInplace({{0, 0}})
16  .IdenticalTypeAndShape()
17  .SetDoc(R"DOC(
18 Calculates the exponential of the given input tensor ($exp(x)$), element-wise. This
19 operation can be done in an in-place fashion too, by providing the same input
20 and output blobs.
21 
22 Github Link:
23 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/exp_op.cc
24 
25 <details>
26 
27 <summary> <b>Example</b> </summary>
28 
29 **Code**
30 
31 ```
32 
33 workspace.ResetWorkspace()
34 
35 op = core.CreateOperator(
36  "Exp",
37  ["X"],
38  ["X"],
39 )
40 
41 workspace.FeedBlob("X", (np.random.rand(3,3)).astype(np.float32))
42 print("X before running op:", workspace.FetchBlob("X"))
43 workspace.RunOperatorOnce(op)
44 print("X after running op:", workspace.FetchBlob("X"))
45 
46 ```
47 
48 **Result**
49 
50 ```
51 
52 X before running op:
53 [[0.5821691 0.07719802 0.50159824]
54  [0.40952456 0.36788362 0.84887683]
55  [0.02472685 0.65730894 0.9066397 ]]
56 X after running op:
57 [[1.7899168 1.080256 1.6513585]
58  [1.5061016 1.4446739 2.3370204]
59  [1.0250351 1.9295927 2.4759884]]
60 
61 ```
62 
63 </details>
64 
65 )DOC")
66  .Input(0, "X", "*(type: Tensor`<float>`)* Input tensor.")
67  .Output(
68  0,
69  "Y",
70  "*(type: Tensor`<float>`)* The exponential of the input tensor computed "
71  "element-wise.")
72  .InheritOnnxSchema();
73 
74 namespace {
75 
77  using GradientMakerBase::GradientMakerBase;
78  std::vector<OperatorDef> GetGradientDefs() override {
79  return SingleGradientDef(
80  "Mul",
81  "",
82  std::vector<std::string>{O(0), GO(0)},
83  std::vector<std::string>{GI(0)});
84  }
85 };
86 
87 } // namespace
88 
89 REGISTER_GRADIENT(Exp, GetExpGradient);
90 
91 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13