1 #include "caffe2/operators/softplus_op.h" 3 #include "caffe2/utils/math.h" 8 bool SoftplusOp<float, CPUContext>::RunOnDevice() {
13 EigenVectorMap<float>(Y->mutable_data<
float>(), X.size()) =
14 (ConstEigenVectorMap<float>(X.data<
float>(), X.size()).array().exp() +
21 bool SoftplusGradientOp<float, CPUContext>::RunOnDevice() {
25 DCHECK_EQ(dY.size(), Y.size());
28 const float* Ydata = Y.data<
float>();
29 const float* dYdata = dY.data<
float>();
30 float* dXdata = dX->mutable_data<
float>();
31 EigenVectorArrayMap<float> dXvec(dXdata, dX->size());
32 ConstEigenVectorArrayMap<float> Yvec(Ydata, Y.size());
33 ConstEigenVectorArrayMap<float> dYvec(dYdata, dY.size());
34 dXvec = dYvec * (1.0 - (-Yvec).exp());
38 REGISTER_CPU_OPERATOR(Softplus, SoftplusOp<float, CPUContext>);
39 REGISTER_CPU_OPERATOR(SoftplusGradient, SoftplusGradientOp<float, CPUContext>);
42 OPERATOR_SCHEMA(Softplus)
45 .AllowInplace({{0, 0}})
46 .IdenticalTypeAndShape()
48 Softplus takes one input data (Tensor<T>) and produces one output data 49 (Tensor<T>) where the softplus function, y = ln(exp(x) + 1), is applied to 50 the tensor elementwise. 52 .Input(0, "X",
"1D input tensor")
53 .Output(0,
"Y",
"1D input tensor")
54 .InheritOnnxSchema(
"Softplus");
57 OPERATOR_SCHEMA(SoftplusGradient)
60 .AllowInplace({{1, 0}});
63 using GradientMakerBase::GradientMakerBase;
64 vector<OperatorDef> GetGradientDefs()
override {
68 vector<string>{O(0), GO(0)},
69 vector<string>{GI(0)});
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...