1 #include "caffe2/operators/utility_ops.h" 5 REGISTER_CPU_OPERATOR(
Sum, SumOp<CPUContext>);
10 .AllowInplace({{0, 0}})
11 .CostInferenceFunction(CostInferenceForSum)
12 .InputsCanCrossDevices()
13 .IdenticalTypeAndShapeOfInput(0)
15 Element-wise sum of each of the input tensors. The first input tensor can be used 16 in-place as the output tensor, in which case the sum will be done in place and 17 results will be accumulated the first input tensor. All inputs and outputs must 18 have the same shape and data type. 22 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/elementwise_sum_op.cc 27 <summary> <b>Example</b> </summary> 33 workspace.ResetWorkspace() 35 op = core.CreateOperator( 41 workspace.FeedBlob("A", np.array([[1,2],[3,4]]).astype(np.float32)) 42 workspace.FeedBlob("B", np.array([[5,6],[7,8]]).astype(np.float32)) 43 print("A:", workspace.FetchBlob("A")) 44 print("B:", workspace.FetchBlob("B")) 45 workspace.RunOperatorOnce(op) 46 print("C:", workspace.FetchBlob("A")) 67 <summary> <b>Example 2</b> </summary> 73 workspace.ResetWorkspace() 75 op = core.CreateOperator( 81 workspace.FeedBlob("A", np.array([[1,2,5],[8,3,4]]).astype(np.float32)) 82 workspace.FeedBlob("B", np.array([[9,5,6],[6,7,8]]).astype(np.float32)) 83 print("A:", workspace.FetchBlob("A")) 84 print("B:", workspace.FetchBlob("B")) 85 workspace.RunOperatorOnce(op) 86 print("A after Sum:", workspace.FetchBlob("A")) 98 A after Sum: [[10. 7. 11.] 109 "*(type: Tensor`<float>`)* First tensor to be added element-wise.")
113 "*(type: Tensor`<float>`)* Second tensor to be added element-wise.")
114 .Output(0,
"C",
"*(type: Tensor`<float>`)* Sum of A and B.")
115 .InheritOnnxSchema();
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...