Caffe2 - C++ API
A deep learning, cross platform ML framework
floor_op.cc
1 #include "caffe2/operators/floor_op.h"
2 
3 #include "caffe2/utils/math.h"
4 
5 namespace caffe2 {
6 
7 REGISTER_CPU_OPERATOR(Floor, FloorOp<float, CPUContext>);
8 
9 OPERATOR_SCHEMA(Floor)
10  .NumInputs(1)
11  .NumOutputs(1)
12  .AllowInplace({{0, 0}})
13  .SetDoc(R"DOC(
14 Element-wise application of the floor function ($y=floor(x)$) to the input
15 tensor `X`. Output tensor shape is the same as the input tensor. This
16 operator can be used in an in-place fashion by using the same input blob as the
17 output blob.
18 
19 Github Link:
20 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/floor_op.cc
21 
22 <details>
23 
24 <summary> <b>Example</b> </summary>
25 
26 **Code**
27 
28 ```
29 
30 workspace.ResetWorkspace()
31 
32 op = core.CreateOperator(
33  "Floor",
34  ["X"],
35  ["X"],
36 )
37 
38 workspace.FeedBlob("X", (np.random.uniform(-10, 10, (5,5))).astype(np.float32))
39 print("X before running op:", workspace.FetchBlob("X"))
40 workspace.RunOperatorOnce(op)
41 print("X after running op:", workspace.FetchBlob("X"))
42 
43 ```
44 
45 **Result**
46 
47 ```
48 
49 X before running op:
50 [[ 3.813361 -1.319647 5.2089314 -4.931328 0.6218652 ]
51  [ 7.2757645 5.5552588 5.785643 -2.4790506 -0.41400087]
52  [ 1.1541046 -6.933266 3.3754056 1.6569928 -1.7670316 ]
53  [-3.4932013 4.891472 1.5530115 -3.2443287 -4.605099 ]
54  [-4.574543 -7.360948 5.91305 -8.196495 -5.357458 ]]
55 X after running op:
56 [[ 3. -2. 5. -5. 0.]
57  [ 7. 5. 5. -3. -1.]
58  [ 1. -7. 3. 1. -2.]
59  [-4. 4. 1. -4. -5.]
60  [-5. -8. 5. -9. -6.]]
61 
62 ```
63 
64 </details>
65 
66 )DOC")
67  .Input(0, "X", "*(type: Tensor`<float>`)* Input tensor.")
68  .Output(0, "Y", "*(type: Tensor`<float>`)* Output tensor.");
69 
70 // TODO: Write gradient for this when needed
71 GRADIENT_NOT_IMPLEMENTED_YET(Floor);
72 
73 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13