Caffe2 - C++ API
A deep learning, cross platform ML framework
minmax_ops.cc
1 #include "caffe2/operators/minmax_ops.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(Max, MaxOp<float, CPUContext>);
6 REGISTER_CPU_OPERATOR(Min, MinOp<float, CPUContext>);
7 
8 OPERATOR_SCHEMA(Max)
9  .NumInputs(1, INT_MAX)
10  .NumOutputs(1)
11  .IdenticalTypeAndShapeOfInput(0)
12  .AllowInplace({{0, 0}})
13  .SetDoc(R"DOC(
14 Element-wise max of each of the input tensors. The first input tensor can be
15 used in-place as the output tensor, in which case the max will be done in
16 place and results will be accumulated in input0. All inputs and outputs must
17 have the same shape and data type.
18 )DOC")
19  .Input(0, "data_0", "First of the input tensors. Can be inplace.")
20  .Output(0, "max", "Output tensor. Same dimension as inputs.")
21  .InheritOnnxSchema("Max");
22 
23 OPERATOR_SCHEMA(Min)
24  .NumInputs(1, INT_MAX)
25  .NumOutputs(1)
26  .IdenticalTypeAndShapeOfInput(0)
27  .AllowInplace({{0, 0}})
28  .SetDoc(R"DOC(
29 Element-wise min of each of the input tensors. The first input tensor can be
30 used in-place as the output tensor, in which case the min will be done in
31 place and results will be accumulated in input0. All inputs and outputs must
32 have the same shape and data type.
33 )DOC")
34  .Input(0, "data_0", "First of the input tensors. Can be inplace.")
35  .Output(0, "min", "Output tensor. Same dimension as inputs.")
36  .InheritOnnxSchema("Min");
37 
38 template <typename T, class Context>
39 bool MaxOp<T, Context>::Compute() {
40  auto& input0 = Input(0);
41  const int N = input0.size();
42  T* output_data = Output(0)->template mutable_data<T>();
43 
44  for (int i = 1; i < InputSize(); i++) {
45  auto input_data = Input(i).template data<T>();
46  EigenVectorMap<T> output_vec(output_data, N);
47  output_vec = output_vec.cwiseMax(ConstEigenVectorMap<T>(input_data, N));
48  }
49 
50  return true;
51 }
52 
53 template <typename T, class Context>
54 bool MinOp<T, Context>::Compute() {
55  auto& input0 = Input(0);
56  const int N = input0.size();
57  T* output_data = Output(0)->template mutable_data<T>();
58 
59  for (int i = 1; i < InputSize(); i++) {
60  auto input_data = Input(i).template data<T>();
61  EigenVectorMap<T> output_vec(output_data, N);
62  output_vec = output_vec.cwiseMin(ConstEigenVectorMap<T>(input_data, N));
63  }
64 
65  return true;
66 }
67 
68 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...